Hanna
Sourcecode Kontrollplatine
usartx.h
gehe zur Dokumentation dieser Datei
1 
23 #ifndef UARTX_H
24 #define UARTX_H
25 
26 /*
27  * Only the file that defines OWNER creates the FILE objects below.
28  */
29 
30 #include <stdio.h>
31 #ifdef OWNER
32 #define EXTERN
33 #else
34 #define EXTERN extern
35 #endif
36 
37 /* Definitionen für USART */
38 #define BAUD_SETTINGS
39 //#define BAUDRATE_USART 38400
40 //#define BAUDRATE_USART 57600
41 #define BAUDRATE_USART 115200
42 //#define BAUDRATE_USART 230400
43 
44 // Excel-Tabelle zur Berechnung von BSEL und BSCALE, Doublespeed beachten !
45 #define DOUBLESPEED 0 /* 1 = 2x clock, 0 = 1x clock */
46 
47 // Werte aus Tabelle im Datenblatt für 32 MHz CPU und 2xCLK = 0
48 #if BAUDRATE_USART == 19200
49 #define BSEL_USART 12
50 #define BSCALE 0x03
51 #elif BAUDRATE_USART == 28800
52 #define BSEL_USART 137
53 #define BSCALE 0xFF // BSCALE -1 => Zweierkomplement 0xFF
54 #elif BAUDRATE_USART == 38400
55 #define BSEL_USART 12
56 #define BSCALE 0x02
57 #elif BAUDRATE_USART == 57600
58 #define BSEL_USART 135
59 #define BSCALE 0xFE // BSCALE -2 => Zweierkomplement 0xFE
60 #elif BAUDRATE_USART == 115200
61 #define BSEL_USART 2094
62 #define BSCALE 0xF9 // BSCALE -7 => Zweierkomplement 0xF9
63 #elif BAUDRATE_USART == 230400
64 #define BSEL_USART 983
65 #define BSCALE 0xF9 // BSCALE -7 => Zweierkomplement 0xF9
66 #endif
67 
68 #define BAUD_A ((BSEL_USART) & 0xFF)
69 #define BAUD_B (((BSEL_USART >> 8) | (BSCALE << 4)) & 0xFF)
70 
71 #ifndef IN_FILENO
72 #define IN_FILENO 0
73 #define OUT_FILENO 1
74 #define ERR_FILENO 2
75 #endif
76 
77 #ifndef NUM_USARTS
78 #define NUM_USARTS 6
79 #endif
80 
81 
82 
83 //extern FILE usartout = FDEV_SETUP_STREAM(USART_putchar, NULL, _FDEV_SETUP_WRITE);
84 //extern FILE usartin = FDEV_SETUP_STREAM(NULL, USART_getchar, _FDEV_SETUP_READ);
85 
86 
87 // -----------------------------------------------------------------------------
88 
89 /*
90  * Define enums for selecting one of the eight USARTS.
91  */
92 enum usart_ids // these are local-only indices into the queue, inptr, and outptr arrays
93 {
94  eUSARTC0 = 0, eUSARTC1, eUSARTD0, eUSARTD1, eUSARTE0, eUSARTF0
95 };
96 
97 /*
98  * USART_Init() Initialise hardware USARTs
99  *
100  * This routine configures the USARTs for selected baud rate, eight data bits,
101  * no parity, one stop bit. It also enables the USARTs' transmitter and
102  * receiver, and enables receive interrupts.
103  *
104  * This function also assigns stdin, stdout, and stderr to UART0 (see FILE
105  * definitions below).
106  *
107  * Note that the arguments bauda and baudb must contain the actual
108  * value to write to the USART's baud rate registers, NOT the desired baud
109  * rate!
110  */
111 void USART_Init ( uint8_t usartnum, uint8_t bauda, uint8_t baudb );
112 
113 /*
114  * USART_Connect() assign an USART to one of the standard I/O streams
115  *
116  * This routine associates a selected USART to one of the standard I/O streams.
117  * The association is made using argument usartnum, which can range from 0 to
118  * 7 and corresponds to the usart_ids enum above.
119  *
120  * Argument streamsel is one of the standard I/O stream identifiers (STDIN_FILENO,
121  * STDOUT_FILENO, or STDERR_FILENO).
122  *
123  * After calling this routine, any standard I/O function, such as printf(), will
124  * use the associated USART until the connection is changed with a later call
125  * to this routine.
126  */
127 void USART_Connect ( int usartnum, int streamsel );
128 
129 
130 #endif