Danger-alarm/SOFTWARE-FreeRTOS/Source/main.c
2024-06-03 16:27:41 +08:00

87 lines
2.0 KiB
C

/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* Standard demo includes. */
#include "TimerDemo.h"
#include "QueueOverwrite.h"
#include "EventGroupsDemo.h"
#include "IntSemTest.h"
#include "TaskNotify.h"
#include "MAIN.h"
#include "lwipopts.h"
#include "common.h"
#ifndef PICO_DEFAULT_LED_PIN
#warning pio/hello_pio example requires a board with a regular LED
#define PICO_DEFAULT_LED_PIN 25
#endif
void Led_Blinky(void *pvParameters)
{
(void)pvParameters;
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
_printTaskStackHighWaterMark();
while (1) {
vTaskDelay(pdMS_TO_TICKS(500));
gpio_put(LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(500));
gpio_put(LED_PIN, 0);
_printTaskStackHighWaterMark();
}
}
void Read_Onboard_Temperature(void *pvParameters)
{
(void)pvParameters;
adc_init();
adc_set_temp_sensor_enabled(true);
adc_select_input(4); // Input 4 is the onboard temperature sensor.
//_printTaskStackHighWaterMark();
while (1) {
const float conversionFactor = 3.3f / (1 << 12);
float adc = (float)adc_read() * conversionFactor;
float tempC = 27.0f - (adc - 0.706f) / 0.001721f;
printf("Onboard temperature %.02f°C %.02f°F\n", tempC, (tempC * 9 / 5 + 32));
//_printTaskStackHighWaterMark();
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
}
}
int main(void)
{
stdio_init_all();
sleep_ms(1000);
//set_sys_clock_khz(250000, true);
BaseType_t xReturned;
TaskHandle_t Led_Blinky_xHandle = NULL;
// 板载LED闪烁
xReturned = xTaskCreate(Led_Blinky, "Blinky task", 512, NULL, tskIDLE_PRIORITY, &Led_Blinky_xHandle);
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
printf("Blinky Task Error!");
}
vTaskStartScheduler();
return 0;
}