42 #include "hw_memmap.h" 55 #define CC26XX_UART_RX_INTERRUPT_TRIGGERS (UART_INT_RX | UART_INT_RT) 58 #define CC26XX_UART_INTERRUPT_ALL (UART_INT_OE | UART_INT_BE | UART_INT_PE | \ 59 UART_INT_FE | UART_INT_RT | UART_INT_TX | \ 60 UART_INT_RX | UART_INT_CTS) 62 #define cc26xx_uart_isr UART0IntHandler 64 static int (*input_handler)(
unsigned char c);
69 if(BOARD_IOID_UART_RX == IOID_UNUSED ||
70 BOARD_IOID_UART_TX == IOID_UNUSED ||
82 ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL);
83 while(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)
84 != PRCM_DOMAIN_POWER_ON);
87 ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_UART0);
88 ti_lib_prcm_load_set();
89 while(!ti_lib_prcm_load_get());
105 if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)
106 != PRCM_DOMAIN_POWER_ON) {
111 if(!(HWREG(PRCM_BASE + PRCM_O_UARTCLKGR) & PRCM_UARTCLKGR_CLK_EN)) {
119 disable_interrupts(
void)
122 ti_lib_int_disable(INT_UART0_COMB);
125 ti_lib_uart_int_disable(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
128 ti_lib_uart_int_clear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
132 enable_interrupts(
void)
135 ti_lib_uart_int_clear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
140 ti_lib_uart_int_enable(UART0_BASE, CC26XX_UART_RX_INTERRUPT_TRIGGERS);
143 ti_lib_int_enable(INT_UART0_COMB);
155 ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_UART_TX);
156 ti_lib_gpio_set_dio(BOARD_IOID_UART_TX);
162 ti_lib_ioc_pin_type_uart(UART0_BASE, BOARD_IOID_UART_RX, BOARD_IOID_UART_TX,
163 BOARD_IOID_UART_CTS, BOARD_IOID_UART_RTS);
166 ti_lib_uart_config_set_exp_clk(UART0_BASE, ti_lib_sys_ctrl_clock_get(),
168 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
169 UART_CONFIG_PAR_NONE));
175 ti_lib_uart_fifo_level_set(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX4_8);
185 HWREG(UART0_BASE + UART_O_CTL) = ctl_val;
189 lpm_drop_handler(uint8_t mode)
200 if(accessible() ==
true) {
201 while(ti_lib_uart_busy(UART0_BASE));
209 if((mode != LPM_MODE_SHUTDOWN) && (input_handler != NULL)) {
219 if(accessible() ==
true) {
221 ti_lib_uart_disable(UART0_BASE);
224 disable_interrupts();
231 ti_lib_prcm_peripheral_run_disable(PRCM_PERIPH_UART0);
232 if(mode == LPM_MODE_SHUTDOWN) {
233 ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_UART0);
234 ti_lib_prcm_peripheral_deep_sleep_disable(PRCM_PERIPH_UART0);
236 ti_lib_prcm_load_set();
237 while(!ti_lib_prcm_load_get());
247 LPM_MODULE(uart_module, NULL, lpm_drop_handler, NULL, LPM_DOMAIN_NONE);
255 ti_lib_uart_disable(UART0_BASE);
258 disable_interrupts();
270 bool interrupts_disabled;
273 if(usable() ==
false) {
278 interrupts_disabled = ti_lib_int_master_disable();
284 input_handler = NULL;
292 if(!interrupts_disabled) {
293 ti_lib_int_master_enable();
301 if(usable() ==
false) {
305 if(accessible() ==
false) {
309 ti_lib_uart_char_put(UART0_BASE, c);
315 input_handler =
input;
318 if(usable() ==
false) {
324 uart_module.domain_lock = LPM_DOMAIN_NONE;
327 ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_UART0);
328 ti_lib_prcm_peripheral_deep_sleep_disable(PRCM_PERIPH_UART0);
331 uart_module.domain_lock = LPM_DOMAIN_SERIAL;
334 ti_lib_prcm_peripheral_sleep_enable(PRCM_PERIPH_UART0);
335 ti_lib_prcm_peripheral_deep_sleep_enable(PRCM_PERIPH_UART0);
338 ti_lib_prcm_load_set();
339 while(!ti_lib_prcm_load_get());
350 if(usable() ==
false) {
355 if(accessible() ==
false) {
359 return ti_lib_uart_busy(UART0_BASE);
363 cc26xx_uart_isr(
void)
371 flags = ti_lib_uart_int_status(UART0_BASE,
true);
374 ti_lib_uart_int_clear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
376 if((flags & CC26XX_UART_RX_INTERRUPT_TRIGGERS) != 0) {
381 while(ti_lib_uart_chars_avail(UART0_BASE)) {
382 the_char = ti_lib_uart_char_get_non_blocking(UART0_BASE);
384 if(input_handler != NULL) {
385 input_handler((
unsigned char)the_char);
#define CC26XX_UART_CONF_ENABLE
Enable/Disable UART I/O.
Header file for the cc2538 UART driver.
Header file with macros which rename TI CC26xxware functions.
#define UART_CTL_TXE
UART transmit enable.
Header file with declarations for the I/O Control module.
void cc26xx_uart_write_byte(uint8_t c)
Sends a single character down the UART.
#define UART_LCRH_FEN
UART enable FIFOs.
#define UART_CTL_UARTEN
UART enable.
void cc26xx_uart_init()
Initialises the UART controller, configures I/O control and interrupts.
#define UART_CTL_RXE
UART receive enable.
void cc26xx_uart_set_input(int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.
#define CC26XX_UART_CONF_BAUD_RATE
Default UART0 baud rate.
Header file for the CC13xx/CC26xx UART driver.
uint8_t cc26xx_uart_busy(void)
Returns the UART busy status.
#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.
static void input(void)
Process a received 6lowpan packet.
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.