static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { uint32_t counter = 0; uint8_t ubWritedata_8b = 0x3C; uint32_t uwReadwritestatus = 0; TimeMeasurement tm; (void)argv; if (argc > 0) { chprintf(chp, "Usage: write\r\n"); return; } tmObjectInit(&tm); tmStartMeasurement(&tm); /* Write data value to all SDRAM memory */ for (counter = 0; counter < IS42S16400J_SIZE; counter++) { *(__IO uint8_t*) (SDRAM_BANK_ADDR + counter) = (uint8_t)(ubWritedata_8b + counter); } tmStopMeasurement(&tm); uint32_t write_ms = RTT2MS(tm.last); if (!uwReadwritestatus) { chprintf(chp, "SDRAM written in %dms.\r\n", write_ms); } }
/** * @brief Initializes the Time Measurement unit. * * @init */ void tmInit(void) { TimeMeasurement tm; /* Time Measurement subsystem calibration, it does a null measurement and calculates the call overhead which is subtracted to real measurements.*/ measurement_offset = 0; tmObjectInit(&tm); tmStartMeasurement(&tm); tmStopMeasurement(&tm); measurement_offset = tm.last; }
static void timerHandler(GPTDriver *gptp) { (void)gptp; #ifdef DEBUG_MB tmStopMeasurement (&tm); palSetPad (BOARD_LED2_P, BOARD_LED2); #endif chSysLockFromIsr(); { vMBPortSetWithinException (TRUE) ; if (pxMBPortCBTimerExpired () == TRUE) rescheduleJbus485FromIsr(); vMBPortSetWithinException (FALSE) ; } chSysUnlockFromIsr(); }
static void tachometer_cb(EXTDriver *extp, expchannel_t channel){ (void)extp; (void)channel; tmStopMeasurement(&tacho_tmup); /* reject short random spikes */ if (tacho_tmup.last > TACHO_LIM){ chSysLockFromIsr(); speedometer_mb.postI(tacho_tmup.last); bkpOdometer++; chSysUnlockFromIsr(); } tmStartMeasurement(&tacho_tmup); }
static void cmd_check(BaseSequentialStream *chp, int argc, char *argv[]) { uint32_t counter = 0; uint8_t ubWritedata_8b = 0x3C, ubReaddata_8b = 0; uint32_t uwReadwritestatus = 0; TimeMeasurement tm; (void)argv; if (argc > 0) { chprintf(chp, "Usage: check\r\n"); return; } tmObjectInit(&tm); tmStartMeasurement(&tm); /* Read back SDRAM memory and check content correctness*/ counter = 0; uwReadwritestatus = 0; while ((counter < IS42S16400J_SIZE) && (uwReadwritestatus == 0)) { ubReaddata_8b = *(__IO uint8_t*)(SDRAM_BANK_ADDR + counter); if ( ubReaddata_8b != (uint8_t)(ubWritedata_8b + counter)) { uwReadwritestatus = 1; chprintf(chp, "Error at %d, expected %d but read %d.\r\n", counter, ubWritedata_8b + counter, ubReaddata_8b); } counter++; } tmStopMeasurement(&tm); uint32_t check_ms = RTT2MS(tm.last); //FIXME time this if (!uwReadwritestatus) { chprintf(chp, "SDRAM read and check completed successfully in %dms.\r\n", check_ms); } }
static void itg3200_cb(EXTDriver *extp, expchannel_t channel){ (void)extp; (void)channel; chSysLockFromIsr(); #if !GYRO_UPDATE_PERIOD_HARDCODED if (itg3200_period_measured < 2){ if (itg3200_period_measured == 0){ tmStartMeasurement(&itg3200_tmup); } else if(itg3200_period_measured == 1){ tmStopMeasurement(&itg3200_tmup); GyroUpdatePeriodUs = RTT2US(itg3200_tmup.last); } itg3200_period_measured++; } #endif /* !GYRO_UPDATE_PERIOD_HARDCODED */ itg3200_sem.signalI(); lsm303_sem.signalI(); chSysUnlockFromIsr(); }
static void cmd_sdram(BaseSequentialStream *chp, int argc, char *argv[]) { uint32_t counter = 0; uint8_t ubWritedata_8b = 0x3C, ubReaddata_8b = 0; uint32_t uwReadwritestatus = 0; TimeMeasurement tm; (void)argv; if (argc > 0) { chprintf(chp, "Usage: sdram\r\n"); return; } tmObjectInit(&tm); tmStartMeasurement(&tm); // /* Erase SDRAM memory */ // for (counter = 0; counter < IS42S16400J_SIZE; counter++) // { // *(__IO uint8_t*) (SDRAM_BANK_ADDR + counter) = (uint8_t)0x0; // } /* Write data value to all SDRAM memory */ for (counter = 0; counter < IS42S16400J_SIZE; counter++) { *(__IO uint8_t*) (SDRAM_BANK_ADDR + counter) = (uint8_t)(ubWritedata_8b + counter); } tmStopMeasurement(&tm); uint32_t write_ms = RTT2MS(tm.last); tmStartMeasurement(&tm); /* Read back SDRAM memory */ counter = 0; while ((counter < IS42S16400J_SIZE)) { ubReaddata_8b = *(__IO uint8_t*)(SDRAM_BANK_ADDR + counter); counter++; } tmStopMeasurement(&tm); uint32_t read_ms = RTT2MS(tm.last); /* Read back SDRAM memory and check content correctness*/ counter = 0; uwReadwritestatus = 0; while ((counter < IS42S16400J_SIZE) && (uwReadwritestatus == 0)) { ubReaddata_8b = *(__IO uint8_t*)(SDRAM_BANK_ADDR + counter); if ( ubReaddata_8b != (uint8_t)(ubWritedata_8b + counter)) { uwReadwritestatus = 1; chprintf(chp, "Error at %d, expected %d but read %d.\r\n", counter, ubWritedata_8b + counter, ubReaddata_8b); } counter++; } if (!uwReadwritestatus) { chprintf(chp, "SDRAM test completed successfully, writing entire memory took %dms, reading it took %dms.\r\n", write_ms, read_ms); } }
/* * @brief ... * @details ... */ static void dht11_lld_ext_handler(EXTDriver *extp, expchannel_t channel) { // (void)extp; dht11_t *sensor = sensor_handlers[channel]; if (sensor == NULL) { return; } // if (lldLockISR(&sensor->lock) == true) { switch (sensor->state) { case DHT11_WAIT_RESPONSE: sensor->bit_count++; if (sensor->bit_count == 3) { sensor->bit_count = 0; sensor->data = 0; sensor->state = DHT11_READ_DATA; } break; case DHT11_READ_DATA: sensor->bit_count++; if (sensor->bit_count % 2 == 1) { tmStartMeasurement(&sensor->time_measurment); sensor->data <<= 1; } else { tmStopMeasurement(&sensor->time_measurment); if (RTT2US(sensor->time_measurment.last) > 50) { sensor->data += 1; } } if (sensor->bit_count == 64) { sensor->bit_count = 0; sensor->crc = 0; sensor->state = DHT11_READ_CRC; } break; case DHT11_READ_CRC: sensor->bit_count++; //sensor->crc = sensor->crc << 1; if (sensor->bit_count % 2 == 1) { tmStartMeasurement(&sensor->time_measurment); sensor->crc <<= 1; } else { tmStopMeasurement(&sensor->time_measurment); if (RTT2US(sensor->time_measurment.last) > 40) { sensor->crc += 1; } } if (sensor->bit_count == 16) { chSysLockFromIsr(); extChannelDisableI(sensor->ext_drv, sensor->ext_pin); if (chVTIsArmedI(&sensor->timer) == true) { chVTResetI(&sensor->timer); } chSysUnlockFromIsr(); sensor->temp = (sensor->data & 0xFF00) >> 8; sensor->humidity = (sensor->data & 0xFF000000) >> 24; sensor->state = DHT11_READ_OK; } break; case DHT11_UNINIT: case DHT11_IDLE: case DHT11_READ_REQUEST: case DHT11_READ_OK: case DHT11_BUSY: case DHT11_ERROR: break; } lldUnlockISR(&sensor->lock); }