2017-10-27 02:05:38 +08:00
|
|
|
.. _96b_carbon_multi_thread_blinky:
|
|
|
|
|
|
|
|
Basic Thread Example
|
|
|
|
####################
|
|
|
|
|
|
|
|
Overview
|
|
|
|
********
|
|
|
|
|
|
|
|
This example demonstrates spawning of multiple threads using K_THREAD_DEFINE.
|
|
|
|
|
2017-12-21 22:03:27 +08:00
|
|
|
The example works by spawning three threads. The first two threads control a
|
2017-10-27 02:05:38 +08:00
|
|
|
separate LED. Both of these LEDs (USR1 and USR2) have their individual loop
|
|
|
|
control and timing logic defined by separate functions.
|
|
|
|
|
2017-12-21 22:03:27 +08:00
|
|
|
After either thread toggles its LED, it also pushes information into a
|
|
|
|
FIFO identifying which thread toggled its LED and how many times it
|
|
|
|
was done.
|
|
|
|
|
|
|
|
The third thread, ``uart_out()``, uses printk (over the UART) to
|
|
|
|
display the information that comes through the FIFO.
|
2017-10-27 02:05:38 +08:00
|
|
|
|
|
|
|
- blink1() controls the USR1 LED that has a 100ms sleep cycle
|
|
|
|
- blink2() controls the USR2 LED that has a 1000ms sleep cycle
|
|
|
|
|
|
|
|
Each thread is then defined at compile time using K_THREAD_DEFINE.
|
|
|
|
|
|
|
|
Building
|
|
|
|
********
|
|
|
|
|
2017-11-12 17:12:44 +08:00
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/basic/threads
|
|
|
|
:board: 96b_carbon
|
|
|
|
:goals: build flash
|
|
|
|
:compact:
|