mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 17:35:54 +08:00
添加智能灯固件代码
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(task_watchdog)
|
||||
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := task_watchdog
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Example: task_watchdog
|
||||
|
||||
This test code shows how to initialize the task watchdog, add tasks to the
|
||||
watchdog task list, feeding the tasks, deleting tasks from the watchdog task
|
||||
list, and deinitializing the task watchdog.
|
||||
|
||||
|
||||
### Test:
|
||||
|
||||
Program should run without error. Comment out "esp_task_wdt_feed()" to observe
|
||||
a watchdog timeout.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
from __future__ import unicode_literals
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
def test_examples_task_watchdog(env, extra_data):
|
||||
|
||||
dut = env.get_dut('task_watchdog', 'examples/system/task_watchdog')
|
||||
dut.start_app()
|
||||
|
||||
dut.expect_all('Initialize TWDT',
|
||||
'Delay for 10 seconds', timeout=30)
|
||||
dut.expect_all('Unsubscribing and deleting tasks',
|
||||
'Complete', timeout=20)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_task_watchdog()
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "task_watchdog_example_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,3 @@
|
||||
#
|
||||
# Main Makefile. This is basically the same as a component makefile.
|
||||
#
|
||||
@@ -0,0 +1,85 @@
|
||||
/* Task_Watchdog Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_task_wdt.h"
|
||||
|
||||
#define TWDT_TIMEOUT_S 3
|
||||
#define TASK_RESET_PERIOD_S 2
|
||||
|
||||
/*
|
||||
* Macro to check the outputs of TWDT functions and trigger an abort if an
|
||||
* incorrect code is returned.
|
||||
*/
|
||||
#define CHECK_ERROR_CODE(returned, expected) ({ \
|
||||
if(returned != expected){ \
|
||||
printf("TWDT ERROR\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
static TaskHandle_t task_handles[portNUM_PROCESSORS];
|
||||
|
||||
//Callback for user tasks created in app_main()
|
||||
void reset_task(void *arg)
|
||||
{
|
||||
//Subscribe this task to TWDT, then check if it is subscribed
|
||||
CHECK_ERROR_CODE(esp_task_wdt_add(NULL), ESP_OK);
|
||||
CHECK_ERROR_CODE(esp_task_wdt_status(NULL), ESP_OK);
|
||||
|
||||
while(1){
|
||||
//reset the watchdog every 2 seconds
|
||||
CHECK_ERROR_CODE(esp_task_wdt_reset(), ESP_OK); //Comment this line to trigger a TWDT timeout
|
||||
vTaskDelay(pdMS_TO_TICKS(TASK_RESET_PERIOD_S * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
printf("Initialize TWDT\n");
|
||||
//Initialize or reinitialize TWDT
|
||||
CHECK_ERROR_CODE(esp_task_wdt_init(TWDT_TIMEOUT_S, false), ESP_OK);
|
||||
|
||||
//Subscribe Idle Tasks to TWDT if they were not subscribed at startup
|
||||
#ifndef CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
|
||||
esp_task_wdt_add(xTaskGetIdleTaskHandleForCPU(0));
|
||||
#endif
|
||||
#ifndef CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
|
||||
esp_task_wdt_add(xTaskGetIdleTaskHandleForCPU(1));
|
||||
#endif
|
||||
|
||||
//Create user tasks and add them to watchdog
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){
|
||||
xTaskCreatePinnedToCore(reset_task, "reset task", 1024, NULL, 10, &task_handles[i], i);
|
||||
}
|
||||
|
||||
printf("Delay for 10 seconds\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(10000)); //Delay for 10 seconds
|
||||
|
||||
printf("Unsubscribing and deleting tasks\n");
|
||||
//Delete and unsubscribe Users Tasks from Task Watchdog, then unsubscribe idle task
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){
|
||||
vTaskDelete(task_handles[i]); //Delete user task first (prevents the resetting of an unsubscribed task)
|
||||
CHECK_ERROR_CODE(esp_task_wdt_delete(task_handles[i]), ESP_OK); //Unsubscribe task from TWDT
|
||||
CHECK_ERROR_CODE(esp_task_wdt_status(task_handles[i]), ESP_ERR_NOT_FOUND); //Confirm task is unsubscribed
|
||||
|
||||
//unsubscribe idle task
|
||||
CHECK_ERROR_CODE(esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(i)), ESP_OK); //Unsubscribe Idle Task from TWDT
|
||||
CHECK_ERROR_CODE(esp_task_wdt_status(xTaskGetIdleTaskHandleForCPU(i)), ESP_ERR_NOT_FOUND); //Confirm Idle task has unsubscribed
|
||||
}
|
||||
|
||||
|
||||
//Deinit TWDT after all tasks have unsubscribed
|
||||
CHECK_ERROR_CODE(esp_task_wdt_deinit(), ESP_OK);
|
||||
CHECK_ERROR_CODE(esp_task_wdt_status(NULL), ESP_ERR_INVALID_STATE); //Confirm TWDT has been deinitialized
|
||||
|
||||
printf("Complete\n");
|
||||
}
|
||||
Reference in New Issue
Block a user