PAN1080 Peripheral API
pan_adc.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
15#ifndef __PAN_ADC_H__
16#define __PAN_ADC_H__
17
24#ifdef __cplusplus
25extern "C"
26{
27#endif
28
29
30#define ADC_INPUTRANGE_HIGH (1UL)
31#define ADC_INPUTRANGE_LOW (0UL)
33#define ADC_CH8_EXT (0UL)
34#define ADC_CH8_BGP (ADC_CHEN_CH8SEL_Msk)
35#define ADC_CMP0_LESS_THAN (0UL << ADC_CMP0_CMPCOND_Pos)
36#define ADC_CMP1_LESS_THAN (0UL << ADC_CMP1_CMPCOND_Pos)
37#define ADC_CMP0_GREATER_OR_EQUAL_TO (1ul << ADC_CMP0_CMPCOND_Pos)
38#define ADC_CMP1_GREATER_OR_EQUAL_TO (1ul << ADC_CMP1_CMPCOND_Pos)
39#define ADC_TRIGGER_BY_EXT_PIN (0UL << ADC_CTL_HWTRGSEL_Pos)
40#define ADC_TRIGGER_BY_PWM (ADC_CTL_HWTRGSEL_Msk)
41#define ADC_FALLING_EDGE_TRIGGER (0UL << ADC_CTL_HWTRGCOND_Pos)
42#define ADC_RISING_EDGE_TRIGGER (ADC_CTL_HWTRGCOND_Msk)
47#define ADC_ADIF_INT (ADC_STATUS_ADIF_Msk)
48#define ADC_CMP0_INT (ADC_STATUS_ADCMPIF0_Msk)
49#define ADC_CMP1_INT (ADC_STATUS_ADCMPIF1_Msk)
50#define ADC_FIFO_FULL_INT (ADC_STATUS_INTFLG_FULL_Msk)
51#define ADC_FIFO_EMPTY_INT (ADC_STATUS_INTFLG_EMPTY_Msk)
52#define ADC_FIFO_OVER_INT (ADC_STATUS_INTFLG_OVER_Msk)
53#define ADC_FIFO_HALF_INT (ADC_STATUS_INTFLG_HALF_Msk)
60#define ADC_SAMPLE_CLOCK_0 (0UL)
61#define ADC_SAMPLE_CLOCK_1 (1UL)
62#define ADC_SAMPLE_CLOCK_2 (2UL)
63#define ADC_SAMPLE_CLOCK_4 (3UL)
64#define ADC_SAMPLE_CLOCK_8 (4UL)
65#define ADC_SAMPLE_CLOCK_16 (5UL)
66#define ADC_SAMPLE_CLOCK_32 (6UL)
67#define ADC_SAMPLE_CLOCK_64 (7UL)
68#define ADC_SAMPLE_CLOCK_128 (8UL)
69#define ADC_SAMPLE_CLOCK_256 (9UL)
70#define ADC_SAMPLE_CLOCK_512 (10UL)
71#define ADC_SAMPLE_CLOCK_1024 (11UL)
77#define ADC_SEQMODE_TYPE_23SHUNT (0UL)
78#define ADC_SEQMODE_TYPE_1SHUNT (1UL)
79#define ADC_SEQMODE_MODESELECT_CH01 (0UL)
80#define ADC_SEQMODE_MODESELECT_CH12 (1UL)
81#define ADC_SEQMODE_MODESELECT_CH02 (2UL)
82#define ADC_SEQMODE_MODESELECT_ONE (3UL)
83#define ADC_SEQMODE_PWM0_RISING (0UL)
84#define ADC_SEQMODE_PWM0_CENTER (1UL)
85#define ADC_SEQMODE_PWM0_FALLING (2UL)
86#define ADC_SEQMODE_PWM0_PERIOD (3UL)
87#define ADC_SEQMODE_PWM2_RISING (4UL)
88#define ADC_SEQMODE_PWM2_CENTER (5UL)
89#define ADC_SEQMODE_PWM2_FALLING (6UL)
90#define ADC_SEQMODE_PWM2_PERIOD (7UL)
91#define ADC_SEQMODE_PWM4_RISING (8UL)
92#define ADC_SEQMODE_PWM4_CENTER (9UL)
93#define ADC_SEQMODE_PWM4_FALLING (10UL)
94#define ADC_SEQMODE_PWM4_PERIOD (11UL)
95#define ADC_SEQMODE_PWM6_RISING (12UL)
96#define ADC_SEQMODE_PWM6_CENTER (13UL)
97#define ADC_SEQMODE_PWM6_FALLING (14UL)
98#define ADC_SEQMODE_PWM6_PERIOD (15UL)
101#define ADC_COMPARATOR_0 (0)
102#define ADC_COMPARATOR_1 (1)
104#define ADC_FIFO_TRIG_LEVEL_HALF (0)
105#define ADC_FIFO_TRIG_LEVEL_FULL (1)
121__STATIC_INLINE uint32_t ADC_GetConversionData(ADC_T *ADCx)
122{
123 return (ADCx->DAT & ADC_DAT_RESULT_Msk);
124}
125
139__STATIC_INLINE bool ADC_StatusFlag(ADC_T *ADCx,uint32_t IntMask)
140{
141 return (ADCx->STATUS & IntMask)?(true):(false);
142}
143
157__STATIC_INLINE void ADC_ClearStatusFlag(ADC_T *ADCx,uint32_t IntMask)
158{
159 ADCx->STATUS |= IntMask;
160}
175__STATIC_INLINE void ADC_IntMask(ADC_T *ADCx,uint32_t IntMask,FunctionalState NewState)
176{
177 (NewState == DISABLE)?(ADCx->STATUS |= IntMask):(ADCx->STATUS &= ~IntMask);
178}
179
193__STATIC_INLINE bool ADC_IsIntOccured(ADC_T *ADCx,uint32_t IntMask)
194{
195 return (ADCx->STATUS & IntMask)?(true):(false);
196}
197
211__STATIC_INLINE void ADC_ClearIntFlag(ADC_T *ADCx,uint32_t IntMask)
212{
213 ADCx->STATUS = ADCx->STATUS | IntMask;
214}
222__STATIC_INLINE bool ADC_IsBusy(ADC_T *ADCx)
223{
224 return (ADCx->STATUS & ADC_STATUS_BUSY_Msk)?(true):(false);
225}
233__STATIC_INLINE bool ADC_IsDataOverrun(ADC_T *ADCx)
234{
235 return (ADCx->STATUS & ADC_STATUS_OV_Msk)?(true):(false);
236}
244__STATIC_INLINE bool ADC_IsDataValid(ADC_T *ADCx)
245{
246 return (ADCx->STATUS & ADC_STATUS_VALID_Msk)?(true):(false);
247}
253__STATIC_INLINE void ADC_PowerDown(ADC_T *ADCx)
254{
255 ADCx->CTL = ADCx->CTL & ~ADC_CTL_ADCEN_Msk;
256}
262__STATIC_INLINE void ADC_PowerOn(ADC_T *ADCx)
263{
264 ADCx->CTL = ADCx->CTL | ADC_CTL_ADCEN_Msk;
265}
271__STATIC_INLINE void ADC_SequentialModeDisable(ADC_T *ADCx)
272{
273 ADCx->SEQCTL = ADCx->SEQCTL & ~ADC_SEQCTL_SEQEN_Msk;
274}
281__STATIC_INLINE void ADC_Trigger2Select(ADC_T *ADCx,FunctionalState NewState)
282{
283 (NewState == ENABLE)?(ADCx->SEQCTL |= ADC_SEQCTL_TRG_SEL_Msk):(ADCx->SEQCTL &= ~ADC_SEQCTL_TRG_SEL_Msk);
284}
285
291__STATIC_INLINE void ADC_DisableCompare0(ADC_T *ADCx)
292{
293 ADCx->CMP0 = 0;
294}
295
301__STATIC_INLINE void ADC_DisableCompare1(ADC_T *ADCx)
302{
303 ADCx->CMP1 = 0;
304}
305
311__STATIC_INLINE void ADC_StartConvert(ADC_T *ADCx)
312{
313 ADCx->CTL = ADCx->CTL | ADC_CTL_SWTRG_Msk;
314}
320__STATIC_INLINE void ADC_StopConvert(ADC_T *ADCx)
321{
322 ADCx->CTL &= ~ADC_CTL_SWTRG_Msk;
323}
324
330__STATIC_INLINE void ADC_TestModeEnable(ADC_T *ADCx)
331{
332 ADCx->CTL2 |= ADC_CTL2_TESTMODE_Msk;
333}
339__STATIC_INLINE void ADC_TestModeDisable(ADC_T *ADCx)
340{
341 ADCx->CTL2 &= ~ADC_CTL2_TESTMODE_Msk;
342}
349__STATIC_INLINE void ADC_DmaModeEnable(ADC_T *ADCx,FunctionalState NewState)
350{
351 (NewState == ENABLE)?(ADCx->CTL2 |= ADC_CTL2_DMA_EN_Msk):(ADCx->CTL2 &= ~ADC_CTL2_DMA_EN_Msk);
352}
353
360__STATIC_INLINE void ADC_SetClockDivider(ADC_T *ADCx,uint32_t Divider)
361{
362 ADCx->CTL2 = (ADCx->CTL2 & ~ADC_CTL2_CLKDIV_Msk) | (Divider << ADC_CTL2_CLKDIV_Pos);
363}
364
374__STATIC_INLINE void ADC_Open(ADC_T *ADCx,uint32_t ChMask)
375{
376 ADCx->CHEN = (ADCx->CHEN & ~ADC_CHEN_ALL_Msk) | ChMask;
377}
385__STATIC_INLINE void ADC_SelInputRange(ADC_T *ADCx,uint32_t EnableHigh)
386{
387 ADCx->CTL2 = (ADCx->CTL2 & ~ADC_SEL_VREF_Msk) | (EnableHigh << ADC_SEL_VREF_Pos);
388}
395__STATIC_INLINE void ADC_TriggerDelay(ADC_T *ADCx,uint32_t Data)
396{
397 ADCx->TRGDLY = Data;
398}
417__STATIC_INLINE void ADC_SetExtraSampleTime(ADC_T *ADCx,uint32_t SampleTime)
418{
419 ADCx->EXTSMPT = (ADCx->EXTSMPT & ~ADC_EXTSMPT_EXTSMPT_Msk) | SampleTime;
420}
421
428__STATIC_INLINE bool ADC_IsOneChConvertEnd(ADC_T *ADCx)
429{
430 return (ADCx->STATUS & ADC_STATUS_ONE_CH_FLAG_Msk)?(true):(false);
431}
432
440__STATIC_INLINE void ADC_ClearByHw(ADC_T *ADCx,FunctionalState NewState)
441{
442 (NewState == ENABLE)?(ADCx->STATUS |= ADC_STATUS_ONE_CH_CLR_SEL_Msk):(ADCx->STATUS &= ~ADC_STATUS_ONE_CH_CLR_SEL_Msk);
443}
444
451__STATIC_INLINE void ADC_LeftShiftEn(ADC_T *ADCx,FunctionalState NewState)
452{
453 (NewState == ENABLE)?(ADCx->LS_CTL |= ADC_LS_CTL_LS_EN_Msk):(ADCx->LS_CTL &= ~ADC_LS_CTL_LS_EN_Msk);
454}
455
461__STATIC_INLINE uint32_t ADC_GetLeftShiftData(ADC_T *ADCx)
462{
463 return ((ADCx->LS_CTL & ADC_LS_CTL_LS_DAT_Msk) >> ADC_LS_CTL_LS_DAT_Pos);
464}
471__STATIC_INLINE void ADC_SubtractBiasEn(ADC_T *ADCx,FunctionalState NewState)
472{
473 (NewState == ENABLE)?(ADCx->SUB_CTL |= ADC_SUB_CTL_BIAS_EN_Msk):(ADCx->SUB_CTL &= ~ADC_SUB_CTL_BIAS_EN_Msk);
474}
475
482__STATIC_INLINE void ADC_SetBiasData(ADC_T *ADCx,uint32_t BiasData)
483{
484 ADCx->SUB_CTL = (ADCx->SUB_CTL & ~ADC_LS_CTL_LS_DAT_Msk) | (BiasData << ADC_LS_CTL_LS_DAT_Pos);
485}
486
492__STATIC_INLINE uint32_t ADC_GetLeftBiasData(ADC_T *ADCx)
493{
494 return ADCx->DATA_SUB & ADC_DAT_SUB_LEFT_BIAS_Msk;
495}
496
505__STATIC_INLINE void ADC_SetFifoTrigLevel(ADC_T *ADCx,uint8_t Level)
506{
507 ADCx->FIFO_CTL = (ADCx->FIFO_CTL & ~ADC_FIFO_CTL_HALF_OR_FULL_Msk) | ((Level << ADC_FIFO_CTL_HALF_OR_FULL_Pos)|ADC_FIFO_CTL_EN_Msk);
508}
509
515__STATIC_INLINE uint32_t ADC_GetFifoPopData(ADC_T *ADCx)
516{
517 return ADCx->POP_DATA & ADC_FIFO_POP_DAT_Msk;
518}
519
526__STATIC_INLINE void ADC_SeqModeOneChEn(ADC_T *ADCx,FunctionalState NewState)
527{
528 (NewState)?(ADCx->SEQCTL |= ADC_SEQCTL_ONE_CH_EN_Msk):(ADCx->SEQCTL &= ~ADC_SEQCTL_ONE_CH_EN_Msk);
529}
530
537__STATIC_INLINE void ADC_SeqModeChSelect(ADC_T *ADCx,uint8_t Ch)
538{
539 ADCx->SEQCTL = (ADCx->SEQCTL & ~ADC_SEQCTL_ONE_CH_SEL_Msk) | (Ch << ADC_SEQCTL_ONE_CH_SEL_Pos);
540}
541
547void ADC_Disable(ADC_T *ADCx);
548
553void ADC_Close(void);
554
569void ADC_EnableHWTrigger(ADC_T *ADCx,
570 uint32_t Source,
571 uint32_t Param);
572
578void ADC_DisableHWTrigger(ADC_T *ADCx);
579
591void ADC_EnableInt(ADC_T *ADCx, uint32_t Mask);
592
604void ADC_DisableInt(ADC_T *ADCx, uint32_t Mask);
605
619void ADC_SeqModeEnable(ADC_T *ADCx, uint32_t SeqTYPE, uint32_t ModeSel);
620
628void ADC_SeqModeTriggerSrc(ADC_T *ADCx, uint32_t SeqModeTriSrc);
629
645void ADC_CompareEnable(ADC_T *ADCx,
646 uint32_t ChNum,
647 uint32_t CmpCondition,
648 uint32_t CmpData,
649 uint32_t MatchCnt,
650 uint32_t CmpSelect);
651
668void ADC_SeqOneChModeConfig(ADC_T *ADCx,
669 uint32_t Trig,
670 uint8_t Level,
671 uint8_t DmaEn,
672 uint8_t HwClrEN,
673 uint8_t AdcCh);
676#ifdef __cplusplus
677}
678#endif
679
680#endif /* __PAN_ADC_H__ */
void ADC_DisableInt(ADC_T *ADCx, uint32_t Mask)
Disable the interrupt(s) selected by u32Mask parameter.
__STATIC_INLINE void ADC_SeqModeChSelect(ADC_T *ADCx, uint8_t Ch)
adc channel select in pwm sequential
Definition: pan_adc.h:537
__STATIC_INLINE void ADC_ClearStatusFlag(ADC_T *ADCx, uint32_t IntMask)
Clear specified interrupt flag.
Definition: pan_adc.h:157
__STATIC_INLINE uint32_t ADC_GetConversionData(ADC_T *ADCx)
Get the latest ADC conversion data.
Definition: pan_adc.h:121
__STATIC_INLINE void ADC_TestModeEnable(ADC_T *ADCx)
Enable the A/D test mode.
Definition: pan_adc.h:330
__STATIC_INLINE bool ADC_IsDataValid(ADC_T *ADCx)
Check if the ADC conversion data is valid or not.
Definition: pan_adc.h:244
__STATIC_INLINE uint32_t ADC_GetLeftBiasData(ADC_T *ADCx)
get adc data after bias & left shift
Definition: pan_adc.h:492
void ADC_DisableHWTrigger(ADC_T *ADCx)
Disable hardware trigger ADC function.
__STATIC_INLINE bool ADC_IsIntOccured(ADC_T *ADCx, uint32_t IntMask)
adjust the user-specified interrupt occured or not
Definition: pan_adc.h:193
__STATIC_INLINE void ADC_PowerDown(ADC_T *ADCx)
Power down ADC module.
Definition: pan_adc.h:253
__STATIC_INLINE bool ADC_IsOneChConvertEnd(ADC_T *ADCx)
adjust pwm sequence convert end or not in adc one channel
Definition: pan_adc.h:428
__STATIC_INLINE void ADC_SetFifoTrigLevel(ADC_T *ADCx, uint8_t Level)
set adc fifo trig level
Definition: pan_adc.h:505
__STATIC_INLINE void ADC_SequentialModeDisable(ADC_T *ADCx)
ADC sequential mode Disabled.
Definition: pan_adc.h:271
__STATIC_INLINE void ADC_TriggerDelay(ADC_T *ADCx, uint32_t Data)
Delay ADC start conversion time after PWM trigger.
Definition: pan_adc.h:395
__STATIC_INLINE void ADC_StopConvert(ADC_T *ADCx)
Stop the A/D conversion.
Definition: pan_adc.h:320
__STATIC_INLINE void ADC_Trigger2Select(ADC_T *ADCx, FunctionalState NewState)
TRG1CTL select for 1-shunt sequential mode.
Definition: pan_adc.h:281
__STATIC_INLINE void ADC_SetBiasData(ADC_T *ADCx, uint32_t BiasData)
set bias data
Definition: pan_adc.h:482
__STATIC_INLINE void ADC_LeftShiftEn(ADC_T *ADCx, FunctionalState NewState)
enable left shift function,if enable,adc data {adc_output[11:0],4'b0 }
Definition: pan_adc.h:451
void ADC_SeqModeTriggerSrc(ADC_T *ADCx, uint32_t SeqModeTriSrc)
ADC PWM Sequential Mode PWM Trigger Source and type.
__STATIC_INLINE void ADC_TestModeDisable(ADC_T *ADCx)
Disable the A/D test mode.
Definition: pan_adc.h:339
__STATIC_INLINE void ADC_SelInputRange(ADC_T *ADCx, uint32_t EnableHigh)
Select ADC range of input sample signal.
Definition: pan_adc.h:385
__STATIC_INLINE void ADC_SubtractBiasEn(ADC_T *ADCx, FunctionalState NewState)
enable subtract bias function
Definition: pan_adc.h:471
void ADC_SeqModeEnable(ADC_T *ADCx, uint32_t SeqTYPE, uint32_t ModeSel)
ADC PWM Sequential Mode Control.
__STATIC_INLINE void ADC_DisableCompare0(ADC_T *ADCx)
Disable comparator 0.
Definition: pan_adc.h:291
__STATIC_INLINE void ADC_Open(ADC_T *ADCx, uint32_t ChMask)
This API configures ADC module to be ready for convert the input from selected channel.
Definition: pan_adc.h:374
__STATIC_INLINE void ADC_SetClockDivider(ADC_T *ADCx, uint32_t Divider)
Set the A/D clock division.
Definition: pan_adc.h:360
__STATIC_INLINE void ADC_DisableCompare1(ADC_T *ADCx)
Disable comparator 1.
Definition: pan_adc.h:301
void ADC_Close(void)
Close ADC peripheral.
void ADC_EnableInt(ADC_T *ADCx, uint32_t Mask)
Enable the interrupt(s) selected by u32Mask parameter.
void ADC_CompareEnable(ADC_T *ADCx, uint32_t ChNum, uint32_t CmpCondition, uint32_t CmpData, uint32_t MatchCnt, uint32_t CmpSelect)
Configure the comparator 0 and enable it.
__STATIC_INLINE void ADC_ClearByHw(ADC_T *ADCx, FunctionalState NewState)
clear pwm sequence end flag
Definition: pan_adc.h:440
__STATIC_INLINE void ADC_SetExtraSampleTime(ADC_T *ADCx, uint32_t SampleTime)
Set ADC sample time for designated channel.
Definition: pan_adc.h:417
__STATIC_INLINE bool ADC_IsDataOverrun(ADC_T *ADCx)
Check if the ADC conversion data is over written or not.
Definition: pan_adc.h:233
__STATIC_INLINE void ADC_IntMask(ADC_T *ADCx, uint32_t IntMask, FunctionalState NewState)
Set interrupt mask,if masked,interrupt will not be happened.
Definition: pan_adc.h:175
void ADC_EnableHWTrigger(ADC_T *ADCx, uint32_t Source, uint32_t Param)
Configure the hardware trigger condition and enable hardware trigger.
__STATIC_INLINE void ADC_SeqModeOneChEn(ADC_T *ADCx, FunctionalState NewState)
pwm sequential enable in adc one channel mode
Definition: pan_adc.h:526
__STATIC_INLINE void ADC_DmaModeEnable(ADC_T *ADCx, FunctionalState NewState)
Enable the A/D dma mode.
Definition: pan_adc.h:349
void ADC_SeqOneChModeConfig(ADC_T *ADCx, uint32_t Trig, uint8_t Level, uint8_t DmaEn, uint8_t HwClrEN, uint8_t AdcCh)
set ADC PWM one channel Sequential Mode configuration.
__STATIC_INLINE bool ADC_StatusFlag(ADC_T *ADCx, uint32_t IntMask)
Get raw status flag.
Definition: pan_adc.h:139
__STATIC_INLINE uint32_t ADC_GetFifoPopData(ADC_T *ADCx)
get fifo pop data
Definition: pan_adc.h:515
__STATIC_INLINE bool ADC_IsBusy(ADC_T *ADCx)
Get the busy state of ADC.
Definition: pan_adc.h:222
__STATIC_INLINE uint32_t ADC_GetLeftShiftData(ADC_T *ADCx)
get left shift data
Definition: pan_adc.h:461
void ADC_Disable(ADC_T *ADCx)
Disable ADC Power.
__STATIC_INLINE void ADC_StartConvert(ADC_T *ADCx)
Start the A/D conversion.
Definition: pan_adc.h:311
__STATIC_INLINE void ADC_ClearIntFlag(ADC_T *ADCx, uint32_t IntMask)
This macro clear the selected interrupt status bits.
Definition: pan_adc.h:211
__STATIC_INLINE void ADC_PowerOn(ADC_T *ADCx)
Power on ADC module.
Definition: pan_adc.h:262