Merge branch 'secperiments'

This commit is contained in:
Stefan `Sec` Zehl 2011-05-21 12:07:43 +02:00
commit 84fb2fa41e
9 changed files with 333 additions and 101 deletions

View File

@ -9,7 +9,8 @@ VPATH +=
OBJS +=
OBJS += basic/basic.o
OBJS += eeprom/eeprom.o
LIBS += core/libcore.a lcd/libfont.a
OBJS += reinvoke_isp.o
LIBS += core/libcore.a lcd/libfont.a modules/libmodules.a
##########################################################################
# GNU GCC compiler flags
@ -25,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
@ -41,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)
@ -64,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

View File

@ -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

99
main.c
View File

@ -13,6 +13,8 @@ void ReinvokeISP(void);
/**************************************************************************/
void wrapper(void);
int main(void) {
// Configure cpu and mandatory peripherals
systemInit();
@ -25,103 +27,10 @@ int main(void) {
lcdInit(); // display
//Make PIO1_11 an analog input
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = 0x41;
adcInit();
lcdFill(255);
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;
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 0;
wrapper(); // see module/ subdirectory
}

50
modules/Makefile Normal file
View File

@ -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)

7
modules/README Normal file
View File

@ -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

7
modules/default.c Normal file
View File

@ -0,0 +1,7 @@
#include <sysinit.h>
/**************************************************************************/
void module_default(void) {
return;
}

111
modules/eeprom.c Normal file
View File

@ -0,0 +1,111 @@
#include <sysinit.h>
#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;
}

16
modules/mkwrapper Executable file
View File

@ -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 "}"

126
modules/sec.c Normal file
View File

@ -0,0 +1,126 @@
#include <sysinit.h>
#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;
}