Skip to content

Commit

Permalink
MAX32690: Only reset ADC, TMR, UART if clock is not locked
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Carter committed Sep 4, 2024
1 parent e82812a commit 6bc6bff
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Libraries/PeriphDrivers/Source/ADC/adc_me18.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ static void initGPIOForTrigSrc(mxc_adc_trig_sel_t hwTrig)
int MXC_ADC_Init(mxc_adc_req_t *req)
{
#ifndef MSDK_NO_GPIO_CLK_INIT
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_ADC);
if (!MXC_ADC_RevB_IsClockSourceLocked((mxc_adc_revb_regs_t *)MXC_ADC)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_ADC);
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_ADC);

/* This is required for temperature sensor only */
Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/ADC/adc_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ int MXC_ADC_RevB_LockClockSource(mxc_adc_revb_regs_t *adc, bool lock)
}
}

bool MXC_ADC_RevB_IsClockSourceLocked(mxc_adc_revb_regs_t *adc)
{
return g_is_clock_locked;
}

int MXC_ADC_RevB_Shutdown(mxc_adc_revb_regs_t *adc)
{
if (async_callback != NULL) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/PeriphDrivers/Source/ADC/adc_revb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ int MXC_ADC_RevB_SetClockDiv(mxc_adc_revb_regs_t *adc, mxc_adc_clkdiv_t div);

int MXC_ADC_RevB_LockClockSource(mxc_adc_revb_regs_t *adc, bool lock);

bool MXC_ADC_RevB_IsClockSourceLocked(mxc_adc_revb_regs_t *adc);

int MXC_ADC_RevB_Shutdown(mxc_adc_revb_regs_t *adc);

void MXC_ADC_RevB_EnableInt(mxc_adc_revb_regs_t *adc, uint32_t flags);
Expand Down
24 changes: 18 additions & 6 deletions Libraries/PeriphDrivers/Source/TMR/tmr_me18.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)
which requires two Init calls. We don't want to reset because that would
wipe out any previous initializations.
*/
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR0);
if (!MXC_TMR_RevB_IsClockSourceLocked((mxc_tmr_revb_regs_t *)tmr)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR0);
}
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TMR0);

Expand All @@ -62,7 +64,9 @@ int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)

case 1:
if (cfg->bitMode == MXC_TMR_BIT_MODE_32) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR1);
if (!MXC_TMR_RevB_IsClockSourceLocked((mxc_tmr_revb_regs_t *)tmr)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR1);
}
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TMR1);

Expand All @@ -78,7 +82,9 @@ int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)

case 2:
if (cfg->bitMode == MXC_TMR_BIT_MODE_32) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR2);
if (!MXC_TMR_RevB_IsClockSourceLocked((mxc_tmr_revb_regs_t *)tmr)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR2);
}
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TMR2);

Expand All @@ -94,7 +100,9 @@ int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)

case 3:
if (cfg->bitMode == MXC_TMR_BIT_MODE_32) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR3);
if (!MXC_TMR_RevB_IsClockSourceLocked((mxc_tmr_revb_regs_t *)tmr)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET0_TMR3);
}
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TMR3);

Expand All @@ -110,13 +118,17 @@ int MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg, bool init_pins)

case 4:
MXC_GPIO_Config(&gpio_cfg_tmr4);
MXC_SYS_Reset_Periph(MXC_SYS_RESET_TMR4);
if (!MXC_TMR_RevB_IsClockSourceLocked((mxc_tmr_revb_regs_t *)tmr)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET_TMR4);
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TMR4);
break;

case 5:
MXC_GPIO_Config(&gpio_cfg_tmr5);
MXC_SYS_Reset_Periph(MXC_SYS_RESET_TMR5);
if (!MXC_TMR_RevB_IsClockSourceLocked((mxc_tmr_revb_regs_t *)tmr)) {
MXC_SYS_Reset_Periph(MXC_SYS_RESET_TMR5);
}
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TMR5);
break;
}
Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/TMR/tmr_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ void MXC_TMR_RevB_LockClockSource(mxc_tmr_revb_regs_t *tmr, bool lock)
g_is_clock_locked[MXC_TMR_GET_IDX((mxc_tmr_regs_t *)tmr)] = lock;
}

bool MXC_TMR_RevB_IsClockSourceLocked(mxc_tmr_revb_regs_t *tmr)
{
return g_is_clock_locked[MXC_TMR_GET_IDX((mxc_tmr_regs_t *)tmr)];
}

void MXC_TMR_RevB_SetClockSource(mxc_tmr_revb_regs_t *tmr, mxc_tmr_bit_mode_t bit_mode,
uint8_t clk_src)
{
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Source/TMR/tmr_revb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef enum {
/* **** Functions **** */
int MXC_TMR_RevB_Init(mxc_tmr_revb_regs_t *tmr, mxc_tmr_cfg_t *cfg, uint8_t clk_src);
void MXC_TMR_RevB_LockClockSource(mxc_tmr_revb_regs_t *tmr, bool lock);
bool MXC_TMR_RevB_IsClockSourceLocked(mxc_tmr_revb_regs_t *tmr);
void MXC_TMR_RevB_SetClockSource(mxc_tmr_revb_regs_t *tmr, mxc_tmr_bit_mode_t bit_mode,
uint8_t clk_src);
void MXC_TMR_RevB_SetPrescalar(mxc_tmr_revb_regs_t *tmr, mxc_tmr_bit_mode_t bit_mode,
Expand Down
11 changes: 6 additions & 5 deletions Libraries/PeriphDrivers/Source/UART/uart_me18.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clo
#ifndef MSDK_NO_GPIO_CLK_INIT
int retval;

retval = MXC_UART_Shutdown(uart);

if (retval) {
return retval;
}
if (!MXC_UART_RevB_IsClockSourceLocked((mxc_uart_revb_regs_t *)uart)) {
retval = MXC_UART_Shutdown(uart);
if (retval) {
return retval;
}
}

switch (MXC_UART_GET_IDX(uart)) {
case 0:
Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/UART/uart_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ void MXC_UART_RevB_LockClockSource(mxc_uart_revb_regs_t *uart, bool lock)
g_is_clock_locked[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] = lock;
}

bool MXC_UART_RevB_IsClockSourceLocked(mxc_uart_revb_regs_t *uart)
{
return g_is_clock_locked[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)];
}

int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCtrl,
int rtsThreshold)
{
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Source/UART/uart_revb.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCt
int MXC_UART_RevB_SetClockSource(mxc_uart_revb_regs_t *uart, uint8_t clock_option);
unsigned int MXC_UART_RevB_GetClockSource(mxc_uart_revb_regs_t *uart);
void MXC_UART_RevB_LockClockSource(mxc_uart_revb_regs_t *uart, bool lock);
bool MXC_UART_RevB_IsClockSourceLocked(mxc_uart_revb_regs_t *uart);
int MXC_UART_RevB_GetActive(mxc_uart_revb_regs_t *uart);
int MXC_UART_RevB_AbortTransmission(mxc_uart_revb_regs_t *uart);
int MXC_UART_RevB_ReadCharacterRaw(mxc_uart_revb_regs_t *uart);
Expand Down

0 comments on commit 6bc6bff

Please sign in to comment.