comparison testavr.c @ 38:0a148f362097

Use \r\n instead of \n\r (keeps pexpect happy)
author darius
date Fri, 23 Nov 2007 12:01:54 +1030
parents 25fa387ef7e9
children 5898fba6593c
comparison
equal deleted inserted replaced
37:25fa387ef7e9 38:0a148f362097
79 c = UDR; 79 c = UDR;
80 80
81 /* End of line? */ 81 /* End of line? */
82 if (c == '\n' || c == '\r') { 82 if (c == '\n' || c == '\r') {
83 cmd.buf[cmd.state + 1] = '\0'; 83 cmd.buf[cmd.state + 1] = '\0';
84 uart_putsP(PSTR("\n\r")); 84 uart_putsP(PSTR("\r\n"));
85 cmd.len = cmd.state; 85 cmd.len = cmd.state;
86 cmd.state = 255; 86 cmd.state = 255;
87 continue; 87 continue;
88 } 88 }
89 89
106 uart_putc(cmd.buf[cmd.state]); 106 uart_putc(cmd.buf[cmd.state]);
107 107
108 cmd.state++; 108 cmd.state++;
109 /* Over flow? */ 109 /* Over flow? */
110 if (cmd.state == ((sizeof(cmd.buf) / sizeof(cmd.buf[0])) - 1)) { 110 if (cmd.state == ((sizeof(cmd.buf) / sizeof(cmd.buf[0])) - 1)) {
111 uart_putsP(PSTR("\n\rLine too long")); 111 uart_putsP(PSTR("\r\nLine too long"));
112 cmd.state = 0; 112 cmd.state = 0;
113 continue; 113 continue;
114 } 114 }
115 } 115 }
116 } 116 }
160 160
161 /* Enable receiver and transmitter. Turn on transmit interrupts */ 161 /* Enable receiver and transmitter. Turn on transmit interrupts */
162 UCSRA = 0; 162 UCSRA = 0;
163 UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE); 163 UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE);
164 UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); 164 UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);
165 uart_putsP(PSTR("\n\r\n\r===============\n\r" 165 uart_putsP(PSTR("\r\n\r\n===============\r\n"
166 "Inited!\n\r\n\r")); 166 "Inited!\r\n\r\n"));
167 167
168 /* Ready to go! */ 168 /* Ready to go! */
169 sei(); 169 sei();
170 170
171 #if 0 171 #if 0
172 DDRA = 0xff; 172 DDRA = 0xff;
173 DDRC = 0xff; 173 DDRC = 0xff;
174 while (1) { 174 while (1) {
175 uart_putsP(PSTR("1\n\r")); 175 uart_putsP(PSTR("1\r\n"));
176 PORTA = 0xff; 176 PORTA = 0xff;
177 uart_putsP(PSTR("2\n\r")); 177 uart_putsP(PSTR("2\r\n"));
178 PORTC = 0x00; 178 PORTC = 0x00;
179 uart_putsP(PSTR("3\n\r")); 179 uart_putsP(PSTR("3\r\n"));
180 _delay_us(1); 180 _delay_us(1);
181 uart_putsP(PSTR("4\n\r")); 181 uart_putsP(PSTR("4\r\n"));
182 PORTA = 0x80; 182 PORTA = 0x80;
183 uart_putsP(PSTR("5\n\r")); 183 uart_putsP(PSTR("5\r\n"));
184 PORTC = 0xff; 184 PORTC = 0xff;
185 uart_putsP(PSTR("6\n\r")); 185 uart_putsP(PSTR("6\r\n"));
186 } 186 }
187 #endif 187 #endif
188 188
189 #ifdef WITHUSB 189 #ifdef WITHUSB
190 uart_putsP(PSTR("Calling usb_init\n\r")); 190 uart_putsP(PSTR("Calling usb_init\r\n"));
191 usb_init(); 191 usb_init();
192 #endif 192 #endif
193 uart_putsP(PSTR("done\n\r")); 193 uart_putsP(PSTR("done\r\n"));
194 _delay_us(1000); 194 _delay_us(1000);
195 uart_putsP(PSTR("> ")); 195 uart_putsP(PSTR("> "));
196 cmd.state = 0; 196 cmd.state = 0;
197 197
198 /* Wait for user input or an "interrupt" */ 198 /* Wait for user input or an "interrupt" */
222 /* User just pressed enter */ 222 /* User just pressed enter */
223 if (cmd.len == 0) 223 if (cmd.len == 0)
224 return; 224 return;
225 225
226 if (cmd.buf[0] == '?') { 226 if (cmd.buf[0] == '?') {
227 uart_putsP(PSTR("rs Reset and check for presence\n\r" 227 uart_putsP(PSTR("rs Reset and check for presence\r\n"
228 "sr Search the bus for ROMs\n\r" 228 "sr Search the bus for ROMs\r\n"
229 "re Read a bit\n\r" 229 "re Read a bit\r\n"
230 "rb Read a byte\n\r" 230 "rb Read a byte\r\n"
231 "wr bit Write a bit\n\r" 231 "wr bit Write a bit\r\n"
232 "wb byte Write a byte (hex)\n\r" 232 "wb byte Write a byte (hex)\r\n"
233 "wc cmd [ROMID] Write command\n\r" 233 "wc cmd [ROMID] Write command\r\n"
234 "te ROMID Read the temperature from a DS1820\n\r" 234 "te ROMID Read the temperature from a DS1820\r\n"
235 "in port Read from a port\n\r" 235 "in port Read from a port\r\n"
236 "out port val Write to a port\n\r" 236 "out port val Write to a port\r\n"
237 "ddr port [val] Read/write DDR for a port\n\r")); 237 "ddr port [val] Read/write DDR for a port\r\n"));
238 238
239 return; 239 return;
240 } 240 }
241 241
242 i = strlen((char *)cmd.buf); 242 i = strlen((char *)cmd.buf);
245 245
246 if (cmd.buf[0] == 'r' && cmd.buf[1] == 's') { 246 if (cmd.buf[0] == 'r' && cmd.buf[1] == 's') {
247 uart_putsP(PSTR("Resetting... ")); 247 uart_putsP(PSTR("Resetting... "));
248 248
249 if (OWTouchReset() == 1) 249 if (OWTouchReset() == 1)
250 uart_putsP(PSTR("No presence pulse found\n\r")); 250 uart_putsP(PSTR("No presence pulse found\r\n"));
251 else 251 else
252 uart_putsP(PSTR("Presence pulse found\n\r")); 252 uart_putsP(PSTR("Presence pulse found\r\n"));
253 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'e') { 253 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'e') {
254 if (OWReadBit()) 254 if (OWReadBit())
255 uart_putsP(PSTR("Read a 1\n\r")); 255 uart_putsP(PSTR("Read a 1\r\n"));
256 else 256 else
257 uart_putsP(PSTR("Read a 0\n\r")); 257 uart_putsP(PSTR("Read a 0\r\n"));
258 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'b') { 258 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'b') {
259 uart_putsP(PSTR("Read a 0x")); 259 uart_putsP(PSTR("Read a 0x"));
260 uart_puts_hex(OWReadByte()); 260 uart_puts_hex(OWReadByte());
261 uart_putsP(PSTR("\n\r")); 261 uart_putsP(PSTR("\r\n"));
262 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'r') { 262 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'r') {
263 arg = strtol((char *)cmd.buf + 3, (char **)NULL, 10); 263 arg = strtol((char *)cmd.buf + 3, (char **)NULL, 10);
264 OWWriteBit(arg); 264 OWWriteBit(arg);
265 uart_putsP(PSTR("Wrote a ")); 265 uart_putsP(PSTR("Wrote a "));
266 if (arg) 266 if (arg)
267 uart_putsP(PSTR("1\n\r")); 267 uart_putsP(PSTR("1\r\n"));
268 else 268 else
269 uart_putsP(PSTR("0\n\r")); 269 uart_putsP(PSTR("0\r\n"));
270 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'b') { 270 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'b') {
271 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16); 271 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16);
272 OWWriteByte(arg); 272 OWWriteByte(arg);
273 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 't') { 273 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 't') {
274 if (cmd.len < 26) { 274 if (cmd.len < 26) {
275 uart_putsP(PSTR("Unable to parse ROM ID\n\r")); 275 uart_putsP(PSTR("Unable to parse ROM ID\r\n"));
276 return; 276 return;
277 } 277 }
278 278
279 if (OWTouchReset() != 0) { 279 if (OWTouchReset() != 0) {
280 uart_putsP(PSTR("No presence\n\r")); 280 uart_putsP(PSTR("No presence\r\n"));
281 return; 281 return;
282 } 282 }
283 283
284 for (i = 0; i < 8; i++) 284 for (i = 0; i < 8; i++)
285 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16); 285 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
286 286
287 if (ROM[0] != OW_FAMILY_ROM) { 287 if (ROM[0] != OW_FAMILY_ROM) {
288 uart_putsP(PSTR("ROM specified isn't a DS2502\n\r")); 288 uart_putsP(PSTR("ROM specified isn't a DS2502\r\n"));
289 return; 289 return;
290 } 290 }
291 291
292 if (OWTouchReset() != 0) { 292 if (OWTouchReset() != 0) {
293 uart_putsP(PSTR("No presence\n\r")); 293 uart_putsP(PSTR("No presence\r\n"));
294 return; 294 return;
295 } 295 }
296 296
297 crc = 0; 297 crc = 0;
298 298
304 304
305 OWWriteByte(0x00); 305 OWWriteByte(0x00);
306 OWCRC(0x00, &crc); 306 OWCRC(0x00, &crc);
307 307
308 if (crc != OWReadByte()) { 308 if (crc != OWReadByte()) {
309 uart_putsP(PSTR("CRC mismatch on command & address\n\r")); 309 uart_putsP(PSTR("CRC mismatch on command & address\r\n"));
310 return; 310 return;
311 } 311 }
312 312
313 crc = 0; 313 crc = 0;
314 for (i = 0; i < 8; i++) { 314 for (i = 0; i < 8; i++) {
315 temp = OWReadByte(); 315 temp = OWReadByte();
316 uart_puts_hex(temp); 316 uart_puts_hex(temp);
317 OWCRC(temp, &crc); 317 OWCRC(temp, &crc);
318 uart_putsP(PSTR(" ")); 318 uart_putsP(PSTR(" "));
319 } 319 }
320 uart_putsP(PSTR("\n\r")); 320 uart_putsP(PSTR("\r\n"));
321 if (crc != OWReadByte()) { 321 if (crc != OWReadByte()) {
322 uart_putsP(PSTR("CRC mismatch on data\n\r")); 322 uart_putsP(PSTR("CRC mismatch on data\r\n"));
323 return; 323 return;
324 } 324 }
325 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'e') { 325 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'e') {
326 if (cmd.len < 26) { 326 if (cmd.len < 26) {
327 uart_putsP(PSTR("Unable to parse ROM ID\n\r")); 327 uart_putsP(PSTR("Unable to parse ROM ID\r\n"));
328 return; 328 return;
329 } 329 }
330 330
331 for (i = 0; i < 8; i++) 331 for (i = 0; i < 8; i++)
332 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16); 332 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
333 333
334 if (ROM[0] != OW_FAMILY_ROM) { 334 if (ROM[0] != OW_FAMILY_ROM) {
335 uart_putsP(PSTR("ROM specified isn't a ROM\n\r")); 335 uart_putsP(PSTR("ROM specified isn't a ROM\r\n"));
336 return; 336 return;
337 } 337 }
338 338
339 buf[0] = (int)strtol((char *)cmd.buf + 27, (char **)NULL, 16); /* Address */ 339 buf[0] = (int)strtol((char *)cmd.buf + 27, (char **)NULL, 16); /* Address */
340 buf[1] = (int)strtol((char *)cmd.buf + 30, (char **)NULL, 16); /* Data .. */ 340 buf[1] = (int)strtol((char *)cmd.buf + 30, (char **)NULL, 16); /* Data .. */
341 buf[2] = (int)strtol((char *)cmd.buf + 33, (char **)NULL, 16); 341 buf[2] = (int)strtol((char *)cmd.buf + 33, (char **)NULL, 16);
342 342
343 if (OWTouchReset() != 0) { 343 if (OWTouchReset() != 0) {
344 uart_putsP(PSTR("No presence\n\r")); 344 uart_putsP(PSTR("No presence\r\n"));
345 return; 345 return;
346 } 346 }
347 347
348 i = OWProgROM(ROM, buf[0], 2, &buf[1], 0, 0); 348 i = OWProgROM(ROM, buf[0], 2, &buf[1], 0, 0);
349 uart_putsP(PSTR("OWProgROM returned ")); 349 uart_putsP(PSTR("OWProgROM returned "));
350 uart_puts_dec(i, 0); 350 uart_puts_dec(i, 0);
351 uart_putsP(PSTR("\n\r")); 351 uart_putsP(PSTR("\r\n"));
352 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'r') { 352 } else if (cmd.buf[0] == 'r' && cmd.buf[1] == 'r') {
353 if (cmd.len < 26) { 353 if (cmd.len < 26) {
354 uart_putsP(PSTR("Unable to parse ROM ID\n\r")); 354 uart_putsP(PSTR("Unable to parse ROM ID\r\n"));
355 return; 355 return;
356 } 356 }
357 357
358 for (i = 0; i < 8; i++) 358 for (i = 0; i < 8; i++)
359 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16); 359 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
360 360
361 if (ROM[0] != OW_FAMILY_ROM) { 361 if (ROM[0] != OW_FAMILY_ROM) {
362 uart_putsP(PSTR("ROM specified isn't a ROM\n\r")); 362 uart_putsP(PSTR("ROM specified isn't a ROM\r\n"));
363 return; 363 return;
364 } 364 }
365 365
366 crc = 0; 366 crc = 0;
367 OWSendCmd(ROM, OW_READ_MEMORY); 367 OWSendCmd(ROM, OW_READ_MEMORY);
372 372
373 OWWriteByte(0x00); 373 OWWriteByte(0x00);
374 OWCRC(0x00, &crc); 374 OWCRC(0x00, &crc);
375 375
376 if (crc != OWReadByte()) { 376 if (crc != OWReadByte()) {
377 uart_putsP(PSTR("CRC mismatch on command & address\n\r")); 377 uart_putsP(PSTR("CRC mismatch on command & address\r\n"));
378 return; 378 return;
379 } 379 }
380 380
381 crc = 0; 381 crc = 0;
382 for (buf[0] = 0; buf[0] < 128; buf[0]++) { 382 for (buf[0] = 0; buf[0] < 128; buf[0]++) {
383 buf[1] = OWReadByte(); 383 buf[1] = OWReadByte();
384 if (buf[0] > 0) { 384 if (buf[0] > 0) {
385 if (buf[0] % 16 != 0) 385 if (buf[0] % 16 != 0)
386 uart_putsP(PSTR(" ")); 386 uart_putsP(PSTR(" "));
387 else 387 else
388 uart_putsP(PSTR("\n\r")); 388 uart_putsP(PSTR("\r\n"));
389 } 389 }
390 390
391 uart_puts_hex(buf[1]); 391 uart_puts_hex(buf[1]);
392 OWCRC(buf[1], &crc); 392 OWCRC(buf[1], &crc);
393 } 393 }
394 uart_putsP(PSTR("\n\r")); 394 uart_putsP(PSTR("\r\n"));
395 if (crc != OWReadByte()) { 395 if (crc != OWReadByte()) {
396 uart_putsP(PSTR("CRC mismatch on data\n\r")); 396 uart_putsP(PSTR("CRC mismatch on data\r\n"));
397 return; 397 return;
398 } 398 }
399 399
400 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'c') { 400 } else if (cmd.buf[0] == 'w' && cmd.buf[1] == 'c') {
401 if (cmd.len < 5) { 401 if (cmd.len < 5) {
402 uart_putsP(PSTR("No arguments\n\r")); 402 uart_putsP(PSTR("No arguments\r\n"));
403 return; 403 return;
404 } 404 }
405 405
406 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16); 406 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16);
407 if (arg == 0) { 407 if (arg == 0) {
408 uart_putsP(PSTR("Unparseable command\n\r")); 408 uart_putsP(PSTR("Unparseable command\r\n"));
409 return; 409 return;
410 } 410 }
411 411
412 if (i == 5) { 412 if (i == 5) {
413 OWSendCmd(NULL, arg); 413 OWSendCmd(NULL, arg);
414 return; 414 return;
415 } 415 }
416 416
417 if (i < 29) { 417 if (i < 29) {
418 uart_putsP(PSTR("Can't parse ROM ID\n\r")); 418 uart_putsP(PSTR("Can't parse ROM ID\r\n"));
419 return; 419 return;
420 } 420 }
421 for (i = 0; i < 8; i++) 421 for (i = 0; i < 8; i++)
422 ROM[i] = (int)strtol((char *)cmd.buf + 6 + (3 * i), (char **)NULL, 16); 422 ROM[i] = (int)strtol((char *)cmd.buf + 6 + (3 * i), (char **)NULL, 16);
423 423
424 OWSendCmd(ROM, arg); 424 OWSendCmd(ROM, arg);
425 } else if (cmd.buf[0] == 't' && cmd.buf[1] == 'e') { 425 } else if (cmd.buf[0] == 't' && cmd.buf[1] == 'e') {
426 if (cmd.len < 26) { 426 if (cmd.len < 26) {
427 uart_putsP(PSTR("Unable to parse ROM ID\n\r")); 427 uart_putsP(PSTR("Unable to parse ROM ID\r\n"));
428 return; 428 return;
429 } 429 }
430 430
431 for (i = 0; i < 8; i++) 431 for (i = 0; i < 8; i++)
432 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16); 432 ROM[i] = (int)strtol((char *)cmd.buf + 3 * (i + 1), (char **)NULL, 16);
433 433
434 if (ROM[0] != OW_FAMILY_TEMP) { 434 if (ROM[0] != OW_FAMILY_TEMP) {
435 uart_putsP(PSTR("ROM specified isn't a temperature sensor\n\r")); 435 uart_putsP(PSTR("ROM specified isn't a temperature sensor\r\n"));
436 return; 436 return;
437 } 437 }
438 438
439 OWSendCmd(ROM, OW_CONVERTT_CMD); 439 OWSendCmd(ROM, OW_CONVERTT_CMD);
440 i = 0; 440 i = 0;
449 if (i < 8) 449 if (i < 8)
450 OWCRC(buf[i], &crc); 450 OWCRC(buf[i], &crc);
451 } 451 }
452 452
453 if (crc != buf[8]) { 453 if (crc != buf[8]) {
454 uart_putsP(PSTR("CRC mismatch\n\r")); 454 uart_putsP(PSTR("CRC mismatch\r\n"));
455 return; 455 return;
456 } 456 }
457 457
458 #if 0 458 #if 0
459 uart_putsP(PSTR("temperature ")); 459 uart_putsP(PSTR("temperature "));
460 uart_puts_dec(temp >> 4, 0); 460 uart_puts_dec(temp >> 4, 0);
461 uart_putsP(PSTR(".")); 461 uart_putsP(PSTR("."));
462 uart_puts_dec((temp << 12) / 6553, 0); 462 uart_puts_dec((temp << 12) / 6553, 0);
463 uart_putsP(PSTR("\n\r")); 463 uart_putsP(PSTR("\r\n"));
464 #else 464 #else
465 /* 0 Temperature LSB 465 /* 0 Temperature LSB
466 * 1 Temperature MSB 466 * 1 Temperature MSB
467 * 2 Th 467 * 2 Th
468 * 3 Tl 468 * 3 Tl
473 * 8 CRC 473 * 8 CRC
474 */ 474 */
475 #if 0 475 #if 0
476 for (i = 0; i < 9; i++) { 476 for (i = 0; i < 9; i++) {
477 uart_puts_dec(buf[i], 0); 477 uart_puts_dec(buf[i], 0);
478 uart_putsP(PSTR("\n\r")); 478 uart_putsP(PSTR("\r\n"));
479 } 479 }
480 #endif 480 #endif
481 temp = buf[0]; 481 temp = buf[0];
482 if (buf[1] & 0x80) 482 if (buf[1] & 0x80)
483 temp -= 256; 483 temp -= 256;
498 uart_puts_dec(-temp, 0); 498 uart_puts_dec(-temp, 0);
499 } else 499 } else
500 uart_puts_dec(temp, 0); 500 uart_puts_dec(temp, 0);
501 uart_putsP(PSTR(".")); 501 uart_putsP(PSTR("."));
502 uart_puts_dec(tfrac, 1); 502 uart_puts_dec(tfrac, 1);
503 uart_putsP(PSTR("\n\r")); 503 uart_putsP(PSTR("\r\n"));
504 504
505 #endif 505 #endif
506 } else if (cmd.buf[0] == 's' && cmd.buf[1] == 'r') { 506 } else if (cmd.buf[0] == 's' && cmd.buf[1] == 'r') {
507 memset(ROM, 0, 8); 507 memset(ROM, 0, 8);
508 508
509 i = OWFirst(ROM, 1, 0); 509 i = OWFirst(ROM, 1, 0);
510 do { 510 do {
511 switch (i) { 511 switch (i) {
512 case OW_BADWIRE: 512 case OW_BADWIRE:
513 uart_putsP(PSTR("Presence pulse, but no module found, bad module/cabling?\n\r")); 513 uart_putsP(PSTR("Presence pulse, but no module found, bad module/cabling?\r\n"));
514 break; 514 break;
515 515
516 case OW_NOPRESENCE: 516 case OW_NOPRESENCE:
517 uart_putsP(PSTR("No presence pulse found\n\r")); 517 uart_putsP(PSTR("No presence pulse found\r\n"));
518 break; 518 break;
519 519
520 case OW_BADCRC: 520 case OW_BADCRC:
521 uart_putsP(PSTR("Bad CRC\n\r")); 521 uart_putsP(PSTR("Bad CRC\r\n"));
522 break; 522 break;
523 523
524 case OW_NOMODULES: 524 case OW_NOMODULES:
525 case OW_FOUND: 525 case OW_FOUND:
526 break; 526 break;
527 527
528 default: 528 default:
529 uart_putsP(PSTR("Unknown error from 1 wire library\n\r")); 529 uart_putsP(PSTR("Unknown error from 1 wire library\r\n"));
530 break; 530 break;
531 } 531 }
532 532
533 if (i != OW_FOUND) 533 if (i != OW_FOUND)
534 break; 534 break;
536 for (i = 0; i < 7; i++) { 536 for (i = 0; i < 7; i++) {
537 uart_puts_hex(ROM[i]); 537 uart_puts_hex(ROM[i]);
538 uart_putc(':'); 538 uart_putc(':');
539 } 539 }
540 uart_puts_hex(ROM[7]); 540 uart_puts_hex(ROM[7]);
541 uart_putsP(PSTR("\n\r")); 541 uart_putsP(PSTR("\r\n"));
542 542
543 i = OWNext(ROM, 1, 0); 543 i = OWNext(ROM, 1, 0);
544 } while (1); 544 } while (1);
545 } else if (cmd.buf[0] == 'i' && cmd.buf[1] == 'n') { 545 } else if (cmd.buf[0] == 'i' && cmd.buf[1] == 'n') {
546 switch (tolower(cmd.buf[3])) { 546 switch (tolower(cmd.buf[3])) {
559 case 'd': 559 case 'd':
560 crc = PIND; 560 crc = PIND;
561 break; 561 break;
562 562
563 default: 563 default:
564 uart_putsP(PSTR("Unknown port\n\r")); 564 uart_putsP(PSTR("Unknown port\r\n"));
565 return; 565 return;
566 } 566 }
567 uart_putsP(PSTR("0x")); 567 uart_putsP(PSTR("0x"));
568 uart_puts_hex(crc); 568 uart_puts_hex(crc);
569 uart_putsP(PSTR("\n\r")); 569 uart_putsP(PSTR("\r\n"));
570 } else if (cmd.buf[0] == 'o' && cmd.buf[1] == 'u') { 570 } else if (cmd.buf[0] == 'o' && cmd.buf[1] == 'u') {
571 crc = strtol((char *)cmd.buf + 8, (char **)NULL, 16); 571 crc = strtol((char *)cmd.buf + 8, (char **)NULL, 16);
572 switch (tolower(cmd.buf[4])) { 572 switch (tolower(cmd.buf[4])) {
573 case 'a': 573 case 'a':
574 PORTA = crc; 574 PORTA = crc;
585 case 'd': 585 case 'd':
586 PORTD = crc; 586 PORTD = crc;
587 break; 587 break;
588 588
589 default: 589 default:
590 uart_putsP(PSTR("Unknown port\n\r")); 590 uart_putsP(PSTR("Unknown port\r\n"));
591 return; 591 return;
592 } 592 }
593 uart_putsP(PSTR("0x")); 593 uart_putsP(PSTR("0x"));
594 uart_puts_hex(crc); 594 uart_puts_hex(crc);
595 uart_putsP(PSTR("\n\r")); 595 uart_putsP(PSTR("\r\n"));
596 } else if (cmd.buf[0] == 'd' && cmd.buf[1] == 'd') { 596 } else if (cmd.buf[0] == 'd' && cmd.buf[1] == 'd') {
597 crc = strtol((char *)cmd.buf + 8, (char **)NULL, 16); 597 crc = strtol((char *)cmd.buf + 8, (char **)NULL, 16);
598 switch (tolower(cmd.buf[4])) { 598 switch (tolower(cmd.buf[4])) {
599 case 'a': 599 case 'a':
600 DDRA = crc; 600 DDRA = crc;
611 case 'd': 611 case 'd':
612 DDRD = crc; 612 DDRD = crc;
613 break; 613 break;
614 614
615 default: 615 default:
616 uart_putsP(PSTR("Unknown port\n\r")); 616 uart_putsP(PSTR("Unknown port\r\n"));
617 return; 617 return;
618 } 618 }
619 uart_putsP(PSTR("0x")); 619 uart_putsP(PSTR("0x"));
620 uart_puts_hex(crc); 620 uart_puts_hex(crc);
621 uart_putsP(PSTR("\n\r")); 621 uart_putsP(PSTR("\r\n"));
622 #ifdef WITHUSB 622 #ifdef WITHUSB
623 } else if (cmd.buf[0] == 'u' && cmd.buf[1] == 's') { 623 } else if (cmd.buf[0] == 'u' && cmd.buf[1] == 's') {
624 usb_gendata(); 624 usb_gendata();
625 #endif 625 #endif
626 } else { 626 } else {
627 badcmd: 627 badcmd:
628 uart_putsP(PSTR("Unknown command, ? for a list\n\r")); 628 uart_putsP(PSTR("Unknown command, ? for a list\r\n"));
629 } 629 }
630 } 630 }
631 631
632 int 632 int
633 uart_putc(char c) { 633 uart_putc(char c) {