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)
uart0_init();
/* display init */
- bl_init();
+ display_bl_init();
/* button init */
button_init(&button);
uart0_send_string(announce);
/* toggle backlight */
- bl_toggle();
+ display_bl_toggle();
//addr=0x82000000;
flash_sector_erase(BANK2,0);
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;
}
#include "spi.h"
#include "display.h"
#include "flash.h"
+#include "pffs.h"
/*
* defines
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);
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);
}
#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
/*
* sector addresses
*/
-static unsigned long sector_address[19]={
+
+unsigned long sector_address[19]={
0x00000,0x02000,0x03000,0x04000,0x08000,
0x10000,0x18000,
0x20000,0x28000,
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;
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);
--- /dev/null
+/*
+ * 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;
+}
+
--- /dev/null
+/*
+ * 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