PAN1080 Peripheral API
pan_clktrim.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Panchip Technology Corp. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef _PAN_CLKTRIM_H_
15#define _PAN_CLKTRIM_H_
16
22#ifdef __cplusplus
23extern "C"
24{
25#endif
26
33__STATIC_INLINE void TRIM_SetIdealCnt(TRIM_T *trim,uint32_t cnt)
34{
35 trim->TRIM_IDEAL_CNT = cnt;
36}
37
43__STATIC_INLINE uint32_t TRIM_GetIdealCnt(TRIM_T *trim)
44{
45 return trim->TRIM_IDEAL_CNT;
46}
47
53__STATIC_INLINE uint32_t TRIM_GetRealCnt(TRIM_T *trim)
54{
55 return trim->TRIM_REAL_CNT;
56}
57
58
77__STATIC_INLINE bool TRIM_IsIntStatusOccured(TRIM_T *trim,uint32_t msk)
78{
79 return (trim->TRIM_INT & msk)?(true):(false);
80}
81
100__STATIC_INLINE void TRIM_ClearIntStatusMsk(TRIM_T *trim,uint32_t msk)
101{
102 trim->TRIM_INT |= msk;
103}
104
111__STATIC_INLINE void TRIM_EnableInt(TRIM_T *trim,FunctionalState NewState)
112{
113 (NewState != DISABLE)?(trim->TRIM_INT |= TRIM_INT_EN_Msk):(trim->TRIM_INT &= ~TRIM_INT_EN_Msk);
114}
115
122__STATIC_INLINE void TRIM_SetRelationIncrease(TRIM_T *trim,FunctionalState NewState)
123{
124 (NewState != DISABLE)?(trim->TRIM_CTRL &= ~TRIM_CLRL_RELATION_Msk):(trim->TRIM_CTRL |= TRIM_CLRL_RELATION_Msk);
125}
126
133__STATIC_INLINE void TRIM_SetEarlyTerminatinEn(TRIM_T *trim,FunctionalState NewState)
134{
135 (NewState != ENABLE)?(trim->TRIM_CTRL &= ~TRIM_CLRL_EARLY_TERM_EN_Msk):(trim->TRIM_CTRL |= TRIM_CLRL_EARLY_TERM_EN_Msk);
136}
137
138
139
146__STATIC_INLINE void TRIM_SetCoarseCode(TRIM_T *trim,uint32_t code)
147{
148 trim->TRIM_CODE = (trim->TRIM_CODE & ~TRIM_COARSE_CODE_Msk) | (code << TRIM_COARSE_CODE_Pos);
149}
150
156__STATIC_INLINE uint32_t TRIM_GetCoarseCode(TRIM_T *trim)
157{
158 return ((trim->TRIM_CODE & TRIM_COARSE_CODE_Msk) >> TRIM_COARSE_CODE_Pos);
159}
166__STATIC_INLINE void TRIM_SetFineCode(TRIM_T *trim,uint32_t code)
167{
168 trim->TRIM_CODE = (trim->TRIM_CODE & ~TRIM_FINE_CODE_Msk) | (code << TRIM_FINE_CODE_Pos);
169}
175__STATIC_INLINE uint32_t TRIM_GetFineCode(TRIM_T *trim)
176{
177 return ((trim->TRIM_CODE & TRIM_FINE_CODE_Msk) >> TRIM_FINE_CODE_Pos);
178}
185__STATIC_INLINE void TRIM_SetPrecisionCode(TRIM_T *trim,uint32_t code)
186{
187 trim->TRIM_CODE = (trim->TRIM_CODE & ~TRIM_PRECISION_CODE_Msk) | (code << TRIM_PRECISION_CODE_Pos);
188}
194__STATIC_INLINE uint32_t TRIM_GetPrecisionCode(TRIM_T *trim)
195{
196 return ((trim->TRIM_CODE & TRIM_PRECISION_CODE_Msk) >> TRIM_PRECISION_CODE_Pos);
197}
204__STATIC_INLINE void TRIM_SetBitWidth(TRIM_T *trim,uint32_t width)
205{
206 trim->TRIM_CODE = (trim->TRIM_CODE & ~TRIM_BIT_WIDTH_Msk) | (width << TRIM_BIT_WIDTH_Pos);
207}
208
214__STATIC_INLINE uint32_t TRIM_GetBitWidth(TRIM_T *trim)
215{
216 return ((trim->TRIM_CODE & TRIM_BIT_WIDTH_Msk) >> TRIM_BIT_WIDTH_Pos);
217}
228__STATIC_INLINE void TRIM_StartTuning(TRIM_T *trim,uint32_t function)
229{
230 trim->TRIM_EN = (trim->TRIM_EN & ~0XF) | (function);
231}
232
239void TRIM_SetCalWaitCnt(TRIM_T *trim,uint32_t cnt);
240
247void TRIM_SetCalCnt(TRIM_T *trim,uint32_t cnt);
248
254uint32_t TRIM_GetCalCnt(TRIM_T *trim);
255
263void TRIM_SetErrRange(TRIM_T *trim,uint32_t deviation);
264
265
269#ifdef __cplusplus
270}
271#endif
272
273#endif /* _PAN_CLKTRIM_H_ */
274
__STATIC_INLINE void TRIM_SetRelationIncrease(TRIM_T *trim, FunctionalState NewState)
This function used to set the relation ship between tuning code and frequency.
Definition: pan_clktrim.h:122
__STATIC_INLINE uint32_t TRIM_GetIdealCnt(TRIM_T *trim)
This function used to read a ideal count value,IDEA_CNT = CAL_CNT * (REF_CLK / CAL_CLK) -1.
Definition: pan_clktrim.h:43
__STATIC_INLINE uint32_t TRIM_GetPrecisionCode(TRIM_T *trim)
This function used to get precision code value.
Definition: pan_clktrim.h:194
__STATIC_INLINE void TRIM_SetCoarseCode(TRIM_T *trim, uint32_t code)
This function used to set coarse code value.
Definition: pan_clktrim.h:146
void TRIM_SetErrRange(TRIM_T *trim, uint32_t deviation)
This function used to set range value.
__STATIC_INLINE void TRIM_StartTuning(TRIM_T *trim, uint32_t function)
This function used to enable clk trim function.
Definition: pan_clktrim.h:228
void TRIM_SetCalWaitCnt(TRIM_T *trim, uint32_t cnt)
This function used to set calibration cnt number to make sure rc32k stable.
__STATIC_INLINE void TRIM_SetIdealCnt(TRIM_T *trim, uint32_t cnt)
This function used to set a ideal count value,IDEA_CNT = CAL_CNT * (REF_CLK / CAL_CLK) -1.
Definition: pan_clktrim.h:33
__STATIC_INLINE uint32_t TRIM_GetFineCode(TRIM_T *trim)
This function used to get fine code value.
Definition: pan_clktrim.h:175
__STATIC_INLINE void TRIM_SetBitWidth(TRIM_T *trim, uint32_t width)
This function used to set bit width,bit_width = width + 1.
Definition: pan_clktrim.h:204
__STATIC_INLINE uint32_t TRIM_GetCoarseCode(TRIM_T *trim)
This function used to get coarse code value.
Definition: pan_clktrim.h:156
__STATIC_INLINE bool TRIM_IsIntStatusOccured(TRIM_T *trim, uint32_t msk)
Adjust which clktrim interrupt occured.
Definition: pan_clktrim.h:77
__STATIC_INLINE void TRIM_EnableInt(TRIM_T *trim, FunctionalState NewState)
This function used to enable interrupt.
Definition: pan_clktrim.h:111
__STATIC_INLINE void TRIM_SetEarlyTerminatinEn(TRIM_T *trim, FunctionalState NewState)
This function used to enable early termination.
Definition: pan_clktrim.h:133
__STATIC_INLINE uint32_t TRIM_GetBitWidth(TRIM_T *trim)
This function used to get bit width.
Definition: pan_clktrim.h:214
uint32_t TRIM_GetCalCnt(TRIM_T *trim)
This function get the number of calibration clock cycles.
__STATIC_INLINE void TRIM_SetPrecisionCode(TRIM_T *trim, uint32_t code)
This function used to set precision code value.
Definition: pan_clktrim.h:185
void TRIM_SetCalCnt(TRIM_T *trim, uint32_t cnt)
This function decide the number of calibration clock cycles you want count.
__STATIC_INLINE void TRIM_SetFineCode(TRIM_T *trim, uint32_t code)
This function used to set fine code value.
Definition: pan_clktrim.h:166
__STATIC_INLINE uint32_t TRIM_GetRealCnt(TRIM_T *trim)
This function used to get a real count value.
Definition: pan_clktrim.h:53
__STATIC_INLINE void TRIM_ClearIntStatusMsk(TRIM_T *trim, uint32_t msk)
Clear the specified interrupt.
Definition: pan_clktrim.h:100