![]() |
PDL for FM4
Version1.2
Peripheral Driverl Library for FM4
|
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... | |
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.
| #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 enum en_input_clk en_input_clk_t |
Enumeration to define source clock of watch counter precaler.
| typedef enum en_output_clk en_output_clk_t |
Enumeration to define output clock of watch counter precaler.
| typedef enum en_wc_cnt_clk en_wc_cnt_clk_t |
Enumeration to set the clock of watch counter.
| typedef enum en_wc_instance_index en_wc_instance_index_t |
Enumeration to define an index for each WC instance.
| typedef struct stc_wc_config stc_wc_config_t |
Structure to configure the watch counter.
| typedef struct stc_wc_instance_data stc_wc_instance_data_t |
Structure of watch counter instance data.
| typedef struct stc_wc_intern_data stc_wc_intern_data_t |
Structure of watch counter internal data.
| typedef struct stc_wc_pres_clk stc_wc_pres_clk_t |
Structure to configure watch counter prescaler.
| enum en_input_clk |
Enumeration to define source clock of watch counter precaler.
| enum en_output_clk |
Enumeration to define output clock of watch counter precaler.
| enum en_wc_cnt_clk |
| enum en_wc_instance_index |
| en_result_t Wc_ClearIntFlag | ( | volatile FM4_WC_TypeDef * | pstcWc | ) |
Clear WC underflow flag.
The Function clear WCIF to 0 of WC
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
Definition at line 474 of file wc.c.
References ErrorInvalidParameter, and Ok.
Referenced by Wc_IrqHandler().

|
static |
Clear NVIC Interrupt depending on ADC instance.
| pstcWc | Pointer 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().

| en_result_t Wc_DisableCount | ( | volatile FM4_WC_TypeDef * | pstcWc | ) |
Disable WC operation.
The Function can clear WCCR:WCEN to 0 of WC
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
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
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
Definition at line 401 of file wc.c.
References ErrorInvalidParameter, Ok, and Wc_DeInitNvic().

| en_result_t Wc_EnableCount | ( | volatile FM4_WC_TypeDef * | pstcWc | ) |
Enable WC operation.
The Function can set WCCR:WCEN to 1 of WC
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
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
| [in] | pstcWc | Pointer to WC instance register area |
| [in] | pfnIntCallback | WC interrupt to be enabled |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
Definition at line 367 of file wc.c.
References ErrorInvalidParameter, Ok, stc_wc_intern_data::pfnIntCallback, stc_wcn_t, Wc_InitNvic(), and WcGetInternDataPtr().

| 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
| [in] | pstcWc | Pointer to WC instance register area |
| PdlClr | CLK_EN_R is 0, oscilation of the division clock is not performed |
| PdlSet | CLK_EN R is 1, oscilation of the division clock is performed |
| en_int_flag_t Wc_GetIntFlag | ( | volatile FM4_WC_TypeDef * | pstcWc | ) |
Get WC underflow flag status.
The Function get value WCIF of WC
| [in] | pstcWc | Pointer to WC instance register area |
| PdlClr | WCIF is 0, WC underflow does not occur |
| PdlSet | WCIF is 1, WC underflow occurs |
Definition at line 497 of file wc.c.
Referenced by Wc_IrqHandler().

| en_stat_flag_t Wc_GetOperationFlag | ( | volatile FM4_WC_TypeDef * | pstcWc | ) |
| 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)
| [in] | pstcWc | Pointer to WC instance register area |
| [in] | pstcWcConfig | Pointer to WC configuration |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
Definition at line 280 of file wc.c.
References stc_wc_config::enCntClk, ErrorInvalidParameter, Ok, and WcGetInternDataPtr().

|
static |
Set NVIC Interrupt depending on ADC instance.
| pstcWc | Pointer 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().

| void Wc_IrqHandler | ( | volatile FM4_WC_TypeDef * | pstcWc, |
| stc_wc_intern_data_t * | pstcWcInternData | ||
| ) |
Watch counter interrupt function.
| [in] | pstcWc | WC register definition
|
| [in] | pstcWcInternData | structure of WC callback function
|
| void |
Definition at line 137 of file wc.c.
References PdlSet, stc_wc_intern_data::pfnIntCallback, Wc_ClearIntFlag(), and Wc_GetIntFlag().

| 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
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
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
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
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)
| [in] | pstcWc | Pointer to WC instance register area |
| [in] | pstcWcPresClk | WC prescaler clock configuration |
| Ok | Write data successfully done or started. |
| ErrorInvalidParameter | If one of following conditions are met:
|
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
| [in] | pstcWc | Pointer to WC instance register area |
| Ok | Write data successfully done or started. |
| 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
| [in] | pstcWc | Pointer to WC instance register area |
| [in] | u8Val | Value of counter |
| Ok | Write data successfully done. |
| ErrorInvalidParameter | If one of following conditions are met:
|
Definition at line 427 of file wc.c.
References ErrorInvalidParameter, and Ok.
|
static |
Return the internal data for a certain WC instance.
| pstcWc | Pointer to WC instance |
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().

| stc_wc_instance_data_t m_astcWcInstanceDataLut[] |
| stc_wc_instance_data_t m_astcWcInstanceDataLut[] |