Skip to content

Commit

Permalink
Sync with the latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
valeros committed Jul 4, 2023
1 parent 8bd7119 commit 205b3a2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 44 deletions.
6 changes: 5 additions & 1 deletion builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
# Target: Build executable and linkable firmware
#

if "zephyr" in env.get("PIOFRAMEWORK", []):
frameworks = env.get("PIOFRAMEWORK", [])
if "zephyr" in frameworks:
env.SConscript(
join(platform.get_package_dir(
"framework-zephyr"), "scripts", "platformio", "platformio-build-pre.py"),
Expand All @@ -96,6 +97,9 @@
else:
target_elf = env.BuildProgram()
target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf)
if "zephyr" in frameworks and "mcuboot-image" in COMMAND_LINE_TARGETS:
target_firm = env.MCUbootImage(
join("$BUILD_DIR", "${PROGNAME}.mcuboot.bin"), target_firm)
env.Depends(target_firm, "checkprogsize")

AlwaysBuild(env.Alias("nobuild", target_firm))
Expand Down
45 changes: 20 additions & 25 deletions examples/zephyr-blink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,43 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
#define SLEEP_TIME_MS 300

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)

#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0 ""
#define PIN 0
#define FLAGS 0
#endif
/*
* A build error on this line means your board is unsupported.
* See the sample documentation for information on how to fix this.
*/
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

void main(void)
{
const struct device *dev;
bool led_is_on = true;
int ret;

dev = device_get_binding(LED0);
if (dev == NULL) {
if (!gpio_is_ready_dt(&led))
{
return;
}

ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
if (ret < 0) {
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0)
{
return;
}

while (1) {
gpio_pin_set(dev, PIN, (int)led_is_on);
led_is_on = !led_is_on;
while (1)
{
ret = gpio_pin_toggle_dt(&led);
if (ret < 0)
{
return;
}
k_msleep(SLEEP_TIME_MS);
}
}
1 change: 0 additions & 1 deletion examples/zephyr-blink/zephyr/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
CONFIG_GPIO=y
CONFIG_SERIAL=n
48 changes: 33 additions & 15 deletions examples/zephyr-synchronization/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <sys/printk.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>

/*
* The hello world demo has two threads that utilize semaphores and sleeping
Expand All @@ -16,6 +16,7 @@
* world application would likely use the static approach for both threads.
*/

#define PIN_THREADS (IS_ENABLED(CONFIG_SMP) && IS_ENABLED(CONFIG_SCHED_CPU_MASK))

/* size of stack area used by each thread */
#define STACKSIZE 1024
Expand Down Expand Up @@ -84,6 +85,9 @@ void threadB(void *dummy1, void *dummy2, void *dummy3)
helloLoop(__func__, &threadB_sem, &threadA_sem);
}

K_THREAD_STACK_DEFINE(threadA_stack_area, STACKSIZE);
static struct k_thread threadA_data;

K_THREAD_STACK_DEFINE(threadB_stack_area, STACKSIZE);
static struct k_thread threadB_data;

Expand All @@ -95,21 +99,35 @@ void threadA(void *dummy1, void *dummy2, void *dummy3)
ARG_UNUSED(dummy2);
ARG_UNUSED(dummy3);

/* spawn threadB */
k_tid_t tid = k_thread_create(&threadB_data, threadB_stack_area,
STACKSIZE, threadB, NULL, NULL, NULL,
/* invoke routine to ping-pong hello messages with threadB */
helloLoop(__func__, &threadA_sem, &threadB_sem);
}

int main(void)
{
k_thread_create(&threadA_data, threadA_stack_area,
K_THREAD_STACK_SIZEOF(threadA_stack_area),
threadA, NULL, NULL, NULL,
PRIORITY, 0, K_FOREVER);
k_thread_name_set(&threadA_data, "thread_a");
#if PIN_THREADS
if (arch_num_cpus() > 1) {
k_thread_cpu_pin(&threadA_data, 0);
}
#endif

k_thread_name_set(tid, "thread_b");
#if CONFIG_SCHED_CPU_MASK
k_thread_cpu_mask_disable(&threadB_data, 1);
k_thread_cpu_mask_enable(&threadB_data, 0);
k_thread_create(&threadB_data, threadB_stack_area,
K_THREAD_STACK_SIZEOF(threadB_stack_area),
threadB, NULL, NULL, NULL,
PRIORITY, 0, K_FOREVER);
k_thread_name_set(&threadB_data, "thread_b");
#if PIN_THREADS
if (arch_num_cpus() > 1) {
k_thread_cpu_pin(&threadB_data, 1);
}
#endif
k_thread_start(&threadB_data);

/* invoke routine to ping-pong hello messages with threadB */
helloLoop(__func__, &threadA_sem, &threadB_sem);
k_thread_start(&threadA_data);
k_thread_start(&threadB_data);
return 0;
}

K_THREAD_DEFINE(thread_a, STACKSIZE, threadA, NULL, NULL, NULL,
PRIORITY, 0, 0);
1 change: 1 addition & 0 deletions examples/zephyr-synchronization/zephyr/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_STDOUT_CONSOLE=y
# enable to use thread names
CONFIG_THREAD_NAME=y
CONFIG_SCHED_CPU_MASK=y
4 changes: 2 additions & 2 deletions platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"toolchain-gccarmnoneeabi": {
"type": "toolchain",
"owner": "platformio",
"version": ">=1.60301.0,<1.80000.0",
"version": "~1.100301.0",
"optionalVersions": [
"~1.90201.0"
]
Expand All @@ -48,7 +48,7 @@
"type": "framework",
"optional": true,
"owner": "platformio",
"version": "~2.20701.0"
"version": "~2.30400.0"
},
"tool-openocd": {
"type": "debugger",
Expand Down

0 comments on commit 205b3a2

Please sign in to comment.