A31G11x F/W Packages  2.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
A31G11x_hal_wt.c
Go to the documentation of this file.
1 /***************************************************************************//****************************************************************************/
34 
35 /* Includes ----------------------------------------------------------------- */
36 //******************************************************************************
37 // Include
38 //******************************************************************************
39 
40 #include "A31G11x_hal_wt.h"
41 #include "A31G11x_hal_scu.h"
42 
43 /* Public Functions --------------------------------------------------------- */
44 //******************************************************************************
45 // Function
46 //******************************************************************************
47 
48 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
56 {
57  /* Check WT_Config */
58  if( WT_Config == NULL )
59  {
60  return HAL_ERROR;
61  }
62 
63  // enable peripheral clock
64  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_WTCLKE, PPxCLKE_Enable );
65 
66  WT->CR = 0
67  | ( ( WT_Config->wtClkDiv & 0x03 ) << 4 ) // WTINTV[1:0]
68  | WT_CR_WTCLR
69  ;
70  WT->DR = ( WT_Config->wtTmrConst & 0xFFF );
71 
72  // return
73  return HAL_OK;
74 }
75 
76 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
82 {
83  WT->CR = 0;
84 
85  // return
86  return HAL_OK;
87 }
88 
89 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
97 {
98  uint32_t reg_val = 0;
99 
100  reg_val = ( WT->CR & 0xFF );
101 
102  if( NewState == ENABLE )
103  {
104  reg_val |= WT_CR_WTIEN; // WTIEN bit
105  }
106  else
107  {
108  reg_val &= ~WT_CR_WTIEN;
109  }
110 
111  WT->CR = reg_val | WT_CR_WTIFLAG; // (1<<1): clear for WTIFLAG
112 
113  return HAL_OK;
114 }
115 
116 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
124 {
125  uint32_t tmp_reg;
126 
127  tmp_reg = WT->CR & 0xFF;
128  tmp_reg &= ~( 0x1 << 7 ); // Disable watch-dog timer counter
129 
130  if( ctrl == ENABLE )
131  {
132  tmp_reg |= ( 0x1 << 7 ); // Enable watch timer counter
133  }
134 
135  tmp_reg |= WT_CR_WTCLR; // clear the counter and divider
136 
137  WT->CR = tmp_reg;
138 
139  return HAL_OK;
140 }
141 
142 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
151 {
152  WT->CR = u32WTSet; // Setting Timer 1n Control Register
153 
154  return HAL_OK;
155 }
156 
157 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
163 {
164  WT->CR |= WT_CR_WTIFLAG; // (1<<1): clear for WTIFLAG
165 
166  return HAL_OK;
167 }
168 
169 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
174 uint32_t HAL_WT_GetStatus( void )
175 {
176  return ( WT->CR & WT_STATUS_BITMASK );
177 }
178 
179 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
184 uint32_t HAL_WT_GetCurrentCount( void )
185 {
186  return ( WT->CNT & 0xFFF );
187 }
188 
HAL_Status_Type
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.
HAL_Status_Type HAL_WT_ClearStatus(void)
Clear the timer status register of WT.
HAL_Status_Type HAL_WT_Start(FunctionalState ctrl)
Enable WT activity.
HAL_Status_Type HAL_WT_SetRegister(uint32_t u32WTSet)
Set WT CR Register.
Contains all macro definitions and function prototypes support for wt firmware library on A31G11x.
FunctionalState
uint32_t HAL_WT_GetCurrentCount(void)
Get the current value of WT.
HAL_Status_Type HAL_WT_ConfigInterrupt(FunctionalState NewState)
Configure the peripheral interrupt.
uint32_t HAL_WT_GetStatus(void)
Get the timer status register of WT.
uint32_t wtTmrConst
uint32_t wtClkDiv
HAL_Status_Type HAL_WT_Init(WT_CFG_Type *WT_Config)
Initialize the WT peripheral with the specified parameters.
HAL_Status_Type HAL_WT_DeInit(void)
deinit for Watch Timer function
Contains all macro definitions and function prototypes support for scu firmware library on A31G11x.