-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sahaj Sarup <[email protected]>
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BOARD ?= 96b_carbon | ||
|
||
CONF_FILE = prj.conf | ||
|
||
include ${ZEPHYR_BASE}/Makefile.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 96Boards Carbon Basic Multi Thread Example | ||
## Overview | ||
|
||
This example demonstrates spawning of multiple threads using K_THREAD_DEFINE. | ||
|
||
The example works by spawning three threads, each controlling a separate LED | ||
on the 96Boards Carbon board. Each of these LEDs (USR1, USR2 and BT) have | ||
their individual loop control and timing logic defined by separate functions. | ||
|
||
- blink1() controls the USR1 LED that has a 100ms sleep cycle | ||
- blink2() controls the USR2 LED that has a 1000ms sleep cycle | ||
- blink3() controls the BT LED that increases sleep by 100ms every cycle | ||
upto 600ms and then resets to 100ms | ||
|
||
|
||
Each thread is then defined at compile time using K_THREAD_DEFINE. | ||
|
||
Apart from that, a main() thread is also present that provides a basic shell | ||
based on the shell sample at zephyr_base/samples/subsys/shell/shell/ | ||
|
||
The sample has been written keeping the 96Boards Carbon in mind, feel free to | ||
modify it accordingly. | ||
*** | ||
|
||
## Building | ||
|
||
### COMPILE | ||
```shell | ||
$ cd zephyr_base/path/to/sample/zephyr_multithread_blinky | ||
$ make | ||
``` | ||
|
||
### Flashing via OTG | ||
```shell | ||
$ sudo dfu-util -d [0483:df11] -a 0 -D outdir/96b_carbon/zephyr.bin -s 0x08000000 | ||
``` | ||
### Flash via UART | ||
```shell | ||
$ sudo stm32flash -b 115200 -g 0x0 -w outdir/96b_carbon/zephyr.bin /dev/ttyUSB0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_PRINTK=y | ||
CONFIG_CONSOLE_SHELL=y | ||
CONFIG_KERNEL_SHELL=y | ||
CONFIG_OBJECT_TRACING=y | ||
CONFIG_THREAD_MONITOR=y | ||
CONFIG_INIT_STACKS=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
obj-y = main.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <zephyr.h> | ||
#include <device.h> | ||
#include <gpio.h> | ||
#include <misc/printk.h> | ||
#include <shell/shell.h> | ||
|
||
/* size of stack area used by each thread */ | ||
#define STACKSIZE 128 | ||
|
||
/* scheduling priority used by each thread */ | ||
#define PRIORITY 7 | ||
|
||
#define MY_SHELL_MODULE "sample_module" | ||
|
||
/*-----shell code fom <zephyr_base>/samples/subsys/shell/shell/------*/ | ||
static int shell_cmd_ping(int argc, char *argv[]) | ||
{ | ||
ARG_UNUSED(argc); | ||
ARG_UNUSED(argv); | ||
|
||
printk("pong\n"); | ||
|
||
return 0; | ||
} | ||
|
||
static int shell_cmd_params(int argc, char *argv[]) | ||
{ | ||
int cnt; | ||
|
||
printk("argc = %d\n", argc); | ||
for (cnt = 0; cnt < argc; cnt++) { | ||
printk(" argv[%d] = %s\n", cnt, argv[cnt]); | ||
} | ||
return 0; | ||
} | ||
|
||
static struct shell_cmd commands[] = { | ||
{ "ping", shell_cmd_ping, NULL }, | ||
{ "params", shell_cmd_params, "print argc" }, | ||
{ NULL, NULL, NULL } | ||
}; | ||
|
||
void main(void) | ||
{ | ||
SHELL_REGISTER(MY_SHELL_MODULE, commands); | ||
} | ||
/*-------------------------------------------------------------------*/ | ||
|
||
|
||
void blink1(void) | ||
{ | ||
int cnt = 0; | ||
struct device *gpioa; | ||
|
||
gpioa = device_get_binding("GPIOA"); | ||
gpio_pin_configure(gpioa, 15, GPIO_DIR_OUT); | ||
while (1) { | ||
gpio_pin_write(gpioa, 15, (cnt + 1) % 2); | ||
k_sleep(100); | ||
cnt++; | ||
} | ||
} | ||
|
||
void blink2(void) | ||
{ | ||
int cnt = 0; | ||
struct device *gpiod; | ||
|
||
gpiod = device_get_binding("GPIOD"); | ||
gpio_pin_configure(gpiod, 2, GPIO_DIR_OUT); | ||
while (1) { | ||
gpio_pin_write(gpiod, 2, cnt % 2); | ||
k_sleep(1000); | ||
cnt++; | ||
} | ||
} | ||
|
||
void blink3(void) | ||
{ | ||
int cnt = 0, cnt2 = 0, sleep = 100; | ||
struct device *gpiob; | ||
|
||
gpiob = device_get_binding("GPIOB"); | ||
gpio_pin_configure(gpiob, 5, GPIO_DIR_OUT); | ||
while (1) { | ||
while (cnt2 != 5) { | ||
gpio_pin_write(gpiob, 5, cnt2 % 2); | ||
k_sleep(sleep); | ||
sleep += 100; | ||
cnt2++; | ||
} | ||
cnt2 = 0; | ||
sleep = 100; | ||
} | ||
} | ||
|
||
K_THREAD_DEFINE(blink1_id, STACKSIZE, blink1, NULL, NULL, NULL, | ||
PRIORITY, 0, K_NO_WAIT); | ||
K_THREAD_DEFINE(blink2_id, STACKSIZE, blink2, NULL, NULL, NULL, | ||
PRIORITY, 0, K_NO_WAIT); | ||
K_THREAD_DEFINE(blink3_id, STACKSIZE, blink3, NULL, NULL, NULL, | ||
PRIORITY, 0, K_NO_WAIT); |