diff --git a/configs/tm4c123g-launchpad/src/tm4c123g-launchpad.h b/configs/tm4c123g-launchpad/src/tm4c123g-launchpad.h index d61bcec378..145127e603 100644 --- a/configs/tm4c123g-launchpad/src/tm4c123g-launchpad.h +++ b/configs/tm4c123g-launchpad/src/tm4c123g-launchpad.h @@ -169,11 +169,11 @@ */ #define GPIO_SW1 (GPIO_FUNC_INTERRUPT | GPIO_INT_BOTHEDGES | \ - GPIO_STRENGTH_2MA | GPIO_PADTYPE_STDWPU | GPIO_PORTF | \ - GPIO_PIN_4) + GPIO_STRENGTH_2MA | GPIO_PADTYPE_STDWPU | \ + GPIO_PORTF | GPIO_PIN_4) #define GPIO_SW2 (GPIO_FUNC_INTERRUPT | GPIO_INT_BOTHEDGES | \ - GPIO_STRENGTH_2MA | GPIO_PADTYPE_STDWPU | GPIO_PORTF | \ - GPIO_PIN_0) + GPIO_STRENGTH_2MA | GPIO_PADTYPE_STDWPU | \ + GPIO_PORTF | GPIO_PIN_0) /************************************************************************************ * Public Functions diff --git a/configs/tm4c123g-launchpad/src/tm4c_adc.c b/configs/tm4c123g-launchpad/src/tm4c_adc.c index 142297a0f3..2c727c3b6a 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_adc.c +++ b/configs/tm4c123g-launchpad/src/tm4c_adc.c @@ -47,6 +47,7 @@ #include "tiva_adc.h" #include "tiva_timer.h" #include "tm4c123g-launchpad.h" +#include "chip/tiva_pinmap.h" /************************************************************************************ * Pre-processor Definitions @@ -68,48 +69,68 @@ * Name: board_adc_initialize * * Description: - * Initialize and register the ADC driver + * Initialize and register the ADC driver. * ************************************************************************************/ #ifdef CONFIG_TIVA_ADC int board_adc_initialize(void) -{ + { +# if defined (CONFIG_TIVA_ADC) && defined (CONFIG_ADC) static bool initialized = false; - struct adc_dev_s *adc; int ret; + uint8_t srate = 0; + + struct tiva_adc_sse_cfg_s sse_cfg0; + struct tiva_adc_cfg_s adc_cfg; + struct tiva_adc_step_cfg_s step_cfg[] = + { + {0, 0, 0, 0, (TIVA_ADC_FLAG_TS | TIVA_ADC_FLAG_IE | TIVA_ADC_FLAG_END), 0}, + }; + + sse_cfg0.priority = 0; +# ifdef CONFIG_EXAMPLES_ADC_SWTRIG + sse_cfg0.trigger = TIVA_ADC_TRIG_SW; +# else + sse_cfg0.trigger = TIVA_ADC_TRIG_ALWAYS; +# endif + + adc_cfg.adc = 0; + adc_cfg.sse[0] = true; + adc_cfg.sse[1] = false; + adc_cfg.sse[2] = false; + adc_cfg.sse[3] = false; + adc_cfg.ssecfg[0] = sse_cfg0; + adc_cfg.steps = 1; + adc_cfg.stepcfg = step_cfg; + +# ifdef CONFIG_EXAMPLES_ADC_SWTRIG + srate = TIVA_ADC_SAMPLE_RATE_FASTEST; +# else + srate = TIVA_ADC_SAMPLE_RATE_SLOWEST; +# endif /* Check if we have already initialized */ if (!initialized) { - /* Call tiva_adcinitialize() to get an instance of the ADC interface */ + /* Call tiva_adc_initialize to configure an instance of the ADC + * interface and register it to the character level driver. + */ - adc = tiva_adc_initialize(0); - if (adc == NULL) - { - adbg("ERROR: Failed to get ADC interface\n"); - return -ENODEV; - } - - /* Register the ADC driver at "/dev/adc0" */ - - ret = adc_register("/dev/adc0", adc); + ret = tiva_adc_initialize(CONFIG_EXAMPLES_ADC_DEVPATH, &adc_cfg, + TIVA_ADC_CLOCK_MAX, srate); if (ret < 0) { - adbg("adc_register failed: %d\n", ret); + syslog(LOG_ERR, "ERROR: Failed to register /dev/adc0" + " to character driver: %d\n", ret); return ret; } - /* Enable ADC interrupts */ - - adc->ad_ops->ao_rxint(adc, true); - /* Now we are initialized */ initialized = true; } - return OK; } #endif /* CONFIG_ADC */ @@ -143,7 +164,7 @@ int adc_devinit(void) * Name: adc_timer_init * * Description: - * Inititalize timer specifically for ADC use. + * Initialize timer specifically for ADC use. * ************************************************************************************/ diff --git a/configs/tm4c123g-launchpad/src/tm4c_bringup.c b/configs/tm4c123g-launchpad/src/tm4c_bringup.c index 0ca78e3ce6..cf090360e3 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_bringup.c +++ b/configs/tm4c123g-launchpad/src/tm4c_bringup.c @@ -61,9 +61,7 @@ int tm4c_bringup(void) { -#if defined (HAVE_AT24) || defined (CONFIG_TIVA_TIMER) - int ret; -#endif /* defined (HAVE_AT24) || defined (CONFIG_TIVA_TIMER) */ + int ret = OK; #ifdef HAVE_AT24 /* Initialize the AT24 driver */ @@ -82,10 +80,10 @@ int tm4c_bringup(void) ret = tiva_timer_initialize(); if (ret < 0) { - syslog(LOG_ERR, "ERROR: Failed to initialize timer driver: %d\n", ret); + syslog(LOG_ERR, "ERROR: tiva_timer_initialize failed: %d\n", ret); return ret; } #endif /* CONFIG_TIVA_TIMER */ - return OK; + return ret; } diff --git a/configs/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c index 78f1b6733b..57c285ea60 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c @@ -57,10 +57,6 @@ * Private Data ****************************************************************************/ -#ifdef CONFIG_ARCH_IRQBUTTONS -static xcpt_t g_irquser; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -95,6 +91,13 @@ void board_button_initialize(void) tiva_configgpio(GPIO_SW1); tiva_configgpio(GPIO_SW2); + /* These pins need to be set to logic high (3.3V) so that the buttons + * can pull them to logic low (0V) + */ + + tiva_gpiowrite(GPIO_SW1, true); + tiva_gpiowrite(GPIO_SW2, true); + /* Configure GPIO interrupts */ #ifdef CONFIG_ARCH_IRQBUTTONS @@ -115,7 +118,7 @@ void board_button_initialize(void) uint8_t board_buttons(void) { - uint8_t ret = 0x0; + uint8_t ret = 0; /* Check that state of each key. A LOW value means that the key is * pressed. @@ -123,12 +126,12 @@ uint8_t board_buttons(void) if (!tiva_gpioread(GPIO_SW1)) { - ret |= (1 << GPIO_PIN_4); + ret |= BUTTON_SW1_BIT; } if (!tiva_gpioread(GPIO_SW2)) { - ret |= (1 << GPIO_PIN_0); + ret |= BUTTON_SW2_BIT; } return ret; @@ -145,52 +148,43 @@ uint8_t board_buttons(void) * ****************************************************************************/ -# ifdef CONFIG_ARCH_IRQBUTTONS +#ifdef CONFIG_ARCH_IRQBUTTONS xcpt_t board_button_irq(int id, xcpt_t irqhandler) { xcpt_t oldhandler = NULL; + uint32_t pinset= 0; - if (id == BUTTON_SW1 || - id == BUTTON_SW2) + /* Determine which switch to set the irq handler for */ + + switch (id) { - irqstate_t flags; + case BUTTON_SW1: + pinset = GPIO_SW1; + break; - /* Disable interrupts until we are done. This guarantees that the - * following operations are atomic. - */ + case BUTTON_SW2: + pinset = GPIO_SW2; + break; - flags = irqsave(); - - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irquser; - g_irquser = irqhandler; - - /* Are we attaching or detaching? */ - - if (irqhandler != NULL) - { - /* Configure the interrupt */ - - (void)tiva_gpioirqattach(CONFIG_TIVA_GPIOF_IRQS, irqhandler); - tiva_gpioirqenable(CONFIG_TIVA_GPIOF_IRQS); - } - else - { - /* Disable and detach the interrupt */ - - tiva_gpioirqdisable(CONFIG_TIVA_GPIOF_IRQS); - (void)tiva_gpioirqattach(CONFIG_TIVA_GPIOF_IRQS, NULL); - } - /* Configure the interrupt */ - - irqrestore(flags); + default: + return NULL; } + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + oldhandler = tiva_gpioirqattach(pinset, irqhandler); + } + else + { + oldhandler = tiva_gpioirqdetach(pinset); + } + /* Return the old button handler (so that it can be restored) */ return oldhandler; } -# endif +#endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/tm4c123g-launchpad/src/tm4c_timer.c b/configs/tm4c123g-launchpad/src/tm4c_timer.c index 17dd5842eb..96f5db9188 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_timer.c +++ b/configs/tm4c123g-launchpad/src/tm4c_timer.c @@ -57,10 +57,6 @@ # error CONFIG_TIVA_TIMER32_PERIODIC is not defined #endif -#define GPTM 0 -#define CONFIG_TM4C_TIMER_DEVNAME "/dev/timer0" -#define ALTCLK false - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -69,20 +65,37 @@ * Name: tiva_timer_initialize * * Description: - * Configure the timer driver + * Configure the timer driver for the timer example application. * ****************************************************************************/ int tiva_timer_initialize(void) { - int ret; + static bool initialized = false; + int ret = OK; - timvdbg("Registering TIMER%d at %s\n", GPTM, CONFIG_TM4C_TIMER_DEVNAME); + /* Check if we have already initialized */ - ret = tiva_timer_register(CONFIG_TM4C_TIMER_DEVNAME, GPTM, ALTCLK); - if (ret < 0) + if (!initialized) { - timdbg("ERROR: Failed to register timer driver: %d\n", ret); + struct tiva_gptm32config_s timer_config; + timer_config.cmn.gptm = 0; + timer_config.cmn.mode = TIMER32_MODE_PERIODIC; + timer_config.cmn.alternate = false; + + timer_config.config.flags = TIMER_FLAG_COUNTUP; + timer_config.config.handler = 0; + timer_config.config.arg = 0; + + ret = tiva_timer_initialize(CONFIG_EXAMPLE_TIMER_DEVNAME, &timer_config); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register timer driver: %d\n", ret); + } + + /* now we are initialized */ + + initialized = true; } return ret;