2015-07-04 09:37:54 +02:00
|
|
|
/*
|
2015-07-16 02:56:33 +02:00
|
|
|
* Copyright (C) 2015 Rakendra Thapa <rakendrathapa@gmail.com>
|
2015-07-04 09:37:54 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License v2.1. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cpu_lm4f120
|
2017-06-22 15:43:17 +02:00
|
|
|
* @ingroup drivers_periph_uart
|
2015-07-04 09:37:54 +02:00
|
|
|
* @{
|
|
|
|
*
|
2015-07-16 02:56:33 +02:00
|
|
|
* @file uart.c
|
2015-07-04 09:37:54 +02:00
|
|
|
* @brief Implementation of the low-level UART driver for the LM4F120
|
|
|
|
*
|
|
|
|
* @author Rakendra Thapa <rakendrathapa@gmail.com>
|
2015-10-20 16:27:05 +02:00
|
|
|
*
|
|
|
|
* @}
|
2015-07-04 09:37:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-09-13 16:18:10 +02:00
|
|
|
#include "assert.h"
|
2015-07-04 09:37:54 +02:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "periph/uart.h"
|
|
|
|
#include "periph_conf.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UART device configurations
|
|
|
|
*/
|
2015-10-20 16:27:05 +02:00
|
|
|
static uart_isr_ctx_t config[UART_NUMOF];
|
2015-07-04 09:37:54 +02:00
|
|
|
|
2015-10-20 16:27:05 +02:00
|
|
|
static int init_base(uart_t uart, uint32_t baudrate);
|
|
|
|
|
2015-07-16 02:56:33 +02:00
|
|
|
/**
|
|
|
|
* Configuring the UART console
|
2015-07-04 09:37:54 +02:00
|
|
|
*/
|
2015-10-20 16:27:05 +02:00
|
|
|
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
2015-07-04 09:37:54 +02:00
|
|
|
{
|
2015-07-24 05:27:40 +02:00
|
|
|
/* Check the arguments */
|
2015-09-13 16:18:10 +02:00
|
|
|
assert(uart == 0);
|
2015-07-24 05:27:40 +02:00
|
|
|
/* Check to make sure the UART peripheral is present */
|
2015-07-14 18:11:25 +02:00
|
|
|
if(!ROM_SysCtlPeripheralPresent(SYSCTL_PERIPH_UART0)){
|
2016-10-28 10:15:46 +02:00
|
|
|
return UART_NODEV;
|
2015-07-14 18:11:25 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 16:27:05 +02:00
|
|
|
int res = init_base(uart, baudrate);
|
2016-10-28 10:15:46 +02:00
|
|
|
if(res != UART_OK){
|
2015-07-14 18:11:25 +02:00
|
|
|
return res;
|
|
|
|
}
|
2015-07-04 09:37:54 +02:00
|
|
|
|
|
|
|
/* save callbacks */
|
|
|
|
config[uart].rx_cb = rx_cb;
|
|
|
|
config[uart].arg = arg;
|
|
|
|
|
2015-07-24 05:27:40 +02:00
|
|
|
/* ulBase = g_ulUARTBase[uart]; */
|
2015-07-14 18:11:25 +02:00
|
|
|
switch (uart){
|
2015-07-04 09:37:54 +02:00
|
|
|
#if UART_0_EN
|
2015-07-14 18:11:25 +02:00
|
|
|
case UART_0:
|
|
|
|
ROM_UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT);
|
2015-07-16 02:56:33 +02:00
|
|
|
ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
|
|
|
|
ROM_UARTFIFOEnable(UART0_BASE);
|
2015-07-15 11:48:31 +02:00
|
|
|
|
2015-07-18 07:55:28 +02:00
|
|
|
/* Enable the UART interrupt */
|
2015-07-04 09:37:54 +02:00
|
|
|
NVIC_EnableIRQ(UART_0_IRQ_CHAN);
|
2015-07-16 02:56:33 +02:00
|
|
|
/* Enable RX interrupt */
|
2015-07-14 18:11:25 +02:00
|
|
|
UART0_IM_R = UART_IM_RXIM | UART_IM_RTIM;
|
|
|
|
break;
|
2015-07-04 09:37:54 +02:00
|
|
|
#endif
|
|
|
|
#if UART_1_EN
|
2015-07-14 18:11:25 +02:00
|
|
|
case UART_1:
|
2015-07-16 02:56:33 +02:00
|
|
|
/* Enable the UART interrupt */
|
2015-07-04 09:37:54 +02:00
|
|
|
NVIC_EnableIRQ(UART_1_IRQ_CHAN);
|
2015-07-14 18:11:25 +02:00
|
|
|
break;
|
2015-07-04 09:37:54 +02:00
|
|
|
#endif
|
2015-07-14 18:11:25 +02:00
|
|
|
}
|
2016-10-28 10:15:46 +02:00
|
|
|
return UART_OK;
|
2015-07-04 09:37:54 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 16:27:05 +02:00
|
|
|
static int init_base(uart_t uart, uint32_t baudrate)
|
2015-07-04 09:37:54 +02:00
|
|
|
{
|
2015-07-14 18:11:25 +02:00
|
|
|
switch(uart){
|
2015-07-04 09:37:54 +02:00
|
|
|
#if UART_0_EN
|
2015-07-14 18:11:25 +02:00
|
|
|
case UART_0:
|
|
|
|
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
|
|
|
|
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
|
|
|
|
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
|
|
|
|
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
|
|
|
|
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
|
2015-07-04 09:37:54 +02:00
|
|
|
|
2015-07-14 18:11:25 +02:00
|
|
|
ROM_UARTDisable(UART0_BASE);
|
|
|
|
ROM_UARTConfigSetExpClk(UART0_BASE,ROM_SysCtlClockGet(), baudrate,
|
|
|
|
(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
|
|
|
|
UART_CONFIG_WLEN_8));
|
2015-07-04 09:37:54 +02:00
|
|
|
|
2015-07-10 04:06:50 +02:00
|
|
|
|
2015-07-14 18:11:25 +02:00
|
|
|
ROM_UARTEnable(UART0_BASE);
|
|
|
|
break;
|
2015-07-04 09:37:54 +02:00
|
|
|
#endif
|
2016-10-28 10:15:46 +02:00
|
|
|
default:
|
|
|
|
return UART_NODEV;
|
2015-07-14 18:11:25 +02:00
|
|
|
}
|
2016-10-28 10:15:46 +02:00
|
|
|
return UART_OK;
|
2015-07-04 09:37:54 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 16:27:05 +02:00
|
|
|
void uart_write(uart_t uart, const uint8_t *data, size_t len)
|
2015-07-04 09:37:54 +02:00
|
|
|
{
|
build: fix unused parameter errors
cpu, sam0_common: fix unused parameter in periph/spi
cpu, kinetis_common: fix unused parameter in periph/spi
cpu, cc2538: fix unused param in periph/i2c
cpu, cc2538: fix unused param in periph/spi
cpu, sam3: fix unused param in periph/spi
cpu, stm32_common: fix unused param in periph/pm
cpu, stm32f3: fix unused params in periph/i2c
cpu, nrf5x_common: fix unused param in periph/gpio
cpu, nrf5x_common: fix unused param in periph/spi
cpu, lpc2387: fix unused params in periph/spi
cpu, cc2538: fix unused params in radio/netdev
cpu, cc2650: fix unused params in periph/uart
cpu, lm4f120: fix unused param in periph/spi
cpu, lm4f120: fix unused params in periph/timer
cpu, lm4f120: fix unused params in periph/uart
cpu, stm32_common: fix unused params in periph/dac
cpu, stm32l0: fix unused params in periph/i2c
cpu, msp430fxyz: fix unused params in periph/uart
cpu, mips: fix unused params
cpu, cc430: fix unused-params in periph/timer
cpu, msp430fxyz: fix unused params in periph/spi
drivers, cc2420: fix unused param
cpu, mips32r2_common: fix unused params in periph/timer
cpu, cc2538: fix unused-param in periph/i2c
cpu, mips32r2_common: fix unused-param in periph/timer
cpu, msp430fxyz: fix unused params in periph/timer
cpu, atmega_common: fix unused params in periph/spi
driver, nrfmin: fix unused params
cpu, cc2538_rf: fix unused params
driver, netdev_ieee802514: fix unused param
cpu, mip_pic32m: fix unused params
cpu, lpc2387: fix unused params in periph/pwm
tests/driver_sdcard_spi: fix unused params
cpu, sam3: fix unused param in periph/pwm
tests/driver_dynamixel: fix unused params, and style issues
cpu, cc430: fix unused param in periph/rtc
cpu, atmega_common: fix unused params in periph/i2c
2017-10-31 12:09:11 +01:00
|
|
|
(void) uart;
|
|
|
|
|
2015-10-20 16:27:05 +02:00
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
ROM_UARTCharPut(UART0_BASE, (char)data[i]);
|
|
|
|
}
|
2015-07-04 09:37:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uart_poweron(uart_t uart)
|
|
|
|
{
|
build: fix unused parameter errors
cpu, sam0_common: fix unused parameter in periph/spi
cpu, kinetis_common: fix unused parameter in periph/spi
cpu, cc2538: fix unused param in periph/i2c
cpu, cc2538: fix unused param in periph/spi
cpu, sam3: fix unused param in periph/spi
cpu, stm32_common: fix unused param in periph/pm
cpu, stm32f3: fix unused params in periph/i2c
cpu, nrf5x_common: fix unused param in periph/gpio
cpu, nrf5x_common: fix unused param in periph/spi
cpu, lpc2387: fix unused params in periph/spi
cpu, cc2538: fix unused params in radio/netdev
cpu, cc2650: fix unused params in periph/uart
cpu, lm4f120: fix unused param in periph/spi
cpu, lm4f120: fix unused params in periph/timer
cpu, lm4f120: fix unused params in periph/uart
cpu, stm32_common: fix unused params in periph/dac
cpu, stm32l0: fix unused params in periph/i2c
cpu, msp430fxyz: fix unused params in periph/uart
cpu, mips: fix unused params
cpu, cc430: fix unused-params in periph/timer
cpu, msp430fxyz: fix unused params in periph/spi
drivers, cc2420: fix unused param
cpu, mips32r2_common: fix unused params in periph/timer
cpu, cc2538: fix unused-param in periph/i2c
cpu, mips32r2_common: fix unused-param in periph/timer
cpu, msp430fxyz: fix unused params in periph/timer
cpu, atmega_common: fix unused params in periph/spi
driver, nrfmin: fix unused params
cpu, cc2538_rf: fix unused params
driver, netdev_ieee802514: fix unused param
cpu, mip_pic32m: fix unused params
cpu, lpc2387: fix unused params in periph/pwm
tests/driver_sdcard_spi: fix unused params
cpu, sam3: fix unused param in periph/pwm
tests/driver_dynamixel: fix unused params, and style issues
cpu, cc430: fix unused param in periph/rtc
cpu, atmega_common: fix unused params in periph/i2c
2017-10-31 12:09:11 +01:00
|
|
|
(void) uart;
|
|
|
|
|
2015-07-14 18:11:25 +02:00
|
|
|
ROM_UARTEnable(UART0_BASE);
|
2015-07-04 09:37:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uart_poweroff(uart_t uart)
|
|
|
|
{
|
build: fix unused parameter errors
cpu, sam0_common: fix unused parameter in periph/spi
cpu, kinetis_common: fix unused parameter in periph/spi
cpu, cc2538: fix unused param in periph/i2c
cpu, cc2538: fix unused param in periph/spi
cpu, sam3: fix unused param in periph/spi
cpu, stm32_common: fix unused param in periph/pm
cpu, stm32f3: fix unused params in periph/i2c
cpu, nrf5x_common: fix unused param in periph/gpio
cpu, nrf5x_common: fix unused param in periph/spi
cpu, lpc2387: fix unused params in periph/spi
cpu, cc2538: fix unused params in radio/netdev
cpu, cc2650: fix unused params in periph/uart
cpu, lm4f120: fix unused param in periph/spi
cpu, lm4f120: fix unused params in periph/timer
cpu, lm4f120: fix unused params in periph/uart
cpu, stm32_common: fix unused params in periph/dac
cpu, stm32l0: fix unused params in periph/i2c
cpu, msp430fxyz: fix unused params in periph/uart
cpu, mips: fix unused params
cpu, cc430: fix unused-params in periph/timer
cpu, msp430fxyz: fix unused params in periph/spi
drivers, cc2420: fix unused param
cpu, mips32r2_common: fix unused params in periph/timer
cpu, cc2538: fix unused-param in periph/i2c
cpu, mips32r2_common: fix unused-param in periph/timer
cpu, msp430fxyz: fix unused params in periph/timer
cpu, atmega_common: fix unused params in periph/spi
driver, nrfmin: fix unused params
cpu, cc2538_rf: fix unused params
driver, netdev_ieee802514: fix unused param
cpu, mip_pic32m: fix unused params
cpu, lpc2387: fix unused params in periph/pwm
tests/driver_sdcard_spi: fix unused params
cpu, sam3: fix unused param in periph/pwm
tests/driver_dynamixel: fix unused params, and style issues
cpu, cc430: fix unused param in periph/rtc
cpu, atmega_common: fix unused params in periph/i2c
2017-10-31 12:09:11 +01:00
|
|
|
(void) uart;
|
|
|
|
|
2015-07-14 18:11:25 +02:00
|
|
|
ROM_UARTDisable(UART0_BASE);
|
2015-07-04 09:37:54 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 02:56:33 +02:00
|
|
|
/**
|
|
|
|
* The UART interrupt handler.
|
|
|
|
*/
|
2015-07-18 09:28:16 +02:00
|
|
|
void isr_uart0(void)
|
2015-07-04 09:37:54 +02:00
|
|
|
{
|
2015-07-14 18:11:25 +02:00
|
|
|
unsigned long ulStatus;
|
|
|
|
|
|
|
|
ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
|
|
|
|
ROM_UARTIntClear(UART0_BASE, ulStatus);
|
|
|
|
|
2015-07-24 05:27:40 +02:00
|
|
|
/* Are we interrupted due to a recieved character */
|
2015-07-14 18:11:25 +02:00
|
|
|
if(ulStatus & (UART_INT_RX | UART_INT_RT))
|
|
|
|
{
|
|
|
|
while(ROM_UARTCharsAvail(UART0_BASE))
|
|
|
|
{
|
2016-03-15 10:58:54 +01:00
|
|
|
long lchar = ROM_UARTCharGetNonBlocking(UART0_BASE);
|
|
|
|
config[UART_0].rx_cb(config[UART_0].arg, (uint8_t)lchar);
|
2015-07-14 18:11:25 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-30 18:26:05 +01:00
|
|
|
cortexm_isr_end();
|
2015-07-04 09:37:54 +02:00
|
|
|
}
|