amiro-os / test / periphery-lld / L3G4200D_v1 / aos_test_L3G4200D.c @ 65ebff5f
History | View | Annotate | Download (11.329 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | e545e620 | Thomas Schöpping | |
| 5 | This program is free software: you can redistribute it and/or modify
|
||
| 6 | it under the terms of the GNU General Public License as published by
|
||
| 7 | the Free Software Foundation, either version 3 of the License, or
|
||
| 8 | (at your option) any later version.
|
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful,
|
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 13 | GNU General Public License for more details.
|
||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License
|
||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
| 17 | */
|
||
| 18 | |||
| 19 | ddf34c3d | Thomas Schöpping | #include <amiroos.h> |
| 20 | 4c72a54c | Thomas Schöpping | #include <aos_test_L3G4200D.h> |
| 21 | e545e620 | Thomas Schöpping | |
| 22 | 4c72a54c | Thomas Schöpping | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
| 23 | ddf34c3d | Thomas Schöpping | |
| 24 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 25 | /* LOCAL DEFINITIONS */
|
||
| 26 | /******************************************************************************/
|
||
| 27 | |||
| 28 | /******************************************************************************/
|
||
| 29 | /* EXPORTED VARIABLES */
|
||
| 30 | /******************************************************************************/
|
||
| 31 | |||
| 32 | /******************************************************************************/
|
||
| 33 | /* LOCAL TYPES */
|
||
| 34 | /******************************************************************************/
|
||
| 35 | |||
| 36 | /******************************************************************************/
|
||
| 37 | /* LOCAL VARIABLES */
|
||
| 38 | /******************************************************************************/
|
||
| 39 | |||
| 40 | /******************************************************************************/
|
||
| 41 | /* LOCAL FUNCTIONS */
|
||
| 42 | /******************************************************************************/
|
||
| 43 | |||
| 44 | /******************************************************************************/
|
||
| 45 | /* EXPORTED FUNCTIONS */
|
||
| 46 | /******************************************************************************/
|
||
| 47 | e545e620 | Thomas Schöpping | |
| 48 | /**
|
||
| 49 | 4c72a54c | Thomas Schöpping | * @brief L3G4200D test function.
|
| 50 | e545e620 | Thomas Schöpping | *
|
| 51 | * @param[in] stream Stream for input/output.
|
||
| 52 | 4c72a54c | Thomas Schöpping | * @param[in] test Test object.
|
| 53 | e545e620 | Thomas Schöpping | *
|
| 54 | 4c72a54c | Thomas Schöpping | * @return Test result value.
|
| 55 | e545e620 | Thomas Schöpping | */
|
| 56 | 4c72a54c | Thomas Schöpping | aos_testresult_t aosTestL3g4200dFunc(BaseSequentialStream* stream, const aos_test_t* test)
|
| 57 | e545e620 | Thomas Schöpping | {
|
| 58 | 4c72a54c | Thomas Schöpping | aosDbgCheck(test->data != NULL && ((aos_test_l3g4200ddata_t*)(test->data)) != NULL); |
| 59 | e545e620 | Thomas Schöpping | |
| 60 | // local variables
|
||
| 61 | 4c72a54c | Thomas Schöpping | aos_testresult_t result = {0, 0};
|
| 62 | b23ca7cc | Thomas Schöpping | int32_t status; |
| 63 | e545e620 | Thomas Schöpping | uint8_t data = 0;
|
| 64 | uint8_t write_data[5];
|
||
| 65 | uint8_t read_data[5];
|
||
| 66 | int16_t sdata[3];
|
||
| 67 | uint8_t status_reg; |
||
| 68 | eventmask_t event_mask; |
||
| 69 | bool success = false; |
||
| 70 | uint8_t fifo = 0x5F;
|
||
| 71 | event_listener_t el; |
||
| 72 | |||
| 73 | for (uint8_t dataIdx = 0; dataIdx < 4; dataIdx++) { |
||
| 74 | write_data[dataIdx] = (dataIdx+1)*11; |
||
| 75 | } |
||
| 76 | write_data[4] = 0; |
||
| 77 | |||
| 78 | chprintf(stream, "check identity...\n");
|
||
| 79 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_read_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, L3G4200D_LLD_REGISTER_WHO_AM_I, &data, 1);
|
| 80 | e545e620 | Thomas Schöpping | if(status == APAL_STATUS_SUCCESS && data == L3G4200D_LLD_WHO_AM_I){
|
| 81 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 82 | e545e620 | Thomas Schöpping | } else {
|
| 83 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X, data: %d\n", status, data);
|
| 84 | e545e620 | Thomas Schöpping | } |
| 85 | |||
| 86 | chprintf(stream, "write register...\n");
|
||
| 87 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_write_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, L3G4200D_LLD_REGISTER_CTRL_REG1, write_data, 1);
|
| 88 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS) {
|
| 89 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 90 | e545e620 | Thomas Schöpping | } else {
|
| 91 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 92 | e545e620 | Thomas Schöpping | } |
| 93 | |||
| 94 | chprintf(stream, "read register...\n");
|
||
| 95 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_read_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, L3G4200D_LLD_REGISTER_CTRL_REG1, &data, 1);
|
| 96 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS && data == write_data[0]) { |
| 97 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 98 | e545e620 | Thomas Schöpping | } else {
|
| 99 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X, data: %d\n", status, data);
|
| 100 | e545e620 | Thomas Schöpping | } |
| 101 | |||
| 102 | chprintf(stream, "write multiple registers...\n");
|
||
| 103 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_write_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, L3G4200D_LLD_REGISTER_CTRL_REG1, write_data, 5);
|
| 104 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS) {
|
| 105 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 106 | e545e620 | Thomas Schöpping | } else {
|
| 107 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 108 | e545e620 | Thomas Schöpping | } |
| 109 | |||
| 110 | chprintf(stream, "read multiple registers...\n");
|
||
| 111 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_read_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, L3G4200D_LLD_REGISTER_CTRL_REG1, read_data, 5);
|
| 112 | e545e620 | Thomas Schöpping | uint8_t errors = 0;
|
| 113 | for (uint8_t dataIdx = 0; dataIdx < 5; dataIdx++) { |
||
| 114 | if (read_data[dataIdx] != write_data[dataIdx]) {
|
||
| 115 | ++errors; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | if (status == APAL_STATUS_SUCCESS && errors == 0) { |
||
| 119 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 120 | e545e620 | Thomas Schöpping | } else {
|
| 121 | for (uint8_t dataIdx = 0; dataIdx < 5; dataIdx++) { |
||
| 122 | chprintf(stream, "\t\tStatus: %d, CTRL_REG%d: %d, write_data: %d\n", status, dataIdx+1, read_data[dataIdx], write_data[dataIdx]); |
||
| 123 | } |
||
| 124 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X, errors: %d\n", status, errors);
|
| 125 | e545e620 | Thomas Schöpping | } |
| 126 | |||
| 127 | chprintf(stream, "read config...\n");
|
||
| 128 | l3g4200d_lld_cfg_t cfg; |
||
| 129 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_read_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &cfg); |
| 130 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS) {
|
| 131 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 132 | e545e620 | Thomas Schöpping | } else {
|
| 133 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 134 | e545e620 | Thomas Schöpping | } |
| 135 | |||
| 136 | chprintf(stream, "write config...\n");
|
||
| 137 | cfg.registers.ctrl_reg1 = L3G4200D_LLD_PD | L3G4200D_LLD_DR_100_HZ | L3G4200D_LLD_BW_12_5 | L3G4200D_LLD_ZEN | L3G4200D_LLD_YEN | L3G4200D_LLD_XEN; |
||
| 138 | //cfg.registers.ctrl_reg1 = L3G4200D_LLD_PD | L3G4200D_LLD_DR_800_HZ | L3G4200D_LLD_BW_20 | L3G4200D_LLD_ZEN | L3G4200D_LLD_YEN | L3G4200D_LLD_XEN;
|
||
| 139 | cfg.registers.ctrl_reg3 = 0x07;
|
||
| 140 | cfg.registers.ctrl_reg5 |= L3G4200D_LLD_FIFO_EN; |
||
| 141 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_write_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, cfg); |
| 142 | e545e620 | Thomas Schöpping | uint8_t reg1 = cfg.data[0];
|
| 143 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &cfg); |
| 144 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS && cfg.data[0] == reg1) { |
| 145 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 146 | e545e620 | Thomas Schöpping | } else {
|
| 147 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 148 | e545e620 | Thomas Schöpping | } |
| 149 | |||
| 150 | chprintf(stream, "read gyro data for five seconds...\n");
|
||
| 151 | status = APAL_STATUS_OK; |
||
| 152 | for (uint8_t i = 0; i < 5; ++i) { |
||
| 153 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_all_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, sdata, &cfg); |
| 154 | e545e620 | Thomas Schöpping | chprintf(stream, "\t\tX = %6d\tY = %6d\tZ = %6d\n", sdata[0], sdata[1], sdata[2]); |
| 155 | aosThdSSleep(1);
|
||
| 156 | } |
||
| 157 | if (status == APAL_STATUS_SUCCESS) {
|
||
| 158 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 159 | e545e620 | Thomas Schöpping | } else {
|
| 160 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 161 | e545e620 | Thomas Schöpping | } |
| 162 | |||
| 163 | chprintf(stream, "read X axis for five seconds...\n");
|
||
| 164 | status = APAL_STATUS_SUCCESS; |
||
| 165 | for (uint32_t i = 0; i <= 5; i++) { |
||
| 166 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &(sdata[0]), L3G4200D_LLD_X_AXIS, &cfg);
|
| 167 | e545e620 | Thomas Schöpping | chprintf(stream, "\t\tX = %6d\n", sdata[0]); |
| 168 | aosThdSSleep(1);
|
||
| 169 | } |
||
| 170 | if (status == APAL_STATUS_SUCCESS) {
|
||
| 171 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 172 | e545e620 | Thomas Schöpping | } else {
|
| 173 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 174 | e545e620 | Thomas Schöpping | } |
| 175 | |||
| 176 | chprintf(stream, "read Y axis for five seconds...\n");
|
||
| 177 | status = APAL_STATUS_SUCCESS; |
||
| 178 | for (uint32_t i = 0; i <= 5; i++) { |
||
| 179 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &(sdata[0]), L3G4200D_LLD_Y_AXIS, &cfg);
|
| 180 | e545e620 | Thomas Schöpping | chprintf(stream, "\t\tY = %6d\n", sdata[0]); |
| 181 | aosThdSSleep(1);
|
||
| 182 | } |
||
| 183 | if (status == APAL_STATUS_SUCCESS) {
|
||
| 184 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 185 | e545e620 | Thomas Schöpping | } else {
|
| 186 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 187 | e545e620 | Thomas Schöpping | } |
| 188 | |||
| 189 | chprintf(stream, "read Z axis for five seconds...\n");
|
||
| 190 | status = APAL_STATUS_SUCCESS; |
||
| 191 | for (uint32_t i = 0; i <= 5; i++) { |
||
| 192 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &(sdata[0]), L3G4200D_LLD_Z_AXIS, &cfg);
|
| 193 | e545e620 | Thomas Schöpping | chprintf(stream, "\t\tZ = %6d\n", sdata[0]); |
| 194 | aosThdSSleep(1);
|
||
| 195 | } |
||
| 196 | if (status == APAL_STATUS_SUCCESS) {
|
||
| 197 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 198 | e545e620 | Thomas Schöpping | } else {
|
| 199 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 200 | e545e620 | Thomas Schöpping | } |
| 201 | aosThdMSleep(10);
|
||
| 202 | |||
| 203 | chprintf(stream, "read status register...\n");
|
||
| 204 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_read_status_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &status_reg); |
| 205 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS) {
|
| 206 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 207 | e545e620 | Thomas Schöpping | } else {
|
| 208 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 209 | e545e620 | Thomas Schöpping | } |
| 210 | |||
| 211 | chprintf(stream, "read interrupt config...\n");
|
||
| 212 | l3g4200d_lld_int_cfg_t int_cfg; |
||
| 213 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_read_int_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &int_cfg); |
| 214 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS) {
|
| 215 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 216 | e545e620 | Thomas Schöpping | } else {
|
| 217 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 218 | e545e620 | Thomas Schöpping | } |
| 219 | |||
| 220 | chprintf(stream, "write interrupt config...\n");
|
||
| 221 | int_cfg.registers.int1_tsh_xh = 10;
|
||
| 222 | 4c72a54c | Thomas Schöpping | status = l3g4200d_lld_write_int_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, int_cfg); |
| 223 | e545e620 | Thomas Schöpping | l3g4200d_lld_int_cfg_t int_cfg2; |
| 224 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_int_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, &int_cfg2); |
| 225 | e545e620 | Thomas Schöpping | if (status == APAL_STATUS_SUCCESS && int_cfg.registers.int1_tsh_xh == 10) { |
| 226 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 227 | e545e620 | Thomas Schöpping | } else {
|
| 228 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 229 | e545e620 | Thomas Schöpping | } |
| 230 | |||
| 231 | chprintf(stream, "interrupt test: read fifo until empty...\n");
|
||
| 232 | 4c72a54c | Thomas Schöpping | chEvtRegister(((aos_test_l3g4200ddata_t*)(test->data))->src, &el, 0);
|
| 233 | status = l3g4200d_lld_write_fifo_ctrl_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd,fifo); |
||
| 234 | e545e620 | Thomas Schöpping | fifo = 0;
|
| 235 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_fifo_ctrl_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd,&fifo); |
| 236 | status |= l3g4200d_lld_read_all_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, sdata, &cfg); |
||
| 237 | e545e620 | Thomas Schöpping | chEvtGetAndClearFlags(&el); |
| 238 | aosThdSSleep(1);
|
||
| 239 | chEvtGetAndClearFlags(&el); |
||
| 240 | success = false;
|
||
| 241 | for (uint8_t i = 0; i < 200; i++) { |
||
| 242 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_all_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, sdata, &cfg); |
| 243 | e545e620 | Thomas Schöpping | event_mask = chEvtWaitAnyTimeout(~0, TIME_IMMEDIATE);
|
| 244 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_fifo_src_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd,&fifo); |
| 245 | e545e620 | Thomas Schöpping | if (event_mask != 0 && ((fifo & L3G4200D_LLD_EMPTY) || fifo == 0)) { |
| 246 | success = true;
|
||
| 247 | break;
|
||
| 248 | } |
||
| 249 | aosThdMSleep(1);
|
||
| 250 | } |
||
| 251 | if (status == APAL_STATUS_SUCCESS && success) {
|
||
| 252 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 253 | e545e620 | Thomas Schöpping | } else {
|
| 254 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 255 | e545e620 | Thomas Schöpping | } |
| 256 | |||
| 257 | fifo = 0x4A;
|
||
| 258 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_write_fifo_ctrl_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd,fifo); |
| 259 | e545e620 | Thomas Schöpping | cfg.registers.ctrl_reg1 = L3G4200D_LLD_PD | L3G4200D_LLD_DR_800_HZ | L3G4200D_LLD_BW_20 | L3G4200D_LLD_ZEN | L3G4200D_LLD_YEN | L3G4200D_LLD_XEN; |
| 260 | cfg.registers.ctrl_reg3 = 0x04;
|
||
| 261 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_write_config(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, cfg); |
| 262 | e545e620 | Thomas Schöpping | chprintf(stream, "interrupt test: wait until wtm reached...\n");
|
| 263 | for (uint8_t i = 0; i < 200; i++) { |
||
| 264 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_all_data(((aos_test_l3g4200ddata_t*)(test->data))->l3gd, sdata, &cfg); |
| 265 | e545e620 | Thomas Schöpping | event_mask = chEvtWaitAnyTimeout(~0, TIME_IMMEDIATE);
|
| 266 | 4c72a54c | Thomas Schöpping | status |= l3g4200d_lld_read_fifo_src_register(((aos_test_l3g4200ddata_t*)(test->data))->l3gd,&fifo); |
| 267 | e545e620 | Thomas Schöpping | if (event_mask != 0 && (fifo & L3G4200D_LLD_WTM)) { |
| 268 | success = true;
|
||
| 269 | break;
|
||
| 270 | } |
||
| 271 | aosThdMSleep(10);
|
||
| 272 | } |
||
| 273 | if (status == APAL_STATUS_SUCCESS && success) {
|
||
| 274 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
| 275 | e545e620 | Thomas Schöpping | } else {
|
| 276 | 4c72a54c | Thomas Schöpping | aosTestFailed(stream, &result); |
| 277 | e545e620 | Thomas Schöpping | } |
| 278 | |||
| 279 | 4c72a54c | Thomas Schöpping | chEvtUnregister(((aos_test_l3g4200ddata_t*)(test->data))->src, &el); |
| 280 | e545e620 | Thomas Schöpping | aosThdMSleep(10);
|
| 281 | |||
| 282 | 4c72a54c | Thomas Schöpping | aosTestInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(L3G4200DDriver)); |
| 283 | e545e620 | Thomas Schöpping | |
| 284 | return result;
|
||
| 285 | } |
||
| 286 | |||
| 287 | 4c72a54c | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |