Mario Bambagini / Mbed 2 deprecated car_chassis

Dependencies:   Servo mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers old.inc Source File

old.inc

00001 in main.cpp
00002 
00003 /*
00004     printf("INIT EEPROM\r\n");
00005     init_eeprom();
00006 */
00007 
00008 /****************** EEPROM ******************/
00009 /*
00010 eeprom_t eeprom(p7, p5, p6, p9, PAGENUMBER, PAGESIZE);
00011 
00012 t_eeprom_data eeprom_data[] = {
00013     //SIZE,   ADDR
00014     {    2,      0}, //SOFTWARE VERSION
00015     {    2,      2}, //DATA VERSION
00016     {    4,      4}, //NUMBER OF STARTS
00017     {    4,     20}, //T_MISSING
00018     {    4,     40}, //ENGINE_LAST_MISSING
00019     {    4,     44}  //BODY_LAST_MISSING
00020 };
00021 
00022 void init_eeprom ()
00023 {
00024     eeprom.init(eeprom_data, sizeof(eeprom_data)/sizeof(t_eeprom_data));
00025 
00026     uint16 sw = 0;
00027     uint16 dd = 0;
00028     uint32 num = 0;
00029     if ((eeprom.read(EEPROM_DATA_SW_VERS, (uint8*)(&sw)) != 2) ||
00030         (eeprom.read(EEPROM_DATA_DD_VERS, (uint8*)(&dd)) != 2) ||
00031         (sw != SW_VERSION) || (dd != DD_VERSION))
00032     {
00033         //error
00034         eeprom.reset();
00035         sw = SW_VERSION;
00036         eeprom.write(EEPROM_DATA_SW_VERS, (uint8*)(&sw));
00037         dd = DD_VERSION;
00038         eeprom.write(EEPROM_DATA_DD_VERS, (uint8*)(&dd));
00039     }
00040 
00041     if (eeprom.read(EEPROM_DATA_NSTARTS, (uint8*)(&num)) != 4)
00042         num = 0xffffffff;
00043     num++;
00044     eeprom.write(EEPROM_DATA_NSTARTS, (unsigned char*)(&num));
00045 }
00046 */
00047 
00048 in eeprom.hpp
00049 
00050 #ifndef __EEPROM_H__
00051 #define __EEPROM_H__  
00052 /*
00053 #include "common_types.h"
00054 
00055 #include "Ser25lcxxx.h"
00056 
00057 #define EEPROM_ENTRY_NOT_VALID      ((int8)(-1))
00058 #define EEPROM_ERR_READ             ((int8)(-2))
00059 #define EEPROM_ERR_WRITE            ((int8)(-3))
00060 
00061 typedef struct {
00062     uint8  size;            // number of bytes
00063     uint32 addr;            // eeprom address
00064 } t_eeprom_data;
00065 
00066 class eeprom_t
00067 {
00068 
00069     t_eeprom_data *eeprom_data; // configuration table of the eeprom
00070 
00071     Ser25LCxxx memory; // memory
00072     
00073     uint32 n; // total number of stored items
00074     uint32 max_pages; // total number of pages in eeprom
00075     uint32 page_size; // size of each page
00076     
00077     uint32 n_used_pages; // total number of used pages
00078 
00079 public:
00080 
00081     eeprom_t (PinName sck, PinName si, PinName so, PinName enable,
00082               int pagenumber, int pagesize):
00083                     memory(sck, si, so, enable, pagenumber, pagesize)
00084     {
00085         max_pages = pagenumber;
00086         page_size = pagesize;
00087     }
00088 
00089     bool init (t_eeprom_data *data, unsigned int num);
00090 
00091     bool reset();
00092 
00093     int8 read (uint32 id, uint8* dst);
00094 
00095     int8 write (uint32 id, const uint8* src);
00096     
00097 };
00098 */
00099 #endif //__EEPROM_H__
00100 
00101 in eeprom.cpp
00102 
00103 /*
00104 #include "eeprom.hpp"
00105 
00106 bool eeprom_t::init (t_eeprom_data *data, unsigned int num)
00107 {
00108     if (!memory.isFullyWritable())
00109         memory.setFullyWritable();
00110 
00111     n = num;
00112     eeprom_data = data;
00113     uint32 max_addr = 0;
00114 
00115     for (int i = 0; i < n; i++) {
00116 //        unsigned int buffer = 0;
00117 //        unsigned int nread = memory.read(eeprom_data[i].addr,
00118 //                                         eeprom_data[i].size,
00119 //                                         (unsigned char*)(&buffer));
00120 //        if (nread == eeprom_data[i].size)
00121 //            local_values[i] = buffer;
00122         if (eeprom_data[i].addr > max_addr)
00123             max_addr = eeprom_data[i].addr + eeprom_data[i].size;
00124     }
00125 
00126     n_used_pages = max_addr / page_size + 1;
00127 
00128     return true;
00129 }
00130 
00131 bool eeprom_t::reset ()
00132 {
00133    for (int i = 0; i <= n_used_pages; i++) {
00134         __disable_irq();
00135         memory.clearPage(i);
00136         __enable_irq();
00137     }
00138 
00139     return true;
00140 }
00141 
00142 int8 eeprom_t::read (uint32 id, uint8* dst)
00143 {
00144     if (id >= n)
00145         return EEPROM_ENTRY_NOT_VALID;
00146 
00147 //critical section
00148     __disable_irq();
00149     int num = memory.read(eeprom_data[id].addr, eeprom_data[id].size, dst);
00150     __enable_irq();
00151 //critical section
00152 
00153     if (num == eeprom_data[id].size)
00154         return num;
00155 
00156     return EEPROM_ERR_READ;
00157 }
00158 
00159 int8 eeprom_t::write (uint32 id, const uint8* src)
00160 {
00161     if (id >= n)
00162         return EEPROM_ENTRY_NOT_VALID;
00163 
00164     //critical section
00165     __disable_irq();
00166     int num = memory.write(eeprom_data[id].addr, eeprom_data[id].size, src);
00167     __enable_irq();
00168     //critical section
00169 
00170     if (num != eeprom_data[id].size)
00171         return EEPROM_ERR_WRITE;
00172 
00173     return num;
00174 }
00175 */