A31L12x F/W Packages  1.4.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
Functions | Variables
A31L12x_hal_scn.c File Reference

Contains all functions support for scn firmware library on A31L12x. More...

Go to the source code of this file.

Functions

static void sc_set_divisors (SCn_Type *SCx, uint32_t mode, uint32_t value, uint32_t baudrate, uint32_t ovrsamp)
 Determines best dividers to get a target clock rate. More...
 
HAL_Status_Type HAL_SC_Init (SCn_Type *SCx, SCn_CFG_Type *SCx_ConfigStruct)
 Initialize the SCn peripheral with the specified parameters. More...
 
HAL_Status_Type HAL_SC_DeInit (SCn_Type *SCx)
 Deinitialize the SCn peripheral registers to their default reset values. More...
 
HAL_Status_Type HAL_SC_ConfigStructInit (SCn_CFG_Type *SCn_Config, SCn_OPMODE_Type mode, uint32_t Baudrate)
 Fills each SCn_Config member with its default value: More...
 
HAL_Status_Type HAL_SC_ConfigInterrupt (SCn_Type *SCx, SCn_INT_Type SCn_IntCfg, FunctionalState NewState)
 Configure the interrupt source of selected SCn peripheral. More...
 
HAL_Status_Type HAL_SC_ControlConfig (SCn_Type *SCx, SCn_CR1_CONTROL_Type Mode, FunctionalState NewState)
 Configure Control mode for SCn peripheral. More...
 
HAL_Status_Type HAL_SC_Enable (SCn_Type *SCx, FunctionalState state)
 SCn enable control. More...
 
HAL_Status_Type HAL_SC_AutoAct (SCn_Type *SCx)
 SCn Auto Activation and Cold Reset. More...
 
HAL_Status_Type HAL_SC_AutoWarmRst (SCn_Type *SCx)
 SCn Auto Warm Reset. More...
 
HAL_Status_Type HAL_SC_AutoDeAct (SCn_Type *SCx)
 SCn Auto Deactivation. More...
 
HAL_Status_Type HAL_SC_SetRxTimeOutData (SCn_Type *SCx, uint32_t RxTimeOutD)
 SCn Receive Time Out Data Register Set. More...
 
HAL_Status_Type HAL_SC_SetExGuardTime (SCn_Type *SCx, uint32_t TxExGuardTime)
 SCn Transmit Extra Guard Time Register Set. More...
 
HAL_Status_Type HAL_SC_SetT34DR (SCn_Type *SCx, uint32_t SCnT3data, uint32_t SCnT4data)
 SCn T3DR and T4DR Registers Set. More...
 
HAL_Status_Type HAL_SC_SetLevel (SCn_Type *SCx, SCn_CR2_LEVEL_POS SelectPin, SetState SetLevel)
 Set Level for SCn peripheral when Smartcard Interface Mode. More...
 
HAL_Status_Type HAL_SC_AutoConvDet (SCn_Type *SCx)
 SCn Auto Convention Detection. More...
 
HAL_Status_Type HAL_SC_SetConv (SCn_Type *SCx, SCn_CONV_Type conv_sel)
 SCn Convention Selection. More...
 
HAL_Status_Type HAL_SC_ConfigRetry (SCn_Type *SCx, uint8_t retry_num, SCn_DTIME_Type retry_dly)
 SCn Retry Configuration with the specified parameters. More...
 
HAL_Status_Type HAL_SC_RetryEnable (SCn_Type *SCx, SCn_RETRY_EN_DISABLE retry_en)
 SCn Retry Enable. More...
 
HAL_Status_Type HAL_SC_SetInPol (SCn_Type *SCx, SCn_INPUT_POLARITY_Type In_pol)
 SCn Input Pin Polarity Set. More...
 
HAL_Status_Type HAL_SC_RxCntEnable (SCn_Type *SCx, SCn_RXCNT_EN_DISABLE RxCnt_en)
 SCn Receive Byte Count Enable. More...
 
HAL_Status_Type HAL_SC_SetRxBlkLen (SCn_Type *SCx, uint8_t blk_len)
 SCn Rx block length set with the specified parameters. More...
 
HAL_Status_Type HAL_SC_ClearStatus (SCn_Type *SCx, SCn_STATUS_Type Status)
 Clear Status register in SCn peripheral. More...
 
uint32_t HAL_SC_GetStatus (SCn_Type *SCx)
 Get current value of Status register in SCn peripheral. More...
 
uint8_t HAL_SC_GetRxLineBusy (SCn_Type *SCx)
 Get the Rx Line Busy bit. More...
 
uint8_t HAL_SC_GetSCnINST (SCn_Type *SCx)
 Get the SCnIN Pin Status. More...
 
FlagStatus HAL_SC_CheckBusy (SCn_Type *SCx)
 Check whether if SCn is busy or not. More...
 
HAL_Status_Type HAL_SC_TransmitByte (SCn_Type *SCx, uint8_t Data)
 Transmit a single data through SCn peripheral. More...
 
uint8_t HAL_SC_ReceiveByte (SCn_Type *SCx)
 Receive a single data from SCn peripheral. More...
 
uint32_t HAL_SC_Transmit (SCn_Type *SCx, uint8_t *txbuf, uint32_t buflen, TRANSFER_BLOCK_Type flag)
 Send a block of data via SCn peripheral. More...
 
uint32_t HAL_SC_Receive (SCn_Type *SCx, uint8_t *rxbuf, uint32_t buflen, TRANSFER_BLOCK_Type flag)
 Receive a block of data via SCn peripheral. More...
 

Variables

uint32_t SCn_BaseClock
 

Detailed Description

Contains all functions support for scn firmware library on A31L12x.

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

Function Documentation

◆ HAL_SC_AutoAct()

HAL_Status_Type HAL_SC_AutoAct ( SCn_Type *  SCx)

SCn Auto Activation and Cold Reset.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
HAL_Status_Type

Definition at line 403 of file A31L12x_hal_scn.c.

404 {
405  /* Check SC handle */
406  if( SCx == NULL )
407  {
408  return HAL_ERROR;
409  }
410 
411  SCx->CR2_b.ACTENn = ENABLE;
412 
413  return HAL_OK;
414 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_SC_AutoConvDet()

HAL_Status_Type HAL_SC_AutoConvDet ( SCn_Type *  SCx)

SCn Auto Convention Detection.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
HAL_Status_Type

Definition at line 595 of file A31L12x_hal_scn.c.

596 {
597  /* Check SC handle */
598  if( SCx == NULL )
599  {
600  return HAL_ERROR;
601  }
602 
603  SCx->CR3_b.ACONDETn = ENABLE;
604 
605  return HAL_OK;
606 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_SC_AutoDeAct()

HAL_Status_Type HAL_SC_AutoDeAct ( SCn_Type *  SCx)

SCn Auto Deactivation.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
HAL_Status_Type

Definition at line 443 of file A31L12x_hal_scn.c.

444 {
445  /* Check SC handle */
446  if( SCx == NULL )
447  {
448  return HAL_ERROR;
449  }
450 
451  SCx->CR2_b.DACTENn = ENABLE;
452 
453  return HAL_OK;
454 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_SC_AutoWarmRst()

HAL_Status_Type HAL_SC_AutoWarmRst ( SCn_Type *  SCx)

SCn Auto Warm Reset.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
HAL_Status_Type

Definition at line 423 of file A31L12x_hal_scn.c.

424 {
425  /* Check SC handle */
426  if( SCx == NULL )
427  {
428  return HAL_ERROR;
429  }
430 
431  SCx->CR2_b.WRENn = ENABLE;
432 
433  return HAL_OK;
434 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_SC_CheckBusy()

FlagStatus HAL_SC_CheckBusy ( SCn_Type *  SCx)

Check whether if SCn is busy or not.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
RESET if SCn is not busy, otherwise return SET.

Definition at line 829 of file A31L12x_hal_scn.c.

830 {
831  if( SCx->IFSR & SCn_IFSR_TXCIFLAGn_Msk )
832  {
833  return RESET;
834  }
835  else
836  {
837  return SET;
838  }
839 }

References RESET, and SET.

◆ HAL_SC_ClearStatus()

HAL_Status_Type HAL_SC_ClearStatus ( SCn_Type *  SCx,
SCn_STATUS_Type  Status 
)

Clear Status register in SCn peripheral.

Parameters
[in]SCxPointer to SCn peripheral
  • SC0 ~ SC1
[in]Status
Returns
HAL_Status_Type

Definition at line 765 of file A31L12x_hal_scn.c.

766 {
767  /* Check SC handle */
768  if( SCx == NULL )
769  {
770  return HAL_ERROR;
771  }
772 
774  {
775  SCx->IFSR = SCn_STATUS_ALL_EXCEPT_TXC;
776  }
777  else
778  {
779  SCx->IFSR = ( 1 << Status );
780  }
781 
782  return HAL_OK;
783 }

References HAL_ERROR, HAL_OK, and SCn_STATUS_ALL_EXCEPT_TXC.

Referenced by HAL_SC_Init(), and HAL_SC_Transmit().

Here is the caller graph for this function:

◆ HAL_SC_ConfigInterrupt()

HAL_Status_Type HAL_SC_ConfigInterrupt ( SCn_Type *  SCx,
SCn_INT_Type  SCn_IntCfg,
FunctionalState  NewState 
)

Configure the interrupt source of selected SCn peripheral.

Parameters
[in]SCxPointer to SCn peripheral
  • SC0 ~ SC1
[in]SCn_IntCfgSpecifies the interrupt source
  • SCn_INTCFG_RXC
  • SCn_INTCFG_TXC
  • SCn_INTCFG_RTO
  • SCn_INTCFG_BLED
  • SCn_INTCFG_SCIN
  • SCn_INTCFG_TRYER
  • SCn_INTCFG_CONED
  • SCn_INTCFG_CONER
  • SCn_INTCFG_SED
  • SCn_INTCFG_SER
  • SCn_INTCFG_RSTA
[in]NewStateNext State of Interrupt Operation
  • ENABLE, DISABLE
Returns
HAL_Status_Type

Definition at line 283 of file A31L12x_hal_scn.c.

284 {
285  uint32_t tmp = 0;
286 
287  /* Check SC handle */
288  if( SCx == NULL )
289  {
290  return HAL_ERROR;
291  }
292 
293  // get mask
294  tmp = ( 1 << SCn_IntCfg );
295 
296  // enable/disable
297  if( NewState == ENABLE )
298  {
299  SCx->IER |= tmp;
300  }
301  else
302  {
303  SCx->IER &= ~tmp;
304  }
305 
306  return HAL_OK;
307 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_SC_ConfigRetry()

HAL_Status_Type HAL_SC_ConfigRetry ( SCn_Type *  SCx,
uint8_t  retry_num,
SCn_DTIME_Type  retry_dly 
)

SCn Retry Configuration with the specified parameters.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]retry_numSpecifies the retry number
[in]retry_dlySpecifies the delay time before retry
  • SCn_DTIME_2J5ETU
  • SCn_DTIME_2J5PEXT
Returns
HAL_Status_Type

Definition at line 645 of file A31L12x_hal_scn.c.

646 {
647  /* Check SC handle */
648  if( SCx == NULL )
649  {
650  return HAL_ERROR;
651  }
652 
653  SCx->CR3_b.RETRYn = retry_num;
654  SCx->CR3_b.DLYRETRYn = retry_dly;
655 
656  return HAL_OK;
657 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_ConfigStructInit()

HAL_Status_Type HAL_SC_ConfigStructInit ( SCn_CFG_Type SCn_Config,
SCn_OPMODE_Type  mode,
uint32_t  Baudrate 
)

Fills each SCn_Config member with its default value:

  • 8 Data Bit
  • Even Parity Bit
  • 1 Stop Bit
  • 16 Oversampling
  • No guard time
  • fsc: PCLK/16 when SCI mode
  • T3DR: 10000 when SCI mode
  • T4DR: 40000 when SCI mode
    Parameters
    [out]SCn_ConfigPointer to a SCn_CFG_Type structure which will be initialized.
    [in]modeSCn Operation Mode Type
  • SCn_SCI_MODE
  • SCn_UART_MODE
    Parameters
    [in]Baudrate
  • 0 ~ 0xffff
    Returns
    HAL_Status_Type

Definition at line 229 of file A31L12x_hal_scn.c.

230 {
231  /* Check SCn_Config */
232  if( SCn_Config == NULL )
233  {
234  return HAL_ERROR;
235  }
236 
237  SCn_Config->Mode = mode;
238  if( mode == SCn_UART_MODE )
239  {
240  SCn_Config->ParityEnDis = SCn_PARITY_DISABLE;
241  }
242  else
243  {
244  SCn_Config->ParityEnDis = SCn_PARITY_ENABLE;
245  }
246  SCn_Config->Parity = SCn_PARITY_BIT_EVEN;
247  SCn_Config->Databits = SCn_DATA_BIT_8;
248  SCn_Config->Stopbits = SCn_STOP_BIT_1;
249  SCn_Config->Oversampling = SCn_OVR_SAMP_16;
250  SCn_Config->Baudrate = Baudrate;
251  SCn_Config->SCI_clock_gen = 8; // SCI clock: To be 2MHz @System clock 32MHz
252  SCn_Config->Baud_rate_Compensation = 0x00000010; // Plus compensation @System clock 32MHz
253  SCn_Config->Extra_guard_time = 0; // No extra guard time
254  SCn_Config->T3_dur_time = 10000 - 1; // Initial Reset Assertion Time when SCI mode
255  SCn_Config->T4_dur_time = 40000 - 1; // Initial ATR Receive Time when SCI mode
256 
257  return HAL_OK;
258 }
SCn_OPMODE_Type Mode
SCn_DATA_BIT_Type Databits
uint32_t T4_dur_time
uint32_t Baudrate
SCn_OVR_SAMP_Type Oversampling
uint32_t Extra_guard_time
uint32_t SCI_clock_gen
uint32_t T3_dur_time
uint32_t Baud_rate_Compensation
SCn_STOP_BIT_Type Stopbits
SCn_PARITY_BIT_Type Parity
SCn_PARITY_EN_DISABLE ParityEnDis

References SCn_CFG_Type::Baud_rate_Compensation, SCn_CFG_Type::Baudrate, SCn_CFG_Type::Databits, SCn_CFG_Type::Extra_guard_time, HAL_ERROR, HAL_OK, SCn_CFG_Type::Mode, SCn_CFG_Type::Oversampling, SCn_CFG_Type::Parity, SCn_CFG_Type::ParityEnDis, SCn_CFG_Type::SCI_clock_gen, SCn_DATA_BIT_8, SCn_OVR_SAMP_16, SCn_PARITY_BIT_EVEN, SCn_PARITY_DISABLE, SCn_PARITY_ENABLE, SCn_STOP_BIT_1, SCn_UART_MODE, SCn_CFG_Type::Stopbits, SCn_CFG_Type::T3_dur_time, and SCn_CFG_Type::T4_dur_time.

◆ HAL_SC_ControlConfig()

HAL_Status_Type HAL_SC_ControlConfig ( SCn_Type *  SCx,
SCn_CR1_CONTROL_Type  Mode,
FunctionalState  NewState 
)

Configure Control mode for SCn peripheral.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]ModeControl Mode
  • SCn_CR1_SCIEN: Activate SCn Block
  • SCn_CR1_RTOEN: Receive Time Out Function Enable
  • SCn_CR1_RXE: Enable/Disable Receiver unit
  • SCn_CR1_TXE: Enable/Disable Transmit unit
  • SCn_CR1_PEN: Enable/Disable Parity bit
[in]NewStateNext State of Functional Operation
  • ENABLE, DISABLE
Returns
HAL_Status_Type

Definition at line 326 of file A31L12x_hal_scn.c.

327 {
328  uint32_t tmp;
329 
330  /* Check SC handle */
331  if( SCx == NULL )
332  {
333  return HAL_ERROR;
334  }
335 
336  switch( Mode )
337  {
338  case SCn_CR1_SCIEN:
339  tmp = SCn_CR1_SCInEN_Msk;
340  break;
341  case SCn_CR1_RTOEN:
342  tmp = SCn_CR1_RTOENn_Msk;
343  break;
344  case SCn_CR1_RXE:
345  tmp = SCn_CR1_RXEn_Msk;
346  break;
347  case SCn_CR1_TXE:
348  tmp = SCn_CR1_TXEn_Msk;
349  break;
350  case SCn_CR1_PEN:
351  tmp = SCn_CR1_PENn_Msk;
352  break;
353  }
354 
355  if( NewState == ENABLE )
356  {
357  SCx->CR1 |= tmp;
358  }
359  else
360  {
361  SCx->CR1 &= ~( tmp & SCn_CR1_CONTROL_BITMASK );
362  }
363 
364  return HAL_OK;
365 }

References ENABLE, HAL_ERROR, HAL_OK, SCn_CR1_PEN, SCn_CR1_RTOEN, SCn_CR1_RXE, SCn_CR1_SCIEN, and SCn_CR1_TXE.

◆ HAL_SC_DeInit()

HAL_Status_Type HAL_SC_DeInit ( SCn_Type *  SCx)

Deinitialize the SCn peripheral registers to their default reset values.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
HAL_Status_Type

Definition at line 180 of file A31L12x_hal_scn.c.

181 {
182  /* Check SC handle */
183  if( SCx == NULL )
184  {
185  return HAL_ERROR;
186  }
187 
188 #if 1 // supported
189  if( SCx == ( SCn_Type* )SC0 )
190  {
191  // Set up peripheral clock for SC0 module
192  HAL_SCU_Peripheral_SetReset2( PPRST2_SC0RST );
193  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_SC0CLKE, PPxCLKE_Disable );
194  }
195 #endif
196 
197 #if 1 // supported
198  if( SCx == ( SCn_Type* )SC1 )
199  {
200  // Set up peripheral clock for SC1 module
201  HAL_SCU_Peripheral_SetReset2( PPRST2_SC1RST );
202  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_SC1CLKE, PPxCLKE_Disable );
203  }
204 #endif
205 
206  return HAL_OK;
207 }
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.
void HAL_SCU_Peripheral_SetReset2(uint32_t u32EachPeri2)
Set/Reset Each Peripheral Block Reset of PPRST2 Register.

References HAL_ERROR, HAL_OK, HAL_SCU_Peripheral_EnableClock2(), and HAL_SCU_Peripheral_SetReset2().

Here is the call graph for this function:

◆ HAL_SC_Enable()

HAL_Status_Type HAL_SC_Enable ( SCn_Type *  SCx,
FunctionalState  state 
)

SCn enable control.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]state
  • ENABLE, DISABLE
Returns
HAL_Status_Type

Definition at line 376 of file A31L12x_hal_scn.c.

377 {
378  /* Check SC handle */
379  if( SCx == NULL )
380  {
381  return HAL_ERROR;
382  }
383 
384  if( state == ENABLE )
385  {
386  SCx->CR1 |= ( 1 << SCn_CR1_SCInEN_Pos ); // SCInEN
387  }
388  else
389  {
390  SCx->CR1 &= ~( 1 << SCn_CR1_SCInEN_Pos ); // SCInEN
391  }
392 
393  return HAL_OK;
394 }

References ENABLE, HAL_ERROR, and HAL_OK.

◆ HAL_SC_GetRxLineBusy()

uint8_t HAL_SC_GetRxLineBusy ( SCn_Type *  SCx)

Get the Rx Line Busy bit.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
Status of Rx Line
Note
Don't Tx during Rx Line Busy when Smartcard Interface Mode

Definition at line 805 of file A31L12x_hal_scn.c.

806 {
807  return SCx->IFSR_b.RXBUSYn;
808 }

◆ HAL_SC_GetSCnINST()

uint8_t HAL_SC_GetSCnINST ( SCn_Type *  SCx)

Get the SCnIN Pin Status.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
Status of SCnIN Pin

Definition at line 817 of file A31L12x_hal_scn.c.

818 {
819  return SCx->CR2_b.SCnINST;
820 }

◆ HAL_SC_GetStatus()

uint32_t HAL_SC_GetStatus ( SCn_Type *  SCx)

Get current value of Status register in SCn peripheral.

Parameters
[in]SCxPointer to SCn peripheral
  • SC0 ~ SC1
Returns
Current value of Status register in SCn peripheral.

Definition at line 792 of file A31L12x_hal_scn.c.

793 {
794  return ( SCx->IFSR );
795 }

◆ HAL_SC_Init()

HAL_Status_Type HAL_SC_Init ( SCn_Type *  SCx,
SCn_CFG_Type SCx_ConfigStruct 
)

Initialize the SCn peripheral with the specified parameters.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]SCx_ConfigStructPointer to a SCn_CFG_Type structure that contains the configuration information for the specified peripheral.
Returns
HAL_Status_Type

Definition at line 112 of file A31L12x_hal_scn.c.

113 {
114  uint32_t tmp;
115 
116  /* Check SC handle */
117  if( SCx == NULL )
118  {
119  return HAL_ERROR;
120  }
121 
122 #if 1 // supported
123  if( SCx == ( SCn_Type* )SC0 )
124  {
125  // Set up peripheral clock for SC0 module
126  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_SC0CLKE, PPxCLKE_Enable );
127  HAL_SCU_Peripheral_SetReset2( PPRST2_SC0RST );
128  }
129 #endif
130 
131 #if 1 // supported
132  if( SCx == ( SCn_Type* )SC1 )
133  {
134  // Set up peripheral clock for SC1 module
135  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_SC1CLKE, PPxCLKE_Enable );
136  HAL_SCU_Peripheral_SetReset2( PPRST2_SC1RST );
137  }
138 #endif
139 
140  SCn_BaseClock = SystemPeriClock;
141 
142  sc_set_divisors( SCx, SCx_ConfigStruct->Mode, SCx_ConfigStruct->SCI_clock_gen, SCx_ConfigStruct->Baudrate, SCx_ConfigStruct->Oversampling );
143 
144  tmp = 0
145  | ( ( SCx_ConfigStruct->Mode & 0x1 ) << SCn_CR1_SCnMD_Pos )
146  | ( ( SCx_ConfigStruct->ParityEnDis & 0x1 ) << SCn_CR1_PENn_Pos )
147  | ( ( SCx_ConfigStruct->Parity & 0x1 ) << SCn_CR1_PSELn_Pos )
148  | ( ( SCx_ConfigStruct->Databits & 0x3 ) << SCn_CR1_DLENn_Pos )
149  | ( ( SCx_ConfigStruct->Stopbits & 0x1 ) << SCn_CR1_STOPBn_Pos )
150  | ( ( SCx_ConfigStruct->Oversampling & 0x1 ) << SCn_CR1_OVRSn_Pos )
151  | ( 1 << SCn_CR1_TXEn_Pos ) // Tx Enable
152  | ( 1 << SCn_CR1_RXEn_Pos ) // Rx Enable
153  ;
154 
155  SCx->CR1 = tmp;
156  SCx->CR2 = 0
157  | ( ( SCx_ConfigStruct->SCI_clock_gen & SCn_CR2_SCnCLKG_Msk ) << SCn_CR2_SCnCLKG_Pos )
158  ;
159  SCx->BCMP = SCx_ConfigStruct->Baud_rate_Compensation;
160  SCx->EGTR = SCx_ConfigStruct->Extra_guard_time;
161  SCx->T3DR = SCx_ConfigStruct->T3_dur_time;
162  SCx->T4DR = SCx_ConfigStruct->T4_dur_time;
163 
165 
166  //Dummy Read
167  tmp = HAL_SC_ReceiveByte( SCx );
168 
169  return HAL_OK;
170 }
SCn_OPMODE_Type Mode
uint8_t HAL_SC_ReceiveByte(SCn_Type *SCx)
Receive a single data from SCn peripheral.
SCn_DATA_BIT_Type Databits
uint32_t T4_dur_time
uint32_t Baudrate
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.
HAL_Status_Type HAL_SC_ClearStatus(SCn_Type *SCx, SCn_STATUS_Type Status)
Clear Status register in SCn peripheral.
SCn_OVR_SAMP_Type Oversampling
uint32_t Extra_guard_time
uint32_t SCI_clock_gen
uint32_t T3_dur_time
uint32_t Baud_rate_Compensation
uint32_t SCn_BaseClock
SCn_STOP_BIT_Type Stopbits
SCn_PARITY_BIT_Type Parity
void HAL_SCU_Peripheral_SetReset2(uint32_t u32EachPeri2)
Set/Reset Each Peripheral Block Reset of PPRST2 Register.
SCn_PARITY_EN_DISABLE ParityEnDis
static void sc_set_divisors(SCn_Type *SCx, uint32_t mode, uint32_t value, uint32_t baudrate, uint32_t ovrsamp)
Determines best dividers to get a target clock rate.

References SCn_CFG_Type::Baud_rate_Compensation, SCn_CFG_Type::Baudrate, SCn_CFG_Type::Databits, SCn_CFG_Type::Extra_guard_time, HAL_ERROR, HAL_OK, HAL_SC_ClearStatus(), HAL_SC_ReceiveByte(), HAL_SCU_Peripheral_EnableClock2(), HAL_SCU_Peripheral_SetReset2(), SCn_CFG_Type::Mode, SCn_CFG_Type::Oversampling, SCn_CFG_Type::Parity, SCn_CFG_Type::ParityEnDis, sc_set_divisors(), SCn_CFG_Type::SCI_clock_gen, SCn_BaseClock, SCn_STATUS_ALL_EXCEPT_TXC, SCn_CFG_Type::Stopbits, SCn_CFG_Type::T3_dur_time, and SCn_CFG_Type::T4_dur_time.

Here is the call graph for this function:

◆ HAL_SC_Receive()

uint32_t HAL_SC_Receive ( SCn_Type *  SCx,
uint8_t *  rxbuf,
uint32_t  buflen,
TRANSFER_BLOCK_Type  flag 
)

Receive a block of data via SCn peripheral.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[out]rxbufPointer to Received buffer
[in]buflenLength of Received buffer
[in]flagFlag mode
  • NONE_BLOCKING
  • BLOCKING
Returns
Number of bytes received
Note
when using SCn in BLOCKING mode, a time-out condition is used via defined symbol SCn_BLOCKING_TIMEOUT.

Definition at line 977 of file A31L12x_hal_scn.c.

978 {
979  uint32_t bToRecv, bRecv, timeOut;
980  uint8_t* pChar = rxbuf;
981 
982  // init counter
983  bToRecv = buflen;
984  bRecv = 0;
985 
986  // Blocking Mode
987  if( flag == BLOCKING )
988  {
989  while( bToRecv )
990  {
991  // wait until data are received with timeout
992  timeOut = SCn_BLOCKING_TIMEOUT;
993  while( !( SCx->IFSR & SCn_IFSR_RXCIFLAGn_Msk ) )
994  {
995  if( timeOut == 0 )
996  {
997  break;
998  }
999  timeOut--;
1000  }
1001 
1002  // if timeout
1003  if( timeOut == 0 )
1004  {
1005  break;
1006  }
1007 
1008  // receive byte
1009  ( *pChar++ ) = HAL_SC_ReceiveByte( SCx );
1010 
1011  // update counter
1012  bToRecv--;
1013  bRecv++;
1014  }
1015  }
1016 
1017  // Non-Blocking Mode
1018  else
1019  {
1020  while( bToRecv )
1021  {
1022  // if no data were received
1023  if( !( SCx->IFSR & SCn_IFSR_RXCIFLAGn_Msk ) )
1024  {
1025  break;
1026  }
1027 
1028  // receive byte
1029  ( *pChar++ ) = HAL_SC_ReceiveByte( SCx );
1030 
1031  // update counter
1032  bRecv++;
1033  bToRecv--;
1034  }
1035  }
1036 
1037  // return
1038  return bRecv;
1039 }
uint8_t HAL_SC_ReceiveByte(SCn_Type *SCx)
Receive a single data from SCn peripheral.

References BLOCKING, and HAL_SC_ReceiveByte().

Here is the call graph for this function:

◆ HAL_SC_ReceiveByte()

uint8_t HAL_SC_ReceiveByte ( SCn_Type *  SCx)

Receive a single data from SCn peripheral.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
Returns
Data received

Definition at line 870 of file A31L12x_hal_scn.c.

871 {
872  return SCx->RDR;
873 }

Referenced by HAL_SC_Init(), and HAL_SC_Receive().

Here is the caller graph for this function:

◆ HAL_SC_RetryEnable()

HAL_Status_Type HAL_SC_RetryEnable ( SCn_Type *  SCx,
SCn_RETRY_EN_DISABLE  retry_en 
)

SCn Retry Enable.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]retry_enEnable/Disable retry
  • SCn_RETRY_DISABLE
  • SCn_RETRY_ENABLE
Returns
HAL_Status_Type

Definition at line 670 of file A31L12x_hal_scn.c.

671 {
672  /* Check SC handle */
673  if( SCx == NULL )
674  {
675  return HAL_ERROR;
676  }
677 
678  SCx->CR3_b.RETRYENn = retry_en;
679 
680  return HAL_OK;
681 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_RxCntEnable()

HAL_Status_Type HAL_SC_RxCntEnable ( SCn_Type *  SCx,
SCn_RXCNT_EN_DISABLE  RxCnt_en 
)

SCn Receive Byte Count Enable.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]RxCnt_enEnable/Disable Rx Byte Count
  • SCn_RXCNT_DISABLE
  • SCn_RXCNT_ENABLE
Returns
HAL_Status_Type

Definition at line 722 of file A31L12x_hal_scn.c.

723 {
724  /* Check SC handle */
725  if( SCx == NULL )
726  {
727  return HAL_ERROR;
728  }
729 
730  SCx->CR3_b.RXCNTENn = RxCnt_en;
731 
732  return HAL_OK;
733 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_SetConv()

HAL_Status_Type HAL_SC_SetConv ( SCn_Type *  SCx,
SCn_CONV_Type  conv_sel 
)

SCn Convention Selection.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]conv_selConvention Selection
  • SCn_DIRECT_CONV
  • SCn_INVERSE_CONV
Returns
HAL_Status_Type

Definition at line 619 of file A31L12x_hal_scn.c.

620 {
621  /* Check SC handle */
622  if( SCx == NULL )
623  {
624  return HAL_ERROR;
625  }
626 
627  SCx->CR3_b.CONSELn = conv_sel;
628 
629  return HAL_OK;
630 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_SetExGuardTime()

HAL_Status_Type HAL_SC_SetExGuardTime ( SCn_Type *  SCx,
uint32_t  TxExGuardTime 
)

SCn Transmit Extra Guard Time Register Set.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]TxExGuardTimeTransmit Extra Guard Time between the last stop bit and the next start bit
  • 0 ~ 0x000000ff
Returns
HAL_Status_Type

Definition at line 489 of file A31L12x_hal_scn.c.

490 {
491  /* Check SC handle */
492  if( SCx == NULL )
493  {
494  return HAL_ERROR;
495  }
496 
497  SCx->EGTR = TxExGuardTime;
498 
499  return HAL_OK;
500 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_SetInPol()

HAL_Status_Type HAL_SC_SetInPol ( SCn_Type *  SCx,
SCn_INPUT_POLARITY_Type  In_pol 
)

SCn Input Pin Polarity Set.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]In_polInput Polarity Setting
  • SCn_INPUT_POLARITY_FALLING
  • SCn_INPUT_POLARITY_RISING
  • SCn_INPUT_POLARITY_BOTH
Returns
HAL_Status_Type

Definition at line 695 of file A31L12x_hal_scn.c.

696 {
697  /* Check SC handle */
698  if( SCx == NULL )
699  {
700  return HAL_ERROR;
701  }
702 
703  if( In_pol <= SCn_INPUT_POLARITY_BOTH )
704  {
705  SCx->CR3_b.SCnINPOL = In_pol;
706  }
707 
708  return HAL_OK;
709 }

References HAL_ERROR, HAL_OK, and SCn_INPUT_POLARITY_BOTH.

◆ HAL_SC_SetLevel()

HAL_Status_Type HAL_SC_SetLevel ( SCn_Type *  SCx,
SCn_CR2_LEVEL_POS  SelectPin,
SetState  SetLevel 
)

Set Level for SCn peripheral when Smartcard Interface Mode.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]ModeControl Mode
  • SCn_CR2_CLKEN: Enable/Disable Clock
  • SCn_CR2_CLKLV: Clock Pin Level when disable
  • SCn_CR2_DATALV: I/O Pin Level
  • SCn_CR2_RSTLV: Reset Pin Level
  • SCn_CR2_PWRLV: Power Pin Level
[in]SetLevelNext State of Functional Operation
  • SET
  • RESET
Returns
HAL_Status_Type

Definition at line 547 of file A31L12x_hal_scn.c.

548 {
549  uint32_t tmp;
550 
551  /* Check SC handle */
552  if( SCx == NULL )
553  {
554  return HAL_ERROR;
555  }
556 
557  switch( SelectPin )
558  {
559  case SCn_CR2_CLKEN:
560  tmp = SCn_CR2_SCnCLKEN_Msk;
561  break;
562  case SCn_CR2_CLKLV:
563  tmp = SCn_CR2_SCnCLKLV_Msk;
564  break;
565  case SCn_CR2_DATALV:
566  tmp = SCn_CR2_SCnDATALV_Msk;
567  break;
568  case SCn_CR2_RSTLV:
569  tmp = SCn_CR2_SCnRSTLV_Msk;
570  break;
571  case SCn_CR2_PWRLV:
572  tmp = SCn_CR2_SCnPWRLV_Msk;
573  break;
574  }
575 
576  if( SetLevel == SET )
577  {
578  SCx->CR2 |= tmp;
579  }
580  else
581  {
582  SCx->CR2 &= ~( tmp & SCn_CR2_CONTROL_BITMASK );
583  }
584 
585  return HAL_OK;
586 }

References HAL_ERROR, HAL_OK, SCn_CR2_CLKEN, SCn_CR2_CLKLV, SCn_CR2_DATALV, SCn_CR2_PWRLV, SCn_CR2_RSTLV, and SET.

◆ HAL_SC_SetRxBlkLen()

HAL_Status_Type HAL_SC_SetRxBlkLen ( SCn_Type *  SCx,
uint8_t  blk_len 
)

SCn Rx block length set with the specified parameters.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]blk_lenSpecifies the rx block length
Returns
HAL_Status_Type

Definition at line 744 of file A31L12x_hal_scn.c.

745 {
746  /* Check SC handle */
747  if( SCx == NULL )
748  {
749  return HAL_ERROR;
750  }
751 
752  SCx->CR3_b.RXBLENn = blk_len;
753 
754  return HAL_OK;
755 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_SetRxTimeOutData()

HAL_Status_Type HAL_SC_SetRxTimeOutData ( SCn_Type *  SCx,
uint32_t  RxTimeOutD 
)

SCn Receive Time Out Data Register Set.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]RxTimeOutDReceive Time Out Data with baud rate unit
  • 0 ~ 0x00ffffff
Returns
HAL_Status_Type

Definition at line 466 of file A31L12x_hal_scn.c.

467 {
468  /* Check SC handle */
469  if( SCx == NULL )
470  {
471  return HAL_ERROR;
472  }
473 
474  SCx->RTODR = RxTimeOutD;
475 
476  return HAL_OK;
477 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_SetT34DR()

HAL_Status_Type HAL_SC_SetT34DR ( SCn_Type *  SCx,
uint32_t  SCnT3data,
uint32_t  SCnT4data 
)

SCn T3DR and T4DR Registers Set.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]SCnT3dataNo. of fsc clock: Time duration for "Reset Assertion" of "Clock Disabe after Reset De-Assertion" of Smartcard Interface mode
  • 0 ~ 0x0000ffff
[in]SCnT4dataNo. of fsc clock: Time duration for "ATR after Reset Assertion" of "from data low to Power down" of Smartcard Interface mode
  • 0 ~ 0x0000ffff
Returns
HAL_Status_Type

Definition at line 515 of file A31L12x_hal_scn.c.

516 {
517  /* Check SC handle */
518  if( SCx == NULL )
519  {
520  return HAL_ERROR;
521  }
522 
523  SCx->T3DR = SCnT3data;
524  SCx->T4DR = SCnT4data;
525 
526  return HAL_OK;
527 }

References HAL_ERROR, and HAL_OK.

◆ HAL_SC_Transmit()

uint32_t HAL_SC_Transmit ( SCn_Type *  SCx,
uint8_t *  txbuf,
uint32_t  buflen,
TRANSFER_BLOCK_Type  flag 
)

Send a block of data via SCn peripheral.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]txbufPointer to Transmit buffer
[in]buflenLength of Transmit buffer
[in]flagFlag used in SCn transfer
  • NONE_BLOCKING
  • BLOCKING
Returns
Number of bytes sent.
Note
when using SCn in BLOCKING mode, a time-out condition is used via defined symbol SCn_BLOCKING_TIMEOUT.

Definition at line 892 of file A31L12x_hal_scn.c.

893 {
894  uint32_t bToSend, bSent, timeOut;
895  uint8_t* pChar = txbuf;
896 
897  // init counter
898  bToSend = buflen;
899  bSent = 0;
900 
901  // Blocking Mode
902  if( flag == BLOCKING )
903  {
904  while( bToSend )
905  {
906  // clear flag
908 
909  // send byte
910  HAL_SC_TransmitByte( SCx, ( *pChar++ ) );
911 
912  // wait until tx is shifted out completely with timeout
913  timeOut = SCn_BLOCKING_TIMEOUT;
914  while( !( SCx->IFSR & SCn_IFSR_TXCIFLAGn_Msk ) )
915  {
916  if( timeOut == 0 )
917  {
918  break;
919  }
920  timeOut--;
921  }
922 
923  // if timeout
924  if( timeOut == 0 )
925  {
926  break;
927  }
928 
929  // update counter
930  bToSend--;
931  bSent++;
932  }
933  }
934 
935  // Non-Blocking Mode
936  else
937  {
938  while( bToSend )
939  {
940  // if tx is not shifted out completely
941  if( !( SCx->IFSR & SCn_IFSR_TXCIFLAGn_Msk ) )
942  {
943  break;
944  }
945 
946  // send byte
947  HAL_SC_TransmitByte( SCx, ( *pChar++ ) );
949 
950  // update counter
951  bToSend--;
952  bSent++;
953  }
954  }
955 
956  // return
957  return bSent;
958 }
HAL_Status_Type HAL_SC_ClearStatus(SCn_Type *SCx, SCn_STATUS_Type Status)
Clear Status register in SCn peripheral.
HAL_Status_Type HAL_SC_TransmitByte(SCn_Type *SCx, uint8_t Data)
Transmit a single data through SCn peripheral.

References BLOCKING, HAL_SC_ClearStatus(), HAL_SC_TransmitByte(), and SCn_STATUS_TXC.

Here is the call graph for this function:

◆ HAL_SC_TransmitByte()

HAL_Status_Type HAL_SC_TransmitByte ( SCn_Type *  SCx,
uint8_t  Data 
)

Transmit a single data through SCn peripheral.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]DataData to transmit (must be 8-bit long)
Returns
HAL_Status_Type

Definition at line 850 of file A31L12x_hal_scn.c.

851 {
852  /* Check SC handle */
853  if( SCx == NULL )
854  {
855  return HAL_ERROR;
856  }
857 
858  SCx->TDR = Data;
859 
860  return HAL_OK;
861 }

References HAL_ERROR, and HAL_OK.

Referenced by HAL_SC_Transmit().

Here is the caller graph for this function:

◆ sc_set_divisors()

static void sc_set_divisors ( SCn_Type *  SCx,
uint32_t  mode,
uint32_t  value,
uint32_t  baudrate,
uint32_t  ovrsamp 
)
static

Determines best dividers to get a target clock rate.

Parameters
[in]SCxPointer to the target SC
  • SC0 ~ SC1
[in]mode
  • SCn_SCI_MODE
  • SCn_UART_MODE
[in]valuedivider to generate smartcard clock
[in]baudrateDesired baudrate
Returns
None

Definition at line 68 of file A31L12x_hal_scn.c.

69 {
70  uint32_t numerator;
71  uint32_t denominator;
72  uint32_t n;
73  uint32_t bdr;
74 
75  if( ( mode == SCn_SCI_MODE ) && ( value != 0 ) )
76  {
77  n = value * 2 * 16; // bdr = (PCLK / (value * 2 * 16 * baudrate)) - 1
78  }
79  else
80  {
81  n = 16; // bdr = (PCLK / (16 * baudrate)) - 1
82  }
83 
84  if( ovrsamp == SCn_OVR_SAMP_8 )
85  {
86  n >>= 1;
87  }
88 
89  //--------------------------------------
90  // numerator & denominator
91  //
92  // bdr = SCn_BaseClock / n / baudrate - 1
93  //--------------------------------------
94  numerator = SCn_BaseClock;
95  denominator = baudrate;
96 
97  bdr = numerator / n / denominator - 1;
98 
99  SCx->BDR = bdr & 0x0000ffff;
100 }
uint32_t SCn_BaseClock

References SCn_BaseClock, SCn_OVR_SAMP_8, and SCn_SCI_MODE.

Referenced by HAL_SC_Init().

Variable Documentation

◆ SCn_BaseClock

uint32_t SCn_BaseClock

Definition at line 47 of file A31L12x_hal_scn.c.

Referenced by HAL_SC_Init(), and sc_set_divisors().