00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00077 #include <dev/debug.h>
00078
00079 #include <cfg/os.h>
00080 #include <sys/device.h>
00081 #include <sys/file.h>
00082 #include <sys/timer.h>
00083
00088
00089 static NUTFILE dbgfile;
00090
00098 static int DebugIOCtl(NUTDEVICE * dev, int req, void *conf)
00099 {
00100 if(req == UART_SETSPEED) {
00101 #if defined(__AVR_ENHANCED__) && ((NUT_CPU_FREQ == 12000000) || (NUT_CPU_FREQ == 16000000))
00102
00103
00104
00105
00106 sbi(UCSR0A, U2X0);
00107 outb(UBRR, (uint8_t) ((((2UL * NutGetCpuClock()) / (*((uint32_t *)conf) * 8UL)) + 1UL) / 2UL) - 1UL);
00108 #else
00109 outb(UBRR, (uint8_t) ((((2UL * NutGetCpuClock()) / (*((uint32_t *)conf) * 16UL)) + 1UL) / 2UL) - 1UL);
00110 #endif
00111 return 0;
00112 }
00113 return -1;
00114 }
00115
00124 static int DebugInit(NUTDEVICE * dev)
00125 {
00126
00127 UCR = BV(RXEN) | BV(TXEN);
00128 return 0;
00129 }
00130
00137 static void DebugPut(char ch)
00138 {
00139 while((USR & BV(UDRE)) == 0);
00140 UDR = ch;
00141 if(ch == '\n')
00142 DebugPut('\r');
00143 }
00144
00153 static int DebugWrite(NUTFILE * fp, CONST void *buffer, int len)
00154 {
00155 int c = len;
00156 CONST char *cp = buffer;
00157
00158 while(c--)
00159 DebugPut(*cp++);
00160 return len;
00161 }
00162
00171 static int DebugWrite_P(NUTFILE * fp, PGM_P buffer, int len)
00172 {
00173 int c = len;
00174 PGM_P cp = buffer;
00175
00176 while(c--) {
00177 DebugPut(PRG_RDB(cp));
00178 cp++;
00179 }
00180 return len;
00181 }
00182
00188 static NUTFILE *DebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00189 {
00190 dbgfile.nf_next = 0;
00191 dbgfile.nf_dev = dev;
00192 dbgfile.nf_fcb = 0;
00193
00194 return &dbgfile;
00195 }
00196
00202 static int DebugClose(NUTFILE * fp)
00203 {
00204 return 0;
00205 }
00206
00210 NUTDEVICE devDebug0 = {
00211 0,
00212 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00213 0,
00214 0,
00215 0,
00216 0,
00217 0,
00218 DebugInit,
00219 DebugIOCtl,
00220 0,
00221 DebugWrite,
00222 DebugWrite_P,
00223 DebugOpen,
00224 DebugClose,
00225 0
00226 };
00227