WizziLab / Mbed 2 deprecated D7A_1x_TRAINING

Dependencies:   X_NUCLEO_IKS01A1 d7a_1x mbed-rtos mbed wizzi-utils

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers files.cpp Source File

files.cpp

00001 #include "files.h"
00002 #include "dbg.h"
00003 #include "sensors.h"
00004 
00005 GENERIC_FILE_INIT(dev_rev,
00006     .rev.manufacturer_id     = 0x01BC50C7,
00007     /// Device ID: Arbitrary number, at user/customer choice
00008     .rev.device_id           = 0x00000010,
00009     /// Hardware Board ID:
00010     .rev.hw_version          = 0x00000152,
00011     /// Firmware Version: made of
00012     ///  - major,minor and patch indexes
00013     ///  - fw_id : "build-flavour"
00014     ///  FW_ID | MAJOR | MINOR | PATCH | HASH |
00015     //     1B  |  1B   |  1B   |   2B  |  4B  |
00016 #if _SENSORS_SIMU_
00017     .rev.fw_version.id       = 1,
00018 #else
00019     .rev.fw_version.id       = 0,
00020 #endif
00021     .rev.fw_version.major    = 1,
00022     .rev.fw_version.minor    = 0,
00023     .rev.fw_version.patch    = 0,
00024     .rev.fw_version.hash     = 0x00000000,
00025     /// "file-system" signature
00026     .rev.fs_crc              = 0x00000000,
00027 );
00028 
00029 
00030 GENERIC_FILE_INIT(simul,
00031     .divider = 500, // Boot value
00032 );
00033 
00034 
00035 GENERIC_FILE_INIT(mag_cfg,
00036     .cfg.report_type = REPORT_ON_DIFFERENCE,
00037     .cfg.period = 1000,
00038     .cfg.max_period = 300,
00039     .cfg.max_diff = 100,
00040     .cfg.threshold_high = 1000,
00041     .cfg.threshold_low = -1000,
00042 );
00043     
00044 GENERIC_FILE_INIT(acc_cfg,
00045     .cfg.report_type = REPORT_ON_DIFFERENCE,
00046     .cfg.period = 1000,
00047     .cfg.max_period = 300,
00048     .cfg.max_diff = 100,
00049     .cfg.threshold_high = 500,
00050     .cfg.threshold_low = -500,
00051 );
00052 
00053 GENERIC_FILE_INIT(gyr_cfg,
00054     .cfg.report_type = REPORT_ON_DIFFERENCE,
00055     .cfg.period = 1000,
00056     .cfg.max_period = 300,
00057     .cfg.max_diff = 1000,
00058     .cfg.threshold_high = 10000,
00059     .cfg.threshold_low = -10000,
00060 );
00061 
00062 GENERIC_FILE_INIT(pre_cfg,
00063     .cfg.report_type = REPORT_ON_DIFFERENCE,
00064     .cfg.period = 1000,
00065     .cfg.max_period = 60,
00066     .cfg.max_diff = 100,
00067     .cfg.threshold_high = 120000,
00068     .cfg.threshold_low = 90000,
00069 );
00070 
00071 GENERIC_FILE_INIT(hum_cfg,
00072     .cfg.report_type = REPORT_ON_DIFFERENCE,
00073     .cfg.period = 1000,
00074     .cfg.max_period = 60,
00075     .cfg.max_diff = 100,
00076     .cfg.threshold_high = 7000,
00077     .cfg.threshold_low = 3000,
00078 );
00079 
00080 GENERIC_FILE_INIT(tem1_cfg,
00081     .cfg.report_type = REPORT_ON_DIFFERENCE,
00082     .cfg.period = 1000,
00083     .cfg.max_period = 60,
00084     .cfg.max_diff = 100,
00085     .cfg.threshold_high = 3500,
00086     .cfg.threshold_low = 2000,
00087 );
00088 
00089 GENERIC_FILE_INIT(tem2_cfg,
00090     .cfg.report_type = REPORT_ON_DIFFERENCE,
00091     .cfg.period = 1000,
00092     .cfg.max_period = 60,
00093     .cfg.max_diff = 100,
00094     .cfg.threshold_high = 9000,
00095     .cfg.threshold_low = 7000,
00096 );
00097 
00098 #define FILE_QTY    8
00099 
00100 static const void* file_map[FILE_QTY][2] = {
00101     GENERIC_FILE_MAP(MAG_CFG_FILE_ID, mag_cfg),
00102     GENERIC_FILE_MAP(ACC_CFG_FILE_ID, acc_cfg),
00103     GENERIC_FILE_MAP(GYR_CFG_FILE_ID, gyr_cfg),
00104     GENERIC_FILE_MAP(PRE_CFG_FILE_ID, pre_cfg),
00105     GENERIC_FILE_MAP(HUM_CFG_FILE_ID, hum_cfg),
00106     GENERIC_FILE_MAP(TEM1_CFG_FILE_ID, tem1_cfg),
00107     GENERIC_FILE_MAP(TEM2_CFG_FILE_ID, tem2_cfg),
00108     GENERIC_FILE_MAP(SIMUL_FILE_ID, simul),
00109 };
00110 
00111 void* file_get( uint8_t file_id )
00112 {    
00113     for (uint8_t i=0 ; i<FILE_QTY ; i++)
00114     {
00115         if ((uint8_t)file_map[i][0] == file_id)
00116         {
00117             return (void*)file_map[i][1];
00118         }
00119     }
00120     
00121     ASSERT(false, "File %d does not exist\r\n");
00122     
00123     return NULL;
00124 }
00125 
00126 uint32_t fs_write_file(const uint8_t file_id,
00127                         const uint16_t offset,
00128                         const uint16_t size,
00129                         const uint8_t* const content)
00130 {
00131     uint32_t file = 0;
00132     
00133     DPRINT("WF %d\r\n", file_id);
00134         
00135     // Retrieve pointer to file
00136     file = (uint32_t)file_get(file_id);
00137         
00138     if (!file)
00139     {
00140         return 0;
00141     }
00142     
00143     // Write the new data
00144     memcpy((void*)(file+offset), (void*)content, size);
00145   
00146     return size;
00147 }
00148 
00149 uint32_t fs_read_file( const uint8_t file_id,
00150                         const uint16_t offset,
00151                         const uint16_t size,
00152                         uint8_t* buf)
00153 {
00154     uint32_t file = 0;
00155     
00156     DPRINT("RF %d\r\n", file_id);
00157     
00158     // Retrieve pointer to file
00159     file = (uint32_t)file_get(file_id);
00160     
00161     if (!file)
00162     {
00163         return 0;
00164     }
00165     
00166     // Read data
00167     memcpy((void*)buf, (void*)(file+offset), size);
00168     
00169     return size;
00170 }