PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
Watch Counter (WC)

How to use WC module. More...

Data Structures

struct  stc_wc_pres_clk
 Structure to configure watch counter prescaler. More...
 
struct  stc_wc_config
 Structure to configure the watch counter. More...
 
struct  stc_wc_intern_data
 Structure of watch counter internal data. More...
 
struct  stc_wc_instance_data
 Structure of watch counter instance data. More...
 

Macros

#define WC_INSTANCE_COUNT   (uint32_t)(sizeof(m_astcWcInstanceDataLut) / sizeof(m_astcWcInstanceDataLut[0]))
 
#define stc_wcn_t   FM4_WC_TypeDef
 
#define WC0   (*((FM4_WC_TypeDef *) FM4_WC_BASE))
 

Typedefs

typedef enum en_wc_instance_index en_wc_instance_index_t
 Enumeration to define an index for each WC instance. More...
 
typedef enum en_input_clk en_input_clk_t
 Enumeration to define source clock of watch counter precaler. More...
 
typedef enum en_output_clk en_output_clk_t
 Enumeration to define output clock of watch counter precaler. More...
 
typedef struct stc_wc_pres_clk stc_wc_pres_clk_t
 Structure to configure watch counter prescaler. More...
 
typedef enum en_wc_cnt_clk en_wc_cnt_clk_t
 Enumeration to set the clock of watch counter. More...
 
typedef struct stc_wc_config stc_wc_config_t
 Structure to configure the watch counter. More...
 
typedef struct stc_wc_intern_data stc_wc_intern_data_t
 Structure of watch counter internal data. More...
 
typedef struct stc_wc_instance_data stc_wc_instance_data_t
 Structure of watch counter instance data. More...
 

Enumerations

enum  en_wc_instance_index { WcInstanceIndexWc0 = 0 }
 Enumeration to define an index for each WC instance. More...
 
enum  en_input_clk {
  WcPresInClkSubOsc = 0,
  WcPresInClkMainOsc,
  WcPresInClkHighCr,
  WcPresInClkLowCr
}
 Enumeration to define source clock of watch counter precaler. More...
 
enum  en_output_clk {
  WcPresOutClkArray0 = 0,
  WcPresOutClkArray1,
  WcPresOutClkArray2,
  WcPresOutClkArray3,
  WcPresOutClkArray4,
  WcPresOutClkArray5,
  WcPresOutClkArray6
}
 Enumeration to define output clock of watch counter precaler. More...
 
enum  en_wc_cnt_clk {
  WcCntClkWcck0 = 0,
  WcCntClkWcck1,
  WcCntClkWcck2,
  WcCntClkWcck3
}
 Enumeration to set the clock of watch counter. More...
 

Functions

static void Wc_InitNvic (volatile FM4_WC_TypeDef *pstcWc)
 Set NVIC Interrupt depending on ADC instance. More...
 
static void Wc_DeInitNvic (volatile FM4_WC_TypeDef *pstcWc)
 Clear NVIC Interrupt depending on ADC instance. More...
 
void Wc_IrqHandler (volatile FM4_WC_TypeDef *pstcWc, stc_wc_intern_data_t *pstcWcInternData)
 Watch counter interrupt function. More...
 
static stc_wc_intern_data_t * WcGetInternDataPtr (volatile FM4_WC_TypeDef *pstcWc)
 Return the internal data for a certain WC instance. More...
 
en_result_t Wc_Pres_SelClk (volatile FM4_WC_TypeDef *pstcWc, stc_wc_pres_clk_t *pstcWcPresClk)
 Select the input clock an and set the division clock to be output. More...
 
en_result_t Wc_Pres_EnableDiv (volatile FM4_WC_TypeDef *pstcWc)
 Enable oscilation of the divison clock. More...
 
en_result_t Wc_Pres_DisableDiv (volatile FM4_WC_TypeDef *pstcWc)
 Disable oscilation of the divison clock. More...
 
en_stat_flag_t Wc_GetDivStat (volatile FM4_WC_TypeDef *pstcWc)
 Get the operation status of the division counter. More...
 
en_result_t Wc_Init (volatile FM4_WC_TypeDef *pstcWc, stc_wc_config_t *pstcWcConfig)
 Select the input clock an and set the division clock to be output. More...
 
en_result_t Wc_EnableCount (volatile FM4_WC_TypeDef *pstcWc)
 Enable WC operation. More...
 
en_result_t Wc_DisableCount (volatile FM4_WC_TypeDef *pstcWc)
 Disable WC operation. More...
 
en_result_t Wc_EnableInt (volatile FM4_WC_TypeDef *pstcWc, func_ptr_t pfnIntCallback)
 Enable WC underflow interrupt. More...
 
en_result_t Wc_DisableInt (volatile FM4_WC_TypeDef *pstcWc)
 Disable WC underflow interrupt. More...
 
en_result_t Wc_WriteReloadVal (volatile FM4_WC_TypeDef *pstcWc, uint8_t u8Val)
 Set the counter value of WC. More...
 
uint8_t Wc_ReadCurCnt (volatile FM4_WC_TypeDef *pstcWc)
 Read the value in the 6-bit down counter. More...
 
en_result_t Wc_ClearIntFlag (volatile FM4_WC_TypeDef *pstcWc)
 Clear WC underflow flag. More...
 
en_int_flag_t Wc_GetIntFlag (volatile FM4_WC_TypeDef *pstcWc)
 Get WC underflow flag status. More...
 
en_stat_flag_t Wc_GetOperationFlag (volatile FM4_WC_TypeDef *pstcWc)
 Get WC operation state. More...
 

Variables

stc_wc_instance_data_t m_astcWcInstanceDataLut []
 Look-up table for all enabled WC instances and their internal data. More...
 
stc_wc_instance_data_t m_astcWcInstanceDataLut []
 Look-up table for all enabled WC instances and their internal data. More...
 

Detailed Description

How to use WC module.

Provided functions of WC module:

Before using WC, WC prescaler must be configured first. Use Wc_Pres_SelClk() to select input clock of prescaler. Following clocks can be selected:

Wc_Pres_EnableDiv() is used to enable watch counter prescaler. Wc_Pres_DisableDiv() is used to disable watch counter prescaler.

Wc_Init() must be used for configuration of watch counter with a structure of the type stc_wc_config_t.

A WC interrupt can be enabled by the function Wc_EnableInt(). This function can set callback function for each channel too.

With Wc_WriteReloadVal() the WC reloader value is set to the value given in the parameter Wc_WriteReloadVal::u8Val.

After above setting, calling Wc_EnableCount() will start WC.

With Wc_ReadCurCnt() the current WC count can be read when WC is counting. with Wc_GetOperationFlag() the current WC operaiton status can be read.

With interrupt mode, when the interrupt occurs, the interrupt flag will be cleared and run into user interrupt callback function.

With polling mode, user can use Wc_GetIntFlag() to check if the interrupt occurs, and clear the interrupt flag by Wc_ClrIntFlag().

When stopping the WC, use Wc_DisableCount() to disable WC and Wc_DisableInt() to disable WC interrupt.

Macro Definition Documentation

#define stc_wcn_t   FM4_WC_TypeDef

Definition at line 123 of file wc.h.

Referenced by Wc_DeInitNvic(), Wc_EnableInt(), and Wc_InitNvic().

#define WC0   (*((FM4_WC_TypeDef *) FM4_WC_BASE))

Definition at line 124 of file wc.h.

Referenced by Wc_DeInitNvic(), and Wc_InitNvic().

#define WC_INSTANCE_COUNT   (uint32_t)(sizeof(m_astcWcInstanceDataLut) / sizeof(m_astcWcInstanceDataLut[0]))

Definition at line 69 of file wc.c.

Referenced by WcGetInternDataPtr().

Typedef Documentation

Enumeration to define source clock of watch counter precaler.

Enumeration to define output clock of watch counter precaler.

Enumeration to set the clock of watch counter.

Enumeration to define an index for each WC instance.

Structure to configure the watch counter.

Structure of watch counter instance data.

Structure of watch counter internal data.

Structure to configure watch counter prescaler.

Enumeration Type Documentation

Enumeration to define source clock of watch counter precaler.

Enumerator
WcPresInClkSubOsc 

Watch counter prescaler source clock: sub oscillator.

WcPresInClkMainOsc 

Watch counter prescaler source clock: main oscillator.

WcPresInClkHighCr 

Watch counter prescaler source clock: high-speed CR.

WcPresInClkLowCr 

Watch counter prescaler source clock: low-speed CR.

Definition at line 140 of file wc.h.

Enumeration to define output clock of watch counter precaler.

Enumerator
WcPresOutClkArray0 

WCCk3 WCCk2 WCCk1 WCCk0.

Watch counter prescaler output array0: 2^15/src clock, 2^14/src clock, 2^13/src clock, 2^12/src clock

WcPresOutClkArray1 

Watch counter prescaler output array0: 2^25/src clock, 2^24/src clock, 2^23/src clock, 2^22/src clock.

WcPresOutClkArray2 

Watch counter prescaler output array0: 2^4/src clock, 2^3/src clock, 2^2/src clock, 2/src clock.

WcPresOutClkArray3 

Watch counter prescaler output array0: 2^8/src clock, 2^7/src clock, 2^6/src clock, 2^5/src clock.

WcPresOutClkArray4 

Watch counter prescaler output array0: 2^12/src clock, 2^11/src clock, 2^10/src clock, 2^9/src clock.

WcPresOutClkArray5 

Watch counter prescaler output array0: 2^19/src clock, 2^18/src clock, 2^17/src clock, 2^16/src clock.

WcPresOutClkArray6 

Watch counter prescaler output array0: 2^23/src clock, 2^22/src clock, 2^21/src clock, 2^20/src clock.

Definition at line 153 of file wc.h.

Enumeration to set the clock of watch counter.

Enumerator
WcCntClkWcck0 

Watch counter source clock: WCCK0.

WcCntClkWcck1 

Watch counter source clock: WCCK1.

WcCntClkWcck2 

Watch counter source clock: WCCK2.

WcCntClkWcck3 

Watch counter source clock: WCCK3.

Definition at line 181 of file wc.h.

Enumeration to define an index for each WC instance.

Enumerator
WcInstanceIndexWc0 

Instance index of WC0.

Definition at line 130 of file wc.h.

Function Documentation

en_result_t Wc_ClearIntFlag ( volatile FM4_WC_TypeDef *  pstcWc)

Clear WC underflow flag.

The Function clear WCIF to 0 of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
Returns
The value of WC 6-bit down counter If pstcWc == NULL 0xFF is returned.

Definition at line 474 of file wc.c.

References ErrorInvalidParameter, and Ok.

Referenced by Wc_IrqHandler().

Here is the caller graph for this function:

static void Wc_DeInitNvic ( volatile FM4_WC_TypeDef *  pstcWc)
static

Clear NVIC Interrupt depending on ADC instance.

Parameters
pstcWcPointer to ADC instance

Definition at line 115 of file wc.c.

References PDL_IRQ_LEVEL_CLK_WC0, stc_wcn_t, and WC0.

Referenced by Wc_DisableInt().

Here is the caller graph for this function:

en_result_t Wc_DisableCount ( volatile FM4_WC_TypeDef *  pstcWc)

Disable WC operation.

The Function can clear WCCR:WCEN to 0 of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 341 of file wc.c.

References ErrorInvalidParameter, and Ok.

en_result_t Wc_DisableInt ( volatile FM4_WC_TypeDef *  pstcWc)

Disable WC underflow interrupt.

The Function can clear WCIE of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 401 of file wc.c.

References ErrorInvalidParameter, Ok, and Wc_DeInitNvic().

Here is the call graph for this function:

en_result_t Wc_EnableCount ( volatile FM4_WC_TypeDef *  pstcWc)

Enable WC operation.

The Function can set WCCR:WCEN to 1 of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 317 of file wc.c.

References ErrorInvalidParameter, and Ok.

en_result_t Wc_EnableInt ( volatile FM4_WC_TypeDef *  pstcWc,
func_ptr_t  pfnIntCallback 
)

Enable WC underflow interrupt.

The Function can set WCIE of WC

Parameters
[in]pstcWcPointer to WC instance register area
[in]pfnIntCallbackWC interrupt to be enabled
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 367 of file wc.c.

References ErrorInvalidParameter, Ok, stc_wc_intern_data::pfnIntCallback, stc_wcn_t, Wc_InitNvic(), and WcGetInternDataPtr().

Here is the call graph for this function:

en_stat_flag_t Wc_GetDivStat ( volatile FM4_WC_TypeDef *  pstcWc)

Get the operation status of the division counter.

The Function can get CLK_EN:CLK_EN_R to 0 of WCP

Parameters
[in]pstcWcPointer to WC instance register area
Return values
PdlClrCLK_EN_R is 0, oscilation of the division clock is not performed
PdlSetCLK_EN R is 1, oscilation of the division clock is performed

Definition at line 261 of file wc.c.

en_int_flag_t Wc_GetIntFlag ( volatile FM4_WC_TypeDef *  pstcWc)

Get WC underflow flag status.

The Function get value WCIF of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
PdlClrWCIF is 0, WC underflow does not occur
PdlSetWCIF is 1, WC underflow occurs

Definition at line 497 of file wc.c.

Referenced by Wc_IrqHandler().

Here is the caller graph for this function:

en_stat_flag_t Wc_GetOperationFlag ( volatile FM4_WC_TypeDef *  pstcWc)

Get WC operation state.

The Function get value WCOP of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
PdlClrWCOP is 0, The WC is stopped
PdlSetWCOP is 1, The WC is active

Definition at line 514 of file wc.c.

en_result_t Wc_Init ( volatile FM4_WC_TypeDef *  pstcWc,
stc_wc_config_t *  pstcWcConfig 
)

Select the input clock an and set the division clock to be output.

The Function can set SEL_OUT, SEL_IN of Watch counter prescaler (hereafter WCP)

Parameters
[in]pstcWcPointer to WC instance register area
[in]pstcWcConfigPointer to WC configuration
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 280 of file wc.c.

References stc_wc_config::enCntClk, ErrorInvalidParameter, Ok, and WcGetInternDataPtr().

Here is the call graph for this function:

static void Wc_InitNvic ( volatile FM4_WC_TypeDef *  pstcWc)
static

Set NVIC Interrupt depending on ADC instance.

Parameters
pstcWcPointer to ADC instance

Definition at line 97 of file wc.c.

References PDL_IRQ_LEVEL_CLK_WC0, stc_wcn_t, and WC0.

Referenced by Wc_EnableInt().

Here is the caller graph for this function:

void Wc_IrqHandler ( volatile FM4_WC_TypeDef *  pstcWc,
stc_wc_intern_data_t *  pstcWcInternData 
)

Watch counter interrupt function.

Parameters
[in]pstcWcWC register definition
  • structure of WC register
[in]pstcWcInternDatastructure of WC callback function
  • structure of stc_wc_intern_data_t
Return values
void

Definition at line 137 of file wc.c.

References PdlSet, stc_wc_intern_data::pfnIntCallback, Wc_ClearIntFlag(), and Wc_GetIntFlag().

Here is the call graph for this function:

en_result_t Wc_Pres_DisableDiv ( volatile FM4_WC_TypeDef *  pstcWc)

Disable oscilation of the divison clock.

The Function can clear CLK_EN:CLK_EN to 0 of WCP

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 238 of file wc.c.

References ErrorInvalidParameter, and Ok.

en_result_t Wc_Pres_EnableDiv ( volatile FM4_WC_TypeDef *  pstcWc)

Enable oscilation of the divison clock.

The Function can set CLK_EN:CLK_EN to 1 of WCP

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 214 of file wc.c.

References ErrorInvalidParameter, and Ok.

en_result_t Wc_Pres_SelClk ( volatile FM4_WC_TypeDef *  pstcWc,
stc_wc_pres_clk_t *  pstcWcPresClk 
)

Select the input clock an and set the division clock to be output.

The Function can set SEL_OUT, SEL_IN of Watch counter prescaler (hereafter WCP)

Parameters
[in]pstcWcPointer to WC instance register area
[in]pstcWcPresClkWC prescaler clock configuration
Return values
OkWrite data successfully done or started.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 189 of file wc.c.

References stc_wc_pres_clk::enInputClk, stc_wc_pres_clk::enOutputClk, ErrorInvalidParameter, and Ok.

uint8_t Wc_ReadCurCnt ( volatile FM4_WC_TypeDef *  pstcWc)

Read the value in the 6-bit down counter.

The Function can read value of WCRD of WC

Parameters
[in]pstcWcPointer to WC instance register area
Return values
OkWrite data successfully done or started.
Returns
The value of WC 6-bit down counter If pstcWc == NULL 0xFF is returned.

Definition at line 451 of file wc.c.

en_result_t Wc_WriteReloadVal ( volatile FM4_WC_TypeDef *  pstcWc,
uint8_t  u8Val 
)

Set the counter value of WC.

The Function can set value to WCRL of WC

Parameters
[in]pstcWcPointer to WC instance register area
[in]u8ValValue of counter
Return values
OkWrite data successfully done.
ErrorInvalidParameterIf one of following conditions are met:
  • pstcWc == NULL

Definition at line 427 of file wc.c.

References ErrorInvalidParameter, and Ok.

static stc_wc_intern_data_t* WcGetInternDataPtr ( volatile FM4_WC_TypeDef *  pstcWc)
static

Return the internal data for a certain WC instance.

Parameters
pstcWcPointer to WC instance
Returns
Pointer to internal data or NULL if instance is not enabled (or not known)

Definition at line 160 of file wc.c.

References stc_wc_instance_data::stcInternData, and WC_INSTANCE_COUNT.

Referenced by Wc_EnableInt(), and Wc_Init().

Here is the caller graph for this function:

Variable Documentation

stc_wc_instance_data_t m_astcWcInstanceDataLut[]
Initial value:
=
{
{
& (*((FM4_WC_TypeDef *) FM4_WC_BASE)) ,
NULL
},
}

Look-up table for all enabled WC instances and their internal data.

Definition at line 76 of file wc.c.

stc_wc_instance_data_t m_astcWcInstanceDataLut[]

Look-up table for all enabled WC instances and their internal data.

Definition at line 76 of file wc.c.