/** * @brief Polled delay. * @note The real delay is always few cycles in excess of the specified * value. * @note This function is only available if the port layer supports the * option @p PORT_SUPPORTS_RT. * * @param[in] cycles number of cycles * * @xclass */ void chSysPolledDelayX(rtcnt_t cycles) { rtcnt_t start = chSysGetRealtimeCounterX(); rtcnt_t end = start + cycles; while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) { } }
/** * @brief Stops a measurement and chains to the next one using the same time * stamp. * * @param[in,out] tmp1 pointer to the @p time_measurement_t structure to be * stopped * @param[in,out] tmp2 pointer to the @p time_measurement_t structure to be * started * * * @xclass */ NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, time_measurement_t *tmp2) { /* Starts new measurement.*/ tmp2->last = chSysGetRealtimeCounterX(); /* Stops previous measurement using the same time stamp.*/ tm_stop(tmp1, tmp2->last, 0); }
static void memtest(void) { red_led_off(); while (true) { memtest_struct.rand_seed = chSysGetRealtimeCounterX(); memtest_run(&memtest_struct, MEMTEST_RUN_ALL); green_led_toggle(); } green_led_on(); green_led_off(); }
/** * @brief Writes a time stamp and increases the trace buffer pointer. * * @notapi */ static NOINLINE void trace_next(void) { ch.dbg.trace_buffer.ptr->time = chVTGetSystemTimeX(); #if PORT_SUPPORTS_RT == TRUE ch.dbg.trace_buffer.ptr->rtstamp = chSysGetRealtimeCounterX(); #else ch.dbg.trace_buffer.ptr->rtstamp = (rtcnt_t)0; #endif /* Trace hook, useful in order to interface debug tools.*/ CH_CFG_TRACE_HOOK(ch.dbg.trace_buffer.ptr); if (++ch.dbg.trace_buffer.ptr >= &ch.dbg.trace_buffer.buffer[CH_DBG_TRACE_BUFFER_SIZE]) { ch.dbg.trace_buffer.ptr = &ch.dbg.trace_buffer.buffer[0]; } }
static void pattern_fill(void) { size_t i; srand(chSysGetRealtimeCounterX()); for(i=0; i<NAND_PAGE_SIZE; i++){ ref_buf[i] = rand() & 0xFF; } /* protect bad mark */ ref_buf[NAND_PAGE_DATA_SIZE] = 0xFF; ref_buf[NAND_PAGE_DATA_SIZE + 1] = 0xFF; memcpy(nand_buf, ref_buf, NAND_PAGE_SIZE); /* paranoid mode ON */ osalDbgCheck(0 == memcmp(ref_buf, nand_buf, NAND_PAGE_SIZE)); }
/** * @brief Stops a measurement. * @pre The @p time_measurement_t structure must be initialized. * * @param[in,out] tmp pointer to a @p time_measurement_t structure * * @xclass */ NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) { tm_stop(tmp, chSysGetRealtimeCounterX(), ch.tm.offset); }
/** * @brief Starts a measurement. * @pre The @p time_measurement_t structure must be initialized. * * @param[in,out] tmp pointer to a @p TimeMeasurement structure * * @xclass */ NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp) { tmp->last = chSysGetRealtimeCounterX(); }
CCM_FUNC static THD_FUNCTION(ThreadCAN, arg) { event_listener_t el; CANTxFrame txmsg; CANRxFrame rxmsg; uint16_t i; bool pidserved; (void)arg; chRegSetThreadName("CAN Bus"); while(CAND1.state != CAN_READY) chThdSleepMilliseconds(10); while(SDU1.state != SDU_READY) chThdSleepMilliseconds(10); chEvtRegister(&CAND1.rxfull_event, &el, 0); while(TRUE) { // Are we using coms for sensor data? If not just sleep. if (settings.sensorsInput != SENSORS_INPUT_COM && (settings.functions & FUNC_OBD_SERVER) == 0) { chThdSleepMilliseconds(100); continue; } //checkCanFilters(&CAND1, &cancfg); if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(10)) == 0) { continue; } while (canReceive(&CAND1, CAN_ANY_MAILBOX, &rxmsg, TIME_IMMEDIATE) == MSG_OK) { /* Process message.*/ if (dbg_can) { chprintf(DBG_STREAM, "->[CANBUS][%08x][SID:%03x][RTR:%01x]", chSysGetRealtimeCounterX(), rxmsg.SID, rxmsg.RTR); for(i = 0; i < rxmsg.DLC; i++) { chprintf(DBG_STREAM, ":%02x", rxmsg.data8[i]); } chprintf(DBG_STREAM, "\r\n"); } if (settings.functions & FUNC_OBD_SERVER) { pidserved = serveCanOBDPidRequest(&CAND1, &txmsg, &rxmsg); if (dbg_can && pidserved) { chprintf(DBG_STREAM, "<-[CANBUS][%08x][SID:%03x][RTR:%01x]", chSysGetRealtimeCounterX(), txmsg.SID, txmsg.RTR); for(i = 0; i < txmsg.DLC; i++) { chprintf(DBG_STREAM, ":%02x", txmsg.data8[i]); } chprintf(DBG_STREAM, "\r\n"); } else if (dbg_can) { chprintf(DBG_STREAM, "!![CANBUS][%08x][ignored sender %03x]\r\n", chSysGetRealtimeCounterX(), rxmsg.SID); } } if ((settings.functions & FUNC_OBD_SERVER) == 0) { if (settings.sensorsInput == SENSORS_INPUT_OBD_CAN) { readCanOBDPidResponse(&rxmsg); } else if (settings.sensorsInput == SENSORS_INPUT_YAMAHA_CAN) { readCanYamahaPid(&rxmsg); } } } if (settings.sensorsInput == SENSORS_INPUT_OBD_CAN && (settings.functions & FUNC_OBD_SERVER) == 0) { // Request OBD PIDs sendCanOBDFrames(&CAND1, &txmsg); if (dbg_can) { chprintf(DBG_STREAM, "<-[CANBUS][%08x][SID:%03x][RTR:%01x]", chSysGetRealtimeCounterX(), txmsg.SID, txmsg.RTR); for(i = 0; i < 8; i++) { chprintf(DBG_STREAM, ":%02x", txmsg.data8[i]); } chprintf(DBG_STREAM, "\r\n"); } chThdSleepMilliseconds(100); // ~10Hz } } chEvtUnregister(&CAND1.rxfull_event, &el); return; }