diff --git a/configs/launchxl-cc1310/README.txt b/configs/launchxl-cc1310/README.txt index 074b0d0779..2e5cf0370b 100644 --- a/configs/launchxl-cc1310/README.txt +++ b/configs/launchxl-cc1310/README.txt @@ -37,9 +37,48 @@ LEDs and Buttons LEDs ---- + The LaunchXL-cc1310 and two LEDs controlled by software: DIO7_GLED (CR1) + and DIO6_RLED (CR2). A high output value illuminates an LED. + + DIO7_GLED CR1 High output illuminuates + DIO6_RLED CR2 High output illuminuates + + If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in + any way. The definitions provided in the board.h header file can be used + to access individual LEDs. + + These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + defined. In that case, the usage by the board port is defined in + include/board.h and src/cc1312_autoleds.c. The LEDs are used to encode + OS-related events as follows: + + SYMBOL Meaning LED state + GLED RLED + ------------------ ------------------------ ------ ------ + LED_STARTED NuttX has been started OFF OFF + LED_HEAPALLOCATE Heap has been allocated OFF ON + LED_IRQSENABLED Interrupts enabled OFF ON + LED_STACKCREATED Idle stack created ON OFF + LED_INIRQ In an interrupt N/C GLOW + LED_SIGNAL In a signal handler N/C GLOW + LED_ASSERTION An assertion failed N/C GLOW + LED_PANIC The system has crashed OFF Blinking + LED_IDLE MCU is is sleep mode Not used + + Thus iF GLED is statically on, NuttX has successfully booted and is, + apparently, running normally. A soft glow of the RLED means that the + board is taking interrupts. If GLED is off and GLED is flashing at + approximately 2Hz, then a fatal error has been detected and the system + has halted. + Buttons ------- + The LaunchXL-CC1310 has two push-puttons: + + DIO13_BTN1 SW1 Low input sensed when depressed + DIO14_BTN2 SW2 Low input sensed when depressed + Using J-Link ============ diff --git a/configs/launchxl-cc1310/include/board.h b/configs/launchxl-cc1310/include/board.h index 48fc74133b..85744be7c2 100644 --- a/configs/launchxl-cc1310/include/board.h +++ b/configs/launchxl-cc1310/include/board.h @@ -107,6 +107,19 @@ /* Button definitions *******************************************************/ +/* The LaunchXL-CC1310 has two push-puttons: + * + * DIO13_BTN1 SW1 Low input sensed when depressed + * DIO14_BTN2 SW2 Low input sensed when depressed + */ + +#define BUTTON_SW1 0 +#define BUTTON_SW2 1 +#define NUM_BUTTONS 2 + +#define BUTTON_SW1_BIT (1 << BUTTON_SW1) +#define BUTTON_SW2_BIT (1 << BUTTON_SW2) + /* Pin configuration ********************************************************/ #ifdef CONFIG_TIVA_UART0 diff --git a/configs/launchxl-cc1310/src/cc1310_autoleds.c b/configs/launchxl-cc1310/src/cc1310_autoleds.c index 951d866ebf..3b83721d66 100644 --- a/configs/launchxl-cc1310/src/cc1310_autoleds.c +++ b/configs/launchxl-cc1310/src/cc1310_autoleds.c @@ -62,7 +62,8 @@ void board_autoled_initialize(void) { -#warning Missing logic + (void)tiva_configgpio(&g_gpio_gled); + (void)tiva_configgpio(&g_gpio_rled); } /**************************************************************************** @@ -71,7 +72,55 @@ void board_autoled_initialize(void) void board_autoled_on(int led) { -#warning Missing logic + bool gled_change = true; /* True: Change GLED */ + bool gled_on = false; /* High output illuminates */ + bool rled_on = false; + + /* SYMBOL VAL MEANING GLED RLED + * ---------------- --- ----------------------- ---- ----- + * LED_STARTED 0 NuttX has been started OFF OFF + * LED_HEAPALLOCATE 1 Heap has been allocated OFF ON + * LED_IRQSENABLED 1 Interrupts enabled OFF ON + * LED_STACKCREATED 2 Idle stack created ON OFF + * LED_INIRQ 3 In an interrupt N/C GLOW + * LED_SIGNAL 3 In a signal handler N/C GLOW + * LED_ASSERTION 3 An assertion failed N/C GLOW + * LED_PANIC 4 The system has crashed OFF BLINK + */ + + switch (led) + { + case 0: /* GLED=OFF RLED=OFF */ + break; + + case 3: /* GLED=N/C RLED=ON */ + gled_change = false; + + /* Fall through */ + + case 1: /* GLED=OFF RLED=ON */ + case 4: /* GLED=OFF RLED=ON */ + rled_on = true; + break; + + case 2: /* GLED=ON RLED=OFF */ + gled_on = true; + break; + + default: + return; + } + + /* Set the new state of the GLED (unless is is N/C) */ + + if (gled_change) + { + tiva_gpiowrite(&g_gpio_gled, gled_on); + } + + /* Set the new state of the RLED */ + + tiva_gpiowrite(&g_gpio_rled, rled_on); } /**************************************************************************** @@ -80,7 +129,35 @@ void board_autoled_on(int led) void board_autoled_off(int led) { -#warning Missing logic + /* SYMBOL VAL MEANING GLED RLED + * ---------------- --- ----------------------- ---- ----- + * LED_STARTED 0 NuttX has been started OFF OFF + * LED_HEAPALLOCATE 1 Heap has been allocated OFF ON + * LED_IRQSENABLED 1 Interrupts enabled OFF ON + * LED_STACKCREATED 2 Idle stack created ON OFF + * LED_INIRQ 3 In an interrupt N/C GLOW + * LED_SIGNAL 3 In a signal handler N/C GLOW + * LED_ASSERTION 3 An assertion failed N/C GLOW + * LED_PANIC 4 The system has crashed OFF BLINK + */ + + switch (led) + { + case 4: /* GLED=OFF RLED=OFF */ + tiva_gpiowrite(&g_gpio_gled, false); + + /* Fall through */ + + case 3: /* GLED=N/C RLED=OFF */ + tiva_gpiowrite(&g_gpio_rled, false); + break; + + case 0: /* Should not happen */ + case 1: /* Should not happen */ + case 2: /* Should not happen */ + default: + return; + } } #endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/launchxl-cc1310/src/cc1310_buttons.c b/configs/launchxl-cc1310/src/cc1310_buttons.c index ba74249190..e33a3cde35 100644 --- a/configs/launchxl-cc1310/src/cc1310_buttons.c +++ b/configs/launchxl-cc1310/src/cc1310_buttons.c @@ -72,7 +72,8 @@ void board_button_initialize(void) { -#warning Missing logic + (void)tiva_configgpio(&g_gpio_sw1); + (void)tiva_configgpio(&g_gpio_sw2); } /**************************************************************************** @@ -88,8 +89,21 @@ void board_button_initialize(void) uint32_t board_buttons(void) { -#warning Missing logic - return 0; + uint32_t ret = 0; + + /* When the button is pressed, a low value will be sensed */ + + if (!tiva_gpioread(&g_gpio_sw1)) + { + ret |= BUTTON_SW1_BIT; + } + + if (!tiva_gpioread(&g_gpio_sw2)) + { + ret |= BUTTON_SW2_BIT; + } + + return ret; } /**************************************************************************** @@ -107,45 +121,49 @@ uint32_t board_buttons(void) * ****************************************************************************/ -#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_TIVA_GPIOP_IRQS) +#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_TIVA_GPIOIRQS) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { -#if 0 irqstate_t flags; - int ret = -EINVAL; + int irq; + int ret; - /* Interrupts are supported only on ports P and Q and, hence, only on button SW4 */ - - if (id == BUTTON_SW4) + if (id == BUTTON_SW1) { - /* The following should be atomic */ - - flags = enter_critical_section(); - - /* Detach and disable the button interrupt */ - - up_disable_irq(IRQ_SW4); - irq_detach(IRQ_SW4); - - /* Attach the new handler if so requested */ - - if (irqhandler != NULL) - { - ret = irq_attach(IRQ_SW4, irqhandler, arg); - if (ret == OK) - { - up_enable_irq(IRQ_SW4); - } - } - - leave_critical_section(flags); + irq = CC1310_SW1_IRQ; + } + else if (id == BUTTON_SW2) + { + irq = CC1310_SW2_IRQ; + } + else + { + return -EINVAL } + /* The following should be atomic */ + + flags = enter_critical_section(); + + /* Detach and disable the button interrupt */ + + up_disable_irq(irq); + irq_detach(irq); + + /* Attach the new handler if so requested */ + + ret = OK; + if (irqhandler != NULL) + { + ret = irq_attach(irq, irqhandler, arg); + if (ret == OK) + { + up_enable_irq(irq); + } + } + + leave_critical_section(flags); return ret; -#else -#warning Missing logic - return -ENOSYS; -#endif } #endif diff --git a/configs/launchxl-cc1310/src/cc1310_pinconfig.c b/configs/launchxl-cc1310/src/cc1310_pinconfig.c index 4264c117f8..c36fe661e3 100644 --- a/configs/launchxl-cc1310/src/cc1310_pinconfig.c +++ b/configs/launchxl-cc1310/src/cc1310_pinconfig.c @@ -65,4 +65,70 @@ const struct cc13xx_pinconfig_s g_gpio_uart0_tx = .gpio = GPIO_DIO(1), .ioc = IOC_IOCFG_PORTID(IOC_IOCFG_PORTID_UART0_TX) | IOC_STD_OUTPUT }; -#endif \ No newline at end of file +#endif +/* The LaunchXL-cc1310 and two LEDs controlled by software: DIO7_GLED (CR1) + * and DIO6_RLED (CR2). A high output value illuminates an LED. + * + * If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in + * any way. The following definitions are used to access individual LEDs. + */ + +const struct cc13xx_pinconfig_s g_gpio_gled = +{ + .gpio = GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_DIO(7), + .ioc = IOC_IOCFG_PORTID(IOC_IOCFG_PORTID_GPIO) | IOC_STD_INPUT +}; + +const struct cc13xx_pinconfig_s g_gpio_rled = +{ + .gpio = GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_DIO(6), + .ioc = IOC_IOCFG_PORTID(IOC_IOCFG_PORTID_GPIO) | IOC_STD_INPUT +}; + +#ifdef CONFIG_ARCH_BUTTONS +/* The LaunchXL-CC1310 has two push-puttons: + * + * DIO13_BTN1 SW1 Low input sensed when depressed + * DIO14_BTN2 SW2 Low input sensed when depressed + */ + +#ifdef CONFIG_ARCH_IRQBUTTONS +/* Like IOC_STD_OUTPUT but with MCU wake-up enable and interrupt edge + * detection enabled on both edges. + */ + +#define IOC_CC1310_BUTTON_OUTPUT (IOC_IOCFG_IOEV_MCU_WUEN | \ + IOC_IOCFG_IOSTR_AUTO | \ + IOC_IOCFG_IOCURR_2MA | \ + IOC_IOCFG_PULLCTL_DIS | \ + IOC_IOCFG_EDGEDET_BOTH | \ + IOC_IOCFG_EDGE_IRQEN | \ + IOC_IOCFG_IOMODE_NORMAL | \ + IOC_IOCFG_WUCFG_WAKEUPL | \ + IOC_IOCFG_IE) + +#else +/* Like IOC_STD_OUTPUT but with MCU wake-up enable. */ + +#define IOC_CC1310_BUTTON_OUTPUT (IOC_IOCFG_IOEV_MCU_WUEN | \ + IOC_IOCFG_IOSTR_AUTO | \ + IOC_IOCFG_IOCURR_2MA | \ + IOC_IOCFG_PULLCTL_DIS | \ + IOC_IOCFG_EDGEDET_NONE | \ + IOC_IOCFG_IOMODE_NORMAL | \ + IOC_IOCFG_WUCFG_WAKEUPL | \ + IOC_IOCFG_IE) +#endif /* CONFIG_ARCH_IRQBUTTONS */ + +const struct cc13xx_pinconfig_s g_gpio_sw1 = +{ + .gpio = GPIO_DIO(14), + .ioc = IOC_IOCFG_PORTID(IOC_IOCFG_PORTID_GPIO) | IOC_CC1310_BUTTON_OUTPUT +}; + +const struct cc13xx_pinconfig_s g_gpio_sw2 = +{ + .gpio = GPIO_DIO(15), + .ioc = IOC_IOCFG_PORTID(IOC_IOCFG_PORTID_GPIO) | IOC_CC1310_BUTTON_OUTPUT +}; +#endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/launchxl-cc1310/src/cc1310_userleds.c b/configs/launchxl-cc1310/src/cc1310_userleds.c index 9b60c2fb42..62d25586ce 100644 --- a/configs/launchxl-cc1310/src/cc1310_userleds.c +++ b/configs/launchxl-cc1310/src/cc1310_userleds.c @@ -58,7 +58,8 @@ void board_userled_initialize(void) { -#warning Missing logic + (void)tiva_configgpio(&g_gpio_gled); + (void)tiva_configgpio(&g_gpio_rled); } /**************************************************************************** @@ -67,7 +68,22 @@ void board_userled_initialize(void) void board_userled(int led, bool ledon) { -#warning Missing logic + const struct cc13xx_pinconfig_s *pinconfig; + + if (led == BOARD_GLED) + { + pinconfig = &g_gpio_gled; + } + else if (led = BOARD_RLED) + { + pinconfig = &g_gpio_rled; + } + else + { + return; + } + + tiva_gpiowrite(pinconfig, ledon); /* High output illuminates */ } /**************************************************************************** @@ -76,5 +92,6 @@ void board_userled(int led, bool ledon) void board_userled_all(uint8_t ledset) { -#warning Missing logic + board_userled(BOARD_GLED, (ledset & BOARD_GLED_BIT) != 0); + board_userled(BOARD_RLED, (ledset & BOARD_RLED_BIT) != 0); } diff --git a/configs/launchxl-cc1310/src/launchxl-cc1310.h b/configs/launchxl-cc1310/src/launchxl-cc1310.h index fc10523cc7..51e7d0dd86 100644 --- a/configs/launchxl-cc1310/src/launchxl-cc1310.h +++ b/configs/launchxl-cc1310/src/launchxl-cc1310.h @@ -46,6 +46,40 @@ * Pre-processor Definitions ****************************************************************************/ +/* Button GPIO IRQ numbers + * + * DIO13_BTN1 SW1 Low input sensed when depressed + * DIO14_BTN2 SW2 Low input sensed when depressed + */ + +#define CC1310_SW1_IRQ TIVA_IRQ_DIO_13 +#define CC1310_SW2_IRQ TIVA_IRQ_DIO_14 + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +struct cc13xx_pinconfig_s; /* Forward reference */ + +/* The LaunchXL-cc1310 has two LEDs controlled by software: DIO7_GLED (CR1) + * and DIO6_RLED (CR2). A high output value illuminates an LED. + * + * If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in + * any way. The following definitions are used to access individual LEDs. + */ + +extern const struct cc13xx_pinconfig_s g_gpio_gled; +extern const struct cc13xx_pinconfig_s g_gpio_rled; + +/* The LaunchXL-CC1310 has two push-puttons: + * + * DIO13_BTN1 SW1 Low input sensed when depressed + * DIO14_BTN2 SW2 Low input sensed when depressed + */ + +extern const struct cc13xx_pinconfig_s g_gpio_sw1; +extern const struct cc13xx_pinconfig_s g_gpio_sw2; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/configs/launchxl-cc1312r1/README.txt b/configs/launchxl-cc1312r1/README.txt index ef5e80b6f6..998648a3b0 100644 --- a/configs/launchxl-cc1312r1/README.txt +++ b/configs/launchxl-cc1312r1/README.txt @@ -46,7 +46,7 @@ LEDs and Buttons LEDs ---- - The LaunchXL-cc1312R1 and two LEDs controlled by software: DIO7_GLED (CR1) + The LaunchXL-cc1312R1 has two LEDs controlled by software: DIO7_GLED (CR1) and DIO6_RLED (CR2). A high output value illuminates an LED. DIO7_GLED CR1 High output illuminuates diff --git a/configs/launchxl-cc1312r1/src/launchxl-cc1312r1.h b/configs/launchxl-cc1312r1/src/launchxl-cc1312r1.h index 3c32044b4a..035279a9ac 100644 --- a/configs/launchxl-cc1312r1/src/launchxl-cc1312r1.h +++ b/configs/launchxl-cc1312r1/src/launchxl-cc1312r1.h @@ -61,7 +61,7 @@ struct cc13xx_pinconfig_s; /* Forward reference */ -/* The LaunchXL-cc1312R1 and two LEDs controlled by software: DIO7_GLED (CR1) +/* The LaunchXL-cc1312R1 has two LEDs controlled by software: DIO7_GLED (CR1) * and DIO6_RLED (CR2). A high output value illuminates an LED. * * If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in