From 94909b5b893d5c60bc44bbafec8de1b3c86d9595 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 9 Sep 2007 03:12:45 +0200 Subject: [PATCH] first pseudo flash filesystem code (not working yet) --- betty/Makefile | 2 +- betty/betty.c | 6 +++--- betty/betty.h | 1 + betty/display.c | 8 ++++---- betty/display.h | 8 ++++---- betty/flash.c | 21 ++++++++++++++++++++- betty/flash.h | 1 + betty/pffs.c | 39 +++++++++++++++++++++++++++++++++++++++ betty/pffs.h | 40 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 betty/pffs.c create mode 100644 betty/pffs.h diff --git a/betty/Makefile b/betty/Makefile index 3883fce..b7a2616 100644 --- a/betty/Makefile +++ b/betty/Makefile @@ -19,7 +19,7 @@ HOST_TARGET = lpcload fwdump CROSS_TARGET = fwbc.hex fwflash.hex betty.hex # betty deps -BETTY_DEPS = system.o uart.o buttons.o spi.o display.o flash.o +BETTY_DEPS = system.o uart.o buttons.o spi.o display.o flash.o pffs.o # all projects all: $(HOST_TARGET) $(CROSS_TARGET) diff --git a/betty/betty.c b/betty/betty.c index 45e6ae7..859860a 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -31,7 +31,7 @@ int main() { uart0_init(); /* display init */ - bl_init(); + display_bl_init(); /* button init */ button_init(&button); @@ -51,7 +51,7 @@ int main() { uart0_send_string(announce); /* toggle backlight */ - bl_toggle(); + display_bl_toggle(); //addr=0x82000000; flash_sector_erase(BANK2,0); @@ -64,7 +64,7 @@ int main() { if(button_get_event(&button)) { uart0_send_string(announce); if(button.key[0]==BUTTON_POWER) { - bl_toggle(); + display_bl_toggle(); flash_write_buf(addr,(u16 *)announce,42); addr+=64; } diff --git a/betty/betty.h b/betty/betty.h index 33e64d5..761f74d 100644 --- a/betty/betty.h +++ b/betty/betty.h @@ -25,6 +25,7 @@ #include "spi.h" #include "display.h" #include "flash.h" +#include "pffs.h" /* * defines diff --git a/betty/display.c b/betty/display.c index 07fb923..210cd17 100644 --- a/betty/display.c +++ b/betty/display.c @@ -16,13 +16,13 @@ void display_init(void) { BCFG1=0x00000c42; } -void bl_init(void) { +void display_bl_init(void) { PINSEL0&=~(1<<9|(1<<8)); IODIR0|=(1<<4); } -void bl_toggle(void) { +void display_bl_toggle(void) { if(IOPIN0&(1<<4)) IOCLR0=(1<<4); @@ -30,12 +30,12 @@ void bl_toggle(void) { IOSET0=(1<<4); } -void bl_on(void) { +void display_bl_on(void) { IOCLR0=(1<<4); } -void bl_off(void) { +void display_bl_off(void) { IOSET0=(1<<4); } diff --git a/betty/display.h b/betty/display.h index cad2e76..afaa399 100644 --- a/betty/display.h +++ b/betty/display.h @@ -12,9 +12,9 @@ #include "types.h" /* function prototypes */ -void bl_init(void); -void bl_toggle(void); -void bl_on(void); -void bl_off(void); +void display_bl_init(void); +void display_bl_toggle(void); +void display_bl_on(void); +void display_bl_off(void); #endif diff --git a/betty/flash.c b/betty/flash.c index 8d9c02a..64488e2 100644 --- a/betty/flash.c +++ b/betty/flash.c @@ -10,7 +10,8 @@ /* * sector addresses */ -static unsigned long sector_address[19]={ + +unsigned long sector_address[19]={ 0x00000,0x02000,0x03000,0x04000,0x08000, 0x10000,0x18000, 0x20000,0x28000, @@ -96,6 +97,24 @@ void flash_sector_erase(u8 bank,u8 sector) { return; } +int flash_sec_erase(u32 addr) { + + u32 a18_12; + u32 base; + + a18_12=addr&0x00000fffff; + base=addr&0xff000000; + + *((volatile u16 *)(base|(0x555<<1)))=0xaa; + *((volatile u16 *)(base|(0x2aa<<1)))=0x55; + *((volatile u16 *)(base|(0x555<<1)))=0x80; + *((volatile u16 *)(base|(0x555<<1)))=0xaa; + *((volatile u16 *)(base|(0x2aa<<1)))=0x55; + *((volatile u16 *)(base|(a18_12<<1)))=0x30; + + return 0; +} + void flash_chip_erase(u8 bank) { u8 status; diff --git a/betty/flash.h b/betty/flash.h index 8683b93..1bb1b2e 100644 --- a/betty/flash.h +++ b/betty/flash.h @@ -36,6 +36,7 @@ void flash_init(void); void flash_reset(u8 bank); void flash_sector_erase(u8 flash,u8 sector); +int flash_sec_erase(u32 addr); void flash_chip_erase(u8 bank); void flash_unlock_bypass(u8 bank); void flash_unlock_bypass_reset(u8 bank); diff --git a/betty/pffs.c b/betty/pffs.c new file mode 100644 index 0000000..995e108 --- /dev/null +++ b/betty/pffs.c @@ -0,0 +1,39 @@ +/* + * pffs.c - pseudo flash filesystem + * + * author: hackbard@hackdaworld.org + * + */ + +#include "pffs.h" + +/* + * functions + */ + +int pffs_flash_register(t_pffs *pffs,u32 base_addr,u8 sec_num,u32 *sec_addr, + u8 dmin,u8 dmax,u8 index1,u8 index2, + int (*fw)(u32 addr,u16 *buf,int len), + int (*fr)(u32 addr,u16 *buf,int len), + int (*fe)(u32 addr)) { + + pffs->base_addr=base_addr; + pffs->sec_num=sec_num; + pffs->sec_addr=sec_addr; + pffs->fw=fw; + pffs->fr=fr; + pffs->fe=fe; + + pffs->state|=PFFS_REGISTERED; + + return 0; +} + +int pffs_init(t_pffs *pffs) { + + if(!(pffs->state&PFFS_REGISTERED)) + return -1; + + return 0; +} + diff --git a/betty/pffs.h b/betty/pffs.h new file mode 100644 index 0000000..92b4821 --- /dev/null +++ b/betty/pffs.h @@ -0,0 +1,40 @@ +/* + * pfs.h - pseudo flash filesystem header file + * + * author: hackbard@hackdaworld.org + * + */ + +#ifndef PFFS_H +#define PFFS_H + +#include "lpc2xxx.h" +#include "types.h" + +/* defines */ + +#define PFFS_REGISTERED (1<<0) + +/* type definitions */ + +typedef struct s_pffs { + /* flash specs */ + u32 base_addr; + u8 sec_num; + u32 *sec_addr; + /* flash write, read and sector erase function pointers */ + int (*fw)(u32 addr,u16 *buf,int len); + int (*fr)(u32 addr,u16 *buf,int len); + int (*fe)(u32 addr); + /* pffs internal variables */ + u8 state; + u8 sec_num_data_min; + u8 sec_num_data_max; + u8 sec_num_index[2]; + u32 data_ptr; + u32 index_ptr; +} t_pffs; + +/* function prototypes */ + +#endif -- 2.39.2