mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cc26xx_cc13xx: add power abstraction
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
This commit is contained in:
parent
45b635f4c5
commit
4643ed5733
@ -1 +1,3 @@
|
||||
USEMODULE += cc26xx_cc13xx
|
||||
|
||||
include ${RIOTCPU}/cc26xx_cc13xx/Makefile.dep
|
||||
|
63
cpu/cc26xx_cc13xx/include/cc26xx_cc13xx_power.h
Normal file
63
cpu/cc26xx_cc13xx/include/cc26xx_cc13xx_power.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Locha Inc
|
||||
*
|
||||
* 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_cc26xx_cc13xx
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief CC26xx/CC13xx Power management
|
||||
*
|
||||
* @author Jean Pierre Dudey <jeandudey@hotmail.com>
|
||||
*/
|
||||
|
||||
#ifndef CC26XX_CC13XX_POWER_H
|
||||
#define CC26XX_CC13XX_POWER_H
|
||||
|
||||
#include <cc26xx_cc13xx.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Power domains
|
||||
*/
|
||||
typedef enum {
|
||||
POWER_DOMAIN_PERIPHERALS, /**< Peripherals domain */
|
||||
POWER_DOMAIN_SERIAL, /**< Serial domain */
|
||||
POWER_DOMAIN_RFC, /**< RF Core domain */
|
||||
POWER_DOMAIN_CPU, /**< CPU domain */
|
||||
POWER_DOMAIN_VIMS, /**< VIMS domain */
|
||||
} power_domain_t;
|
||||
|
||||
/**
|
||||
* @brief Is power domain enabled?
|
||||
*
|
||||
* @param[in] domain The domain.
|
||||
*
|
||||
* @return true Is enabled.
|
||||
* @return false Is not enabled.
|
||||
*/
|
||||
bool power_is_domain_enabled(const power_domain_t domain);
|
||||
|
||||
/**
|
||||
* @brief Enable the specified power domain.
|
||||
*
|
||||
* @params[in] domain The domain.
|
||||
*/
|
||||
void power_enable_domain(const power_domain_t domain);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* CC26XX_CC13XX_POWER_H */
|
||||
|
||||
/*@}*/
|
@ -38,9 +38,12 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
|
||||
if ((unsigned int)pin > 31)
|
||||
return -1;
|
||||
|
||||
/* enable peripherals power domain */
|
||||
if (!power_is_domain_enabled(POWER_DOMAIN_PERIPHERALS)) {
|
||||
power_enable_domain(POWER_DOMAIN_PERIPHERALS);
|
||||
}
|
||||
|
||||
/* enable GPIO clock */
|
||||
PRCM->PDCTL0 |= PDCTL0_PERIPH_ON;
|
||||
while(!(PRCM->PDSTAT0 & PDSTAT0_PERIPH_ON)) ;
|
||||
PRCM->GPIOCLKGR |= 1;
|
||||
PRCM->CLKLOADCTL |= CLKLOADCTL_LOAD;
|
||||
while (!(PRCM->CLKLOADCTL & CLKLOADCTL_LOADDONE)) ;
|
||||
|
@ -57,9 +57,11 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
||||
int rts_pin = uart_config[uart].rts_pin;
|
||||
int cts_pin = uart_config[uart].cts_pin;
|
||||
#endif
|
||||
|
||||
/* enable clocks: serial power domain and UART */
|
||||
PRCM->PDCTL0SERIAL = 1;
|
||||
while (!(PRCM->PDSTAT0 & PDSTAT0_SERIAL_ON)) ;
|
||||
if (!power_is_domain_enabled(POWER_DOMAIN_SERIAL)) {
|
||||
power_enable_domain(POWER_DOMAIN_SERIAL);
|
||||
}
|
||||
uart_poweron(uart);
|
||||
|
||||
/* disable and reset the UART */
|
||||
|
82
cpu/cc26xx_cc13xx/power_arch.c
Normal file
82
cpu/cc26xx_cc13xx/power_arch.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Locha Inc
|
||||
*
|
||||
* 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_cc26xx_cc13xx
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Power management abstractions
|
||||
*
|
||||
* @author Jean Pierre Dudey <jeandudey@hotmail.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
|
||||
#define DOMAIN_ON (1)
|
||||
|
||||
bool power_is_domain_enabled(const power_domain_t domain)
|
||||
{
|
||||
switch (domain) {
|
||||
case POWER_DOMAIN_PERIPHERALS:
|
||||
return PRCM->PDSTAT0PERIPH == DOMAIN_ON;
|
||||
|
||||
case POWER_DOMAIN_SERIAL:
|
||||
return PRCM->PDSTAT0SERIAL == DOMAIN_ON;
|
||||
|
||||
case POWER_DOMAIN_RFC:
|
||||
/* At least one of the registers need to indicate that the power
|
||||
* domain is on */
|
||||
return (PRCM->PDSTAT1RFC == DOMAIN_ON) ||
|
||||
(PRCM->PDSTAT0RFC == DOMAIN_ON);
|
||||
|
||||
case POWER_DOMAIN_VIMS:
|
||||
return PRCM->PDSTAT1VIMS == DOMAIN_ON;
|
||||
|
||||
case POWER_DOMAIN_CPU:
|
||||
return PRCM->PDSTAT1CPU == DOMAIN_ON;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void power_enable_domain(const power_domain_t domain)
|
||||
{
|
||||
switch (domain) {
|
||||
case POWER_DOMAIN_PERIPHERALS:
|
||||
PRCM->PDCTL0PERIPH = DOMAIN_ON;
|
||||
break;
|
||||
|
||||
case POWER_DOMAIN_SERIAL:
|
||||
PRCM->PDCTL0SERIAL = DOMAIN_ON;
|
||||
break;
|
||||
|
||||
case POWER_DOMAIN_RFC:
|
||||
/* On CC26x0 MCUs PDCTL1RFC needs to be written too in order to
|
||||
* enable the RF Core power domain. On `cc13x2_cc26x2` it's not
|
||||
* necessary and domain is powered normally. */
|
||||
PRCM->PDCTL0RFC = DOMAIN_ON;
|
||||
PRCM->PDCTL1RFC = DOMAIN_ON;
|
||||
break;
|
||||
|
||||
case POWER_DOMAIN_CPU:
|
||||
PRCM->PDCTL1CPU = DOMAIN_ON;
|
||||
break;
|
||||
|
||||
case POWER_DOMAIN_VIMS:
|
||||
PRCM->PDCTL1VIMS = DOMAIN_ON;
|
||||
break;
|
||||
}
|
||||
|
||||
while (!power_is_domain_enabled(domain)) {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user