From 9ea5e9235f18aeebe9ca55ac0c914592ded8e779 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sat, 21 May 2011 03:05:57 +0200 Subject: [PATCH 1/2] main.c for LED blinking/receiving and test of ReinvokeISP --- Makefile | 1 + main.c | 94 +++++++++++++++++++++++++++++++++----------------------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index dcefde5..13b35f7 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ VPATH += OBJS += OBJS += basic/basic.o OBJS += eeprom/eeprom.o +OBJS += reinvoke_isp.o LIBS += core/libcore.a lcd/libfont.a ########################################################################## diff --git a/main.c b/main.c index c0837e6..5b8c72a 100644 --- a/main.c +++ b/main.c @@ -31,7 +31,7 @@ int main(void) { adcInit(); - lcdFill(255); + lcdFill(0); lcdDisplay(0); uint32_t j=0; @@ -55,53 +55,71 @@ int main(void) { uint8_t written = 0; uint8_t eeprom_val = 0; + uint8_t trigger; +#define SEND +#ifdef SEND + trigger=200; + gpioSetDir(RB_LED0, gpioDirection_Output); + IOCON_JTAG_TDI_PIO0_11 = 0x11; +#else + trigger=380; + gpioSetDir(RB_LED0, gpioDirection_Input); + IOCON_JTAG_TDI_PIO0_11 = 0x42; +#endif + + + uint32_t ctr=0; while (1) { + ctr++; + uint32_t results; lcdDisplay(j); delayms(10); font=fonts[fontctr]; - if (!written) { - if (eeprom_ready()) { - if (eeprom_write_byte(127,15,42)) { - DoString(1, yctr, "Write OK!"); - written++; - } else { - DoString(1, yctr, "Write NOK!"); - } - } else { - DoString(1, yctr, "NOT READY!"); - } - } else { - if (eeprom_ready()) { - if (eeprom_read_byte(127,15,&eeprom_val)) { - if (eeprom_val == 42) { - DoString(1, yctr, "verified!"); - } else { - DoString(1, yctr, "failed!"); - } - } else { - DoString(1, yctr, "Read NOK!"); - } - } else { - DoString(1, yctr, "NOT READY!!"); - } - } + if(gpioGetValue(RB_BTN3)==0){ + while(gpioGetValue(RB_BTN3)==0); + trigger +=10; + }; + if(gpioGetValue(RB_BTN2)==0){ + while(gpioGetValue(RB_BTN2)==0); + trigger -=10; + }; + dx=DoString(0,0,"Trig:"); + dx=DoInt(dx,0,trigger); + DoString(dx,0," "); - if(1 && gpioGetValue(RB_LED3) == 0){ - gpioSetValue (RB_LED3, 0); - while(gpioGetValue(RB_LED3) == 0){ - }; - gpioSetValue (RB_LED3, 1); - lcdFill(255); - fontctr++; - if(fontctr > 2) { - fontctr = 0; - } + if(gpioGetValue(RB_BTN0)==0){ + while(gpioGetValue(RB_BTN0)==0); + DoString(0,8,"Enter ISP!"); + lcdDisplay(0); + ReinvokeISP(); }; - uint32_t results = adcRead(7); + dx=DoString(0,20,"LED:"); +#ifdef SEND + if(ctr++>trigger/10){ + ctr=0; + if (gpioGetValue(RB_LED0) == CFG_LED_OFF){ + gpioSetValue (RB_LED0, CFG_LED_ON); + DoString(dx,20,"ON!"); + } else { + gpioSetValue (RB_LED0, CFG_LED_OFF); + DoString(dx,20,"off"); + }; + }; +#else + results = adcRead(0); + DoInt(dx,20,results); + + if(results>trigger){ + DoString(dx,30,"YES!"); + }else{ + DoString(dx,30," no "); + }; + +#endif results = adcRead(1); dx=DoString(0,yctr+20,"Voltage:"); From 617a6f5720cc2414da90e767896148df2a86b5d2 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sat, 21 May 2011 12:05:48 +0200 Subject: [PATCH 2/2] Add new modules/ support infrastructure. Hope you like it. add modules/$(USERNAME).c for your coding use "make MODULE=foo" to build a specific module --- Makefile | 13 ++++- Makefile.inc | 4 -- main.c | 115 ++---------------------------------------- modules/Makefile | 50 ++++++++++++++++++ modules/README | 7 +++ modules/default.c | 7 +++ modules/eeprom.c | 111 ++++++++++++++++++++++++++++++++++++++++ modules/mkwrapper | 16 ++++++ modules/sec.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 331 insertions(+), 118 deletions(-) create mode 100644 modules/Makefile create mode 100644 modules/README create mode 100644 modules/default.c create mode 100644 modules/eeprom.c create mode 100755 modules/mkwrapper create mode 100644 modules/sec.c diff --git a/Makefile b/Makefile index 13b35f7..05ede9e 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ OBJS += OBJS += basic/basic.o OBJS += eeprom/eeprom.o OBJS += reinvoke_isp.o -LIBS += core/libcore.a lcd/libfont.a +LIBS += core/libcore.a lcd/libfont.a modules/libmodules.a ########################################################################## # GNU GCC compiler flags @@ -26,6 +26,11 @@ OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o ########################################################################## # Startup files ########################################################################## +LDLIBS = -lm +LDLIBS += -Lmodules -lmodules +LDLIBS += -Lcore -lcore +LDLIBS += -Llcd -lfont +OCFLAGS = --strip-unneeded LD_PATH = lpc1xxx LD_SCRIPT = $(LD_PATH)/linkscript.ld @@ -42,6 +47,9 @@ core/libcore.a: core/projectconfig.h lcd/libfont.a lcd/render.o lcd/display.o: cd lcd && $(MAKE) ROOT_PATH=../$(ROOT_PATH) +modules/libmodules.a: + cd modules && $(MAKE) ROOT_PATH=../$(ROOT_PATH) + tools/lpcrc: cd tools && $(MAKE) @@ -65,7 +73,8 @@ clean: @cd core && $(MAKE) clean @cd tools && $(MAKE) clean @cd lcd && $(MAKE) clean + @cd modules && $(MAKE) clean -.PHONY: lcd/libfont.a +.PHONY: lcd/libfont.a modules/libmodules.a diff --git a/Makefile.inc b/Makefile.inc index b79793a..0dd19e7 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -40,8 +40,4 @@ CPU_TYPE = cortex-$(CORTEX_TYPE) CFLAGS = -std=c99 -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin LDFLAGS = -nostartfiles -mthumb -mcpu=$(CPU_TYPE) -Wl,--gc-sections -LDLIBS = -lm -LDLIBS += -Lcore -lcore -LDLIBS += -Llcd -lfont -OCFLAGS = --strip-unneeded diff --git a/main.c b/main.c index 5b8c72a..904a71b 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,8 @@ void ReinvokeISP(void); /**************************************************************************/ +void wrapper(void); + int main(void) { // Configure cpu and mandatory peripherals systemInit(); @@ -25,121 +27,10 @@ int main(void) { lcdInit(); // display - //Make PIO1_11 an analog input - gpioSetDir(RB_LED3, gpioDirection_Input); - IOCON_PIO1_11 = 0x41; - adcInit(); lcdFill(0); lcdDisplay(0); - uint32_t j=0; - - //disable the JTAG on PIO3_3 - IOCON_PIO3_3 = 0x10; - - int yctr=8; - int dx=0; - - font_direction = FONT_DIR_LTR; // LeftToRight is the default - font = &Font_8x8; - - static FONT fonts[] = { - &Font_7x8, - &Font_Ubuntu18pt, // 3 byte-font - &Font_8x8, - }; - - int fontctr=0; - yctr=18; - - uint8_t written = 0; - uint8_t eeprom_val = 0; - uint8_t trigger; - -#define SEND -#ifdef SEND - trigger=200; - gpioSetDir(RB_LED0, gpioDirection_Output); - IOCON_JTAG_TDI_PIO0_11 = 0x11; -#else - trigger=380; - gpioSetDir(RB_LED0, gpioDirection_Input); - IOCON_JTAG_TDI_PIO0_11 = 0x42; -#endif - - - uint32_t ctr=0; - while (1) { - ctr++; - uint32_t results; - lcdDisplay(j); - delayms(10); - - font=fonts[fontctr]; - - if(gpioGetValue(RB_BTN3)==0){ - while(gpioGetValue(RB_BTN3)==0); - trigger +=10; - }; - if(gpioGetValue(RB_BTN2)==0){ - while(gpioGetValue(RB_BTN2)==0); - trigger -=10; - }; - dx=DoString(0,0,"Trig:"); - dx=DoInt(dx,0,trigger); - DoString(dx,0," "); - - if(gpioGetValue(RB_BTN0)==0){ - while(gpioGetValue(RB_BTN0)==0); - DoString(0,8,"Enter ISP!"); - lcdDisplay(0); - ReinvokeISP(); - }; - - dx=DoString(0,20,"LED:"); -#ifdef SEND - if(ctr++>trigger/10){ - ctr=0; - if (gpioGetValue(RB_LED0) == CFG_LED_OFF){ - gpioSetValue (RB_LED0, CFG_LED_ON); - DoString(dx,20,"ON!"); - } else { - gpioSetValue (RB_LED0, CFG_LED_OFF); - DoString(dx,20,"off"); - }; - }; -#else - results = adcRead(0); - DoInt(dx,20,results); - - if(results>trigger){ - DoString(dx,30,"YES!"); - }else{ - DoString(dx,30," no "); - }; - -#endif - - results = adcRead(1); - dx=DoString(0,yctr+20,"Voltage:"); - results *= 10560; - results /= 1024; - DoInt(dx,yctr+20,results); - - if( results < 3500 ){ - DoString(0,yctr+30,"Shutdown"); - gpioSetValue (RB_PWR_GOOD, 0); - gpioSetValue (RB_LCD_BL, 0); - SCB_SCR |= SCB_SCR_SLEEPDEEP; - PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; - __asm volatile ("WFI"); - }else{ - DoString(0,yctr+30,"OK "); - } - - } - - return 0; + wrapper(); // see module/ subdirectory } diff --git a/modules/Makefile b/modules/Makefile new file mode 100644 index 0000000..8763a54 --- /dev/null +++ b/modules/Makefile @@ -0,0 +1,50 @@ +########################################################################## +# User configuration and firmware specific object files +########################################################################## + +OBJS = default.o +OBJS += $(foreach mod,$(MODULE),$(mod).o) + +ifndef MODULE +ME_OBJ=$(USERNAME) + +ifeq "$(ME_OBJ)" "" +ME_OBJ=nouser +endif +OBJS += $(ME_OBJ).o +endif + +WRAP=wrapper +LIBNAME=modules + +########################################################################## +# GNU GCC compiler flags +########################################################################## +ROOT_PATH?= .. +INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. + +include $(ROOT_PATH)/Makefile.inc + +WRAPOBJ=$(WRAP).o +WRAPSRC=$(WRAP).c +LIBFILE=lib$(LIBNAME).a + +########################################################################## +# Compiler settings, parameters and flags +########################################################################## + +all: $(LIBFILE) + +$(LIBFILE): $(OBJS) $(WRAPOBJ) + $(AR) rcs $@ $(OBJS) $(WRAPOBJ) + +%.o : %.c + $(CC) $(CFLAGS) -o $@ $< + +clean: + rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o + +$(WRAPSRC): + ./mkwrapper $(OBJS) > $@ + +.PHONY: $(LIBFILE) diff --git a/modules/README b/modules/README new file mode 100644 index 0000000..25482ba --- /dev/null +++ b/modules/README @@ -0,0 +1,7 @@ +Call make as + +make MODULE=eeprom + +to build a specific module. + +The module defaults to $(USERNAME) so everyone can have its own default module diff --git a/modules/default.c b/modules/default.c new file mode 100644 index 0000000..33bf3de --- /dev/null +++ b/modules/default.c @@ -0,0 +1,7 @@ +#include + +/**************************************************************************/ + +void module_default(void) { + return; +} diff --git a/modules/eeprom.c b/modules/eeprom.c new file mode 100644 index 0000000..51945d7 --- /dev/null +++ b/modules/eeprom.c @@ -0,0 +1,111 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/smallfonts.h" +#include "lcd/ubuntu18.h" + +#include "pmu/pmu.h" +#include "eeprom/eeprom.h" + +/**************************************************************************/ + +void module_eeprom(void) { + //Make PIO1_11 an analog input + gpioSetDir(RB_LED3, gpioDirection_Input); + IOCON_PIO1_11 = 0x41; + + lcdFill(255); + lcdDisplay(0); + uint32_t j=0; + + //disable the JTAG on PIO3_3 + IOCON_PIO3_3 = 0x10; + + int yctr=8; + int dx=0; + + font_direction = FONT_DIR_LTR; // LeftToRight is the default + font = &Font_8x8; + + static FONT fonts[] = { + &Font_7x8, + &Font_Ubuntu18pt, // 3 byte-font + &Font_8x8, + }; + + int fontctr=0; + yctr=18; + + uint8_t written = 0; + uint8_t eeprom_val = 0; + + while (1) { + lcdDisplay(j); + delayms(10); + + font=fonts[fontctr]; + + if (!written) { + if (eeprom_ready()) { + if (eeprom_write_byte(127,15,42)) { + DoString(1, yctr, "Write OK!"); + written++; + } else { + DoString(1, yctr, "Write NOK!"); + } + } else { + DoString(1, yctr, "NOT READY!"); + } + } else { + if (eeprom_ready()) { + if (eeprom_read_byte(127,15,&eeprom_val)) { + if (eeprom_val == 42) { + DoString(1, yctr, "verified!"); + } else { + DoString(1, yctr, "failed!"); + } + } else { + DoString(1, yctr, "Read NOK!"); + } + } else { + DoString(1, yctr, "NOT READY!!"); + } + } + + if(1 && gpioGetValue(RB_LED3) == 0){ + gpioSetValue (RB_LED3, 0); + while(gpioGetValue(RB_LED3) == 0){ + }; + gpioSetValue (RB_LED3, 1); + lcdFill(255); + fontctr++; + if(fontctr > 2) { + fontctr = 0; + } + }; + + uint32_t results = adcRead(7); + + results = adcRead(1); + dx=DoString(0,yctr+20,"Voltage:"); + results *= 10560; + results /= 1024; + DoInt(dx,yctr+20,results); + + if( results < 3500 ){ + DoString(0,yctr+30,"Shutdown"); + gpioSetValue (RB_PWR_GOOD, 0); + gpioSetValue (RB_LCD_BL, 0); + SCB_SCR |= SCB_SCR_SLEEPDEEP; + PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; + __asm volatile ("WFI"); + }else{ + DoString(0,yctr+30,"OK "); + } + + } + + return; +} diff --git a/modules/mkwrapper b/modules/mkwrapper new file mode 100755 index 0000000..2b6ef98 --- /dev/null +++ b/modules/mkwrapper @@ -0,0 +1,16 @@ +#!/bin/sh + +for a in $* ; do + base=${a%.o} + echo "void module_$base(void);" +done + +echo +echo "void wrapper(void){" + +for a in $* ; do + base=${a%.o} + echo "module_$base();" +done + +echo "}" diff --git a/modules/sec.c b/modules/sec.c new file mode 100644 index 0000000..46fb6ed --- /dev/null +++ b/modules/sec.c @@ -0,0 +1,126 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/smallfonts.h" +#include "lcd/ubuntu18.h" + +void ReinvokeISP(void); + +/**************************************************************************/ + +void module_sec(void) { + //Make PIO1_11 an analog input + gpioSetDir(RB_LED3, gpioDirection_Input); + IOCON_PIO1_11 = 0x41; + + uint32_t j=0; + + //disable the JTAG on PIO3_3 + IOCON_PIO3_3 = 0x10; + + int yctr=8; + int dx=0; + + font_direction = FONT_DIR_LTR; // LeftToRight is the default + font = &Font_8x8; + + static FONT fonts[] = { + &Font_7x8, + &Font_Ubuntu18pt, // 3 byte-font + &Font_8x8, + }; + + int fontctr=0; + yctr=18; + + uint8_t written = 0; + uint8_t eeprom_val = 0; + uint8_t trigger; + +#define SEND +#ifdef SEND + trigger=200; + gpioSetDir(RB_LED0, gpioDirection_Output); + IOCON_JTAG_TDI_PIO0_11 = 0x11; +#else + trigger=380; + gpioSetDir(RB_LED0, gpioDirection_Input); + IOCON_JTAG_TDI_PIO0_11 = 0x42; +#endif + + + uint32_t ctr=0; + while (1) { + ctr++; + uint32_t results; + lcdDisplay(j); + delayms(10); + + font=fonts[fontctr]; + + if(gpioGetValue(RB_BTN3)==0){ + while(gpioGetValue(RB_BTN3)==0); + trigger +=10; + }; + if(gpioGetValue(RB_BTN2)==0){ + while(gpioGetValue(RB_BTN2)==0); + trigger -=10; + }; + dx=DoString(0,0,"Trig:"); + dx=DoInt(dx,0,trigger); + DoString(dx,0," "); + + if(gpioGetValue(RB_BTN0)==0){ + while(gpioGetValue(RB_BTN0)==0); + DoString(0,8,"Enter ISP!"); + lcdDisplay(0); + ReinvokeISP(); + }; + + dx=DoString(0,20,"LED:"); +#ifdef SEND + if(ctr++>trigger/10){ + ctr=0; + if (gpioGetValue(RB_LED0) == CFG_LED_OFF){ + gpioSetValue (RB_LED0, CFG_LED_ON); + DoString(dx,20,"ON!"); + } else { + gpioSetValue (RB_LED0, CFG_LED_OFF); + DoString(dx,20,"off"); + }; + }; +#else + results = adcRead(0); + DoInt(dx,20,results); + + if(results>trigger){ + DoString(dx,30,"YES!"); + }else{ + DoString(dx,30," no "); + }; + +#endif + + results = adcRead(1); + dx=DoString(0,yctr+20,"Voltage:"); + results *= 10560; + results /= 1024; + DoInt(dx,yctr+20,results); + + if( results < 3500 ){ + DoString(0,yctr+30,"Shutdown"); + gpioSetValue (RB_PWR_GOOD, 0); + gpioSetValue (RB_LCD_BL, 0); + SCB_SCR |= SCB_SCR_SLEEPDEEP; + PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; + __asm volatile ("WFI"); + }else{ + DoString(0,yctr+30,"OK "); + } + + } + + return; +}