openchronos-ng
opensource firmware for the ez430 chronos
|
00001 /**** 00002 * written by Lukas Middendorf 00003 * 00004 * use as desired but do not remove this notice 00005 */ 00006 00007 #include "project.h" 00008 00009 #ifndef INFOMEM_H_ 00010 #define INFOMEM_H_ 00011 00012 /* 00013 * This driver allows applications to store data in the information memory flash 00014 * without interfering with each other (except for the total available memory) or 00015 * having to care about the characteristics of flash memory. 00016 * 00017 * infomem_ready() has to be called before any other function does work (except 00018 * infomem_init, but use infomem_ready to check if infomem_init is really needed). 00019 * 00020 * Single applications should only use the infomem_app_*() functions ary infomem_space(), 00021 * the rest of the functions should be used only in the global part of the firmware 00022 * (or in a dedicated application which's function it is to do memory maintenance tasks). 00023 * 00024 * Use infomem_app_replace() with count>0 to initialize memory for application. This has 00025 * to be redone if data of size zero was present and the application header was therefore 00026 * also removed (replace with zero count, clear, delete with zero offset or modify with 00027 * zero count and offset). 00028 * 00029 * All pointers and addresses have to be word addresses (even numbers) and all counts 00030 * are given in units of words (two bytes). 00031 */ 00032 00033 00034 //check if infomem is initialized and in sane state, return amount of data present 00035 extern int16_t infomem_ready(); 00036 //write infomem data structure 00037 extern int16_t infomem_init(uint16_t start, uint16_t end); 00038 //return amount of free space 00039 extern int16_t infomem_space(); 00040 //change start and end address of data storage (can change size) 00041 extern int16_t infomem_relocate(uint16_t start, uint16_t end); 00042 //delete complete data storage (only managed space) 00043 extern int16_t infomem_delete_all(void); 00044 00045 //return how much data for the application is available 00046 extern int16_t infomem_app_amount(uint8_t identifier); 00047 //read count bytes of data with offset for given application into prepared memory 00048 extern int16_t infomem_app_read(uint8_t identifier, uint16_t *data, uint8_t count, uint8_t offset); 00049 //replace all memory content for application by new data 00050 extern int16_t infomem_app_replace(uint8_t identifier, uint16_t *data, uint8_t count); 00051 //delete all memory content for application 00052 extern int16_t infomem_app_clear(uint8_t identifier); 00053 //delete all memory content beginning with offset 00054 extern int16_t infomem_app_delete(uint8_t identifier, uint8_t offset); 00055 //modify given bytes of data 00056 extern int16_t infomem_app_modify(uint8_t identifier, uint16_t *data, uint8_t count, uint8_t offset); 00057 00058 00059 00060 struct infomem { 00061 uint16_t *startaddr; //starting address (position of header) 00062 uint8_t size; //size of payload in words 00063 uint8_t maxsize; //maximum size of payload in words 00064 volatile uint8_t not_lock; //memory is not locked for write 00065 uint8_t sane; //sanity check passed 00066 }; 00067 // extern struct infomem sInfomem; 00068 00069 00070 #define INFOMEM_IDENTIFIER 0x5a74 00071 #define INFOMEM_TERMINATOR 0xdaf4 00072 #define INFOMEM_SANE 0xda 00073 00074 #define INFOMEM_START 0x1800 00075 #define INFOMEM_D 0x1800 00076 #define INFOMEM_C 0x1880 00077 #define INFOMEM_B 0x1900 00078 #define INFOMEM_A 0x1980 00079 #define INFOMEM_SEGMENT_SIZE 128 00080 #define INFOMEM_SEGMENT_WORDS INFOMEM_SEGMENT_SIZE/2 00081 #define INFOMEM_ERASED_WORD 0xFFFF 00082 00083 00084 #endif /*INFOMEM_H_*/