usart.h
Go to the documentation of this file.
1 /*
2 Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
3 Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
4 Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
36 #ifndef USART_H_
37 #define USART_H_
38 
39 #include <stdint.h>
40 
45 struct usart_conf {
46  const char *device;
47  uint32_t baudrate;
48  uint8_t databits;
49  uint8_t stopbits;
50  uint8_t paritysetting;
51  uint8_t checkparity;
52 };
53 
59 void usart_init(struct usart_conf *conf);
60 
68 typedef void (*usart_callback_t) (uint8_t *buf, int len, void *pxTaskWoken);
69 
75 
82 void usart_insert(char c, void *pxTaskWoken);
83 
91 void usart_putc(char c);
92 
101 void usart_putstr(char *buf, int len);
102 
110 char usart_getc(void);
111 
116 int usart_messages_waiting(int handle);
117 
122 static inline int usart_stdio_msgwaiting(void) {
123  return usart_messages_waiting(0);
124 }
125 
126 #endif /* USART_H_ */
127 
128 /* @} */
void usart_set_callback(usart_callback_t callback)
char usart_getc(void)
Buffered getchar.
void(* usart_callback_t)(uint8_t *buf, int len, void *pxTaskWoken)
In order to catch incoming chars use the callback.
Definition: usart.h:68
uint32_t baudrate
Definition: usart.h:47
int usart_messages_waiting(int handle)
void usart_putstr(char *buf, int len)
Send char buffer on UART.
void usart_insert(char c, void *pxTaskWoken)
Insert a character to the RX buffer of a usart.
uint8_t paritysetting
Definition: usart.h:50
const char * device
Definition: usart.h:46
void usart_init(struct usart_conf *conf)
Initialise UART with the usart_conf data structure.
uint8_t stopbits
Definition: usart.h:49
uint8_t checkparity
Definition: usart.h:51
Usart configuration, to be used with the usart_init call.
Definition: usart.h:45
uint8_t databits
Definition: usart.h:48
void usart_putc(char c)
Polling putchar.