forked from EmbeddedNim/picostdlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
freertos_blink.nim
44 lines (31 loc) · 948 Bytes
/
freertos_blink.nim
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
import picostdlib
import picostdlib/lib/freertos
let led = DefaultLedPin
let mainTaskPriority = tskIDLE_PRIORITY + 2
let blinkTaskPriority = tskIDLE_PRIORITY + 1
proc blinkTask(params: pointer) {.cdecl.} =
let blinkDelay = cast[ptr uint32](params)[]
while true:
echo "blink task!"
led.put(High)
vTaskDelay(blinkDelay)
led.put(Low)
vTaskDelay(blinkDelay)
proc mainTask(params: pointer) {.cdecl.} =
led.init()
led.setDir(Out)
echo "main task!"
var blink1TaskHandle: TaskHandleT
var blink1Delay: uint32 = 500
discard xTaskCreate(blinkTask, "BlinkTask1", 128, blink1Delay.addr, blinkTaskPriority, blink1TaskHandle.addr)
while true:
vTaskDelay(1000)
led.deinit()
proc vLaunch() =
stdioInitAll()
var mainTaskHandle: TaskHandleT
discard xTaskCreate(mainTask, "MainTask", 128, nil, mainTaskPriority, mainTaskHandle.addr)
vTaskStartScheduler()
while true:
tightLoopContents()
vLaunch()