Esempio n. 1
0
os_timerHandle_t os_timerTaskNew(os_timerConfig_t* conf, uint16_t initDelay)
{
    bool ret = false;
    os_timerHandle_t handle = calloc(1, sizeof(struct os_timerHandle));
    handle->timerHandle = xTimerCreate(conf->name,
            msToTicks(conf->period),
            !conf->oneShot,
            NULL,
            conf->callback);
    if(handle->timerHandle && !conf->startLater) {
        ret = xTimerStart(handle->timerHandle, initDelay);
        if(ret) {
            return handle;
        } else {
            xTimerDelete(handle->timerHandle, 0);
            free(handle);
            return NULL;
        }
    } else if(conf->startLater) {
        handle->initDelay = initDelay;
        return handle;
    } else {
        free(handle);
        return NULL;
    }
}
Esempio n. 2
0
static int logDeleteBlock(int id)
{
  int i;
  struct log_ops * ops;
  struct log_ops * opsNext;
  
  for (i=0; i<LOG_MAX_BLOCKS; i++)
    if (logBlocks[i].id == id) break;
  
  if (i >= LOG_MAX_BLOCKS) {
    ERROR("trying to delete block id %d that doesn't exist.", id);
    return ENOENT;
  }
  
  ops = logBlocks[i].ops;
  while (ops)
  {
    opsNext = ops->next;
    opsFree(ops);
    ops = opsNext;
  }
  
  if (logBlocks[i].timer != 0) {
    xTimerStop(logBlocks[i].timer, portMAX_DELAY);
    xTimerDelete(logBlocks[i].timer, portMAX_DELAY);
    logBlocks[i].timer = 0;
  }
  
  logBlocks[i].id = BLOCK_ID_FREE;
  return 0;
}
Esempio n. 3
0
static void sj_timer_callback(TimerHandle_t t) {
  v7_val_t *cb = (v7_val_t *) pvTimerGetTimerID(t);
  xTimerDelete(t, 0);
  sj_invoke_cb0(s_v7, *cb);
  v7_disown(s_v7, cb);
  free(cb);
}
Esempio n. 4
0
static void sj_timer_callback(xTimerHandle t) {
  struct timer_info *ti = (struct timer_info *) t;
  xTimerDelete(ti->t, 0);
  sj_invoke_cb0(v7, *ti->cb);
  v7_disown(v7, ti->cb);
  free(ti->cb);
  free(ti);
}
Esempio n. 5
0
bool os_timerTaskDelete(os_timerHandle_t handle)
{
    bool ret;
    ret = xTimerDelete(handle->timerHandle, 0);
    if(ret)
        free(handle);
    return ret;
}
void prvShutdown( void )
{
	 /* Check if timer is created */
	 if (xTimer)
		 xTimerDelete(xTimer, 0);
	 vSemaphoreDelete( xSemaphore_led );
	 vTaskDelete( xTask );
}
Esempio n. 7
0
wiced_result_t wiced_rtos_deinit_timer( wiced_timer_t* timer )
{
    if ( xTimerDelete( timer->handle, WICED_WAIT_FOREVER ) != pdPASS )
    {
        return WICED_ERROR;
    }

    return WICED_SUCCESS;
}
Esempio n. 8
0
void ICACHE_FLASH_ATTR
MQTT_DeleteClient(MQTT_Client *mqttClient)
{
	mqttClient->connState = MQTT_DELETING;
	xSemaphoreGive(mqttClient->mqttTaskSem);
	xTimerDelete(mqttClient->mqttTimer, portMAX_DELAY);

	xSemaphoreTake(mqttClient->mqttExitSem, portMAX_DELAY);
}
Esempio n. 9
0
/// Delete a timer that was created by \ref osTimerCreate.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerCreate.
/// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
osStatus osTimerDelete (osTimerId timer_id)
{
    osStatus result = osOK;
    
    /* try to delete the soft timer and wait max RTL_TIMER_API_MAX_BLOCK_TICKS 
        to send the delete command to the timer command queue */
    if (xTimerDelete(timer_id, portMAX_DELAY ) != pdPASS) {
        result = osErrorOS;
    }

    return result;
}
Esempio n. 10
0
static void sj_timer_callback(xTimerHandle t) {
  struct timer_info *ti = (struct timer_info *) t;
  xTimerDelete(ti->t, 0);

  /*
   * Invoke the timer callback (depending on the build options, it might not be
   * actually invoked immediately, but might be scheduled for the invocation
   * asap instead; see `sj_invoke_cb()`)
   */
  sj_invoke_cb0(v7, *ti->cb);

  /*
   * Disown and free the callback value which was allocated and owned in
   * `global_set_timeout()`
   */
  v7_disown(v7, ti->cb);
  free(ti->cb);

  /* Also free `timer_info` which was allocated in `sj_set_timeout()` */
  free(ti);
}
Esempio n. 11
0
/**
* @brief  Delete a timer.
* @param  timer_id      timer ID obtained by \ref osTimerCreate
* @retval  status code that indicates the execution status of the function.
* @note   MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
*/
osStatus osTimerDelete (osTimerId timer_id)
{
osStatus result = osOK;

#if (configUSE_TIMERS == 1)

   if (inHandlerMode()) {
     return osErrorISR;
  }
  else { 
    if ((xTimerDelete(timer_id, osWaitForever )) != pdPASS) {
      result = osErrorOS;
    }
  } 
    
#else 
  result = osErrorOS;
#endif 
 
  return result;
}
Esempio n. 12
0
SoftTimer::~SoftTimer()
{
	xTimerDelete(_hnd, portMAX_DELAY);
}
Esempio n. 13
0
esp_err_t iot_ota_start(const char *server_ip, uint16_t server_port, const char *file_dir, uint32_t ticks_to_wait)
{
    TimerHandle_t ota_timer = NULL;
    int socket_id = -1;
    esp_err_t ret = ESP_FAIL;
    esp_ota_handle_t upgrade_handle = 0;
    POINT_ASSERT(TAG, server_ip, ESP_ERR_INVALID_ARG);
    POINT_ASSERT(TAG, file_dir, ESP_ERR_INVALID_ARG);
    if (g_ota_mux == NULL) {
        g_ota_mux = xSemaphoreCreateMutex();
    }
    if (g_ota_mux == NULL) {
        ret = ESP_ERR_NO_MEM;
        goto OTA_FINISH;
    }
    if (pdTRUE != xSemaphoreTake(g_ota_mux, ticks_to_wait)){
        ret = ESP_ERR_TIMEOUT;
        goto OTA_FINISH;
    }
    g_ota_timeout = false;

    ESP_LOGI(TAG, "ota starting");
    const esp_partition_t *upgrade_part = NULL;
    const esp_partition_t *part_confed = esp_ota_get_boot_partition();
    const esp_partition_t *part_running = esp_ota_get_running_partition();
    if (part_confed != part_running) {
        ESP_LOGI(TAG, "partition error");
        ret = ESP_FAIL;
        goto OTA_FINISH;
    }
    ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)",
             part_confed->type, part_confed->subtype, part_confed->address);
    socket_id = socket(AF_INET, SOCK_STREAM, 0);
    if (socket_id == -1) {
        ESP_LOGI(TAG, "create socket error!");
        goto OTA_FINISH;
    }
    if (ticks_to_wait != portMAX_DELAY) {
        ota_timer = xTimerCreate("ota_timer", ticks_to_wait, pdFALSE, (void*)socket_id, download_timer_cb);
        if (ota_timer == NULL) {
            ret = ESP_ERR_NO_MEM;
            goto OTA_FINISH;
        }
        //todo: to check the result of RTOS timer APIs.
        xTimerStart(ota_timer, ticks_to_wait / portTICK_PERIOD_MS);
    }
    ret = connect_http_server(server_ip, server_port, socket_id);
    OTA_CHECK(TAG, "connect http server error!", ret, OTA_FINISH);
    char http_request[64];
    sprintf(http_request, "GET %s HTTP/1.1\r\nHost: %s:%d \r\n\r\n", file_dir, server_ip, server_port);
    ret = send(socket_id, http_request, strlen(http_request), 0);
    if (ret == -1) {
        ESP_LOGI(TAG, "send request to server  error!");
        ret = ESP_FAIL;
        goto OTA_FINISH;
    }
    upgrade_part = esp_ota_get_next_update_partition(NULL);
    if (upgrade_part == NULL) {
        ret = ESP_FAIL;
        goto OTA_FINISH;
    }
    ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
                upgrade_part->subtype, upgrade_part->address);
    ret = esp_ota_begin(upgrade_part, OTA_SIZE_UNKNOWN, &upgrade_handle);
    OTA_CHECK(TAG, "ota begin error!", ret, OTA_FINISH);
    ret = ota_download(socket_id, upgrade_handle);
    OTA_CHECK(TAG, "ota data download error!", ret, OTA_FINISH);
    //Stop timer since downloading has finished.
    xTimerStop(ota_timer, ticks_to_wait / portTICK_PERIOD_MS);
    ret = esp_ota_end(upgrade_handle);
    upgrade_handle = 0;
    OTA_CHECK(TAG, "ota end error!", ret, OTA_FINISH);
    ret = esp_ota_set_boot_partition(upgrade_part);
    OTA_CHECK(TAG, "set boot partition error!", ret, OTA_FINISH);
    ESP_LOGI(TAG, "ota succeed");

OTA_FINISH:
    if (upgrade_handle != 0) {
        esp_ota_end(upgrade_handle);
        upgrade_handle = 0;
    }
    if (g_ota_timeout == true) {
        ESP_LOGI(TAG, "ota timeout");
        ret = ESP_ERR_TIMEOUT;
    } else if (socket_id != -1) {
        close(socket_id);
    }
    if (ticks_to_wait != portMAX_DELAY && ota_timer != NULL) {
        xTimerStop(ota_timer, 0);
        xTimerDelete(ota_timer, 0);
        ota_timer = NULL;
    }
    if (g_ota_mux != NULL) {
        xSemaphoreGive(g_ota_mux);
    }
    return ret;
}
void
IIS328DQ::stop()
{
    if(_call != NULL)
        xTimerDelete(_call, portMAX_DELAY);
}
Esempio n. 15
0
static void prvCreateAndDeleteStaticallyAllocatedTimers( void )
{
TimerHandle_t xTimer;
UBaseType_t uxVariableToIncrement;
const TickType_t xTimerPeriod = pdMS_TO_TICKS( 20 );
BaseType_t xReturned;

/* StaticTimer_t is a publicly accessible structure that has the same size
and alignment requirements as the real timer structure.  It is provided as a
mechanism for applications to know the size of the timer structure (which is
dependent on the architecture and configuration file settings) without breaking
the strict data hiding policy by exposing the real timer internals.  This
StaticTimer_t variable is passed into the xTimerCreateStatic() function calls
within this function. */
StaticTimer_t xTimerBuffer;

	/* Create the software time.  xTimerCreateStatic() has an extra parameter
	than the normal xTimerCreate() API function.  The parameter is a pointer to
	the StaticTimer_t structure that will hold the software timer structure.  If
	the parameter is passed as NULL then the structure will be allocated
	dynamically, just as if xTimerCreate() had been called. */
	xTimer = xTimerCreateStatic( "T1",					/* Text name for the task.  Helps debugging only.  Not used by FreeRTOS. */
								 xTimerPeriod,			/* The period of the timer in ticks. */
								 pdTRUE,				/* This is an auto-reload timer. */
								 ( void * ) &uxVariableToIncrement,	/* The variable incremented by the test is passed into the timer callback using the timer ID. */
								 prvTimerCallback,		/* The function to execute when the timer expires. */
								 &xTimerBuffer );		/* The buffer that will hold the software timer structure. */

	/* The timer handle should equal the static timer structure passed into the
	xTimerCreateStatic() function. */
	configASSERT( xTimer == ( TimerHandle_t ) &xTimerBuffer );

	/* Set the variable to 0, wait for a few timer periods to expire, then check
	the timer callback has incremented the variable to the expected value. */
	uxVariableToIncrement = 0;

	/* This is a low priority so a block time should not be needed. */
	xReturned = xTimerStart( xTimer, staticDONT_BLOCK );

	if( xReturned != pdPASS )
	{
		xErrorOccurred = pdTRUE;
	}

	vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );

	/* By now the timer should have expired staticMAX_TIMER_CALLBACK_EXECUTIONS
	times, and then stopped itself. */
	if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
	{
		xErrorOccurred = pdTRUE;
	}

	/* Finished with the timer, delete it. */
	xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );

	/* Again, as this is a low priority task it is expected that the timer
	command will have been sent even without a block time being used. */
	if( xReturned != pdPASS )
	{
		xErrorOccurred = pdTRUE;
	}

	/* Just to show the check task that this task is still executing. */
	uxCycleCounter++;

	/* Now do the same using a dynamically allocated software timer to ensure
	the delete function is working correctly in both the static and dynamic
	allocation cases. */
	#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
	{
		xTimer = xTimerCreate( "T1",								/* Text name for the task.  Helps debugging only.  Not used by FreeRTOS. */
							    xTimerPeriod,						/* The period of the timer in ticks. */
								pdTRUE,								/* This is an auto-reload timer. */
								( void * ) &uxVariableToIncrement,	/* The variable incremented by the test is passed into the timer callback using the timer ID. */
								prvTimerCallback );					/* The function to execute when the timer expires. */

		configASSERT( xTimer != NULL );

		uxVariableToIncrement = 0;
		xReturned = xTimerStart( xTimer, staticDONT_BLOCK );

		if( xReturned != pdPASS )
		{
			xErrorOccurred = pdTRUE;
		}

		vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );

		if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
		{
			xErrorOccurred = pdTRUE;
		}

		xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );

		if( xReturned != pdPASS )
		{
			xErrorOccurred = pdTRUE;
		}
	}
	#endif
}
Esempio n. 16
0
int os_timer_destroy(os_timer_t timer, void* reserved)
{
    return xTimerDelete(timer, CONCURRENT_WAIT_FOREVER)!=pdPASS;
}
Esempio n. 17
0
FreeRTOSTimer::~FreeRTOSTimer()
{
	xTimerDelete(mTimerHandle, 0);
}