From e991fe0091da37b549b86aa4410ea5300a819bac Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Thu, 10 Jun 2021 12:44:19 +0100 Subject: [PATCH 01/12] led.c: Implement Zephyrs GPIO APIs Signed-off-by: Iker Perez del Palomar Sustatxa --- src/led.c | 124 +++++++++++++++++++++++++++++++++++++++++++----------- src/led.h | 4 +- 2 files changed, 102 insertions(+), 26 deletions(-) diff --git a/src/led.c b/src/led.c index a4e57a7..4821847 100644 --- a/src/led.c +++ b/src/led.c @@ -17,10 +17,10 @@ #include #include -// #include -// #include +#include +#include -#include "common/error.h" +#include "error.h" #include "common/util.h" #include "common/msg.h" @@ -46,6 +46,21 @@ #define LED_BR(pin) (LED_BS(pin) << 16) #define LED_BSRR(port) ((port) + 0x18) +/* The devicetree node identifier for the "led0" alias. */ +#define STATUS_NODE DT_ALIAS(statusled) + +#if DT_NODE_HAS_STATUS(STATUS_NODE, okay) +#define STATUS_LED DT_GPIO_LABEL(STATUS_NODE, gpios) +#define STATUS_PIN DT_GPIO_PIN(STATUS_NODE, gpios) +#define STATUS_FLAGS DT_GPIO_FLAGS(STATUS_NODE, gpios) +#else +/* A build error here means your board isn't set up to blink an LED. */ +#error "Unsupported board: statusled devicetree alias is not defined" +#define STATUS_LED "" +#define STATUS_PIN 0 +#define STATUS_FLAGS 0 +#endif + unsigned bl_led_count; volatile unsigned bl_led_active; bl_led_channel_t bl_led_channel[BL_LED_COUNT]; @@ -63,7 +78,7 @@ enum led_port { #define GPIOC 3 /** GPIO port addresses */ -static const uint32_t led_port[] = { +static const GPIO_TypeDef * led_port[] = { [LED_PORT_A] = GPIOA, [LED_PORT_B] = GPIOB, [LED_PORT_C] = GPIOC, @@ -128,12 +143,44 @@ static inline uint16_t bl_led__get_pin_mask( return pin_mask; } +/** GPIO binding function, needed to avoid variables holding desired node value*/ +static inline const struct device * gpio_binding (enum led_port port) { + const struct device * gpio; + switch (port) { + case LED_PORT_A: + gpio = device_get_binding(DT_LABEL(DT_NODELABEL(gpioa))); + if (gpio == NULL) { + printk("GPIOA binding error\n"); + } + break; + case LED_PORT_B: + gpio = device_get_binding(DT_LABEL(DT_NODELABEL(gpiob))); + if (gpio == NULL) { + printk("GPIOB binding error\n"); + } + break; + case LED_PORT_C: + gpio = device_get_binding(DT_LABEL(DT_NODELABEL(gpioc))); + if (gpio == NULL) { + printk("GPIOC binding error\n"); + } + break; + default: + gpio = NULL; //check NULL + break; + } + return gpio; +} + static inline void bl_led__gpio_mode_setup(enum led_port port) { - /* - gpio_mode_setup(led_port[port], GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, - bl_led__get_pin_mask(port, 0xffff)); - */ + const struct device * gpio = gpio_binding(port); + if (gpio == NULL) { + printk("GPIOB binding error\n"); + } + if (gpio_pin_configure(gpio, bl_led__get_pin_mask(port, 0xffff), GPIO_OUTPUT) !=0){ + printk("Error configuring port=%d\n", port); + } } /* Exported function, documented in led.h */ @@ -144,9 +191,19 @@ void bl_led_init(void) rcc_periph_clock_enable(RCC_GPIOB); rcc_periph_clock_enable(RCC_GPIOC); */ + for (uint8_t port = 0 ; port < sizeof(led_port)/sizeof(led_port[0]); port++) { + const struct device * gpio = gpio_binding(port); + const clock_control_subsys_t *subsys = gpio -> config; + if (clock_control_on(gpio, *subsys) < 0) { + printk("Error: Can't turn clock on\n"); + } + }; + printk("PORT A setup\n"); bl_led__gpio_mode_setup(LED_PORT_A); + printk("PORT B setup\n"); bl_led__gpio_mode_setup(LED_PORT_B); + printk("PORT C setup\n"); bl_led__gpio_mode_setup(LED_PORT_C); bl_led_set(0x0000); @@ -162,10 +219,14 @@ static inline void bl_led__set( * 2. Making bl_led_init() cache the clear masks so they can be reused * here. */ - /* - gpio_clear(led_port[port], bl_led__get_pin_mask(port, 0xffff)); - gpio_set(led_port[port], bl_led__get_pin_mask(port, led_mask)); - */ + typedef uint32_t gpio_port_pins_t; + const struct device * gpio; + + gpio_port_pins_t pinmask = bl_led__get_pin_mask(port, 0xffff); + gpio = gpio_binding(port); + gpio_port_set_masked(gpio, pinmask, 0); + pinmask = bl_led__get_pin_mask(port, led_mask); + gpio_port_set_masked(gpio, pinmask, 0xffff); } /* Exported function, documented in led.h */ @@ -181,15 +242,23 @@ enum bl_error bl_led_set(uint16_t led_mask) void bl_led_status_set(bool enable) { #if (BL_REVISION >= 2) + const struct device * gpio; + + gpio=device_get_binding(STATUS_LED); + if (gpio == NULL) { + return; + } + if (enable) { - /* - gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7); - gpio_clear(GPIOB, GPIO7); - */ + if (gpio_pin_configure(gpio, STATUS_PIN, GPIO_OUTPUT_LOW | STATUS_FLAGS) < 0) { + printk("Error: failed to enable status pin\n"); + return; + } } else { - /* - gpio_mode_setup(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO7); - */ + if (gpio_pin_configure(gpio, STATUS_PIN, GPIO_INPUT | STATUS_FLAGS) < 0) { + printk("Error: failed to disable status pin\n"); + return; + } } #else BL_UNUSED(enable); @@ -215,7 +284,7 @@ enum bl_error bl_led_setup(uint16_t led_mask) active->src_mask = LED_SRC(bl_acq_channel_get_source(i)); active->gpios = LED_BS(led_table[i].pin); active->gpior = LED_BR(led_table[i].pin); - active->gpio_bsrr = LED_BSRR(led_port[led_table[i].port_idx]); + active->gpio_bsrr = LED_BSRR(led_port[led_table[i].port_idx]->BSRR); led_mask &= ~(1U << i); @@ -243,9 +312,14 @@ static inline void bl_led__gpio_set(unsigned led) /* Exported function, documented in led.h */ enum bl_error bl_led_loop(void) { - /* - gpio_set(GPIOB, GPIO12); - */ + const struct device * gpio; + + gpio = device_get_binding(DT_LABEL(DT_NODELABEL(gpiob))); + if (gpio_pin_configure(gpio, 12, GPIO_OUTPUT | STATUS_FLAGS) < 0) { + printk("Error: failed to configure pin 12\n"); + return BL_ERROR_HARDWARE_CONFLICT; + } + gpio_port_set_bits(gpio, 12); //Commented to avoid depending on spi, to be uncommented /*if (bl_spi_mode == BL_ACQ_SPI_NONE) { bl_led__gpio_clear(bl_led_active); @@ -262,7 +336,7 @@ enum bl_error bl_led_loop(void) led_to_send = 0; bl_spi_send(bl_led_channel[led_to_send].led); - gpio_clear(GPIOB, GPIO12); + gpio_port_clear_bits(gpio, GPIO12); } else if (bl_spi_mode == BL_ACQ_SPI_NONE) { bl_led__gpio_set(bl_led_active); }*/ @@ -271,7 +345,7 @@ enum bl_error bl_led_loop(void) } /* Exported function, documented in led.h */ -uint32_t bl_led_get_port(uint8_t led) +const GPIO_TypeDef * bl_led_get_port(uint8_t led) { return led_port[led_table[led].port_idx]; } diff --git a/src/led.h b/src/led.h index cb53b4c..fa47b43 100644 --- a/src/led.h +++ b/src/led.h @@ -23,6 +23,8 @@ #include "common/error.h" #include "common/led.h" +#include + /** LED source globals */ typedef struct { uint8_t led; @@ -73,7 +75,7 @@ enum bl_error bl_led_loop(void); * \param[in] led LED index to be checked * \return \ref GPIO port for specified LED */ -uint32_t bl_led_get_port(uint8_t led); +const GPIO_TypeDef * bl_led_get_port(uint8_t led); /** * Get the corresponding GPIO pin number for specified LED From b1cac8fa3f4669b30dd72c1a8bc134f3239b5fae Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Fri, 30 Apr 2021 09:59:49 +0100 Subject: [PATCH 02/12] led.c: Replace RCC APIs Signed-off-by: Iker Perez del Palomar Sustatxa --- src/led.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/led.c b/src/led.c index 4821847..5128a20 100644 --- a/src/led.c +++ b/src/led.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include "error.h" @@ -186,11 +186,6 @@ static inline void bl_led__gpio_mode_setup(enum led_port port) /* Exported function, documented in led.h */ void bl_led_init(void) { - /* - rcc_periph_clock_enable(RCC_GPIOA); - rcc_periph_clock_enable(RCC_GPIOB); - rcc_periph_clock_enable(RCC_GPIOC); - */ for (uint8_t port = 0 ; port < sizeof(led_port)/sizeof(led_port[0]); port++) { const struct device * gpio = gpio_binding(port); From 7b2f5617ec3c7b7ecc46052e83e9e3e65d43118f Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Fri, 14 May 2021 15:34:48 +0100 Subject: [PATCH 03/12] channel.h and led.c: Fix header paths Signed-off-by: Iker Perez del Palomar Sustatxa --- src/led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/led.c b/src/led.c index 5128a20..1aed37e 100644 --- a/src/led.c +++ b/src/led.c @@ -20,7 +20,7 @@ #include #include -#include "error.h" +#include "common/error.h" #include "common/util.h" #include "common/msg.h" From d1a5a1f57a2d2829c967631350916eea72ac3b25 Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Tue, 25 May 2021 10:13:21 +0100 Subject: [PATCH 04/12] led.c: Remove building hack Signed-off-by: Iker Perez del Palomar Sustatxa --- src/led.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/led.c b/src/led.c index 1aed37e..7b84ce4 100644 --- a/src/led.c +++ b/src/led.c @@ -72,11 +72,6 @@ enum led_port { LED_PORT_C, }; -/* HACK: define GPIOx values to allow build */ -#define GPIOA 1 -#define GPIOB 2 -#define GPIOC 3 - /** GPIO port addresses */ static const GPIO_TypeDef * led_port[] = { [LED_PORT_A] = GPIOA, From 750ac102358d073e95e088d2219eed20dfe592f8 Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Tue, 8 Jun 2021 09:02:34 +0100 Subject: [PATCH 05/12] led.c:bl_led__gpio_mode_setup(): Configure all ports and pins in one go. Configure inside bl_led__gpio_mode_setup() all pins containing a LED connected to them on each port. Signed-off-by: Iker Perez del Palomar Sustatxa --- src/led.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/led.c b/src/led.c index 7b84ce4..d413afd 100644 --- a/src/led.c +++ b/src/led.c @@ -167,14 +167,35 @@ static inline const struct device * gpio_binding (enum led_port port) { return gpio; } -static inline void bl_led__gpio_mode_setup(enum led_port port) + + +static inline void bl_led__gpio_mode_setup() { - const struct device * gpio = gpio_binding(port); - if (gpio == NULL) { - printk("GPIOB binding error\n"); - } - if (gpio_pin_configure(gpio, bl_led__get_pin_mask(port, 0xffff), GPIO_OUTPUT) !=0){ - printk("Error configuring port=%d\n", port); + //Get the gpio bindings + const struct device * gpioa = gpio_binding(LED_PORT_A); + const struct device * gpiob = gpio_binding(LED_PORT_B); + const struct device * gpioc = gpio_binding(LED_PORT_C); + + //Configure the pins connected to leds as output. + for (int led = 0; led < BL_LED_COUNT ; led++) { + switch (led_table[led].port_idx){ + case LED_PORT_A: + if (gpio_pin_configure(gpioa, led_table[led].pin, GPIO_OUTPUT) !=0){ + printk("Error configuring port\n"); + } + break; + case LED_PORT_B: + if (gpio_pin_configure(gpiob, led_table[led].pin, GPIO_OUTPUT) !=0){ + printk("Error configuring port\n"); + } + break; + case LED_PORT_C: + if (gpio_pin_configure(gpioc, led_table[led].pin, GPIO_OUTPUT) !=0){ + printk("Error configuring port\n"); + } + break; + } + } } @@ -189,12 +210,8 @@ void bl_led_init(void) printk("Error: Can't turn clock on\n"); } }; - printk("PORT A setup\n"); - bl_led__gpio_mode_setup(LED_PORT_A); - printk("PORT B setup\n"); - bl_led__gpio_mode_setup(LED_PORT_B); - printk("PORT C setup\n"); - bl_led__gpio_mode_setup(LED_PORT_C); + + bl_led__gpio_mode_setup(); bl_led_set(0x0000); } From 02182ea8557a67eec2196bcb9f4985096640d007 Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Thu, 10 Jun 2021 12:26:26 +0100 Subject: [PATCH 06/12] led.c/led.h/spi.c: Make gpio_binding() public and use it in spi.c This ensures that bl_led_get_port() can be used in spi.c Signed-off-by: Iker Perez del Palomar Sustatxa --- src/led.c | 6 +++--- src/led.h | 12 ++++++++++++ src/spi.c | 8 ++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/led.c b/src/led.c index d413afd..5686ec0 100644 --- a/src/led.c +++ b/src/led.c @@ -65,12 +65,12 @@ unsigned bl_led_count; volatile unsigned bl_led_active; bl_led_channel_t bl_led_channel[BL_LED_COUNT]; -/** GPIO ports used for LEDs */ +/** GPIO ports used for LEDs *//* enum led_port { LED_PORT_A, LED_PORT_B, LED_PORT_C, -}; +};*/ /** GPIO port addresses */ static const GPIO_TypeDef * led_port[] = { @@ -139,7 +139,7 @@ static inline uint16_t bl_led__get_pin_mask( } /** GPIO binding function, needed to avoid variables holding desired node value*/ -static inline const struct device * gpio_binding (enum led_port port) { +const struct device * gpio_binding (enum led_port port) { const struct device * gpio; switch (port) { case LED_PORT_A: diff --git a/src/led.h b/src/led.h index fa47b43..2103013 100644 --- a/src/led.h +++ b/src/led.h @@ -34,6 +34,11 @@ typedef struct { uint32_t gpio_bsrr; } bl_led_channel_t; +enum led_port { + LED_PORT_A, + LED_PORT_B, + LED_PORT_C, +}; extern unsigned bl_led_count; extern volatile unsigned bl_led_active; @@ -85,5 +90,12 @@ const GPIO_TypeDef * bl_led_get_port(uint8_t led); */ uint16_t bl_led_get_gpio(uint8_t led); +/** + * Get the corresponding GPIO port device binding for the specified enum led_port value + * + * \param[in] port Desired gpio port's enum led_port value + * \return \ref GPIO port device binding + */ +const struct device * gpio_binding (enum led_port port); #endif diff --git a/src/spi.c b/src/spi.c index 02897db..11f738e 100644 --- a/src/spi.c +++ b/src/spi.c @@ -223,6 +223,8 @@ void bl_spi_daughter_poll(void) static uint32_t gpioport, old_gpioport; static uint16_t gpio, old_gpio; static bool to_next = false; + const struct device * oldgpio_binding; + const struct device * gpio_binding; if (SPI_SR(SPI2) & SPI_SR_RXNE) { bl_spi_mode = BL_ACQ_SPI_DAUGHTER; @@ -232,8 +234,10 @@ void bl_spi_daughter_poll(void) to_next = true; } if (to_next && gpio_get(GPIOB, GPIO12)) { - gpio_clear(old_gpioport, old_gpio); - gpio_set(gpioport, gpio); + gpio_binding = gpio_binding(gpioport); + oldgpio_binding= gpio_binding(old_gpioport); + gpio_port_clear_bits(oldgpio_binding, old_gpio); + gpio_port_set_bits(gpio_binding, gpio); old_gpioport = gpioport; old_gpio = gpio; to_next = false; From e47c0aeced9adb5b8ff7979501ea92d6ef39dcda Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Thu, 27 May 2021 12:28:47 +0100 Subject: [PATCH 07/12] CMakeLists.txt: Add board revision flag Signed-off-by: Iker Perez del Palomar Sustatxa --- CMakeLists.txt | 5 +++++ tests/led/CMakeLists.txt | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34a63b4..e370183 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,3 +33,8 @@ target_sources(app PRIVATE # src/acq/source.c # src/acq/timer.c ) + +add_compile_definitions( + BL_REVISION=2 + REVISION=2 +) \ No newline at end of file diff --git a/tests/led/CMakeLists.txt b/tests/led/CMakeLists.txt index 06ebc6f..5b79583 100644 --- a/tests/led/CMakeLists.txt +++ b/tests/led/CMakeLists.txt @@ -18,3 +18,8 @@ target_sources(app PRIVATE main.c ../../src/led.c ) + +add_compile_definitions( + BL_REVISION=2 + REVISION=2 +) \ No newline at end of file From 31723c8bf093768f75e7932bd92e2d635fd2602c Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Wed, 19 May 2021 15:05:57 +0100 Subject: [PATCH 08/12] bloodlight_based.c: Create test for led.c * Include console support * Bloodlight_based.c: Test leds with led.c APIs. * Build bloodlight_based.c by default. * Test bl_led_status_set() Keep both tests zephyr_based (previous main) and bloodlight_based.c so the user can select in CMakeFie which test wants to run. zephyr_based to test leds using zephyrs APIs or bloodlight_based to test them using bloodlight's APIs. Signed-off-by: Iker Perez del Palomar Sustatxa --- boards/arm/bloodlight_rev2/Kconfig.defconfig | 4 ++ tests/led/CMakeLists.txt | 2 +- tests/led/bloodlight_based.c | 45 ++++++++++++++++++++ tests/led/{main.c => zephyr_based.c} | 0 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/led/bloodlight_based.c rename tests/led/{main.c => zephyr_based.c} (100%) diff --git a/boards/arm/bloodlight_rev2/Kconfig.defconfig b/boards/arm/bloodlight_rev2/Kconfig.defconfig index f28a3ff..e2335b1 100644 --- a/boards/arm/bloodlight_rev2/Kconfig.defconfig +++ b/boards/arm/bloodlight_rev2/Kconfig.defconfig @@ -13,3 +13,7 @@ config SPI_STM32_INTERRUPT depends on SPI endif + +config PRINTK + bool "Send printk() to console" + default y diff --git a/tests/led/CMakeLists.txt b/tests/led/CMakeLists.txt index 5b79583..22c4485 100644 --- a/tests/led/CMakeLists.txt +++ b/tests/led/CMakeLists.txt @@ -15,7 +15,7 @@ zephyr_include_directories(${CMAKE_SOURCE_DIR}/../..) project(led_test) target_sources(app PRIVATE - main.c + bloodlight_based.c ../../src/led.c ) diff --git a/tests/led/bloodlight_based.c b/tests/led/bloodlight_based.c new file mode 100644 index 0000000..aabebc3 --- /dev/null +++ b/tests/led/bloodlight_based.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void main (void) { + const struct device *dev = device_get_binding( + CONFIG_UART_CONSOLE_ON_DEV_NAME); + uint32_t dtr = 0; + + + if (usb_enable(NULL)) { + return; + } + +#define SLEEP_TIME_MS 1000 +/* The devicetree node identifier for the "led0" alias. */ +#define STATUS_NODE DT_ALIAS(statusled) + +#if DT_NODE_HAS_STATUS(STATUS_NODE, okay) +#define STATUS_LED DT_GPIO_LABEL(STATUS_NODE, gpios) +#define STATUS_PIN DT_GPIO_PIN(STATUS_NODE, gpios) +#define STATUS_FLAGS DT_GPIO_FLAGS(STATUS_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 STATUS_LED "" +#define STATUS_PIN 0 +#define STATUS_FLAGS 0 +#endif + +void main (void) { + while (1) { + bl_led_status_set(true); + k_msleep(SLEEP_TIME_MS); + bl_led_status_set(false); + k_msleep(SLEEP_TIME_MS); + } +}; \ No newline at end of file diff --git a/tests/led/main.c b/tests/led/zephyr_based.c similarity index 100% rename from tests/led/main.c rename to tests/led/zephyr_based.c From f06f3c3b6bc9dcf5338d4093eb736b95d2ff1410 Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Tue, 8 Jun 2021 09:48:12 +0100 Subject: [PATCH 09/12] bloodlight_based.c: Test bl_led_set() Signed-off-by: Iker Perez del Palomar Sustatxa --- tests/led/bloodlight_based.c | 48 +++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/tests/led/bloodlight_based.c b/tests/led/bloodlight_based.c index aabebc3..66d2414 100644 --- a/tests/led/bloodlight_based.c +++ b/tests/led/bloodlight_based.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -7,19 +8,11 @@ #include #include #include -#include - -void main (void) { - const struct device *dev = device_get_binding( - CONFIG_UART_CONSOLE_ON_DEV_NAME); - uint32_t dtr = 0; - - if (usb_enable(NULL)) { - return; - } +#include #define SLEEP_TIME_MS 1000 +#define LOOPS 10 /* The devicetree node identifier for the "led0" alias. */ #define STATUS_NODE DT_ALIAS(statusled) @@ -36,10 +29,43 @@ void main (void) { #endif void main (void) { - while (1) { + const struct device *dev = device_get_binding( + CONFIG_UART_CONSOLE_ON_DEV_NAME); + uint32_t dtr = 0; + + if (usb_enable(NULL)) { + return; + } + + while (!dtr) { + uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr); + } + + if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) != + strlen("CDC_ACM_0") || + strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0", + strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) { + printk("Error: Console device name is not USB ACM\n"); + + return; + } + + printf("*****Starting LED APIs tests****\n"); + printf("Testing bl_led_status_set()\n"); + for (int i = 0 ; i < LOOPS ; i++){ bl_led_status_set(true); k_msleep(SLEEP_TIME_MS); bl_led_status_set(false); k_msleep(SLEEP_TIME_MS); } + + bl_led_init(); + + printf("Testing bl_led_set()\n"); + for (int i = 0 ; i < LOOPS ; i++){ + bl_led_set(0xffff); + k_msleep(SLEEP_TIME_MS); + bl_led_set(0); + k_msleep(SLEEP_TIME_MS); + } }; \ No newline at end of file From 149dee47400f44309c9cf053538601e66d3c488f Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Thu, 10 Jun 2021 12:25:40 +0100 Subject: [PATCH 10/12] bloodlight_based.c: Test bl_led_get_port() Signed-off-by: Iker Perez del Palomar Sustatxa --- tests/led/bloodlight_based.c | 71 ++++++++++++++++++++++++++++++++++-- tests/led/prj.conf | 1 + 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/led/prj.conf diff --git a/tests/led/bloodlight_based.c b/tests/led/bloodlight_based.c index 66d2414..709e7d2 100644 --- a/tests/led/bloodlight_based.c +++ b/tests/led/bloodlight_based.c @@ -10,6 +10,8 @@ #include #include +#include "../../common/led.h" +#include #define SLEEP_TIME_MS 1000 #define LOOPS 10 @@ -50,8 +52,71 @@ void main (void) { return; } - printf("*****Starting LED APIs tests****\n"); - printf("Testing bl_led_status_set()\n"); + printf("\n*****Starting LED APIs tests****\n"); + + printf("\nTesting bl_led_get_port\n"); + for (int led = 0; led < BL_LED_COUNT; led++){ + switch (led) + { + #if (BL_REVISION == 1) + case 4: + case 5: + case 6: + case 7: + __ASSERT(((GPIO_TypeDef *) GPIOA_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); + break; + case 0: + case 1: + case 2: + case 3: + case 11: + case 12: + case 13: + case 14: + case 15: + __ASSERT(((GPIO_TypeDef *) GPIOB_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); + break; + case 8: + case 9: + case 10: + __ASSERT(((GPIO_TypeDef *) GPIOC_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); + break; + #else + case 1: + case 4: + case 5: + case 6: + case 7: + case 11: + case 13: + case 14: + case 15: + __ASSERT(((GPIO_TypeDef *) GPIOA_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); + break; + } + case 2: + case 9: + case 10: + case 12: + __ASSERT(((GPIO_TypeDef *) GPIOB_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); + break; + case 0: + case 3: + case 8: + __ASSERT(((GPIO_TypeDef *) GPIOC_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); + break; + #endif + } + } + + + + printf("\nTesting bl_led_get_gpio\n"); + for (int led = 0; led < BL_LED_COUNT; led++){ + printf("LED %d port is %d\n", led, bl_led_get_gpio(led)); + } + + printf("\nTesting bl_led_status_set()\n"); for (int i = 0 ; i < LOOPS ; i++){ bl_led_status_set(true); k_msleep(SLEEP_TIME_MS); @@ -61,7 +126,7 @@ void main (void) { bl_led_init(); - printf("Testing bl_led_set()\n"); + printf("\nTesting bl_led_set()\n"); for (int i = 0 ; i < LOOPS ; i++){ bl_led_set(0xffff); k_msleep(SLEEP_TIME_MS); diff --git a/tests/led/prj.conf b/tests/led/prj.conf new file mode 100644 index 0000000..573117c --- /dev/null +++ b/tests/led/prj.conf @@ -0,0 +1 @@ +CONFIG_ASSERT=y \ No newline at end of file From 7d00809eb072e73a03b38a69e68f442e258675c1 Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Thu, 10 Jun 2021 09:58:52 +0100 Subject: [PATCH 11/12] bloodlight_based: Add assertions to bl_led_get_gpio and printfs Signed-off-by: Iker Perez del Palomar Sustatxa --- tests/led/bloodlight_based.c | 111 +++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 5 deletions(-) diff --git a/tests/led/bloodlight_based.c b/tests/led/bloodlight_based.c index 709e7d2..8202e57 100644 --- a/tests/led/bloodlight_based.c +++ b/tests/led/bloodlight_based.c @@ -93,7 +93,6 @@ void main (void) { case 15: __ASSERT(((GPIO_TypeDef *) GPIOA_BASE) == bl_led_get_port(led), "Invalid port value in led %i\n", led); break; - } case 2: case 9: case 10: @@ -108,15 +107,117 @@ void main (void) { #endif } } - + printf("\nSuccess testing bl_led_get_port\n"); printf("\nTesting bl_led_get_gpio\n"); for (int led = 0; led < BL_LED_COUNT; led++){ - printf("LED %d port is %d\n", led, bl_led_get_gpio(led)); + switch (led) + { + #if (BL_REVISION == 1) + case 0: + __ASSERT((1U << 1) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 1: + __ASSERT((1U << 2) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 2: + __ASSERT((1U << 10) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 3: + __ASSERT((1U << 11) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 4: + __ASSERT((1U << 8) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 5: + __ASSERT((1U << 9) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 6: + __ASSERT((1U << 10) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 7: + __ASSERT((1U << 15) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 8: + __ASSERT((1U << 13) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 9: + __ASSERT((1U << 14) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 10: + __ASSERT((1U << 15) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 11: + __ASSERT((1U << 9) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 12: + __ASSERT((1U << 8) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 13: + __ASSERT((1U << 7) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 14: + __ASSERT((1U << 6) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 15: + __ASSERT((1U << 5) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + #else + case 0: + __ASSERT((1U << 14) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 1: + __ASSERT((1U << 10) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 2: + __ASSERT((1U << 11) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 3: + __ASSERT((1U << 13) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 4: + __ASSERT((1U << 6) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 5: + __ASSERT((1U << 8) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 6: + __ASSERT((1U << 9) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 7: + __ASSERT((1U << 5) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 8: + __ASSERT((1U << 15) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 9: + __ASSERT((1U << 6) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 10: + __ASSERT((1U << 5) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 11: + __ASSERT((1U << 0) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 12: + __ASSERT((1U << 4) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 13: + __ASSERT((1U << 15) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 14: + __ASSERT((1U << 1) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + case 15: + __ASSERT((1U << 2) == bl_led_get_gpio(led), "Invalid pin value in led %i\n", led); + break; + #endif + } } + printf("\nSuccess testing bl_led_get_gpio\n"); - printf("\nTesting bl_led_status_set()\n"); + printf("\nTesting bl_led_status_set(), please check for a red led blinking\n"); for (int i = 0 ; i < LOOPS ; i++){ bl_led_status_set(true); k_msleep(SLEEP_TIME_MS); @@ -126,7 +227,7 @@ void main (void) { bl_led_init(); - printf("\nTesting bl_led_set()\n"); + printf("\nTesting bl_led_set(), please check for all leds blinking\n"); for (int i = 0 ; i < LOOPS ; i++){ bl_led_set(0xffff); k_msleep(SLEEP_TIME_MS); From fa33bb8ed88cef0e743d6416b8e3f886f07c90cf Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Wed, 7 Jul 2021 09:02:54 +0100 Subject: [PATCH 12/12] bloodlight_based.c: Reorganice includes Signed-off-by: Iker Perez del Palomar Sustatxa --- tests/led/bloodlight_based.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/led/bloodlight_based.c b/tests/led/bloodlight_based.c index 8202e57..ecbbd26 100644 --- a/tests/led/bloodlight_based.c +++ b/tests/led/bloodlight_based.c @@ -1,17 +1,17 @@ +#include #include #include -#include -#include #include -#include -#include #include -#include +#include +#include +#include +#include #include - #include +#include #include "../../common/led.h" -#include +#include "../../src/led.h" #define SLEEP_TIME_MS 1000 #define LOOPS 10