Rev 361 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 361 | andfri | 1 | /** |
| 2 | * Serial communication software module. |
||
| 3 | * |
||
| 4 | * @author Jimmy Myhrman |
||
| 5 | * |
||
| 6 | * @date 2006-11-22 |
||
| 7 | */ |
||
| 8 | |||
| 9 | /*----------------------------------------------------------------------------- |
||
| 10 | * Includes |
||
| 11 | *---------------------------------------------------------------------------*/ |
||
| 12 | #include <stdlib.h> |
||
| 13 | #include <stdio.h> |
||
| 14 | #include <config.h> |
||
| 15 | #include <drivers/uart/serial.h> |
||
| 16 | #include <drivers/uart/uart.h> |
||
| 17 | |||
| 18 | |||
| 19 | /*----------------------------------------------------------------------------- |
||
| 20 | * Private Function Prototypes |
||
| 21 | *---------------------------------------------------------------------------*/ |
||
| 22 | static int serial_putchar(char c, FILE *stream); |
||
| 23 | |||
| 24 | |||
| 25 | /*----------------------------------------------------------------------------- |
||
| 26 | * Variables |
||
| 27 | *---------------------------------------------------------------------------*/ |
||
| 28 | static FILE myStdOut = FDEV_SETUP_STREAM(serial_putchar, NULL,_FDEV_SETUP_WRITE); |
||
| 29 | |||
| 30 | |||
| 31 | /*----------------------------------------------------------------------------- |
||
| 32 | * Public Functions |
||
| 33 | *---------------------------------------------------------------------------*/ |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Initializes the serial communication. Sets the baudrate and redirects |
||
| 37 | * STDOUT to the serial communication channel. |
||
| 38 | */ |
||
| 39 | void Serial_Init() { |
||
| 40 | uart_init((UART_BAUD_SELECT((SERIAL_BAUDRATE),F_CPU))); |
||
| 41 | |||
| 42 | stdout = &myStdOut; |
||
| 43 | } |
||
| 44 | |||
| 45 | |||
| 46 | /*----------------------------------------------------------------------------- |
||
| 47 | * Private Functions |
||
| 48 | *---------------------------------------------------------------------------*/ |
||
| 49 | |||
| 50 | static int serial_putchar(char c, FILE *stream) { |
||
| 51 | if (c == '\n') serial_putchar('\r', stream); |
||
| 52 | uart_putc(c); |
||
| 53 | return 0; |
||
| 54 | } |