39 #include "contiki-conf.h"
42 #include "hw_memmap.h"
56 #define CC26XX_UART_RX_INTERRUPT_TRIGGERS (UART_INT_RX | UART_INT_RT)
59 #define CC26XX_UART_INTERRUPT_ALL (UART_INT_OE | UART_INT_BE | UART_INT_PE | \
60 UART_INT_FE | UART_INT_RT | UART_INT_TX | \
61 UART_INT_RX | UART_INT_CTS)
63 #define cc26xx_uart_isr UART0IntHandler
65 static int (*input_handler)(
unsigned char c);
70 if(BOARD_IOID_UART_RX == IOID_UNUSED ||
71 BOARD_IOID_UART_TX == IOID_UNUSED ||
83 ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL);
84 while(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)
85 != PRCM_DOMAIN_POWER_ON);
88 ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_UART0);
89 ti_lib_prcm_load_set();
90 while(!ti_lib_prcm_load_get());
106 if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)
107 != PRCM_DOMAIN_POWER_ON) {
112 if(!(HWREG(PRCM_BASE + PRCM_O_UARTCLKGR) & PRCM_UARTCLKGR_CLK_EN)) {
120 disable_interrupts(
void)
123 ti_lib_int_disable(INT_UART0);
126 ti_lib_uart_int_disable(
UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
129 ti_lib_uart_int_clear(
UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
133 enable_interrupts(
void)
136 ti_lib_uart_int_clear(
UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
141 ti_lib_uart_int_enable(
UART0_BASE, CC26XX_UART_RX_INTERRUPT_TRIGGERS);
144 ti_lib_int_enable(INT_UART0);
156 ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_UART_TX);
157 ti_lib_gpio_pin_write(BOARD_UART_TX, 1);
163 ti_lib_ioc_pin_type_uart(
UART0_BASE, BOARD_IOID_UART_RX, BOARD_IOID_UART_TX,
164 BOARD_IOID_UART_CTS, BOARD_IOID_UART_RTS);
167 ti_lib_uart_config_set_exp_clk(
UART0_BASE, ti_lib_sys_ctrl_clock_get(),
169 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
170 UART_CONFIG_PAR_NONE));
176 ti_lib_uart_fifo_level_set(
UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX4_8);
190 lpm_drop_handler(uint8_t mode)
201 if(accessible() ==
true) {
210 if((mode != LPM_MODE_SHUTDOWN) && (input_handler !=
NULL)) {
220 if(accessible() ==
true) {
225 disable_interrupts();
232 ti_lib_prcm_peripheral_run_disable(PRCM_PERIPH_UART0);
233 if(mode == LPM_MODE_SHUTDOWN) {
234 ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_UART0);
235 ti_lib_prcm_peripheral_deep_sleep_disable(PRCM_PERIPH_UART0);
237 ti_lib_prcm_load_set();
238 while(!ti_lib_prcm_load_get());
259 disable_interrupts();
271 bool interrupts_disabled;
274 if(usable() ==
false) {
279 interrupts_disabled = ti_lib_int_master_disable();
285 input_handler =
NULL;
293 if(!interrupts_disabled) {
294 ti_lib_int_master_enable();
302 if(usable() ==
false) {
306 if(accessible() ==
false) {
316 input_handler =
input;
319 if(usable() ==
false) {
325 uart_module.domain_lock = LPM_DOMAIN_NONE;
328 ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_UART0);
329 ti_lib_prcm_peripheral_deep_sleep_disable(PRCM_PERIPH_UART0);
332 uart_module.domain_lock = LPM_DOMAIN_SERIAL;
335 ti_lib_prcm_peripheral_sleep_enable(PRCM_PERIPH_UART0);
336 ti_lib_prcm_peripheral_deep_sleep_enable(PRCM_PERIPH_UART0);
339 ti_lib_prcm_load_set();
340 while(!ti_lib_prcm_load_get());
351 if(usable() ==
false) {
356 if(accessible() ==
false) {
364 cc26xx_uart_isr(
void)
369 ENERGEST_ON(ENERGEST_TYPE_IRQ);
374 flags = ti_lib_uart_int_status(
UART0_BASE,
true);
377 ti_lib_uart_int_clear(
UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
379 if((flags & CC26XX_UART_RX_INTERRUPT_TRIGGERS) != 0) {
385 the_char = ti_lib_uart_char_get_non_blocking(
UART0_BASE);
387 if(input_handler !=
NULL) {
388 input_handler((
unsigned char)the_char);
393 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
void cc26xx_uart_init()
Initialises the UART controller, configures I/O control and interrupts.
Header file with macros which rename TI CC26xxware functions.
uint8_t cc26xx_uart_busy(void)
Returns the UART busy status.
#define CC26XX_UART_CONF_BAUD_RATE
Default UART0 baud rate.
static void input(void)
Process a received 6lowpan packet.
#define CC26XX_UART_CONF_ENABLE
Enable/Disable UART I/O.
void cc26xx_uart_write_byte(uint8_t c)
Sends a single character down the UART.
Header file for the energy estimation mechanism
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.
#define UART_LCRH_FEN
UART enable FIFOs.
#define LPM_MODULE(n, m, s, w, l)
Declare a variable to be used in order to get notifications from LPM.
void lpm_pin_set_default_state(uint32_t ioid)
Sets an IOID to a default state.
#define NULL
The null pointer.
Header file with declarations for the I/O Control module.
#define UART_CTL_TXE
UART transmit enable.
#define UART_CTL_UARTEN
UART enable.
#define UART0_BASE
Peripheral UART0 base address.
#define UART_CTL_RXE
UART receive enable.
Header file for the CC13xx/CC26xx UART driver.
void cc26xx_uart_set_input(int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.