Permalink
Browse files

Embedded minimus hacks.

Signed-off-by: Paul Brook <paul@codesourcery.com>
  • Loading branch information...
1 parent 1fe273b commit 582a377a508efba7607223747a049dc0a17ae404 Paul Brook committed Oct 13, 2012
@@ -36,6 +36,21 @@
#include "AVRISP-MKII.h"
+static uint8_t current_leds;
+
+static void
+restore_leds(void)
+{
+ LEDs_SetAllLEDs(current_leds);
+}
+
+static void
+set_leds(uint8_t mask)
+{
+ current_leds = mask;
+ restore_leds();
+}
+
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
@@ -44,7 +59,7 @@ int main(void)
SetupHardware();
V2Protocol_Init();
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
+ set_leds(LEDMASK_USB_NOTREADY);
GlobalInterruptEnable();
for (;;)
@@ -57,6 +72,8 @@ int main(void)
AVRISP_Task();
USB_USBTask();
+ if (program_minimus())
+ restore_leds();
}
}
@@ -83,13 +100,13 @@ void SetupHardware(void)
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
- LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
+ set_leds(LEDMASK_USB_ENUMERATING);
}
/** Event handler for the library USB Disconnection event. */
void EVENT_USB_Device_Disconnect(void)
{
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
+ set_leds(LEDMASK_USB_NOTREADY);
}
/** Event handler for the library USB Configuration Changed event. */
@@ -105,7 +122,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
ConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_IN_EPADDR, EP_TYPE_BULK, AVRISP_DATA_EPSIZE, 1);
/* Indicate endpoint configuration success or failure */
- LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
+ set_leds(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Processes incoming V2 Protocol commands from the host, returning a response when required. */
@@ -122,12 +139,12 @@ void AVRISP_Task(void)
/* Check to see if a V2 Protocol command has been received */
if (Endpoint_IsOUTReceived())
{
- LEDs_SetAllLEDs(LEDMASK_BUSY);
+ set_leds(LEDMASK_BUSY);
/* Pass off processing of the V2 Protocol command to the V2 Protocol handler */
V2Protocol_ProcessCommand();
- LEDs_SetAllLEDs(LEDMASK_USB_READY);
+ set_leds(LEDMASK_USB_READY);
}
}
@@ -86,5 +86,6 @@
uint8_t* const DescriptorMemorySpace)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3) ATTR_NON_NULL_PTR_ARG(4);
+bool program_minimus(void);
#endif
@@ -37,6 +37,8 @@
#if defined(ENABLE_ISP_PROTOCOL) || defined(__DOXYGEN__)
+bool ISPActive;
+
/** Handler for the CMD_ENTER_PROGMODE_ISP command, which attempts to enter programming mode on
* the attached device, returning success or failure back to the host.
*/
@@ -101,6 +103,8 @@ void ISPProtocol_EnterISPMode(void)
Endpoint_Write_8(CMD_ENTER_PROGMODE_ISP);
Endpoint_Write_8(ResponseStatus);
Endpoint_ClearIN();
+
+ ISPActive = true;
}
/** Handler for the CMD_LEAVE_ISP command, which releases the target from programming mode. */
@@ -127,6 +131,8 @@ void ISPProtocol_LeaveISPMode(void)
Endpoint_Write_8(CMD_LEAVE_PROGMODE_ISP);
Endpoint_Write_8(STATUS_CMD_OK);
Endpoint_ClearIN();
+
+ ISPActive = false;
}
/** Handler for the CMD_PROGRAM_FLASH_ISP and CMD_PROGRAM_EEPROM_ISP commands, writing out bytes,
@@ -67,6 +67,8 @@
#define PROG_MODE_PAGED_READYBUSY_MASK (1 << 6)
#define PROG_MODE_COMMIT_PAGE_MASK (1 << 7)
+ extern bool ISPActive;
+
/* Function Prototypes: */
void ISPProtocol_EnterISPMode(void);
void ISPProtocol_LeaveISPMode(void);
@@ -0,0 +1,38 @@
+#! /usr/bin/python
+
+import io
+
+line = 0
+fin = io.open("minimus.rom", "rt")
+fout = io.open("minimus_rom.h", "wt")
+fout.write(u"static const uint8_t mm_rom[] PROGMEM = {\n");
+first_addr = -1;
+rom_len = 0;
+for s in fin:
+ line += 1
+ s = s.strip();
+ if s[0] != ':':
+ raise Exception("Bad character at line %d" % line);
+ n = int(s[1:3], 16);
+ addr = int(s[3:7], 16);
+ flags = int(s[7:9], 16);
+ if first_addr == -1:
+ first_addr = addr;
+ elif first_addr + rom_len != addr:
+ raise Exception("Bad address 0x%x (expected 0x%x) at line %d" % (addr, next_addr, line))
+ for i in range(0, n):
+ b = int(s[9 + i * 2: 11 + i * 2], 16)
+ fout.write(u"0x%02x," % b)
+ rom_len += n
+ fout.write(u"\n")
+
+while (rom_len & 127) != 0:
+ fout.write(u"0xff,")
+ rom_len += 1
+fout.write(u"\n};\n")
+if (first_addr & 127) != 0:
+ raise Exception("Image no page aligned")
+fout.write(u"#define mm_rom_len 0x%xu\n" % rom_len);
+fout.write(u"#define mm_rom_start 0x%xu\n" % first_addr);
+fout.close();
+fin.close();
@@ -11,22 +11,39 @@
# Run "make help" for target help.
-MCU = at90usb162
+MCU = atmega32u2
ARCH = AVR8
-BOARD = USBTINYMKII
+BOARD = MINIMUS
F_CPU = 16000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = AVRISP-MKII
-SRC = $(TARGET).c AVRISPDescriptors.c Lib/V2Protocol.c Lib/V2ProtocolParams.c Lib/ISP/ISPProtocol.c Lib/ISP/ISPTarget.c Lib/XPROG/XPROGProtocol.c \
- Lib/XPROG/XPROGTarget.c Lib/XPROG/XMEGANVM.c Lib/XPROG/TINYNVM.c $(LUFA_SRC_USB)
+SRC = $(TARGET).c minimus_hack.c AVRISPDescriptors.c Lib/V2Protocol.c Lib/V2ProtocolParams.c Lib/ISP/ISPProtocol.c Lib/ISP/ISPTarget.c Lib/XPROG/XPROGProtocol.c \
+ Lib/XPROG/XPROGTarget.c Lib/XPROG/XMEGANVM.c Lib/XPROG/TINYNVM.c $(LUFA_SRC_USB) \
+ $(LUFA_SRC_SERIAL)
LUFA_PATH = ../../LUFA
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/
LD_FLAGS =
+AVRDUDE_PROGRAMMER = avr109
+AVRDUDE_PORT = /dev/ttyACM1
+AVRDUDE_FLAGS =
+
# Default target
all:
+minimus_hack.o: minimus_rom.h
+
+minimus_rom.h: minimus.rom build_rom.py
+ ./build_rom.py
+
+clean: cleanrom
+
+cleanrom:
+ rm -f minimus_rom.h
+
+.phony: cleanrom
+
# Include LUFA build script makefiles
include $(LUFA_PATH)/Build/lufa_core.mk
include $(LUFA_PATH)/Build/lufa_sources.mk
Oops, something went wrong.

0 comments on commit 582a377

Please sign in to comment.