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