A31R71x F/W Packages  1.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
Functions
A31R71x_hal_timer2n.c File Reference

Contains all functions support for timer2n firmware library on A31R71x. More...

Go to the source code of this file.

Functions

HAL_Status_Type HAL_TIMER2n_Init (TIMER2n_Type *TIMER2x, TIMER2n_MODE_OPT TimerCounterMode, void *TIMER2n_Config)
 Initialize the TIMER2n peripheral with the specified parameters. More...
 
HAL_Status_Type HAL_TIMER2n_DeInit (TIMER2n_Type *TIMER2x)
 Close Timer/Counter device. More...
 
HAL_Status_Type HAL_TIMER2n_ConfigInterrupt (TIMER2n_Type *TIMER2x, TIMER2n_INT_Type TIMER2n_IntCfg, FunctionalState NewState)
 Configure the peripheral interrupt. More...
 
HAL_Status_Type HAL_TIMER2n_Cmd (TIMER2n_Type *TIMER2x, FunctionalState NewState)
 Start/Stop Timer/Counter device. More...
 
HAL_Status_Type HAL_TIMER2n_ClearCounter (TIMER2n_Type *TIMER2x)
 Clear Timer/Counter device,. More...
 
HAL_Status_Type HAL_TIMER2n_UpdateCountValue (TIMER2n_Type *TIMER2x, uint8_t CountCh, uint16_t Value)
 Update value. More...
 
HAL_Status_Type HAL_TIMER2n_ClearStatus (TIMER2n_Type *TIMER2x, uint8_t value)
 Clear Timer Status. More...
 
uint8_t HAL_TIMER2n_GetStatus (TIMER2n_Type *TIMER2x)
 Get Timer Status. More...
 
uint32_t HAL_TIMER2n_GetCaptureData (TIMER2n_Type *TIMER2x)
 Read value of capture register in timer/counter device. More...
 

Detailed Description

Contains all functions support for timer2n firmware library on A31R71x.

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 A31R71x_hal_timer2n.c.

Function Documentation

◆ HAL_TIMER2n_ClearCounter()

HAL_Status_Type HAL_TIMER2n_ClearCounter ( TIMER2n_Type *  TIMER2x)

Clear Timer/Counter device,.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
Returns
HAL_Status_Type

Definition at line 266 of file A31R71x_hal_timer2n.c.

267 {
268  /* Check TIMER2 handle */
269  if( TIMER2x == NULL )
270  {
271  return HAL_ERROR;
272  }
273 
274  TIMER2x->CR_b.T2nCLR |= TIMER2n_CLEAR;
275 
276  return HAL_OK;
277 }

References HAL_ERROR, and HAL_OK.

◆ HAL_TIMER2n_ClearStatus()

HAL_Status_Type HAL_TIMER2n_ClearStatus ( TIMER2n_Type *  TIMER2x,
uint8_t  value 
)

Clear Timer Status.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
[in]valueclear value
Returns
HAL_Status_Type

Definition at line 321 of file A31R71x_hal_timer2n.c.

322 {
323  /* Check TIMER2 handle */
324  if( TIMER2x == NULL )
325  {
326  return HAL_ERROR;
327  }
328 
329  TIMER2x->CR |= ( 0xD & value );
330 
331  return HAL_OK;
332 }

References HAL_ERROR, and HAL_OK.

◆ HAL_TIMER2n_Cmd()

HAL_Status_Type HAL_TIMER2n_Cmd ( TIMER2n_Type *  TIMER2x,
FunctionalState  NewState 
)

Start/Stop Timer/Counter device.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
[in]NewStateNext State of Functional Operation
  • ENABLE, DISABLE
Returns
HAL_Status_Type

Definition at line 239 of file A31R71x_hal_timer2n.c.

240 {
241  /* Check TIMER2 handle */
242  if( TIMER2x == NULL )
243  {
244  return HAL_ERROR;
245  }
246 
247  if( NewState == ENABLE )
248  {
249  TIMER2x->CR_b.T2nEN = TIMER2n_ENABLE;
250  }
251  else
252  {
253  TIMER2x->CR_b.T2nEN = TIMER2n_DISABLE;
254  }
255 
256  return HAL_OK;
257 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_TIMER2n_ConfigInterrupt()

HAL_Status_Type HAL_TIMER2n_ConfigInterrupt ( TIMER2n_Type *  TIMER2x,
TIMER2n_INT_Type  TIMER2n_IntCfg,
FunctionalState  NewState 
)

Configure the peripheral interrupt.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
[in]TIMER2n_IntCfgSpecifies the interrupt flag
  • TIMER2n_CR_MATCH_INTR: Match interrupt enable
  • TIMER2n_CR_CAPTURE_INTR: Capture interrupt enable
[in]NewStateNext State of Interrupt Operation
  • ENABLE, DISABLE
Returns
HAL_Status_Type

Definition at line 194 of file A31R71x_hal_timer2n.c.

195 {
196  /* Check TIMER2 handle */
197  if( TIMER2x == NULL )
198  {
199  return HAL_ERROR;
200  }
201 
202  switch( TIMER2n_IntCfg )
203  {
205  if( NewState == ENABLE )
206  {
207  TIMER2x->CR_b.T2nMIEN = 1;
208  }
209  else if( NewState == DISABLE )
210  {
211  TIMER2x->CR_b.T2nMIEN = 0;
212  }
213  break;
215  if( NewState == ENABLE )
216  {
217  TIMER2x->CR_b.T2nCIEN = 1;
218  }
219  else if( NewState == DISABLE )
220  {
221  TIMER2x->CR_b.T2nCIEN = 0;
222  }
223  break;
224  }
225 
226  return HAL_OK;
227 }

References DISABLE, ENABLE, HAL_ERROR, HAL_OK, TIMER2n_CR_CAPTURE_INTR, and TIMER2n_CR_MATCH_INTR.

◆ HAL_TIMER2n_DeInit()

HAL_Status_Type HAL_TIMER2n_DeInit ( TIMER2n_Type *  TIMER2x)

Close Timer/Counter device.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
Returns
HAL_Status_Type

Definition at line 152 of file A31R71x_hal_timer2n.c.

153 {
154  /* Check TIMER2 handle */
155  if( TIMER2x == NULL )
156  {
157  return HAL_ERROR;
158  }
159 
160  // Disable timer/counter
161  TIMER2x->CR_b.T2nEN = 0;
162 
163 #if 1 // supported
164  if( TIMER2x == ( TIMER2n_Type* )TIMER20 )
165  {
166  SCUCG->PPCLKEN1_b.T20CLKE = 0;
167  }
168 #endif
169 
170 #if 1 // supported
171  if( TIMER2x == ( TIMER2n_Type* )TIMER21 )
172  {
173  SCUCG->PPCLKEN1_b.T21CLKE = 0;
174  }
175 #endif
176 
177  return HAL_OK;
178 }

References HAL_ERROR, and HAL_OK.

◆ HAL_TIMER2n_GetCaptureData()

uint32_t HAL_TIMER2n_GetCaptureData ( TIMER2n_Type *  TIMER2x)

Read value of capture register in timer/counter device.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
Returns
Value of count register

Definition at line 353 of file A31R71x_hal_timer2n.c.

354 {
355  return TIMER2x->CAPDR ;
356 }

◆ HAL_TIMER2n_GetStatus()

uint8_t HAL_TIMER2n_GetStatus ( TIMER2n_Type *  TIMER2x)

Get Timer Status.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
Returns
Value of status register

Definition at line 341 of file A31R71x_hal_timer2n.c.

342 {
343  return TIMER2x->CR;
344 }

◆ HAL_TIMER2n_Init()

HAL_Status_Type HAL_TIMER2n_Init ( TIMER2n_Type *  TIMER2x,
TIMER2n_MODE_OPT  TimerCounterMode,
void *  TIMER2n_Config 
)

Initialize the TIMER2n peripheral with the specified parameters.

  • Set Clock frequency for Timer
  • Set initial configuration for Timer
    Parameters
    [in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
    Parameters
    [in]TimerCounterModeTimer Counter Mode
  • TIMER2n_PERIODIC_MODE
  • TIMER2n_CAPTURE_MODE
  • TIMER2n_ONESHOT_MODE
  • TIMER2n_PWM_MODE
    Parameters
    [in]TIMER2n_ConfigPointer to the configuration information for the specified peripheral.
    Returns
    HAL_Status_Type

Definition at line 64 of file A31R71x_hal_timer2n.c.

65 {
66  TIMER2n_PERIODICCFG_Type* pTimeCfg;
67  TIMER2n_PWMCFG_Type* pPwmOneshotCfg;
68  TIMER2n_CAPTURECFG_Type* pCaptureCfg;
69  uint16_t reg_val16;
70 
71  /* Check TIMER2 handle */
72  if( TIMER2x == NULL )
73  {
74  return HAL_ERROR;
75  }
76 
77 #if 1 // supported
78  if( TIMER2x == ( TIMER2n_Type* )TIMER20 )
79  {
80  SCUCG->PPCLKEN1_b.T20CLKE = 1;
81  }
82 #endif
83 
84 #if 1 // supported
85  if( TIMER2x == ( TIMER2n_Type* )TIMER21 )
86  {
87  SCUCG->PPCLKEN1_b.T21CLKE = 1;
88  }
89 #endif
90 
91  if( TimerCounterMode == TIMER2n_PERIODIC_MODE )
92  {
93  pTimeCfg = ( TIMER2n_PERIODICCFG_Type* )TIMER2n_Config;
94 
95  SCUCG->PPCLKSR_b.T20CLK = pTimeCfg->TCLK_SEL;
96  reg_val16 = 0
97  | ( TimerCounterMode << 12 )
98  | TIMER2n_CR_CLK_SET( pTimeCfg->CkSel )
99  | TIMER2n_CR_ECE_SET( pTimeCfg->ExtCkEdge )
100  | TIMER2n_CR_OPOL_SET( pTimeCfg->StartLevel )
101  | TIMER2n_CR_CPOL_SET( pTimeCfg->CapEdge )
102  ;
103  TIMER2x->CR = reg_val16;
104  TIMER2x->PREDR = ( ( pTimeCfg->Prescaler - 1 ) & TIMER2n_PREDR_MASK );
105  TIMER2x->ADR = pTimeCfg->ADR;
106  TIMER2x->BDR = pTimeCfg->BDR;
107  }
108  else if( ( TimerCounterMode == TIMER2n_PWM_MODE ) || ( TimerCounterMode == TIMER2n_ONESHOT_MODE ) )
109  {
110  pPwmOneshotCfg = ( TIMER2n_PWMCFG_Type* )TIMER2n_Config;
111 
112  SCUCG->PPCLKSR_b.T20CLK = pPwmOneshotCfg->TCLK_SEL;
113  reg_val16 = 0
114  | ( TimerCounterMode << 12 )
115  | TIMER2n_CR_CLK_SET( pPwmOneshotCfg->CkSel )
116  | TIMER2n_CR_ECE_SET( pPwmOneshotCfg->ExtCkEdge )
117  | TIMER2n_CR_OPOL_SET( pPwmOneshotCfg->StartLevel )
118  | TIMER2n_CR_CPOL_SET( pPwmOneshotCfg->CapEdge )
119  ;
120  TIMER2x->CR = reg_val16;
121  TIMER2x->PREDR = ( ( pPwmOneshotCfg->Prescaler - 1 ) & TIMER2n_PREDR_MASK );
122  TIMER2x->ADR = pPwmOneshotCfg->ADR;
123  TIMER2x->BDR = pPwmOneshotCfg->BDR;
124  }
125  else if( TimerCounterMode == TIMER2n_CAPTURE_MODE )
126  {
127  pCaptureCfg = ( TIMER2n_CAPTURECFG_Type* )TIMER2n_Config;
128 
129  SCUCG->PPCLKSR_b.T20CLK = pCaptureCfg->TCLK_SEL;
130  reg_val16 = 0
131  | ( TimerCounterMode << 12 )
132  | TIMER2n_CR_CLK_SET( pCaptureCfg->CkSel )
133  | TIMER2n_CR_CPOL_SET( pCaptureCfg->ClrMode )
134  | TIMER2n_CR_CAPSEL_SET( pCaptureCfg->CAPCkSel )
135  ;
136  TIMER2x->CR = reg_val16;
137  TIMER2x->PREDR = ( ( pCaptureCfg->Prescaler - 1 ) & TIMER2n_PREDR_MASK );
138  }
139 
140  TIMER2x->CR_b.T2nCLR = TIMER2n_CLEAR;
141 
142  return HAL_OK;
143 }

References TIMER2n_PERIODICCFG_Type::ADR, TIMER2n_PWMCFG_Type::ADR, TIMER2n_PERIODICCFG_Type::BDR, TIMER2n_PWMCFG_Type::BDR, TIMER2n_CAPTURECFG_Type::CAPCkSel, TIMER2n_PERIODICCFG_Type::CapEdge, TIMER2n_PWMCFG_Type::CapEdge, TIMER2n_PERIODICCFG_Type::CkSel, TIMER2n_PWMCFG_Type::CkSel, TIMER2n_CAPTURECFG_Type::CkSel, TIMER2n_CAPTURECFG_Type::ClrMode, TIMER2n_PERIODICCFG_Type::ExtCkEdge, TIMER2n_PWMCFG_Type::ExtCkEdge, HAL_ERROR, HAL_OK, TIMER2n_PERIODICCFG_Type::Prescaler, TIMER2n_PWMCFG_Type::Prescaler, TIMER2n_CAPTURECFG_Type::Prescaler, TIMER2n_PERIODICCFG_Type::StartLevel, TIMER2n_PWMCFG_Type::StartLevel, TIMER2n_PERIODICCFG_Type::TCLK_SEL, TIMER2n_PWMCFG_Type::TCLK_SEL, TIMER2n_CAPTURECFG_Type::TCLK_SEL, TIMER2n_CAPTURE_MODE, TIMER2n_ONESHOT_MODE, TIMER2n_PERIODIC_MODE, and TIMER2n_PWM_MODE.

◆ HAL_TIMER2n_UpdateCountValue()

HAL_Status_Type HAL_TIMER2n_UpdateCountValue ( TIMER2n_Type *  TIMER2x,
uint8_t  CountCh,
uint16_t  Value 
)

Update value.

Parameters
[in]TIMER2xPointer to the target TIMER2
  • TIMER20 ~ TIMER21
[in]CountCh
  • 0 = GRA
  • 1 = GRB
[in]Valueupdated match value
Returns
HAL_Status_Type

Definition at line 291 of file A31R71x_hal_timer2n.c.

292 {
293  /* Check TIMER2 handle */
294  if( TIMER2x == NULL )
295  {
296  return HAL_ERROR;
297  }
298 
299  switch( CountCh )
300  {
301  case 0:
302  TIMER2x->ADR = Value;
303  break;
304  case 1:
305  TIMER2x->BDR = Value;
306  break;
307  }
308 
309  return HAL_OK;
310 }

References HAL_ERROR, and HAL_OK.