|
| 1 | +/* |
| 2 | + * Copyright (c) 2016 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <stdio.h> |
| 8 | +#include <zephyr/kernel.h> |
| 9 | +#include <zephyr/drivers/gpio.h> |
| 10 | + |
| 11 | +/* 1000 msec = 1 sec */ |
| 12 | +#define SLEEP_TIME_MS 1000 |
| 13 | + |
| 14 | +/* The devicetree node identifier for the "led0" alias. */ |
| 15 | +#define LED0_NODE DT_ALIAS(led0) |
| 16 | +#define LED1_NODE DT_ALIAS(led1) |
| 17 | +#define LED2_NODE DT_ALIAS(led2) |
| 18 | + |
| 19 | +/* |
| 20 | + * A build error on this line means your board is unsupported. |
| 21 | + * See the sample documentation for information on how to fix this. |
| 22 | + */ |
| 23 | +static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); |
| 24 | +static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); |
| 25 | +static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); |
| 26 | + |
| 27 | +#define __ASM __asm /*!< asm keyword for GNU Compiler */ |
| 28 | +#define __INLINE inline /*!< inline keyword for GNU Compiler */ |
| 29 | +#define __STATIC_INLINE static inline |
| 30 | + |
| 31 | +__attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PC(void) |
| 32 | +{ |
| 33 | + register uint32_t result; |
| 34 | + |
| 35 | + __ASM volatile ("MOV %0, PC\n" : "=r" (result)); |
| 36 | + return result; |
| 37 | +} |
| 38 | + |
| 39 | +int main(void) |
| 40 | +{ |
| 41 | + int ret; |
| 42 | + |
| 43 | + printk("Hello World! from external flash %s\n", CONFIG_BOARD); |
| 44 | + printf("--> PC at 0x%x\n", __get_PC()); |
| 45 | + |
| 46 | + if (!gpio_is_ready_dt(&led0)) { |
| 47 | + return -1; |
| 48 | + } |
| 49 | + if (!gpio_is_ready_dt(&led1)) { |
| 50 | + return -1; |
| 51 | + } |
| 52 | + if (!gpio_is_ready_dt(&led2)) { |
| 53 | + return -1; |
| 54 | + } |
| 55 | + |
| 56 | + ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); |
| 57 | + if (ret < 0) { |
| 58 | + return -1; |
| 59 | + } |
| 60 | + ret = gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); |
| 61 | + if (ret < 0) { |
| 62 | + return -1; |
| 63 | + } |
| 64 | + ret = gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); |
| 65 | + if (ret < 0) { |
| 66 | + return -1; |
| 67 | + } |
| 68 | + |
| 69 | + while (1) { |
| 70 | + ret = gpio_pin_toggle_dt(&led0); |
| 71 | + if (ret < 0) { |
| 72 | + return -1; |
| 73 | + } |
| 74 | + k_msleep(200); |
| 75 | + ret = gpio_pin_toggle_dt(&led1); |
| 76 | + if (ret < 0) { |
| 77 | + return -1; |
| 78 | + } |
| 79 | + k_msleep(300); |
| 80 | + ret = gpio_pin_toggle_dt(&led2); |
| 81 | + if (ret < 0) { |
| 82 | + return -1; |
| 83 | + } |
| 84 | + |
| 85 | + k_msleep(SLEEP_TIME_MS); |
| 86 | + } |
| 87 | + return 0; |
| 88 | +} |
0 commit comments