]> git.zerfleddert.de Git - rsbs2/blob - bmc/usart.c
implement all remaining IPMB queries seen on the wire
[rsbs2] / bmc / usart.c
1 #include <avr/io.h>
2 #include <stdio.h>
3
4 #include "config.h"
5 #include "usart.h"
6
7 #ifdef DEBUG
8
9 #define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1)
10 #define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1)))
11 #define BAUD_ERROR ((BAUD_REAL*1000)/BAUD)
12
13 #if ((BAUD_ERROR<990) || (BAUD_ERROR>1010))
14 #error Systematischer Fehler der Baudrate grösser 1% und damit zu hoch!
15 #endif
16
17 int usart_put(char c, FILE *stream)
18 {
19 if (c == '\n')
20 usart_put('\r', stream);
21
22 while(!(UCSRA & (1<<UDRE))) {}
23 UDR = c;
24 return 0;
25 }
26
27 static FILE usart_stdout = FDEV_SETUP_STREAM(usart_put, NULL, _FDEV_SETUP_WRITE);
28 #endif
29
30 void usart_init()
31 {
32 #ifdef DEBUG
33 UCSRB |= (1<<TXEN);
34 UCSRC |= (1<<URSEL)|(1 << UCSZ1)|(1 << UCSZ0);
35
36 UBRRH = UBRR_VAL >> 8;
37 UBRRL = UBRR_VAL & 0xFF;
38
39 stdout = &usart_stdout;
40 #endif
41 }
Impressum, Datenschutz