Make sure SSI0 is powered and clocked before accessing it
* Fail all SSI0 operations if the module is not powered and clocked * Make sure SERIAL is powered before trying to enable run mode clock
This commit is contained in:
parent
78d04f812b
commit
7ae3cd49ba
1 changed files with 37 additions and 1 deletions
|
@ -40,12 +40,35 @@
|
||||||
#include "ti-lib.h"
|
#include "ti-lib.h"
|
||||||
#include "board-spi.h"
|
#include "board-spi.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#define CPU_FREQ 48000000ul
|
#define CPU_FREQ 48000000ul
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static bool
|
||||||
|
accessible(void)
|
||||||
|
{
|
||||||
|
/* First, check the PD */
|
||||||
|
if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)
|
||||||
|
!= PRCM_DOMAIN_POWER_ON) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Then check the 'run mode' clock gate */
|
||||||
|
if(!(HWREG(PRCM_BASE + PRCM_O_SSICLKGR) & PRCM_SSICLKGR_CLK_EN_SSI0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
board_spi_write(const uint8_t *buf, size_t len)
|
board_spi_write(const uint8_t *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
if(accessible() == false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while(len > 0) {
|
while(len > 0) {
|
||||||
uint32_t ul;
|
uint32_t ul;
|
||||||
|
|
||||||
|
@ -61,6 +84,10 @@ board_spi_write(const uint8_t *buf, size_t len)
|
||||||
int
|
int
|
||||||
board_spi_read(uint8_t *buf, size_t len)
|
board_spi_read(uint8_t *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
if(accessible() == false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while(len > 0) {
|
while(len > 0) {
|
||||||
uint32_t ul;
|
uint32_t ul;
|
||||||
|
|
||||||
|
@ -79,6 +106,10 @@ board_spi_read(uint8_t *buf, size_t len)
|
||||||
void
|
void
|
||||||
board_spi_flush()
|
board_spi_flush()
|
||||||
{
|
{
|
||||||
|
if(accessible() == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t ul;
|
uint32_t ul;
|
||||||
while(ti_lib_rom_ssi_data_get_non_blocking(SSI0_BASE, &ul));
|
while(ti_lib_rom_ssi_data_get_non_blocking(SSI0_BASE, &ul));
|
||||||
}
|
}
|
||||||
|
@ -88,7 +119,12 @@ board_spi_open(uint32_t bit_rate, uint32_t clk_pin)
|
||||||
{
|
{
|
||||||
uint32_t buf;
|
uint32_t buf;
|
||||||
|
|
||||||
/* SPI power */
|
/* First, make sure the SERIAL PD is on */
|
||||||
|
ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL);
|
||||||
|
while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)
|
||||||
|
!= PRCM_DOMAIN_POWER_ON));
|
||||||
|
|
||||||
|
/* Enable clock in active mode */
|
||||||
ti_lib_rom_prcm_peripheral_run_enable(PRCM_PERIPH_SSI0);
|
ti_lib_rom_prcm_peripheral_run_enable(PRCM_PERIPH_SSI0);
|
||||||
ti_lib_prcm_load_set();
|
ti_lib_prcm_load_set();
|
||||||
while(!ti_lib_prcm_load_get());
|
while(!ti_lib_prcm_load_get());
|
||||||
|
|
Loading…
Add table
Reference in a new issue