Subversion Repositories HomeAutomation

Rev

Rev 924 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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 <avr/io.h>
  16. #include <avr/interrupt.h>
  17. #include <avr/pgmspace.h>
  18. #include <drivers/uart/serial.h>
  19. #include <drivers/uart/uart.h>
  20.  
  21.  
  22. /*-----------------------------------------------------------------------------
  23.  * Private Function Prototypes
  24.  *---------------------------------------------------------------------------*/
  25. static int serial_putchar(char c, FILE *stream);
  26.  
  27.  
  28. /*-----------------------------------------------------------------------------
  29.  * Variables
  30.  *---------------------------------------------------------------------------*/
  31. static FILE myStdOut = FDEV_SETUP_STREAM(serial_putchar, NULL,_FDEV_SETUP_WRITE);
  32.  
  33.  
  34. /*-----------------------------------------------------------------------------
  35.  * Public Functions
  36.  *---------------------------------------------------------------------------*/
  37.  
  38. /**
  39.  * Initializes the serial communication. Sets the baudrate and redirects
  40.  * STDOUT to the serial communication channel.
  41.  */
  42. void Serial_Init() {
  43. #if (SERIAL_DOUBLE_SPEED==1)
  44.     uart_init((UART_BAUD_SELECT_DOUBLE_SPEED((SERIAL_BAUDRATE),F_CPU)));
  45. #else
  46.     uart_init((UART_BAUD_SELECT((SERIAL_BAUDRATE),F_CPU)));
  47. #endif
  48.    
  49. #if CAN_PRINTF==0
  50.     stdout = &myStdOut;
  51. #endif
  52. }
  53.  
  54.  
  55. /*-----------------------------------------------------------------------------
  56.  * Private Functions
  57.  *---------------------------------------------------------------------------*/
  58.  
  59. static int serial_putchar(char c, FILE *stream) {
  60.     if (c == '\n') serial_putchar('\r', stream);
  61.     uart_putc(c);
  62.     return 0;
  63. }
  64.