41
41
* read by the program. See the README file for a discussion of
42
42
* the failure semantics.
43
43
*/
44
- #define RECV_BUF_SIZE 128 // Arbitrary buffer size
44
+ #define RECV_BUF_SIZE 128 /* Arbitrary buffer size */
45
45
char recv_buf [RECV_BUF_SIZE ];
46
- volatile int recv_ndx_nxt ; // Next place to store
47
- volatile int recv_ndx_cur ; // Next place to read
46
+ volatile int recv_ndx_nxt ; /* Next place to store */
47
+ volatile int recv_ndx_cur ; /* Next place to read */
48
48
49
49
/* For interrupt handling we add a new function which is called
50
50
* when recieve interrupts happen. The name (usart1_isr) is created
@@ -57,7 +57,8 @@ volatile int recv_ndx_cur; // Next place to read
57
57
* right or it won't work. And you'll wonder where your interrupts
58
58
* are going.
59
59
*/
60
- void usart1_isr (void ) {
60
+ void usart1_isr (void )
61
+ {
61
62
uint32_t reg ;
62
63
int i ;
63
64
@@ -79,7 +80,8 @@ void usart1_isr(void) {
79
80
recv_ndx_nxt = i ;
80
81
}
81
82
}
82
- } while ((reg & USART_SR_RXNE ) != 0 ); // can read back-to-back interrupts
83
+ } while ((reg & USART_SR_RXNE ) != 0 ); /* can read back-to-back
84
+ interrupts */
83
85
}
84
86
85
87
/*
@@ -88,7 +90,8 @@ void usart1_isr(void) {
88
90
* Send the character 'c' to the USART, wait for the USART
89
91
* transmit buffer to be empty first.
90
92
*/
91
- void console_putc (char c ) {
93
+ void console_putc (char c )
94
+ {
92
95
uint32_t reg ;
93
96
do {
94
97
reg = USART_SR (CONSOLE_UART );
@@ -106,10 +109,11 @@ void console_putc(char c) {
106
109
* The implementation is a bit different however, now it looks
107
110
* in the ring buffer to see if a character has arrived.
108
111
*/
109
- char console_getc (int wait ) {
112
+ char console_getc (int wait )
113
+ {
110
114
char c = 0 ;
111
115
112
- while ((wait != 0 ) && (recv_ndx_cur == recv_ndx_nxt )) ;
116
+ while ((wait != 0 ) && (recv_ndx_cur == recv_ndx_nxt ));
113
117
if (recv_ndx_cur != recv_ndx_nxt ) {
114
118
c = recv_buf [recv_ndx_cur ];
115
119
recv_ndx_cur = (recv_ndx_cur + 1 ) % RECV_BUF_SIZE ;
@@ -124,7 +128,8 @@ char console_getc(int wait) {
124
128
* after the last character, as indicated by a NUL character, is
125
129
* reached.
126
130
*/
127
- void console_puts (char * s ) {
131
+ void console_puts (char * s )
132
+ {
128
133
while (* s != '\000' ) {
129
134
console_putc (* s );
130
135
/* Add in a carraige return, after sending line feed */
@@ -142,7 +147,8 @@ void console_puts(char *s) {
142
147
* support for editing characters (back space and delete)
143
148
* end when a <CR> character is received.
144
149
*/
145
- int console_gets (char * s , int len ) {
150
+ int console_gets (char * s , int len )
151
+ {
146
152
char * t = s ;
147
153
char c ;
148
154
@@ -165,7 +171,7 @@ int console_gets(char *s, int len) {
165
171
/* update end of string with NUL */
166
172
* t = '\000' ;
167
173
}
168
- return ( t - s ) ;
174
+ return t - s ;
169
175
}
170
176
171
177
/*
@@ -174,7 +180,8 @@ int console_gets(char *s, int len) {
174
180
* Set the pins and clocks to create a console that we can
175
181
* use for serial messages and getting text from the user.
176
182
*/
177
- void console_setup (int baud ) {
183
+ void console_setup (int baud )
184
+ {
178
185
179
186
/* MUST enable the GPIO clock in ADDITION to the USART clock */
180
187
rcc_periph_clock_enable (RCC_GPIOA );
0 commit comments