cc2538: uart: Fix crippled output occurring upon lpm_enter()

lpm_enter() must not enter PM1+ if the UART TX FIFO is not empty. Otherwise, the
UART clock gets disabled, and its TX is broken.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
This commit is contained in:
Benoît Thébaudeau 2013-11-15 17:24:26 +01:00
parent 0692ee251d
commit b8b54a033c
3 changed files with 14 additions and 2 deletions

View File

@ -41,8 +41,10 @@
#include "dev/ioc.h"
#include "dev/gpio.h"
#include "dev/uart.h"
#include "lpm.h"
#include "reg.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
@ -96,9 +98,19 @@ reset(void)
REG(UART_BASE | UART_CTL) |= UART_CTL_UARTEN;
}
/*---------------------------------------------------------------------------*/
static bool
permit_pm1(void)
{
/* Note: UART_FR.TXFE reads 0 if the UART clock is gated. */
return (REG(SYS_CTRL_RCGCUART) & SYS_CTRL_RCGCUART_UART) == 0 ||
(REG(UART_BASE | UART_FR) & UART_FR_TXFE) != 0;
}
/*---------------------------------------------------------------------------*/
void
uart_init(void)
{
lpm_register_peripheral(permit_pm1);
/* Enable clock for the UART while Running, in Sleep and Deep Sleep */
REG(SYS_CTRL_RCGCUART) |= SYS_CTRL_RCGCUART_UART;
REG(SYS_CTRL_SCGCUART) |= SYS_CTRL_SCGCUART_UART;

View File

@ -102,7 +102,7 @@ static uint8_t max_pm;
#ifdef LPM_CONF_PERIPH_PERMIT_PM1_FUNCS_MAX
#define LPM_PERIPH_PERMIT_PM1_FUNCS_MAX LPM_CONF_PERIPH_PERMIT_PM1_FUNCS_MAX
#else
#define LPM_PERIPH_PERMIT_PM1_FUNCS_MAX 1
#define LPM_PERIPH_PERMIT_PM1_FUNCS_MAX 2
#endif
lpm_periph_permit_pm1_func_t

View File

@ -182,7 +182,7 @@ typedef bool (*lpm_periph_permit_pm1_func_t)(void);
* \param permit_pm1_func Pointer to the function
*
* Some peripherals are sensitive to PM changes. For instance, we don't want to
* drop to PM1+ if the USB PLL is active.
* drop to PM1+ if the USB PLL is active or if the UART TX FIFO is not clear.
*
* When changing power modes, the LPM driver will call all FPs registered with
* this function. The peripheral's function will return true or false to permit