Simon Hawe / D7_MLX_AND_BAT

Dependencies:   X_NUCLEO_IKS01A1 MLX90614 d7a_1x wizzi-utils

Fork of D7A_1x_demo_sensors_OS5 by WizziLab

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 defined(TARGET_STM32L152RE)
00017     #ifdef TARGET_HAS_IKS01A1    
00018     .rev.fw_version.id       = 0,
00019     #else // simulated sensors
00020     .rev.fw_version.id       = 1,
00021     #endif // TARGET_HAS_IKS01A1
00022 #elif defined(TARGET_STM32L432KC)
00023     .rev.fw_version.id       = 2,
00024 #else
00025     #error "Please choose or add the right platform."
00026 #endif
00027     .rev.fw_version.major    = 1,
00028     .rev.fw_version.minor    = 0,
00029     .rev.fw_version.patch    = 0,
00030     .rev.fw_version.hash     = 0x00000000,
00031     /// "file-system" signature
00032     .rev.fs_crc              = 0x00000000,
00033 );
00034 
00035 GENERIC_FILE_INIT(simul,
00036     .divider = 500, // Boot value
00037 );
00038 
00039 
00040 
00041 GENERIC_FILE_INIT(tem1_cfg,
00042     .cfg.report_type = REPORT_ALWAYS,
00043     .cfg.period = 5000,
00044     .cfg.max_period = 5,
00045     .cfg.max_diff = 100,
00046     .cfg.threshold_high = 3500,
00047     .cfg.threshold_low = 2000,
00048 );
00049 
00050 GENERIC_FILE_INIT(volt_cfg,
00051     .cfg.report_type = REPORT_ALWAYS,
00052     .cfg.period = 20000, // ms
00053     .cfg.max_period = 60, // sec
00054     .cfg.max_diff = 10, // percent
00055     .cfg.threshold_high = 0, // disabled
00056     .cfg.threshold_low = 100, // disabled
00057 );
00058 
00059 #define FILE_QTY    3
00060 
00061 static const void* file_map[FILE_QTY][2] = {
00062     GENERIC_FILE_MAP(TEM1_CFG_FILE_ID, tem1_cfg),
00063     GENERIC_FILE_MAP(SIMUL_FILE_ID, simul),
00064     GENERIC_FILE_MAP(VOLT_CFG_FILE_ID, volt_cfg),
00065 };
00066 
00067 void* file_get( uint8_t file_id )
00068 {    
00069     for (uint8_t i=0 ; i<FILE_QTY ; i++)
00070     {
00071         if ((uint8_t)file_map[i][0] == file_id)
00072         {
00073             return (void*)file_map[i][1];
00074         }
00075     }
00076     
00077     ASSERT(false, "File %d does not exist\r\n");
00078     
00079     return NULL;
00080 }
00081 
00082 uint32_t fs_write_file(const uint8_t file_id,
00083                         const uint16_t offset,
00084                         const uint16_t size,
00085                         const uint8_t* const content)
00086 {
00087     uint32_t file = 0;
00088     
00089     DPRINT("WF %d\r\n", file_id);
00090         
00091     // Retrieve pointer to file
00092     file = (uint32_t)file_get(file_id);
00093         
00094     if (!file)
00095     {
00096         return 0;
00097     }
00098     
00099     // Write the new data
00100     memcpy((void*)(file+offset), (void*)content, size);
00101   
00102     return size;
00103 }
00104 
00105 uint32_t fs_read_file( const uint8_t file_id,
00106                         const uint16_t offset,
00107                         const uint16_t size,
00108                         uint8_t* buf)
00109 {
00110     uint32_t file = 0;
00111     
00112     DPRINT("RF %d\r\n", file_id);
00113     
00114     // Retrieve pointer to file
00115     file = (uint32_t)file_get(file_id);
00116     
00117     if (!file)
00118     {
00119         return 0;
00120     }
00121     
00122     // Read data
00123     memcpy((void*)buf, (void*)(file+offset), size);
00124     
00125     return size;
00126 }