ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
tusb_tasks.c File Reference
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_check.h"
#include "tinyusb.h"
#include "tusb_tasks.h"
Include dependency graph for tusb_tasks.c:

Go to the source code of this file.

Functions

static void tusb_device_task (void *arg)
 This top level thread processes all usb events and invokes callbacks.
esp_err_t tusb_run_task (void)
 This helper function creates and starts a task which wraps tud_task().
esp_err_t tusb_stop_task (void)
 This helper function stops and destroys the task created by tusb_run_task().

Variables

static const char * TAG = "tusb_tsk"
static TaskHandle_t s_tusb_tskh

Function Documentation

◆ tusb_device_task()

void tusb_device_task ( void * arg)
static

This top level thread processes all usb events and invokes callbacks.

Definition at line 21 of file tusb_tasks.c.

22{
23 ESP_LOGD(TAG, "tinyusb task started");
24 while (1) { // RTOS forever loop
25 tud_task();
26 }
27}
#define ESP_LOGD
Definition esp_log.h:22
static const char * TAG
Definition main/main.c:31

References ESP_LOGD, and TAG.

Referenced by tusb_run_task().

Here is the caller graph for this function:

◆ tusb_run_task()

esp_err_t tusb_run_task ( void )

This helper function creates and starts a task which wraps tud_task().

The wrapper function basically wraps tud_task and some log. Default parameters: stack size and priority as configured, argument = NULL, not pinned to any core. If you have more requirements for this task, you can create your own task which calls tud_task as the last step.

Return values
ESP_OKrun tinyusb main task successfully
ESP_FAILrun tinyusb main task failed of internal error
ESP_ERR_INVALID_STATEtinyusb main task has been created before

Definition at line 29 of file tusb_tasks.c.

30{
31 // This function is not garanteed to be thread safe, if invoked multiple times without calling `tusb_stop_task`, will cause memory leak
32 // doing a sanity check anyway
33 ESP_RETURN_ON_FALSE(!s_tusb_tskh, ESP_ERR_INVALID_STATE, TAG, "TinyUSB main task already started");
34 // Create a task for tinyusb device stack:
35 xTaskCreate(tusb_device_task, "TinyUSB", CONFIG_TINYUSB_TASK_STACK_SIZE, NULL, CONFIG_TINYUSB_TASK_PRIORITY, &s_tusb_tskh);
36 ESP_RETURN_ON_FALSE(s_tusb_tskh, ESP_FAIL, TAG, "create TinyUSB main task failed");
37 return ESP_OK;
38}
#define ESP_OK
Definition esp_err.h:23
static void tusb_device_task(void *arg)
This top level thread processes all usb events and invokes callbacks.
Definition tusb_tasks.c:21
static TaskHandle_t s_tusb_tskh
Definition tusb_tasks.c:16

References ESP_OK, s_tusb_tskh, TAG, and tusb_device_task().

Referenced by tinyusb_driver_install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tusb_stop_task()

esp_err_t tusb_stop_task ( void )

This helper function stops and destroys the task created by tusb_run_task().

Return values
ESP_OKstop and destory tinyusb main task successfully
ESP_ERR_INVALID_STATEtinyusb main task hasn't been created yet

Definition at line 40 of file tusb_tasks.c.

41{
42 ESP_RETURN_ON_FALSE(s_tusb_tskh, ESP_ERR_INVALID_STATE, TAG, "TinyUSB main task not started yet");
43 vTaskDelete(s_tusb_tskh);
44 s_tusb_tskh = NULL;
45 return ESP_OK;
46}

References ESP_OK, s_tusb_tskh, and TAG.

Variable Documentation

◆ s_tusb_tskh

TaskHandle_t s_tusb_tskh
static

Definition at line 16 of file tusb_tasks.c.

Referenced by tusb_run_task(), and tusb_stop_task().

◆ TAG

const char* TAG = "tusb_tsk"
static

Definition at line 15 of file tusb_tasks.c.