A31G11x F/W Packages  2.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
Functions
A31G11x_hal_scu.h File Reference

Contains all macro definitions and function prototypes support for scu firmware library on A31G11x. More...

Go to the source code of this file.

Functions

uint32_t HAL_SCU_ResetSourceStatus (void)
 Get Reset Source Status. More...
 
void HAL_SCU_SetNMI (uint32_t u32NmiCon)
 Set Non-Maskable Interrupt(NMI) Source Selection Register. More...
 
void HAL_SCU_SoftwareReset_Config (void)
 Check whether system reset ok or not. Generate s/w reset if a weak reset. More...
 
void HAL_SCU_SetWakupData (uint32_t u32Data)
 Set Wake-Up Timer Data. More...
 
void HAL_SCU_HIRCTRM_ClockConfig (uint32_t u32Ind)
 Change fine trim value of HIRC by one step. More...
 
void HAL_SCU_WDTRCTRM_ClockConfig (uint32_t u32Ind)
 Change fine trim value of WDTRC by one step. More...
 
void HAL_SCU_ClockMonitoring (uint32_t u32Acts, uint32_t u32Target)
 Configure Clock Monitoring. More...
 
void HAL_SCU_ClockMonitoring_Disable (void)
 Disable Clock Monitoring. More...
 
void HAL_SCU_ClockSource_Config (uint32_t u32FreIRC, uint32_t u32TypeXM, uint32_t u32ClkSrc)
 Set Clock Source, HIRC Frequency, and type of XMOSC. More...
 
void HAL_SCU_ClockSource_Enable (uint32_t u32ClkSrc, uint32_t u32HircDiv)
 Enable Clock Source. More...
 
void HAL_SCU_ClockSource_Disable (uint32_t u32ClkSrc)
 Disable Clock Source. More...
 
void HAL_SCU_SystemClockChange (uint32_t u32Target)
 Change System Clock. More...
 
void HAL_SCU_MainXtal_PinConfig (uint32_t u32XtalFilter)
 Set XMOSC Pins for x-tal. More...
 
void HAL_SCU_SubXtal_PinConfig (void)
 Set XSOSC Pins for x-tal. More...
 
void HAL_SCU_SystemClockDivider (uint32_t u32Div02, uint32_t u32Div13)
 Set System Clock Dividers, SCDIVR1 for WT and LCD Driver in case of using MCLK, SCDIVR2 for SysTick Timer and PCLK. More...
 
void HAL_SCU_CLKO_PinConfig (void)
 Set CLKO Pin for Clock Output. More...
 
void HAL_SCU_ClockOutput (uint32_t u32ClkSrc, uint32_t u32Level, uint32_t u32Div)
 Set Configuration for Clock Output. More...
 
void HAL_SCU_Peripheral_ClockConfig (uint32_t u32PeriClk1, uint32_t u32PeriClk2)
 Set Peripheral Clock, The peripheral doesn't work if the corresponding bit is "0b". More...
 
void HAL_SCU_Peripheral_EnableClock1 (uint32_t u32PeriClk1, uint32_t Ind)
 Set Each Peripheral Clock. More...
 
void HAL_SCU_Peripheral_EnableClock2 (uint32_t u32PeriClk2, uint32_t u32Ind)
 Set Each Peripheral Clock. More...
 
void HAL_SCU_Peripheral_ResetConfig (uint32_t u32PeriRst1, uint32_t u32PeriRst2)
 Reset Peripheral Block, The peripheral is reset if the corresponding bit is "1b". More...
 
void HAL_SCU_Peripheral_SetReset1 (uint32_t u32EachPeri1)
 Set/Reset Each Peripheral Block Reset of PPRST1 Register. More...
 
void HAL_SCU_Peripheral_SetReset2 (uint32_t u32EachPeri2)
 Set/Reset Each Peripheral Block Reset of PPRST2 Register. More...
 
void HAL_SCU_Peripheral_ClockSelection (uint32_t u32Peri, uint32_t u32ClkSrc)
 Peripheral Clock Selection of PPCLKSR Register. More...
 

Detailed Description

Contains all macro definitions and function prototypes support for scu firmware library on A31G11x.

Version
1.00
Date
2020-05-29
Author
ABOV Application Team

Copyright(C) 2019, ABOV Semiconductor All rights reserved.

ABOV Disclaimer

IMPORTANT NOTICE ? PLEASE READ CAREFULLY ABOV Semiconductor ("ABOV") reserves the right to make changes, corrections, enhancements, modifications, and improvements to ABOV products and/or to this document at any time without notice. ABOV does not give warranties as to the accuracy or completeness of the information included herein. Purchasers should obtain the latest relevant information of ABOV products before placing orders. Purchasers are entirely responsible for the choice, selection, and use of ABOV products and ABOV assumes no liability for application assistance or the design of purchasers' products. No license, express or implied, to any intellectual property rights is granted by ABOV herein. ABOV disclaims all express and implied warranties and shall not be responsible or liable for any injuries or damages related to use of ABOV products in such unauthorized applications. ABOV and the ABOV logo are trademarks of ABOV. All other product or service names are the property of their respective owners. Information in this document supersedes and replaces the information previously supplied in any former versions of this document. 2020 ABOV Semiconductor All rights reserved

Definition in file A31G11x_hal_scu.h.

Function Documentation

◆ HAL_SCU_CLKO_PinConfig()

void HAL_SCU_CLKO_PinConfig ( void  )

Set CLKO Pin for Clock Output.

Returns
None

This function sets selected pin's alternative for CLKO.

Definition at line 396 of file A31G11x_hal_scu.c.

397 {
398  PF->AFSR1 &= 0xFFF0FFFF; // PF4 CLKO 0: CLKO 1: ---- 2: ---- 3: ---- 4: ----
399  PF->PUPD &= 0xFCFF; // PF4 CLKO 0: Disable Pull-Up/Down 1: Enable Pull-Up 2: Enable Pull-Down
400  PF->MOD &= 0xFCFFuL; // PF4 CLKO 0: Input Mode 1: Output Mode 2: Alternative Function Mode
401  PF->MOD |= 0x0200uL; // PF4 CLKO 0: Input Mode 1: Output Mode 2: Alternative Function Mode
402 }

◆ HAL_SCU_ClockMonitoring()

void HAL_SCU_ClockMonitoring ( uint32_t  u32Acts,
uint32_t  u32Target 
)

Configure Clock Monitoring.

Parameters
[in]u32ActsClock Monitoring Action Selection
  • MACTS_FlagChk, MACTS_RstGen, MACTS_SysClkChg
[in]u32TargetClock Monitoring Target Selection
  • MONCS_MCLK, MONCS_HIRC, MONCS_XMOSC, MONCS_XSOSC
Returns
None

This function checks whether the target clock oscillates.

Definition at line 202 of file A31G11x_hal_scu.c.

203 {
204  if( SCUCG->CLKSRCR_b.WDTRCEN == 0 )
205  {
206  SCUCG->CLKSRCR = SCUCG->CLKSRCR
207  | ( ( uint32_t )SCUCG_CLKSRCR_WTIDKY_Value << SCUCG_CLKSRCR_WTIDKY_Pos )
208  | CLKSRCR_WDTRCEN; // The WDTRC should be enabled to use clock monitoring
209  }
210  SCUCG->CMONCR = ( 0x3uL << 2 ) | u32Acts | u32Target; // Clear MONFLAG and NMINTFG, Set Monitoring Target and Monitoring Action
211  SCUCG->CMONCR_b.MONEN = 1; // Clock Monitoring Enable
212 }

◆ HAL_SCU_ClockMonitoring_Disable()

void HAL_SCU_ClockMonitoring_Disable ( void  )

Disable Clock Monitoring.

Returns
None

This function disables clock monitoring. Before disabling the ¡°clock monitoring¡± function, you need to take step to clear the MACTS[1:0] bits of SCU_CMONCR register to ¡°00b¡±.

Definition at line 221 of file A31G11x_hal_scu.c.

222 {
223  SCUCG->CMONCR_b.MACTS = 0; // Clear MACTS bits first
224  SCUCG->CMONCR_b.MONEN = 0; // Disable clock monitoring function
225 }

◆ HAL_SCU_ClockOutput()

void HAL_SCU_ClockOutput ( uint32_t  u32ClkSrc,
uint32_t  u32Level,
uint32_t  u32Div 
)

Set Configuration for Clock Output.

Parameters
[in]u32ClkSrcClock to output
  • CLKOS_MCLK, CLKOS_WDTRC, CLKOS_HIRC, CLKOS_HCLK, CLKOS_PCLK
[in]u32LevelClock Output Polarity when Disable
  • POLSEL_Low, POLSEL_High
[in]u32DivOutput Clock Divide
  • CLKODIV_SelectedClock1, CLKODIV_SelectedClock2
  • CLKODIV_SelectedClock4, CLKODIV_SelectedClock8
  • CLKODIV_SelectedClock16, CLKODIV_SelectedClock32
  • CLKODIV_SelectedClock64, CLKODIV_SelectedClock128
Returns
None

This function sets clock output related configuration.

Definition at line 421 of file A31G11x_hal_scu.c.

422 {
423  SCUCG->CLKOCR = 0
424  | ( 1 << SCUCG_CLKOCR_CLKOEN_Pos ) // CLKO Enable
425  | u32Level // 0: Low Level 1: High Level
426  | u32Div // 0: div_1 1: div_2 2: div_4 3: div_8 4: div_16 5: div_32 6: div_64 7: div_128
427  | u32ClkSrc // 0: MCLK 1: WDTRC 2: HIRC 3: HCLK 4: PCLK
428  ;
429 }

◆ HAL_SCU_ClockSource_Config()

void HAL_SCU_ClockSource_Config ( uint32_t  u32FreIRC,
uint32_t  u32TypeXM,
uint32_t  u32ClkSrc 
)

Set Clock Source, HIRC Frequency, and type of XMOSC.

Parameters
[in]u32FreIRCHIRC Frequency Selection
  • HIRCSEL_HIRC1, HIRCSEL_HIRC2, HIRCSEL_HIRC4, HIRCSEL_HIRC8
[in]u32TypeXMMain Oscillator Type and Frequency Range Selection
  • XMFRNG_Xtal, XMFRNG_Clock
[in]u32ClkSrcClock Source
  • CLKSRCR_WDTRCEN | CLKSRCR_HIRCEN | CLKSRCR_XMOSCEN | CLKSRCR_XSOSCEN
Returns
None

This function sets clock source, HIRC frequency, and x-tal type of XMOSC. If target clock source is one of XMOSC and XSOSC, the x-tal pins should be set as alternative before this function call. To set alternative for x-tal, Use HAL_SCU_MainXtal_PinConfig() and HAL_SCU_SubXtal_PinConfig() functions.

Definition at line 244 of file A31G11x_hal_scu.c.

245 {
246  uint32_t tmp;
247 
248  tmp = SCUCG->CLKSRCR & 0x0000000F;
249  tmp |= ( ( ( uint32_t )SCUCG_CLKSRCR_WTIDKY_Value << SCUCG_CLKSRCR_WTIDKY_Pos ) // Write ID
250  | u32FreIRC // HIRC Frequency
251  | u32TypeXM // XMOSC type: x-tal or external clock
252  | u32ClkSrc );
253  SCUCG->CLKSRCR = tmp;
254 }

◆ HAL_SCU_ClockSource_Disable()

void HAL_SCU_ClockSource_Disable ( uint32_t  u32ClkSrc)

Disable Clock Source.

Parameters
[in]u32ClkSrcClock Source
  • CLKSRCR_WDTRCEN | CLKSRCR_HIRCEN | CLKSRCR_XMOSCEN | CLKSRCR_XSOSCEN
Returns
None

This function is used to disable original source after system clock change.

[Example]
// disable XMOSC, SXOSC
HAL_SCU_ClockSource_Disable( CLKSRCR_XMOSCEN | CLKSRCR_XSOSCEN );

Definition at line 307 of file A31G11x_hal_scu.c.

308 {
309  uint32_t tmp;
310 
311  tmp = SCUCG->CLKSRCR & 0x0000FFFF;
312  tmp |= ( ( uint32_t )SCUCG_CLKSRCR_WTIDKY_Value << SCUCG_CLKSRCR_WTIDKY_Pos ); // Write ID
313  tmp &= ~u32ClkSrc;
314  SCUCG->CLKSRCR = tmp;
315 }

◆ HAL_SCU_ClockSource_Enable()

void HAL_SCU_ClockSource_Enable ( uint32_t  u32ClkSrc,
uint32_t  u32HircDiv 
)

Enable Clock Source.

Parameters
[in]u32ClkSrcClock Source
  • CLKSRCR_WDTRCEN | CLKSRCR_HIRCEN | CLKSRCR_XMOSCEN | CLKSRCR_XSOSCEN
[in]u32HircDivHIRC Frequency Selection
  • HIRCSEL_HIRC1, HIRCSEL_HIRC2, HIRCSEL_HIRC4, HIRCSEL_HIRC8
Returns
None

This function is used to enable original source after system clock change.

[Example]
// eable HIRC, XMOSC, SXOSC, WDTRC and select HIRCSEL_HIRC1(40MHz HIRC)
HAL_SCU_ClockSource_Enable( CLKSRCR_HIRCEN | CLKSRCR_XMOSCEN | CLKSRCR_XSOSCEN | CLKSRCR_WDTRCEN, HIRCSEL_HIRC1 );

Definition at line 273 of file A31G11x_hal_scu.c.

274 {
275 #if 0 // before bug fix
276  uint32_t tmp;
277 
278  tmp = SCUCG->CLKSRCR & 0x0000FFFF; // 0x00000fff°¡ ¿ÇÀ» µí...
279  tmp |= ( ( uint32_t )SCUCG_CLKSRCR_WTIDKY_Value << SCUCG_CLKSRCR_WTIDKY_Pos ); // Write ID
280  tmp |= u32ClkSrc;
281  tmp |= u32HircDiv;
282  SCUCG->CLKSRCR = tmp;
283 #else // after bug fix
284  SCUCG->CLKSRCR = SCUCG->CLKSRCR
285  & ~( SCUCG_CLKSRCR_WTIDKY_Msk | SCUCG_CLKSRCR_HIRCSEL_Msk )
286  | ( ( uint32_t )SCUCG_CLKSRCR_WTIDKY_Value << SCUCG_CLKSRCR_WTIDKY_Pos ) // Write ID
287  | u32HircDiv
288  | u32ClkSrc
289  ;
290 #endif
291 }

◆ HAL_SCU_HIRCTRM_ClockConfig()

void HAL_SCU_HIRCTRM_ClockConfig ( uint32_t  u32Ind)

Change fine trim value of HIRC by one step.

Parameters
[in]u32IndIndicator for +/- one step
  • HIRC_UP_ONESTEP, HIRC_DOWN_ONESTEP
Returns
None

This function changes fine trim value by one step. If the u32Ind is HIRC_UP_ONESTEP, HIRC frequency is changed up by about 140kHz. If the u32Ind is HIRC_DOWN_ONESTEP, HIRC frequency is changed down by about 140kHz.

Definition at line 108 of file A31G11x_hal_scu.c.

109 {
110  uint32_t tmp, ntrim;
111 
112  tmp = ( SCUCC->HIRCTRM ) & 0x001fuL; // Read current fine trim value of HIRC
113  if( u32Ind == HIRC_UP_ONESTEP ) // Increment by one step(about 140kHz)
114  {
115  if( tmp != 0x0f )
116  {
117  tmp++;
118  }
119  }
120  else // Decrement by one step(about 140kHz)
121  {
122  if( tmp != 0x10 )
123  {
124  tmp--;
125  }
126  }
127  tmp &= 0x1f; // Fine trim value is only 5-bits
128  tmp |= ( ( SCUCC->HIRCTRM ) & 0x00E0uL ); // Read Coarse trim value
129  ntrim = ( tmp << 8 ) ^ 0x0000FF00; // Make write complement key
130  SCUCC->HIRCTRM = ( ( uint32_t )SCUCC_HIRCTRM_WTIDKY_Value << SCUCC_HIRCTRM_WTIDKY_Pos ) // Write new HIRC trim value with write ID and complement key
131  | ntrim
132  | tmp;
133 }

◆ HAL_SCU_MainXtal_PinConfig()

void HAL_SCU_MainXtal_PinConfig ( uint32_t  u32XtalFilter)

Set XMOSC Pins for x-tal.

Parameters
[in]u32XtalFilterthe filter of x-tal frequency
  • XRNS_LE4p5MHz, XRNS_LE6p5MHz, XRNS_LE8p5MHz
  • XRNS_LE10p5MHz, XRNS_LE12p5MHz, XRNS_LE16p5MHz
Returns
None

This function sets PF[1:0]'s alternative for x-tal of XMOSC.

Definition at line 326 of file A31G11x_hal_scu.c.

327 {
328  PF->AFSR1 &= 0xFFFFFF00; // PF[1:0]: XIN/XOUT
329  PF->PUPD &= 0xFFF0; // PF[1:0]: Pull-up/down resistors Disable
330  PF->MOD &= 0xFFF0uL;
331  PF->MOD |= 0x000AuL; // PF[1:0]: Alternative Function
332  SCUCG->XTFLSR = ( ( uint32_t )SCUCG_XTFLSR_WTIDKY_Value << SCUCG_XTFLSR_WTIDKY_Pos ) // Write ID
333  | u32XtalFilter; // x-tal filter value
334 }

◆ HAL_SCU_Peripheral_ClockConfig()

void HAL_SCU_Peripheral_ClockConfig ( uint32_t  u32PeriClk1,
uint32_t  u32PeriClk2 
)

Set Peripheral Clock, The peripheral doesn't work if the corresponding bit is "0b".

Parameters
[in]u32PeriClk1Values for TIMER20 ~ TIMER21, TIMER30, TIMER10 ~ TIMER12, PA ~ PF
[in]u32PeriClk2Values for the Others Peripheral
Returns
None

This function sets the peripheral clock. A peripheral works properly during the corresponding bit is set to "1b".

Definition at line 441 of file A31G11x_hal_scu.c.

442 {
443  SCUCG->PPCLKEN1 = u32PeriClk1; // Set peripheral clock of timers and ports
444  SCUCG->PPCLKEN2 = u32PeriClk2; // Set peripheral clock of the others
445 }

◆ HAL_SCU_Peripheral_ClockSelection()

void HAL_SCU_Peripheral_ClockSelection ( uint32_t  u32Peri,
uint32_t  u32ClkSrc 
)

Peripheral Clock Selection of PPCLKSR Register.

Parameters
[in]u32PeriPeripheral Selection
  • PPCLKSR_T20CLK, PPCLKSR_T30CLK, PPCLKSR_LCDCLK, PPCLKSR_WTCLK, PPCLKSR_WDTCLK
[in]u32ClkSrcPeripheral Clock Selection
  • PPCLKSR_T20CLK: T20CLK_XSOSC, T20CLK_PCLK
  • PPCLKSR_T30CLK: T30CLK_MCLK, T30CLK_PCLK
  • PPCLKSR_LCDCLK: LCDCLK_DividedMCLK, LCDCLK_XSOSC, LCDCLK_WDTRC
  • PPCLKSR_WTCLK: WTCLK_DividedMCLK, WTCLK_XSOSC, WTCLK_WDTRC
  • PPCLKSR_WDTCLK: WDTCLK_WDTRC, WDTCLK_PCLK

This function resets each peripheral block.

Definition at line 577 of file A31G11x_hal_scu.c.

578 {
579  SCUCG->PPCLKSR &= ~u32Peri;
580  SCUCG->PPCLKSR |= u32ClkSrc;
581 }

◆ HAL_SCU_Peripheral_EnableClock1()

void HAL_SCU_Peripheral_EnableClock1 ( uint32_t  u32PeriClk1,
uint32_t  Ind 
)

Set Each Peripheral Clock.

Parameters
[in]u32PeriClk1PeriClk1
  • PPCLKEN1_T20CLKE ~ PPCLKEN1_T21CLKE, PPCLKEN1_T30CLKE
  • PPCLKEN1_T10CLKE ~ PPCLKEN1_T12CLKE, PPCLKEN1_PACLKE ~ PPCLKEN1_PFCLKE
[in]IndEnable/Disable Peripheral Clock.
  • PPxCLKE_Disable, PPxCLKE_Enable
Returns
None

This function sets each peripheral clock of timers and Ports.

Definition at line 459 of file A31G11x_hal_scu.c.

460 {
461  if( Ind )
462  {
463  SCUCG->PPCLKEN1 |= u32PeriClk1; // Enable a peripheral clock of timers and ports
464  }
465  else
466  {
467  SCUCG->PPCLKEN1 &= ~u32PeriClk1; // Disable a peripheral clock of timers and ports
468  }
469 }

Referenced by HAL_TIMER1n_DeInit(), and HAL_TIMER1n_Init().

Here is the caller graph for this function:

◆ HAL_SCU_Peripheral_EnableClock2()

void HAL_SCU_Peripheral_EnableClock2 ( uint32_t  u32PeriClk2,
uint32_t  u32Ind 
)

Set Each Peripheral Clock.

Parameters
[in]u32PeriClk2PeriClk2
  • PPCLKEN2_FMCLKE, PPCLKEN2_LVICLKE, PPCLKEN2_WDTCLKE, PPCLKEN2_WTCLKE
  • PPCLKEN2_LCDCLKE, PPCLKEN2_CRCLKE, PPCLKEN2_ADCLKE,
  • PPCLKEN2_I2C0CLKE ~ PPCLKEN2_I2C1CLKE
  • PPCLKEN2_UT0CLKE ~ PPCLKEN2_UT1CLKE, PPCLKEN2_UST10CLKE ~ PPCLKEN2_UST11CLKE
[in]u32IndEnable/Disable Peripheral Clock.
  • PPxCLKE_Disable, PPxCLKE_Enable
Returns
None

This function sets each peripheral clock of the others.

Definition at line 485 of file A31G11x_hal_scu.c.

486 {
487  if( u32Ind )
488  {
489  SCUCG->PPCLKEN2 |= u32PeriClk2; // Enable a peripheral clock of others
490  }
491  else
492  {
493  SCUCG->PPCLKEN2 &= ~u32PeriClk2; // Disable a peripheral clock of others
494  }
495 }

Referenced by HAL_ADC_DeInit(), HAL_ADC_Init(), HAL_CRC_DeInit(), HAL_CRC_Init(), HAL_LCD_Init(), HAL_LVI_Init(), HAL_UART_DeInit(), HAL_UART_Init(), HAL_USART_DeInit(), HAL_USART_Init(), HAL_WDT_Init(), and HAL_WT_Init().

Here is the caller graph for this function:

◆ HAL_SCU_Peripheral_ResetConfig()

void HAL_SCU_Peripheral_ResetConfig ( uint32_t  u32PeriRst1,
uint32_t  u32PeriRst2 
)

Reset Peripheral Block, The peripheral is reset if the corresponding bit is "1b".

Parameters
[in]u32PeriRst1Values for TIMER20 ~ TIMER21, TIMER30, TIMER10 ~ TIMER12, PA ~ PF
[in]u32PeriRst2Values for the Others Peripheral
Returns
None

This function reset peripheral block during the corresponding bit is set to "1b". After reset of a block, the corresponding bit should be cleared to "0b" for operation.

Definition at line 507 of file A31G11x_hal_scu.c.

508 {
509  uint32_t i;
510 
511  SCUCG->PPRST1 = u32PeriRst1; // Reset peripheral block of timers and ports if the corresponding bit is "1b"
512  SCUCG->PPRST2 = u32PeriRst2; // Reset peripheral block of the others
513  for( i = 0 ; i < 10 ; i++ )
514  {
515  NOP();
516  }
517  SCUCG->PPRST1 = 0x0uL; // Clear the peripheral reset bits
518  SCUCG->PPRST2 = 0x0uL;
519 }

◆ HAL_SCU_Peripheral_SetReset1()

void HAL_SCU_Peripheral_SetReset1 ( uint32_t  u32EachPeri1)

Set/Reset Each Peripheral Block Reset of PPRST1 Register.

Parameters
[in]u32EachPeri1Peri1
  • PPRST1_T20RST ~ PPRST1_T21RST, PPRST1_T30RST
  • PPRST1_T10RST ~ PPRST1_T12RST, PPRST1_PARST ~ PPRST1_PFRST

This function resets each peripheral block.

Definition at line 529 of file A31G11x_hal_scu.c.

530 {
531  uint32_t i;
532 
533  SCUCG->PPRST1 = u32EachPeri1; // Reset a peripheral block
534  for( i = 0 ; i < 10 ; i++ )
535  {
536  NOP();
537  }
538  SCUCG->PPRST1 = 0; // Clear the peripheral reset bit
539 }

◆ HAL_SCU_Peripheral_SetReset2()

void HAL_SCU_Peripheral_SetReset2 ( uint32_t  u32EachPeri2)

Set/Reset Each Peripheral Block Reset of PPRST2 Register.

Parameters
[in]u32EachPeri2Peri2
  • PPRST2_FMCRST, PPRST2_LVIRST, PPRST2_WTRST, PPRST2_LCDRST
  • PPRST2_CRRST, PPRST2_ADRST, PPRST2_I2C0RST ~ PPRST2_I2C1RST
  • PPRST2_UT0RST ~ PPRST2_UT1RST, PPRST2_UST10RST ~ PPRST2_UST11RST

This function resets each peripheral block.

Definition at line 550 of file A31G11x_hal_scu.c.

551 {
552  uint32_t i;
553 
554  SCUCG->PPRST2 = u32EachPeri2; // Reset a peripheral block
555  for( i = 0 ; i < 10 ; i++ )
556  {
557  NOP();
558  }
559  SCUCG->PPRST2 = 0; // Clear the peripheral reset bit
560 }

Referenced by HAL_CRC_DeInit(), HAL_I2C_Init(), HAL_UART_DeInit(), HAL_USART_DeInit(), and HAL_USART_Init().

Here is the caller graph for this function:

◆ HAL_SCU_ResetSourceStatus()

uint32_t HAL_SCU_ResetSourceStatus ( void  )

Get Reset Source Status.

Returns
Reset Source

This function gets reset source status and clear the register.

Definition at line 52 of file A31G11x_hal_scu.c.

53 {
54  uint32_t tmp;
55 
56  tmp = SCUCC->RSTSSR; // Get reset source status
57  SCUCC->RSTSSR = 0x3FuL; // Clear all reset source status
58  return tmp;
59 }

◆ HAL_SCU_SetNMI()

void HAL_SCU_SetNMI ( uint32_t  u32NmiCon)

Set Non-Maskable Interrupt(NMI) Source Selection Register.

Parameters
[in]u32NmiConValues for NMISRCR register
Returns
None

This function sets NMISRCR register.

Definition at line 68 of file A31G11x_hal_scu.c.

69 {
70  SCUCC->NMISRCR = u32NmiCon;
71 }

◆ HAL_SCU_SetWakupData()

void HAL_SCU_SetWakupData ( uint32_t  u32Data)

Set Wake-Up Timer Data.

Parameters
[in]u32Data
Returns
None

This function sets wake-up timer data to wait for release of deep sleep mode. Its value should be set to be at least more than 150usec.

Definition at line 93 of file A31G11x_hal_scu.c.

94 {
95  SCUCC->WUTDR = u32Data; // On HCLK=40MHz, (150us x 40)/32 = 187.5. So, the data should be more than 187
96 }

◆ HAL_SCU_SoftwareReset_Config()

void HAL_SCU_SoftwareReset_Config ( void  )

Check whether system reset ok or not. Generate s/w reset if a weak reset.

Returns
None

This function checks system reset validation and Generate s/w reset if a weak reset.

Definition at line 78 of file A31G11x_hal_scu.c.

79 {
80  if( SCUCC->SRSTVR_b.VALID != 0x55 )
81  {
82  SCUCC_GenSwRst(); // Generate S/W reset on invalid reset
83  }
84 }

◆ HAL_SCU_SubXtal_PinConfig()

void HAL_SCU_SubXtal_PinConfig ( void  )

Set XSOSC Pins for x-tal.

Returns
None

This function sets PF[3:2]'s alternative for x-tal of XSOSC.

Definition at line 341 of file A31G11x_hal_scu.c.

342 {
343  PF->AFSR1 &= 0xFFFF00FF; // PF[3:2]: SXIN/SXOUT
344  PF->PUPD &= 0xFF0F; // PF[3:2]: Pull-up/down resistors Disable
345  PF->MOD &= 0xFF0FuL;
346  PF->MOD |= 0x00A0uL; // PF[3:2]: Alternative Function
347 }

◆ HAL_SCU_SystemClockChange()

void HAL_SCU_SystemClockChange ( uint32_t  u32Target)

Change System Clock.

Parameters
[in]u32TargetTarget Clock
  • MCLKSEL_HIRC, MCLKSEL_XMOSC, MCLKSEL_XSOSC, MCLKSEL_WDTRC
Returns
None

This function changes system clock to target source.

Definition at line 357 of file A31G11x_hal_scu.c.

358 {
359  SCUCG->SCCR = ( SCUCG_SCCR_WTIDKY_Value << SCUCG_SCCR_WTIDKY_Pos ) // Write ID
360  | u32Target; // Target Clock Source
361 }

◆ HAL_SCU_SystemClockDivider()

void HAL_SCU_SystemClockDivider ( uint32_t  u32Div02,
uint32_t  u32Div13 
)

Set System Clock Dividers, SCDIVR1 for WT and LCD Driver in case of using MCLK, SCDIVR2 for SysTick Timer and PCLK.

Parameters
[in]u32Div02Values for Divider 0 and 2
  • Clock Divide for HCLK (Divider 0)
    • HDIV_MCLK16, HDIV_MCLK8, HDIV_MCLK4, HDIV_MCLK2, HDIV_MCLK1
  • Clock Divide for Watch Timer and LCD Driver (Divider 2)
    • WLDIV_MCLK64, WLDIV_MCLK128, WLDIV_MCLK256, WLDIV_MCLK512, WLDIV_MCLK1024
[in]u32Div13Values for Divider 1 and 3
  • Clock Divide for PCLK (Divider 1)
    • PDIV_HCLK1, PDIV_HCLK2, PDIV_HCLK4, PDIV_HCLK8
  • Clock Divide for SysTick Timer (Divider 3)
    • SYSTDIV_HCLK1, SYSTDIV_HCLK2, SYSTDIV_HCLK4, SYSTDIV_HCLK8
Returns
None

This function changes system clock to target source.

Definition at line 380 of file A31G11x_hal_scu.c.

381 {
382  // Divider 0 for HCLK: 000/001/010/011/100: MCLK is divided by 16/8/4/2/1
383  // Divider 2 for WT and LCD Driver: 000/001/010/011/100: MCLK is divided by 64/128/256/512/1024
384  SCUCG->SCDIVR1 = u32Div02;
385 
386  // Divider 1 for PCLK: 00/01/10/11: HCLK is divided by 1/2/4/8
387  // Divider 3 for SysTick Timer: 00/01/10/11: HCLK is divided by 1/2/4/8
388  SCUCG->SCDIVR2 = u32Div13;
389 }

◆ HAL_SCU_WDTRCTRM_ClockConfig()

void HAL_SCU_WDTRCTRM_ClockConfig ( uint32_t  u32Ind)

Change fine trim value of WDTRC by one step.

Parameters
[in]u32IndIndicator for +/- one step
  • WDTRC_UP_ONESTEP, WDTRC_DOWN_ONESTEP
Returns
None

This function changes fine trim value by one step. If the u32Ind is WDTRC_UP_ONESTEP, WDTRC frequency is changed up by about 1.1kHz. If the u32Ind is WDTRC_DOWN_ONESTEP, WDTRC frequency is changed down by about 1.1kHz.

Definition at line 145 of file A31G11x_hal_scu.c.

146 {
147  uint32_t ctmp, ftmp, ntrim;
148 
149  ftmp = ( SCUCC->WDTRCTRM ) & 0x0007uL; // Read current fine trim value of WDTRC
150  ctmp = ( SCUCC->WDTRCTRM ) & 0x00F0uL; // Read current coarse trim value of WDTRC
151  if( u32Ind == WDTRC_UP_ONESTEP ) // Increment by one step(about 1.1kHz)
152  {
153  ftmp++;
154  ftmp &= 0x07uL; // Fine trim value is only 3-bits
155  if( ftmp == 0x04 )
156  {
157  if( ctmp != 0x70 )
158  {
159  ctmp += 0x10uL;
160  }
161  else
162  {
163  ftmp = 0x03uL;
164  }
165  }
166  }
167  else // Decrement by one step(about 1.1kHz)
168  {
169  ftmp--;
170  ftmp &= 0x07uL; // Fine trim value is only 3-bits
171  if( ftmp == 0x03 )
172  {
173  if( ctmp != 0x80 )
174  {
175  ctmp -= 0x10uL;
176  }
177  else
178  {
179  ftmp = 0x04uL;
180  }
181  }
182  }
183  ctmp &= 0x00f0uL; // Coarse trim value is only 4-bits
184  ctmp |= ftmp;
185  ntrim = ( ctmp << 8 ) ^ 0x0000FF00; // Make write complement key
186  SCUCC->WDTRCTRM = ( SCUCC_WDTRCTRM_WTIDKY_Value << SCUCC_WDTRCTRM_WTIDKY_Pos ) // Write new WDTRC trim value with write ID and complement key
187  | ntrim
188  | ctmp;
189 }