Demo fro training
Dependencies: X_NUCLEO_IKS01A1 d7a_1x mbed-rtos mbed wizzi-utils
files.cpp@0:429446fe396d, 2016-11-21 (annotated)
- Committer:
- mikl_andre
- Date:
- Mon Nov 21 07:24:34 2016 +0000
- Revision:
- 0:429446fe396d
Initial Revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mikl_andre | 0:429446fe396d | 1 | #include "files.h" |
mikl_andre | 0:429446fe396d | 2 | #include "dbg.h" |
mikl_andre | 0:429446fe396d | 3 | #include "sensors.h" |
mikl_andre | 0:429446fe396d | 4 | |
mikl_andre | 0:429446fe396d | 5 | GENERIC_FILE_INIT(dev_rev, |
mikl_andre | 0:429446fe396d | 6 | .rev.manufacturer_id = 0x01BC50C7, |
mikl_andre | 0:429446fe396d | 7 | /// Device ID: Arbitrary number, at user/customer choice |
mikl_andre | 0:429446fe396d | 8 | .rev.device_id = 0x00000010, |
mikl_andre | 0:429446fe396d | 9 | /// Hardware Board ID: |
mikl_andre | 0:429446fe396d | 10 | .rev.hw_version = 0x00000152, |
mikl_andre | 0:429446fe396d | 11 | /// Firmware Version: made of |
mikl_andre | 0:429446fe396d | 12 | /// - major,minor and patch indexes |
mikl_andre | 0:429446fe396d | 13 | /// - fw_id : "build-flavour" |
mikl_andre | 0:429446fe396d | 14 | /// FW_ID | MAJOR | MINOR | PATCH | HASH | |
mikl_andre | 0:429446fe396d | 15 | // 1B | 1B | 1B | 2B | 4B | |
mikl_andre | 0:429446fe396d | 16 | #if _SENSORS_SIMU_ |
mikl_andre | 0:429446fe396d | 17 | .rev.fw_version.id = 1, |
mikl_andre | 0:429446fe396d | 18 | #else |
mikl_andre | 0:429446fe396d | 19 | .rev.fw_version.id = 0, |
mikl_andre | 0:429446fe396d | 20 | #endif |
mikl_andre | 0:429446fe396d | 21 | .rev.fw_version.major = 1, |
mikl_andre | 0:429446fe396d | 22 | .rev.fw_version.minor = 0, |
mikl_andre | 0:429446fe396d | 23 | .rev.fw_version.patch = 0, |
mikl_andre | 0:429446fe396d | 24 | .rev.fw_version.hash = 0x00000000, |
mikl_andre | 0:429446fe396d | 25 | /// "file-system" signature |
mikl_andre | 0:429446fe396d | 26 | .rev.fs_crc = 0x00000000, |
mikl_andre | 0:429446fe396d | 27 | ); |
mikl_andre | 0:429446fe396d | 28 | |
mikl_andre | 0:429446fe396d | 29 | |
mikl_andre | 0:429446fe396d | 30 | GENERIC_FILE_INIT(simul, |
mikl_andre | 0:429446fe396d | 31 | .divider = 500, // Boot value |
mikl_andre | 0:429446fe396d | 32 | ); |
mikl_andre | 0:429446fe396d | 33 | |
mikl_andre | 0:429446fe396d | 34 | |
mikl_andre | 0:429446fe396d | 35 | GENERIC_FILE_INIT(mag_cfg, |
mikl_andre | 0:429446fe396d | 36 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 37 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 38 | .cfg.max_period = 300, |
mikl_andre | 0:429446fe396d | 39 | .cfg.max_diff = 100, |
mikl_andre | 0:429446fe396d | 40 | .cfg.threshold_high = 1000, |
mikl_andre | 0:429446fe396d | 41 | .cfg.threshold_low = -1000, |
mikl_andre | 0:429446fe396d | 42 | ); |
mikl_andre | 0:429446fe396d | 43 | |
mikl_andre | 0:429446fe396d | 44 | GENERIC_FILE_INIT(acc_cfg, |
mikl_andre | 0:429446fe396d | 45 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 46 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 47 | .cfg.max_period = 300, |
mikl_andre | 0:429446fe396d | 48 | .cfg.max_diff = 100, |
mikl_andre | 0:429446fe396d | 49 | .cfg.threshold_high = 500, |
mikl_andre | 0:429446fe396d | 50 | .cfg.threshold_low = -500, |
mikl_andre | 0:429446fe396d | 51 | ); |
mikl_andre | 0:429446fe396d | 52 | |
mikl_andre | 0:429446fe396d | 53 | GENERIC_FILE_INIT(gyr_cfg, |
mikl_andre | 0:429446fe396d | 54 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 55 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 56 | .cfg.max_period = 300, |
mikl_andre | 0:429446fe396d | 57 | .cfg.max_diff = 1000, |
mikl_andre | 0:429446fe396d | 58 | .cfg.threshold_high = 10000, |
mikl_andre | 0:429446fe396d | 59 | .cfg.threshold_low = -10000, |
mikl_andre | 0:429446fe396d | 60 | ); |
mikl_andre | 0:429446fe396d | 61 | |
mikl_andre | 0:429446fe396d | 62 | GENERIC_FILE_INIT(pre_cfg, |
mikl_andre | 0:429446fe396d | 63 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 64 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 65 | .cfg.max_period = 60, |
mikl_andre | 0:429446fe396d | 66 | .cfg.max_diff = 100, |
mikl_andre | 0:429446fe396d | 67 | .cfg.threshold_high = 120000, |
mikl_andre | 0:429446fe396d | 68 | .cfg.threshold_low = 90000, |
mikl_andre | 0:429446fe396d | 69 | ); |
mikl_andre | 0:429446fe396d | 70 | |
mikl_andre | 0:429446fe396d | 71 | GENERIC_FILE_INIT(hum_cfg, |
mikl_andre | 0:429446fe396d | 72 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 73 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 74 | .cfg.max_period = 60, |
mikl_andre | 0:429446fe396d | 75 | .cfg.max_diff = 100, |
mikl_andre | 0:429446fe396d | 76 | .cfg.threshold_high = 7000, |
mikl_andre | 0:429446fe396d | 77 | .cfg.threshold_low = 3000, |
mikl_andre | 0:429446fe396d | 78 | ); |
mikl_andre | 0:429446fe396d | 79 | |
mikl_andre | 0:429446fe396d | 80 | GENERIC_FILE_INIT(tem1_cfg, |
mikl_andre | 0:429446fe396d | 81 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 82 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 83 | .cfg.max_period = 60, |
mikl_andre | 0:429446fe396d | 84 | .cfg.max_diff = 100, |
mikl_andre | 0:429446fe396d | 85 | .cfg.threshold_high = 3500, |
mikl_andre | 0:429446fe396d | 86 | .cfg.threshold_low = 2000, |
mikl_andre | 0:429446fe396d | 87 | ); |
mikl_andre | 0:429446fe396d | 88 | |
mikl_andre | 0:429446fe396d | 89 | GENERIC_FILE_INIT(tem2_cfg, |
mikl_andre | 0:429446fe396d | 90 | .cfg.report_type = REPORT_ON_DIFFERENCE, |
mikl_andre | 0:429446fe396d | 91 | .cfg.period = 1000, |
mikl_andre | 0:429446fe396d | 92 | .cfg.max_period = 60, |
mikl_andre | 0:429446fe396d | 93 | .cfg.max_diff = 100, |
mikl_andre | 0:429446fe396d | 94 | .cfg.threshold_high = 9000, |
mikl_andre | 0:429446fe396d | 95 | .cfg.threshold_low = 7000, |
mikl_andre | 0:429446fe396d | 96 | ); |
mikl_andre | 0:429446fe396d | 97 | |
mikl_andre | 0:429446fe396d | 98 | #define FILE_QTY 8 |
mikl_andre | 0:429446fe396d | 99 | |
mikl_andre | 0:429446fe396d | 100 | static const void* file_map[FILE_QTY][2] = { |
mikl_andre | 0:429446fe396d | 101 | GENERIC_FILE_MAP(MAG_CFG_FILE_ID, mag_cfg), |
mikl_andre | 0:429446fe396d | 102 | GENERIC_FILE_MAP(ACC_CFG_FILE_ID, acc_cfg), |
mikl_andre | 0:429446fe396d | 103 | GENERIC_FILE_MAP(GYR_CFG_FILE_ID, gyr_cfg), |
mikl_andre | 0:429446fe396d | 104 | GENERIC_FILE_MAP(PRE_CFG_FILE_ID, pre_cfg), |
mikl_andre | 0:429446fe396d | 105 | GENERIC_FILE_MAP(HUM_CFG_FILE_ID, hum_cfg), |
mikl_andre | 0:429446fe396d | 106 | GENERIC_FILE_MAP(TEM1_CFG_FILE_ID, tem1_cfg), |
mikl_andre | 0:429446fe396d | 107 | GENERIC_FILE_MAP(TEM2_CFG_FILE_ID, tem2_cfg), |
mikl_andre | 0:429446fe396d | 108 | GENERIC_FILE_MAP(SIMUL_FILE_ID, simul), |
mikl_andre | 0:429446fe396d | 109 | }; |
mikl_andre | 0:429446fe396d | 110 | |
mikl_andre | 0:429446fe396d | 111 | void* file_get( uint8_t file_id ) |
mikl_andre | 0:429446fe396d | 112 | { |
mikl_andre | 0:429446fe396d | 113 | for (uint8_t i=0 ; i<FILE_QTY ; i++) |
mikl_andre | 0:429446fe396d | 114 | { |
mikl_andre | 0:429446fe396d | 115 | if ((uint8_t)file_map[i][0] == file_id) |
mikl_andre | 0:429446fe396d | 116 | { |
mikl_andre | 0:429446fe396d | 117 | return (void*)file_map[i][1]; |
mikl_andre | 0:429446fe396d | 118 | } |
mikl_andre | 0:429446fe396d | 119 | } |
mikl_andre | 0:429446fe396d | 120 | |
mikl_andre | 0:429446fe396d | 121 | ASSERT(false, "File %d does not exist\r\n"); |
mikl_andre | 0:429446fe396d | 122 | |
mikl_andre | 0:429446fe396d | 123 | return NULL; |
mikl_andre | 0:429446fe396d | 124 | } |
mikl_andre | 0:429446fe396d | 125 | |
mikl_andre | 0:429446fe396d | 126 | uint32_t fs_write_file(const uint8_t file_id, |
mikl_andre | 0:429446fe396d | 127 | const uint16_t offset, |
mikl_andre | 0:429446fe396d | 128 | const uint16_t size, |
mikl_andre | 0:429446fe396d | 129 | const uint8_t* const content) |
mikl_andre | 0:429446fe396d | 130 | { |
mikl_andre | 0:429446fe396d | 131 | uint32_t file = 0; |
mikl_andre | 0:429446fe396d | 132 | |
mikl_andre | 0:429446fe396d | 133 | DPRINT("WF %d\r\n", file_id); |
mikl_andre | 0:429446fe396d | 134 | |
mikl_andre | 0:429446fe396d | 135 | // Retrieve pointer to file |
mikl_andre | 0:429446fe396d | 136 | file = (uint32_t)file_get(file_id); |
mikl_andre | 0:429446fe396d | 137 | |
mikl_andre | 0:429446fe396d | 138 | if (!file) |
mikl_andre | 0:429446fe396d | 139 | { |
mikl_andre | 0:429446fe396d | 140 | return 0; |
mikl_andre | 0:429446fe396d | 141 | } |
mikl_andre | 0:429446fe396d | 142 | |
mikl_andre | 0:429446fe396d | 143 | // Write the new data |
mikl_andre | 0:429446fe396d | 144 | memcpy((void*)(file+offset), (void*)content, size); |
mikl_andre | 0:429446fe396d | 145 | |
mikl_andre | 0:429446fe396d | 146 | return size; |
mikl_andre | 0:429446fe396d | 147 | } |
mikl_andre | 0:429446fe396d | 148 | |
mikl_andre | 0:429446fe396d | 149 | uint32_t fs_read_file( const uint8_t file_id, |
mikl_andre | 0:429446fe396d | 150 | const uint16_t offset, |
mikl_andre | 0:429446fe396d | 151 | const uint16_t size, |
mikl_andre | 0:429446fe396d | 152 | uint8_t* buf) |
mikl_andre | 0:429446fe396d | 153 | { |
mikl_andre | 0:429446fe396d | 154 | uint32_t file = 0; |
mikl_andre | 0:429446fe396d | 155 | |
mikl_andre | 0:429446fe396d | 156 | DPRINT("RF %d\r\n", file_id); |
mikl_andre | 0:429446fe396d | 157 | |
mikl_andre | 0:429446fe396d | 158 | // Retrieve pointer to file |
mikl_andre | 0:429446fe396d | 159 | file = (uint32_t)file_get(file_id); |
mikl_andre | 0:429446fe396d | 160 | |
mikl_andre | 0:429446fe396d | 161 | if (!file) |
mikl_andre | 0:429446fe396d | 162 | { |
mikl_andre | 0:429446fe396d | 163 | return 0; |
mikl_andre | 0:429446fe396d | 164 | } |
mikl_andre | 0:429446fe396d | 165 | |
mikl_andre | 0:429446fe396d | 166 | // Read data |
mikl_andre | 0:429446fe396d | 167 | memcpy((void*)buf, (void*)(file+offset), size); |
mikl_andre | 0:429446fe396d | 168 | |
mikl_andre | 0:429446fe396d | 169 | return size; |
mikl_andre | 0:429446fe396d | 170 | } |