int os_timer_change(os_timer_t timer, os_timer_change_t change, bool fromISR, unsigned period, unsigned block, void* reserved) { portBASE_TYPE woken; switch (change) { case OS_TIMER_CHANGE_START: if (fromISR) return xTimerStartFromISR(timer, &woken)!=pdPASS; else return xTimerStart(timer, block)!=pdPASS; case OS_TIMER_CHANGE_RESET: if (fromISR) return xTimerResetFromISR(timer, &woken)!=pdPASS; else return xTimerReset(timer, block)!=pdPASS; case OS_TIMER_CHANGE_STOP: if (fromISR) return xTimerStopFromISR(timer, &woken)!=pdPASS; else return xTimerStop(timer, block)!=pdPASS; case OS_TIMER_CHANGE_PERIOD: if (fromISR) return xTimerChangePeriodFromISR(timer, period, &woken)!=pdPASS; else return xTimerChangePeriod(timer, period, block)!=pdPASS; } return -1; }
void prvCommsTask(void *pvParameters) { pvParameters = pvParameters; static uint8_t line[80]; static uint8_t characterPosition = 0; initGlobals(); /* Timer to cause outgoing communications to cease if nothing received for 10 seconds */ lapseCommsTimer = xTimerCreate("Lapse Comms",10000,pdFALSE,0,lapseCommsCallback); while(1) { /* Build a command line string before actioning. The task will block indefinitely waiting for input. */ char character; xQueueReceive(commsReceiveQueue,&character,portMAX_DELAY); if ((character == 0x0D) || (character == 0x0A) || (characterPosition > 78)) { if (lapseCommsTimer != NULL) xTimerReset(lapseCommsTimer,0); line[characterPosition] = 0; characterPosition = 0; parseCommand(line); } else line[characterPosition++] = character; } }
wiced_result_t wiced_rtos_start_timer( wiced_timer_t* timer ) { if ( xTimerReset( timer->handle, WICED_WAIT_FOREVER ) != pdPASS ) { return WICED_ERROR; } if ( xTimerStart( timer->handle, WICED_WAIT_FOREVER ) != pdPASS ) { return WICED_ERROR; } return WICED_SUCCESS; }
void GPS_NewData(uint16_t c) { gps.bytes_rx ++; if (!GPS_newFrame(c)) return; gps.frames_rx ++; sensorsSet(SENSOR_GPS); xTimerReset(gpsLostTimer, 10); gps.update = (gps.update == 1 ? 0 : 1); if (flag(FLAG_GPS_FIX) && gps.numSat > 4) xSemaphoreGive(gpsSemaphore); }
/* Overridden weak function, from hw_rf.c */ void hw_rf_postconf_cb(void) { BaseType_t xHigherPriorityTaskWoken; if (dg_configRF_RECALIBRATION_TIMER_TIMEOUT == 0) return; /* Start/Reset Timer */ if (is_called_from_isr()) { xTimerResetFromISR(recalib_timer, &xHigherPriorityTaskWoken); portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); } else { xTimerReset(recalib_timer, portMAX_DELAY); } }
static void prvQueueReceiveTask( void *pvParameters ) { unsigned long ulReceivedValue; /* Remove compiler warning in the case that configASSERT() is not defined. */ ( void ) pvParameters; /* Check the task parameter is as expected. */ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER ); for( ;; ) { /* Wait until something arrives in the queue - this task will block indefinitely provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. */ xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY ); /* To get here something must have been received from the queue, but is it the expected value? Normally calling printf() from a task is not a good idea. Here there is lots of stack space and only one task is using console IO so it is ok. */ if( ulReceivedValue == mainVALUE_SENT_FROM_TASK ) { printf( "Message received from task\r\n" ); } else if( ulReceivedValue == mainVALUE_SENT_FROM_TIMER ) { printf( "Message received from software timer\r\n" ); } else { printf( "Unexpected message\r\n" ); } /* Reset the timer if a key has been pressed. The timer will write mainVALUE_SENT_FROM_TIMER to the queue when it expires. */ if( _kbhit() != 0 ) { /* Remove the key from the input buffer. */ ( void ) _getch(); /* Reset the software timer. */ xTimerReset( xTimer, portMAX_DELAY ); } } }
/** * @brief Begin connect to MQTT broker * @param client: MQTT_Client reference * @retval None */ void ICACHE_FLASH_ATTR MQTT_Connect(MQTT_Client *mqttClient) { if (mqttClient->pCon) { // Clean up the old connection forcefully - using MQTT_Disconnect // does not actually release the old connection until the // disconnection callback is invoked. mqtt_tcpclient_delete(mqttClient); } mqttClient->pCon = (struct espconn *)calloc(1, sizeof(struct espconn)); mqttClient->pCon->type = ESPCONN_TCP; mqttClient->pCon->state = ESPCONN_NONE; mqttClient->pCon->proto.tcp = (esp_tcp *)calloc(1, sizeof(esp_tcp)); mqttClient->pCon->proto.tcp->local_port = espconn_port(); mqttClient->pCon->proto.tcp->remote_port = mqttClient->port; mqttClient->pCon->reserve = mqttClient; espconn_regist_connectcb(mqttClient->pCon, mqtt_tcpclient_connect_cb); espconn_regist_reconcb(mqttClient->pCon, mqtt_tcpclient_recon_cb); mqttClient->keepAliveTick = 0; mqttClient->reconnectTick = 0; xTimerReset(mqttClient->mqttTimer, portMAX_DELAY); xTimerStart(mqttClient->mqttTimer, portMAX_DELAY); if (UTILS_StrToIP(mqttClient->host, &mqttClient->pCon->proto.tcp->remote_ip)) { INFO("TCP: Connect to ip %s:%d\r\n", mqttClient->host, mqttClient->port); if (mqttClient->security) { #ifdef MQTT_SSL_ENABLE espconn_secure_connect(mqttClient->pCon); #else INFO("TCP: Do not support SSL\r\n"); #endif } else { espconn_connect(mqttClient->pCon); } } else { INFO("TCP: Connect to domain %s:%d\r\n", mqttClient->host, mqttClient->port); espconn_gethostbyname(mqttClient->pCon, mqttClient->host, &mqttClient->ip, mqtt_dns_found); } mqttClient->connState = TCP_CONNECTING; }
static bool_t gprs_write_fifo(const uint8_t *const payload, const uint16_t len) { DBG_ASSERT(payload != NULL __DBG_LINE); if (gprs_info.gprs_state == WORK_ON && len < SEND_SIZE) { if(gprs_info.data_mode) { wdt_clear(SOFT_WDT); led_set(LED_RED, TRUE); osel_memset(send.buf, 0x00, SEND_SIZE); osel_memcpy(send.buf, payload, len); send.len = len; write_fifo(send.buf, send.len); led_set(LED_RED, FALSE); return TRUE; } else { if(xSemaphoreTake(gprs_mutex, 600) == pdTRUE) { led_set(LED_RED, TRUE); //等待数据发送完成 xTimerReset(gprs_daemon_timer, 400); osel_memset(send_data, 0x00, SIZE); tfp_sprintf((char *)send_data, CIPSEND, len); osel_memset(send.buf, 0x00, SEND_SIZE); osel_memcpy(send.buf, payload, len); send.len = len; write_fifo(send_data, mystrlen((char *)send_data)); return TRUE; } } } return FALSE; }
void readTimerCallback( TimerHandle_t pxTimer ) { if(validData){ outputEvent(LINE_VALID_DATA); //Read pins and send message to sensor queue bool pin1 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_11); bool pin2 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_13); bool pin3 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_12); bool pin4 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_8); bool pin5 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_10); bool pin6 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_0); bool pin7 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_1); bool pin8 = SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_D, PORTS_BIT_POS_6); uint8_t line = 0; if(pin1) line += 0x1; if(pin2) line += 0x2; if(pin3) line += 0x4; if(pin4) line += 0x8; if(pin5) line += 0x10; if(pin6) line += 0x20; if(pin7) line += 0x40; if(pin8) line += 0x80; MESSAGE lineMsg; lineMsg.id = 0x36; lineMsg.msg = 0x12; lineMsg.data1 = line; lineMsg.data2 = 0x0; if( xQueueSendToBack(sensorQueue, (void *)&lineMsg, (TickType_t)0) != pdPASS ) { outputEvent(SENSOR_QUEUE_FULL); } else { outputEvent(SENT_TO_SENSOR_QUEUE); } validData = false; }else{ outputEvent(LINE_CAP_CHARGED); //Set Pins to digital input SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_B, PORTS_BIT_POS_11); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_B, PORTS_BIT_POS_13); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_B, PORTS_BIT_POS_12); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_G, PORTS_BIT_POS_8); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_A, PORTS_BIT_POS_10); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_F, PORTS_BIT_POS_0); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_F, PORTS_BIT_POS_1); SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_INPUT, PORT_CHANNEL_D, PORTS_BIT_POS_6); //Reset timer validData = true; if( xTimerReset( readTimer, 0 ) != pdPASS ){ outputEvent(READTIMER_NOT_RESET); } } }
bool os_timerTaskRestart(os_timerHandle_t handle) { return xTimerReset(handle->timerHandle, 0); }
bool SoftTimer::reset(uint32_t xBlockTime) { return xTimerReset(_hnd, xBlockTime) == pdPASS; }
/** * @brief Start or restart a timer. * @param timer_id timer ID obtained by \ref osTimerCreate. * @param millisec time delay value of the timer. * @retval status code that indicates the execution status of the function * @note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. */ osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) { osStatus result = osOK; #if (configUSE_TIMERS == 1) portBASE_TYPE taskWoken = pdFALSE; TickType_t ticks = millisec / portTICK_PERIOD_MS; if (xTimerIsTimerActive(timer_id) != pdFALSE) { if (inHandlerMode()) { if(xTimerResetFromISR(timer_id, &taskWoken) != pdPASS) { result = osErrorOS; } else { portEND_SWITCHING_ISR(taskWoken); result = osOK; } } else { if (xTimerReset(timer_id, 0) != pdPASS) result = osErrorOS; else result = osOK; } } else { if (ticks == 0) ticks = 1; if (inHandlerMode()) { if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) != pdPASS) result = osErrorOS; else { xTimerStartFromISR(timer_id, &taskWoken); portEND_SWITCHING_ISR(taskWoken); result = osOK; } } else { if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS) result = osErrorOS; else { if (xTimerStart(timer_id, 0) != pdPASS) result = osErrorOS; } } } #else result = osErrorOS; #endif return result; }
static void umac_impl_request_future_tick(umtick delta_tick) { xTimerChangePeriod(um_tim_hdl, delta_tick, 0); xTimerReset(um_tim_hdl, 0); }
void FreeRTOSTimer::reset() { xTimerReset(mTimerHandle, 0); }