50 void ee_write_page(unsigned int); //function adds a record in EEPROM |
50 void ee_write_page(unsigned int); //function adds a record in EEPROM |
51 void ee_read_page(unsigned int); //function reads the latest valid record in EEPROM |
51 void ee_read_page(unsigned int); //function reads the latest valid record in EEPROM |
52 |
52 |
53 typedef void (*IAP)(unsigned int [],unsigned int[]); |
53 typedef void (*IAP)(unsigned int [],unsigned int[]); |
54 IAP iap_entry; |
54 IAP iap_entry; |
|
55 |
|
56 |
|
57 int iat_init() |
|
58 { |
|
59 int n = NVRAM_BLOCK_SIZE / sizeof(unsigned int); |
|
60 |
|
61 /* some actions to initialise the flash */ |
|
62 data_len = 0; |
|
63 data_num_pages = 0; |
|
64 |
|
65 data_page = (unsigned int *)malloc(sizeof(unsigned int) * n); |
|
66 memset(data_page, 0, sizeof(unsigned int)*n); |
|
67 |
|
68 if (data_page == NULL) |
|
69 return -1; |
|
70 |
|
71 regs_page = (unsigned int *)malloc(sizeof(unsigned int) * n); |
|
72 memset(regs_page, 0, sizeof(unsigned int)*n); |
|
73 if (regs_page == NULL) |
|
74 return -2; |
|
75 |
|
76 iat_flash_read_regs(); |
|
77 |
|
78 /* start the data at the location specified in the registers */ |
|
79 if (0) /* for now it is 0, but put here a test to know whether |
|
80 or not the NVRAM has been written before */ |
|
81 data_addr = regs_page[1]; |
|
82 else |
|
83 data_addr = NVRAM_BLOCK_SIZE; /* let start at block 1 */ |
|
84 |
|
85 return 0; |
|
86 } |
|
87 |
|
88 |
|
89 void iat_end() |
|
90 { |
|
91 /* write the last page before closing */ |
|
92 iat_flash_write_page(data_addr); |
|
93 |
|
94 /* some actions to end accessing the flash */ |
|
95 free(data_page); |
|
96 |
|
97 regs_page[4] = data_num_pages; |
|
98 /* write the registers to the NVRAM before closing */ |
|
99 iat_flash_write_regs(); |
|
100 free(regs_page); |
|
101 } |
55 |
102 |
56 |
103 |
57 |
104 |
58 /************************************************************************/ |
105 /************************************************************************/ |
59 /* */ |
106 /* */ |