-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
91 lines (71 loc) · 2.15 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include "pico/stdlib.h"
// FreeRTOS
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#define LED_PIN_1 8
#define LED_PIN_2 (LED_PIN_1 + 1)
/* Prototypes for the standard FreeRTOS callback/hook functions implemented
within this file. */
void vApplicationMallocFailedHook( void );
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
void task1_handle(void *p);
void task2_handle(void *p);
TaskHandle_t htask1 = NULL;
TaskHandle_t htask2 = NULL;
int main()
{
stdio_init_all();
puts("Hello world RP2040 FreeRTOS!\n");
gpio_init(LED_PIN_1);
gpio_set_dir(LED_PIN_1, GPIO_OUT);
gpio_init(LED_PIN_2);
gpio_set_dir(LED_PIN_2, GPIO_OUT);
xTaskCreate(task1_handle, "task1", 512, NULL, 1, &htask1);
xTaskCreate(task2_handle, "task2", 512, NULL, 1, &htask2);
vTaskStartScheduler();
while(1);
return 0;
}
void task1_handle(void *p)
{
while(1)
{
gpio_put(LED_PIN_1, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_put(LED_PIN_1, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void task2_handle(void *p)
{
while(1)
{
gpio_put(LED_PIN_2, 0);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_put(LED_PIN_2, 1);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void vApplicationMallocFailedHook( void )
{
/* Called if a call to pvPortMalloc() fails because there is insufficient
free memory available in the FreeRTOS heap. pvPortMalloc() is called
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores. The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
/* Force an assert. */
configASSERT( ( volatile void * ) NULL );
}
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
/* Force an assert. */
configASSERT( ( volatile void * ) NULL );
}