ser_simple_avr.c
Go to the documentation of this file.00001
00040 #warning FIXME:This module is obsolete, yuo must refactor it.
00041
00042 #if 0
00043 #include "ser_simple_avr.h"
00044
00045 #include <cfg/compiler.h>
00046 #include <appconfig.h>
00047 #include <cfg/macros.h>
00048 #include <hw/hw_cpufreq.h>
00049
00050 #include <avr/io.h>
00051
00057 int _ser_putchar(int c)
00058 {
00059
00060 UCSR0B &= ~BV(RXEN);
00061
00062 UCSR0B |= BV(TXEN);
00063
00064 UDR0 = c;
00065
00066 while (!(UCSR0A & BV(TXC))) {}
00067
00068 UCSR0B &= ~BV(TXEN);
00069
00070 UCSR0B |= BV(RXEN);
00071
00072 UCSR0A |= BV(TXC);
00073 return c;
00074 }
00075
00076
00084 int _ser_getchar(void)
00085 {
00086
00087 while (!(UCSR0A & BV(RXC))) {}
00088 return UDR0;
00089
00090 }
00091
00092
00098 int _ser_getchar_nowait(void)
00099 {
00100 if (!(UCSR0A & BV(RXC))) return EOF;
00101 else return UDR0;
00102 }
00103
00104 void _ser_settimeouts(void)
00105 {
00106 }
00107
00111 void _ser_setbaudrate(unsigned long rate)
00112 {
00113
00114 uint16_t period = DIV_ROUND(CPU_FREQ / 16UL, rate) - 1;
00115
00116 UBRR0H = (period) >> 8;
00117 UBRR0L = (period);
00118 }
00119
00123 int _ser_print(const char *s)
00124 {
00125 while(*s) _ser_putchar(*s++);
00126 return 0;
00127 }
00128
00129
00130 void _ser_setparity(int parity)
00131 {
00132
00133 UCSR0C |= (UCSR0C & ~(BV(UPM1) | BV(UPM0))) | (parity << UPM0);
00134 }
00135
00139 void _ser_purge(void)
00140 {
00141 while (_ser_getchar_nowait() != EOF) {}
00142 }
00143
00147 struct Serial * _ser_open(void)
00148 {
00149
00150
00151
00152
00153 DDRE &= ~(BV(PE0)|BV(PE1));
00154 PORTE &= ~BV(PE0);
00155 PORTE |= BV(PE1);
00156
00157 UCSR0B = BV(RXEN);
00158 return NULL;
00159 }
00160
00161
00165 void _ser_close(void)
00166 {
00167
00168 UCSR0B &= ~(BV(RXEN) | BV(TXEN));
00169 }
00170
00171 #endif
00172