Difference between revisions of "Zephyr rtos threads"

From Wiki at Neela Nurseries
Jump to: navigation, search
m
m
Line 1: Line 1:
 +
Keywords:  Zephyr thread analyzer module
 +
 +
 +
 
== [[#top|^]] OVERVIEW ==
 
== [[#top|^]] OVERVIEW ==
  
Line 4: Line 8:
  
 
Also worth noting Zephyr provides a [https://docs.zephyrproject.org/2.6.0/guides/flash_debug/thread-analyzer.html thread analyzer module] for Zephyr based apps.
 
Also worth noting Zephyr provides a [https://docs.zephyrproject.org/2.6.0/guides/flash_debug/thread-analyzer.html thread analyzer module] for Zephyr based apps.
 +
 +
On this top level page there is mention of passing data between threads:
 +
*  https://docs.zephyrproject.org/2.6.0/reference/kernel/index.html
  
  

Revision as of 07:34, 5 October 2021

Keywords: Zephyr thread analyzer module


^ OVERVIEW

Kinda limited tutorials on Zephyr RTOS threads, but seemingly solid documentation on zephyrproject.org site. A specific example starting point may be among Zephyr source tree's samples directory . . . `$ grep -nr k_thread_create ./*` shows thread creation in a SPI Bluetooth driver sample. Path from root Zephyr RTOS source tree is zephyr/drivers/bluetooth/hci.

Also worth noting Zephyr provides a thread analyzer module for Zephyr based apps.

On this top level page there is mention of passing data between threads:


^ Zephyr RTOS Thread API

Some Zephyr RTOS API functions to learn:

    • k_sem_take(&lte_connected, K_FOREVER);
    • k_work_schedule(&connect_work, K_NO_WAIT);

Additionally some further Zephyr thread entities and mostly API functions include:

    • k_thread
    • K_THREAD_STACK versus K_KERNEL_STACK
    • k_thread_create()
    • k_thread_
    • k_thread_join()
    • k_thread_abort()
    • k_thread_suspend()
    • k_thread_resume()
    Thread options K_ESSENTIAL, K_SSE_REGS and more . . .

Unsure whether this routine a Zephyr one:

 work_init();


Following non-function entities from aws_iot main.c appear important:

77 static struct k_work_delayable shadow_update_work;
78 static struct k_work_delayable connect_work;
79 static struct k_work shadow_update_version_work;


^ Specific Zephyr documentation pages

Following example code block matches k_thread_create() code in zephyr/drivers/bluetooth/hci/spi.c:519:


^ Example Zephyr Thread Creation

Rough search narrowing in on specific thread creation and use in aws_iot sample project from nRF Connect SDK:

cpguest@ubuntu-vm-0p2:/mnt/host-os-dev-area/pulse-pro/firmware-stage1/aws-iot-stand-alone/src$ grep -nr k_ ./*.c
30:static struct k_work_delayable shadow_update_work;
31:static struct k_work_delayable connect_work;
32:static struct k_work shadow_update_version_work;
150:static void connect_work_fn(struct k_work *work)
166:    k_work_schedule(&connect_work,
170:static void shadow_update_work_fn(struct k_work *work)
186:    k_work_schedule(&shadow_update_work,
190:static void shadow_update_version_work_fn(struct k_work *work)
242:            (void)k_work_cancel_delayable(&connect_work);
258:            k_work_submit(&shadow_update_version_work);
262:            k_work_schedule(&shadow_update_work,
283:            (void)k_work_cancel_delayable(&shadow_update_work);
284:            k_work_schedule(&connect_work, K_NO_WAIT);
335:static void work_init(void)
337:    k_work_init_delayable(&shadow_update_work, shadow_update_work_fn);
338:    k_work_init_delayable(&connect_work, connect_work_fn);
339:    k_work_init(&shadow_update_version_work, shadow_update_version_work_fn);
356:            k_sem_give(&lte_connected);
513:    work_init();
523:    k_sem_take(&lte_connected, K_FOREVER);
528:    k_work_schedule(&connect_work, K_NO_WAIT);

cpguest@ubuntu-vm-0p2:/mnt/host-os-dev-area/pulse-pro/firmware-stage1/aws-iot-stand-alone/src$ grep -n connect_work ./*.c
31:static struct k_work_delayable connect_work;
150:static void connect_work_fn(struct k_work *work)
166:    k_work_schedule(&connect_work,
242:            (void)k_work_cancel_delayable(&connect_work);
284:            k_work_schedule(&connect_work, K_NO_WAIT);
338:    k_work_init_delayable(&connect_work, connect_work_fn);
528:    k_work_schedule(&connect_work, K_NO_WAIT);
cpguest@ubuntu-vm-0p2:/mnt/host-os-dev-area/pulse-pro/firmware-stage1/aws-iot-stand-alone/src$

.
.
.


^ Specific Function Associated With Zephyr Thread

150 static void connect_work_fn(struct k_work *work)
151 {
152         int err;
153
154         if (cloud_connected) {
155                 return;
156         }
157
158         err = aws_iot_connect(NULL);
159         if (err) {
160                 printk("aws_iot_connect, error: %d\n", err);
161         }
162
163         printk("Next connection retry in %d seconds\n",
164                CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS);
165
166         k_work_schedule(&connect_work,
167                         K_SECONDS(CONFIG_CONNECTION_RETRY_TIMEOUT_SECONDS));
168 }
150:static void connect_work_fn(struct k_work *work)
338:    k_work_init_delayable(&connect_work, connect_work_fn);


z