From 533813e94907be4b5a0245ae10cc9205531376c3 Mon Sep 17 00:00:00 2001 From: Doug Brown Date: Sun, 27 May 2012 15:41:16 -0700 Subject: [PATCH] Added LED toggle to write/read modes. Read is so fast that you can't even see the blinking, but oh well. I also added an "led.h" header file that I should have done long ago. --- led.h | 19 +++++++++++++++++++ main.c | 8 ++++---- usb_serial/usb_serial.c | 6 ++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 led.h diff --git a/led.h b/led.h new file mode 100644 index 0000000..7d8d318 --- /dev/null +++ b/led.h @@ -0,0 +1,19 @@ +/* + * led.h + * + * Created on: May 27, 2012 + * Author: Doug + */ + +#ifndef LED_H_ +#define LED_H_ + +#include +#define PIN_MASK (1 << 7) + +#define LED_Init() do { DDRD |= PIN_MASK; LED_Off(); } while (0) +#define LED_On() PORTD |= PIN_MASK +#define LED_Off() PORTD &= ~PIN_MASK +#define LED_Toggle() PIND = PIN_MASK + +#endif /* LED_H_ */ diff --git a/main.c b/main.c index 8319d63..e6245e5 100644 --- a/main.c +++ b/main.c @@ -28,21 +28,21 @@ #include "external_mem.h" #include "tests/simm_electrical_test.h" #include "usb_serial/usb_serial.h" +#include "led.h" int main(void) { cli(); - DDRD |= (1 << 7); - PORTD &= ~(1 << 7); + LED_Init(); // If there was a brownout detected, turn on the LED momentarily if (MCUSR & (1 << BORF)) { MCUSR = 0; - PORTD |= (1 << 7); + LED_On(); _delay_ms(500); - PORTD &= ~(1 << 7); + LED_Off(); } ExternalMem_Init(); diff --git a/usb_serial/usb_serial.c b/usb_serial/usb_serial.c index ea241b9..bd3a27f 100644 --- a/usb_serial/usb_serial.c +++ b/usb_serial/usb_serial.c @@ -28,6 +28,7 @@ #include "../external_mem.h" #include "../tests/simm_electrical_test.h" #include "../programmer_protocol.h" +#include "../led.h" #define MAX_CHIP_SIZE (512UL * 1024UL) #define READ_CHUNK_SIZE_BYTES 1024UL @@ -228,11 +229,13 @@ void USBSerial_HandleReadingChipsByte(uint8_t byte) // that they have finished, and enter command state. if (curReadIndex >= readLength) { + LED_Off(); SendByte(ProgrammerReadFinished); curCommandState = WaitingForCommand; } else // There's more data left to read, so read it and send it to them! { + LED_Toggle(); SendByte(ProgrammerReadMoreData); USBSerial_SendReadDataChunk(); } @@ -341,11 +344,13 @@ void USBSerial_HandleWritingChipsByte(uint8_t byte) break; // The computer said that it's done writing. case ComputerWriteFinish: + LED_Off(); SendByte(ProgrammerWriteOK); curCommandState = WaitingForCommand; break; // The computer asked to cancel. case ComputerWriteCancel: + LED_Off(); SendByte(ProgrammerWriteConfirmCancel); curCommandState = WaitingForCommand; break; @@ -364,6 +369,7 @@ void USBSerial_HandleWritingChipsByte(uint8_t byte) SendByte(ProgrammerWriteOK); curWriteIndex++; writePosInChunk = -1; + LED_Toggle(); } } }