]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/board/arm/ul_usb1/libs/bspbase/uart.h
Merge master into can-usb1 branch to include proc update for 3.12+ kernels.
[lincan.git] / embedded / board / arm / ul_usb1 / libs / bspbase / uart.h
1 /******************************************************************************
2  * based on software from:
3  * Copyright 2004, R O SoftWare
4  * No guarantees, warrantees, or promises, implied or otherwise.
5  * May be used for hobby or commercial purposes provided copyright
6  * notice remains intact.
7  * 
8  * reduced to learn what has to be done to enable and use UART0
9  *****************************************************************************/
10 #ifndef INC_UART_H
11 #define INC_UART_H
12
13 #include <system_def.h>
14
15 ///////////////////////////////////////////////////////////////////////////////
16 // use the following macros to determine the 'baud' parameter values
17 // for uart0Init() and uart1Init()
18 // CAUTION - 'baud' SHOULD ALWAYS BE A CONSTANT or
19 // a lot of code will be generated.
20 // Baud-Rate is calculated based on pclk (VPB-clock)
21 // the devisor must be 16 times the desired baudrate
22 #define UART_BAUD(baud) (uint16_t)((PCLK / ((baud) * 16.0)) + 0.5)
23
24 ///////////////////////////////////////////////////////////////////////////////
25 // Definitions for typical UART 'baud' settings
26 #define B1200         UART_BAUD(1200)
27 #define B9600         UART_BAUD(9600)
28 #define B19200        UART_BAUD(19200)
29 #define B38400        UART_BAUD(38400)
30 #define B57600        UART_BAUD(57600)
31 #define B115200       UART_BAUD(115200)
32
33 ///////////////////////////////////////////////////////////////////////////////
34 // Definitions for typical UART 'mode' settings
35 #define UART_8N1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO   + ULCR_STOP_1)
36 #define UART_7N1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO   + ULCR_STOP_1)
37 #define UART_8N2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO   + ULCR_STOP_2)
38 #define UART_7N2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO   + ULCR_STOP_2)
39 #define UART_8E1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_1)
40 #define UART_7E1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_1)
41 #define UART_8E2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_2)
42 #define UART_7E2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_2)
43 #define UART_8O1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD  + ULCR_STOP_1)
44 #define UART_7O1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD  + ULCR_STOP_1)
45 #define UART_8O2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD  + ULCR_STOP_2)
46 #define UART_7O2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD  + ULCR_STOP_2)
47
48 ///////////////////////////////////////////////////////////////////////////////
49 // Definitions for typical UART 'fmode' settings
50 #define UART_FIFO_OFF (0x00)
51 #define UART_FIFO_1   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG1)
52 #define UART_FIFO_4   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG4)
53 #define UART_FIFO_8   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG8)
54 #define UART_FIFO_14  (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG14)
55
56 void uart0Init(uint16_t baud, uint8_t mode, uint8_t fmode);
57 int uart0Putch(int ch);
58 uint16_t uart0Space(void);
59 const char *uart0Puts(const char *string);
60 int uart0TxEmpty(void);
61 void uart0TxFlush(void);
62 int uart0Getch(void);
63 int uart0GetchW(void);
64
65 #endif