drivers/afec/afec.h
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #ifndef AFEC_H_INCLUDED
38 #define AFEC_H_INCLUDED
39 
40 #include "compiler.h"
41 #include "status_codes.h"
42 
43 #if (SAMV71 || SAMV70 || SAME70 || SAMS70)
44 
45 enum afec_resolution {
46  AFEC_12_BITS = AFEC_EMR_RES_NO_AVERAGE, /* AFEC 12-bit resolution */
47  AFEC_13_BITS = AFEC_EMR_RES_OSR4, /* AFEC 13-bit resolution */
48  AFEC_14_BITS = AFEC_EMR_RES_OSR16, /* AFEC 14-bit resolution */
49  AFEC_15_BITS = AFEC_EMR_RES_OSR64, /* AFEC 15-bit resolution */
50  AFEC_16_BITS = AFEC_EMR_RES_OSR256 /* AFEC 16-bit resolution */
51 };
52 #else
53 
55  AFEC_10_BITS = AFEC_EMR_RES_LOW_RES, /* AFEC 10-bit resolution */
56  AFEC_12_BITS = AFEC_EMR_RES_NO_AVERAGE, /* AFEC 12-bit resolution */
57  AFEC_13_BITS = AFEC_EMR_RES_OSR4, /* AFEC 13-bit resolution */
58  AFEC_14_BITS = AFEC_EMR_RES_OSR16, /* AFEC 14-bit resolution */
59  AFEC_15_BITS = AFEC_EMR_RES_OSR64, /* AFEC 15-bit resolution */
60  AFEC_16_BITS = AFEC_EMR_RES_OSR256 /* AFEC 16-bit resolution */
61 };
62 #endif
63 
65  /* AFEC core on and reference voltage circuitry on */
67  /* AFEC core off and reference voltage circuitry on */
69  /* AFEC core off and reference voltage circuitry off */
71 };
72 
75  /* Starting a conversion is only possible by software. */
77  /* External trigger */
79  /* TIO Output of the Timer Counter Channel 0 */
81  /* TIO Output of the Timer Counter Channel 1 */
83  /* TIO Output of the Timer Counter Channel 2 */
85  /* PWM Event Line 0 */
87  /* PWM Event Line 1 */
89 #if (SAMV71 || SAMV70 || SAME70 || SAMS70)
90  /*Analog Comparator*/
91  AFEC_TRIG_ANALOG_COMPARATOR = AFEC_MR_TRGSEL_AFEC_TRIG6 | AFEC_MR_TRGEN,
92 #endif
93  /* Freerun mode conversion. */
95 };
96 
97 #if defined __SAM4E8C__ || defined __SAM4E16C__ || defined __SAM4E8CB__ || defined __SAM4E16CB__
98 
99 enum afec_channel_num {
100  AFEC_CHANNEL_0 = 0,
101  AFEC_CHANNEL_1,
102  AFEC_CHANNEL_2,
103  AFEC_CHANNEL_3,
104  AFEC_CHANNEL_4,
105  AFEC_CHANNEL_5,
106  AFEC_TEMPERATURE_SENSOR = 15,
107  AFEC_CHANNEL_ALL = 0x803F,
108 } ;
109 #elif defined __SAM4E8E__ || defined __SAM4E16E__
110 
111 enum afec_channel_num {
112  AFEC_CHANNEL_0 = 0,
113  AFEC_CHANNEL_1,
114  AFEC_CHANNEL_2,
115  AFEC_CHANNEL_3,
116  AFEC_CHANNEL_4,
117  AFEC_CHANNEL_5,
118  AFEC_CHANNEL_6,
119  AFEC_CHANNEL_7,
120  AFEC_CHANNEL_8,
121  AFEC_CHANNEL_9,
122  AFEC_CHANNEL_10,
123  AFEC_CHANNEL_11,
124  AFEC_CHANNEL_12,
125  AFEC_CHANNEL_13,
126  AFEC_CHANNEL_14,
127  AFEC_TEMPERATURE_SENSOR,
128  AFEC_CHANNEL_ALL = 0xFFFF,
129 } ;
130 #elif (SAMV71 || SAMV70 || SAME70 || SAMS70)
131 
132 enum afec_channel_num {
133  AFEC_CHANNEL_0 = 0,
134  AFEC_CHANNEL_1,
135  AFEC_CHANNEL_2,
136  AFEC_CHANNEL_3,
137  AFEC_CHANNEL_4,
138  AFEC_CHANNEL_5,
139  AFEC_CHANNEL_6,
140  AFEC_CHANNEL_7,
141  AFEC_CHANNEL_8,
142  AFEC_CHANNEL_9,
143  AFEC_CHANNEL_10,
144  AFEC_TEMPERATURE_SENSOR,
145  AFEC_CHANNEL_ALL = 0x0FFF,
146 } ;
147 
148 #define NB_CH_AFE0 (12UL)
149 #define NB_CH_AFE1 (12UL)
150 #endif
151 
152 #if (SAMV71 || SAMV70 || SAME70 || SAMS70)
153 enum afec_sample_hold_mode {
154  /*Single Sample-and-Hold mode*/
155  AFEC_SAMPLE_HOLD_MODE_0,
156  /*Dual Sample-and-Hold mode*/
157  AFEC_SAMPLE_HOLD_MODE_1,
158 };
159 #endif
160 
167 };
168 
187 };
188 
189 #if SAM4E
190 
191 enum afec_settling_time {
192  AFEC_SETTLING_TIME_0 = AFEC_MR_SETTLING_AST3,
193  AFEC_SETTLING_TIME_1 = AFEC_MR_SETTLING_AST5,
194  AFEC_SETTLING_TIME_2 = AFEC_MR_SETTLING_AST9,
195  AFEC_SETTLING_TIME_3 = AFEC_MR_SETTLING_AST17
196 };
197 #endif
198 
205 };
206 
213 };
214 
222 struct afec_config {
226  uint32_t mck;
228  uint32_t afec_clock;
231  #if SAM4E
232 
233  enum afec_settling_time settling_time;
234  #endif
235 
236  uint8_t tracktim;
238  uint8_t transfer;
240  bool anach;
242  bool useq;
244  bool tag;
246  bool stm;
248  uint8_t ibctl;
249 };
250 
254  bool diff;
256  enum afec_gainvalue gain;
257 };
258 
262  bool rctc;
266  uint16_t low_threshold;
268  uint16_t high_threshold;
269 };
270 
271 #if defined __SAM4E8C__ || defined __SAM4E16C__ || defined __SAM4E8CB__ || defined __SAM4E16CB__
272 
273 enum afec_interrupt_source {
274  AFEC_INTERRUPT_EOC_0 = 0,
275  AFEC_INTERRUPT_EOC_1,
276  AFEC_INTERRUPT_EOC_2,
277  AFEC_INTERRUPT_EOC_3,
278  AFEC_INTERRUPT_EOC_4,
279  AFEC_INTERRUPT_EOC_5,
280  AFEC_INTERRUPT_EOC_15,
281  AFEC_INTERRUPT_DATA_READY,
282  AFEC_INTERRUPT_OVERRUN_ERROR,
283  AFEC_INTERRUPT_COMP_ERROR,
284  AFEC_INTERRUPT_END_RXBUF,
285  AFEC_INTERRUPT_RXBUF_FULL,
286  AFEC_INTERRUPT_TEMP_CHANGE,
287  AFEC_INTERRUPT_END_CAL,
288  _AFEC_NUM_OF_INTERRUPT_SOURCE,
289  AFEC_INTERRUPT_ALL = 0xDF00803F,
290 };
291 #elif defined __SAM4E8E__ || defined __SAM4E16E__
292 
293 enum afec_interrupt_source {
294  AFEC_INTERRUPT_EOC_0 = 0,
295  AFEC_INTERRUPT_EOC_1,
296  AFEC_INTERRUPT_EOC_2,
297  AFEC_INTERRUPT_EOC_3,
298  AFEC_INTERRUPT_EOC_4,
299  AFEC_INTERRUPT_EOC_5,
300  AFEC_INTERRUPT_EOC_6,
301  AFEC_INTERRUPT_EOC_7,
302  AFEC_INTERRUPT_EOC_8,
303  AFEC_INTERRUPT_EOC_9,
304  AFEC_INTERRUPT_EOC_10,
305  AFEC_INTERRUPT_EOC_11,
306  AFEC_INTERRUPT_EOC_12,
307  AFEC_INTERRUPT_EOC_13,
308  AFEC_INTERRUPT_EOC_14,
309  AFEC_INTERRUPT_EOC_15,
310  AFEC_INTERRUPT_DATA_READY,
311  AFEC_INTERRUPT_OVERRUN_ERROR,
312  AFEC_INTERRUPT_COMP_ERROR,
313  AFEC_INTERRUPT_END_RXBUF,
314  AFEC_INTERRUPT_RXBUF_FULL,
315  AFEC_INTERRUPT_TEMP_CHANGE,
316  AFEC_INTERRUPT_END_CAL,
317  _AFEC_NUM_OF_INTERRUPT_SOURCE,
318  AFEC_INTERRUPT_ALL = 0xDF00FFFF,
319 };
320 #elif (SAMV71 || SAMV70 || SAME70 || SAMS70)
321 
322 enum afec_interrupt_source {
323  AFEC_INTERRUPT_EOC_0 = 0,
324  AFEC_INTERRUPT_EOC_1,
325  AFEC_INTERRUPT_EOC_2,
326  AFEC_INTERRUPT_EOC_3,
327  AFEC_INTERRUPT_EOC_4,
328  AFEC_INTERRUPT_EOC_5,
329  AFEC_INTERRUPT_EOC_6,
330  AFEC_INTERRUPT_EOC_7,
331  AFEC_INTERRUPT_EOC_8,
332  AFEC_INTERRUPT_EOC_9,
333  AFEC_INTERRUPT_EOC_10,
334  AFEC_INTERRUPT_EOC_11,
335  AFEC_INTERRUPT_DATA_READY,
336  AFEC_INTERRUPT_OVERRUN_ERROR,
337  AFEC_INTERRUPT_COMP_ERROR,
338  AFEC_INTERRUPT_TEMP_CHANGE,
339  _AFEC_NUM_OF_INTERRUPT_SOURCE,
340  AFEC_INTERRUPT_ALL = 0x47000FFF,
341 };
342 #endif
343 
344 typedef void (*afec_callback_t)(void);
345 
346 void afec_get_config_defaults(struct afec_config *const cfg);
347 void afec_ch_get_config_defaults(struct afec_ch_config *const cfg);
349  struct afec_temp_sensor_config *const cfg);
350 enum status_code afec_init(Afec *const afec, struct afec_config *const config);
351 void afec_temp_sensor_set_config(Afec *const afec,
353 void afec_ch_set_config(Afec *const afec, const enum afec_channel_num channel,
354  struct afec_ch_config *config);
355 void afec_configure_sequence(Afec *const afec,
356  const enum afec_channel_num ch_list[], const uint8_t uc_num);
357 void afec_enable(Afec *const afec);
358 void afec_disable(Afec *const afec);
359 void afec_set_callback(Afec *const afec, enum afec_interrupt_source source,
360  afec_callback_t callback, uint8_t irq_level);
361 
362 #if (SAMV71 || SAMV70 || SAME70 || SAMS70)
363 void afec_configure_auto_error_correction(Afec *const afec,
364  const enum afec_channel_num channel,int16_t offsetcorr, uint16_t gaincorr);
365 
366 uint32_t afec_get_correction_value(Afec *const afec,
367  const enum afec_channel_num afec_ch);
368 void afec_set_sample_hold_mode(Afec *const afec,
369  const enum afec_channel_num channel,const enum afec_sample_hold_mode mode);
370 
371 #endif
372 
380 static inline void afec_ch_sanity_check(Afec *const afec,
381  const enum afec_channel_num channel)
382 {
383  if (afec == AFEC0) {
384  #if defined __SAM4E8C__ || defined __SAM4E16C__ || defined __SAM4E8CB__ || defined __SAM4E16CB__
385  Assert((channel < NB_CH_AFE0) || (channel == AFEC_TEMPERATURE_SENSOR));
386  #elif defined __SAM4E8E__ || defined __SAM4E16E__
387  Assert(channel < NB_CH_AFE0);
388  #elif (SAMV71 || SAMV70 || SAME70 || SAMS70)
389  Assert(channel < NB_CH_AFE0);
390  #endif
391  } else if (afec == AFEC1) {
392  Assert(channel < NB_CH_AFE1);
393  }
394  UNUSED(channel);
395 }
396 
404 static inline void afec_set_trigger(Afec *const afec,
405  const enum afec_trigger trigger)
406 {
407  uint32_t reg;
408 
409  reg = afec->AFEC_MR;
410 
411  if (trigger == AFEC_TRIG_FREERUN) {
412  reg |= AFEC_MR_FREERUN_ON;
413  } else {
415  reg |= trigger;
416  }
417 
418  afec->AFEC_MR = reg;
419 }
420 
428 static inline void afec_set_resolution(Afec *const afec,
429  const enum afec_resolution res)
430 {
431  uint32_t reg;
432 
433  reg = afec->AFEC_EMR;
434 
435  reg &= ~AFEC_EMR_RES_Msk;
436  reg |= res;
437 
438  afec->AFEC_EMR = reg;
439 }
440 
441 void afec_set_comparison_mode(Afec *const afec,
442  const enum afec_cmp_mode mode, const enum afec_channel_num channel,
443  uint8_t cmp_filter);
444 
452 static inline enum afec_cmp_mode afec_get_comparison_mode(Afec *const afec)
453 {
454  return (enum afec_cmp_mode)(afec->AFEC_EMR & AFEC_EMR_CMPMODE_Msk);
455 }
456 
464 static inline void afec_set_comparison_window(Afec *const afec,
465  const uint16_t us_low_threshold, const uint16_t us_high_threshold)
466 {
467  afec->AFEC_CWR = AFEC_CWR_LOWTHRES(us_low_threshold) |
468  AFEC_CWR_HIGHTHRES(us_high_threshold);
469 }
470 
477 static inline void afec_set_writeprotect(Afec *const afec,
478  const bool is_enable)
479 {
480  if (is_enable) {
482  } else {
484  }
485 }
486 
495 static inline uint32_t afec_get_writeprotect_status(Afec *const afec)
496 {
497  uint32_t reg_value;
498 
499  reg_value = afec->AFEC_WPSR;
500  if (reg_value & AFEC_WPSR_WPVS) {
501  return (reg_value & AFEC_WPSR_WPVSRC_Msk) >> AFEC_WPSR_WPVSRC_Pos;
502  } else {
503  return 0;
504  }
505 }
506 
514 static inline uint32_t afec_get_overrun_status(Afec *const afec)
515 {
516  return afec->AFEC_OVER;
517 }
518 
527 static inline void afec_start_software_conversion(Afec *const afec)
528 {
529  afec->AFEC_CR = AFEC_CR_START;
530 }
531 
532 void afec_set_power_mode(Afec *const afec,
533  const enum afec_power_mode mode);
534 
541 static inline void afec_channel_enable(Afec *const afec,
542  const enum afec_channel_num afec_ch)
543 {
544  if (afec_ch != AFEC_CHANNEL_ALL) {
545  afec_ch_sanity_check(afec, afec_ch);
546  }
547 
548  afec->AFEC_CHER = (afec_ch == AFEC_CHANNEL_ALL) ?
549  AFEC_CHANNEL_ALL : 1 << afec_ch;
550 }
551 
558 static inline void afec_channel_disable(Afec *const afec,
559  const enum afec_channel_num afec_ch)
560 {
561  if (afec_ch != AFEC_CHANNEL_ALL) {
562  afec_ch_sanity_check(afec, afec_ch);
563  }
564 
565  afec->AFEC_CHDR = (afec_ch == AFEC_CHANNEL_ALL) ?
566  AFEC_CHANNEL_ALL : 1 << afec_ch;
567 }
568 
578 static inline uint32_t afec_channel_get_status(Afec *const afec,
579  const enum afec_channel_num afec_ch)
580 {
581  afec_ch_sanity_check(afec, afec_ch);
582 
583  return afec->AFEC_CHSR & (1 << afec_ch);
584 }
585 
594 static inline uint32_t afec_channel_get_value(Afec *const afec,
595  enum afec_channel_num afec_ch)
596 {
597  afec_ch_sanity_check(afec, afec_ch);
598 
599  afec->AFEC_CSELR = afec_ch;
600  return afec->AFEC_CDR;
601 }
602 
610 static inline void afec_channel_set_analog_offset(Afec *const afec,
611  enum afec_channel_num afec_ch, uint16_t aoffset)
612 {
613  afec_ch_sanity_check(afec, afec_ch);
614 
615  afec->AFEC_CSELR = afec_ch;
616  afec->AFEC_COCR = (aoffset & AFEC_COCR_AOFF_Msk);
617 }
618 
626 static inline uint32_t afec_get_latest_value(Afec *const afec)
627 {
628  return afec->AFEC_LCDR & AFEC_LCDR_LDATA_Msk;
629 }
630 
638 static inline uint32_t afec_get_latest_chan_num(Afec *const afec)
639 {
640  return (afec->AFEC_LCDR & AFEC_LCDR_CHNB_Msk) >> AFEC_LCDR_CHNB_Pos;
641 }
642 
643 void afec_enable_interrupt(Afec *const afec,
644  enum afec_interrupt_source interrupt_source);
645 
646 void afec_disable_interrupt(Afec *const afec,
647  enum afec_interrupt_source interrupt_source);
648 
656 static inline uint32_t afec_get_interrupt_status(Afec *const afec)
657 {
658  return afec->AFEC_ISR;
659 }
660 
668 static inline uint32_t afec_get_interrupt_mask(Afec *const afec)
669 {
670  return afec->AFEC_IMR;
671 }
672 
673 #if SAM4E
674 
681 static inline Pdc *afec_get_pdc_base(Afec *const afec)
682 {
683  Pdc *p_pdc_base = NULL;
684 
685 #ifdef PDC_AFEC0
686  if (afec == AFEC0) {
687  p_pdc_base = PDC_AFEC0;
688  }
689 #endif
690 
691 #ifdef PDC_AFEC1
692  else if (afec == AFEC1) {
693  p_pdc_base = PDC_AFEC1;
694  }
695 #endif
696 
697  return p_pdc_base;
698 }
699 
709 static inline enum status_code afec_start_calibration(Afec *const afec)
710 {
711  uint32_t reg;
712 
713  reg = afec->AFEC_CHSR;
714  afec->AFEC_CDOR = reg;
715 
716  if ((afec->AFEC_MR & AFEC_MR_FREERUN) == AFEC_MR_FREERUN_ON) {
717  return STATUS_ERR_BUSY;
718  }
719  afec->AFEC_CR = AFEC_CR_AUTOCAL;
720  return STATUS_OK;
721 }
722 #endif
723 
797 #endif /* AFEC_H_INCLUDED */
__IO uint32_t AFEC_COCR
(Afec Offset: 0x6C) AFEC Channel Offset Compensation Register
#define AFEC_MR_TRGSEL_AFEC_TRIG5
(AFEC_MR) PWM0 event line 1 for AFEC0 / PWM1 event line 1 for AFEC1
void afec_set_power_mode(Afec *const afec, const enum afec_power_mode mode)
Configure AFEC power mode.
Definition: afec.c:380
#define AFEC_MR_FREERUN
(AFEC_MR) Free Run Mode
afec_resolution
#define UNUSED(v)
Marking v as a unused parameter or value.
Definition: compiler.h:86
#define AFEC_EMR_RES_Msk
(AFEC_EMR) Resolution
static uint32_t afec_channel_get_status(Afec *const afec, const enum afec_channel_num afec_ch)
Get the AFEC channel status.
__I uint32_t AFEC_LCDR
(Afec Offset: 0x20) AFEC Last Converted Data Register
#define AFEC_MR_TRGSEL_AFEC_TRIG1
(AFEC_MR) TIOA Output of the Timer Counter Channel 0 for AFEC0/TIOA Output of the Timer Counter Chann...
void afec_temp_sensor_get_config_defaults(struct afec_temp_sensor_config *const cfg)
Get the AFEC Temperature Sensor default configurations.
Definition: afec.c:294
#define AFEC_MR_STARTUP_SUT960
(AFEC_MR) 960 periods of AFE clock
void afec_ch_get_config_defaults(struct afec_ch_config *const cfg)
Get the AFEC channel default configurations.
Definition: afec.c:271
Success.
Definition: status_codes.h:66
enum afec_resolution resolution
Status code definitions.
afec_temp_cmp_mode
#define AFEC_TEMPMR_TEMPCMPMOD_OUT
(AFEC_TEMPMR) Generates an event when the converted data is out of the comparison window...
#define AFEC_TEMPMR_TEMPCMPMOD_LOW
(AFEC_TEMPMR) Generates an event when the converted data is lower than the low threshold of the windo...
static void afec_set_resolution(Afec *const afec, const enum afec_resolution res)
Configure conversion resolution.
#define AFEC_EMR_CMPMODE_LOW
(AFEC_EMR) Generates an event when the converted data is lower than the low threshold of the window...
Analog-Front-End Controller configuration structure.
__I uint32_t AFEC_IMR
(Afec Offset: 0x2C) AFEC Interrupt Mask Register
void afec_temp_sensor_set_config(Afec *const afec, struct afec_temp_sensor_config *config)
Configure the AFEC temperature sensor.
Definition: afec.c:203
__IO uint32_t AFEC_WPMR
(Afec Offset: 0xE4) AFEC Write Protection Mode Register
#define AFEC1
(AFEC1 ) Base Address
Definition: same70j19.h:517
enum afec_startup_time startup_time
#define AFEC_MR_STARTUP_SUT16
(AFEC_MR) 16 periods of AFE clock
static uint32_t afec_get_writeprotect_status(Afec *const afec)
Indicate write protect status.
static void afec_set_comparison_window(Afec *const afec, const uint16_t us_low_threshold, const uint16_t us_high_threshold)
Configure AFEC compare window.
#define AFEC_MR_STARTUP_SUT832
(AFEC_MR) 832 periods of AFE clock
#define AFEC_MR_TRGSEL_AFEC_TRIG3
(AFEC_MR) TIOA Output of the Timer Counter Channel 2 for AFEC0/TIOA Output of the Timer Counter Chann...
#define AFEC_MR_STARTUP_SUT96
(AFEC_MR) 96 periods of AFE clock
__O uint32_t AFEC_CHDR
(Afec Offset: 0x18) AFEC Channel Disable Register
void afec_enable(Afec *const afec)
Enable AFEC Module.
Definition: afec.c:576
#define AFEC_MR_TRGSEL_AFEC_TRIG2
(AFEC_MR) TIOA Output of the Timer Counter Channel 1 for AFEC0/TIOA Output of the Timer Counter Chann...
__I uint32_t AFEC_OVER
(Afec Offset: 0x4C) AFEC Overrun Status Register
#define NULL
Definition: nm_bsp.h:52
static void afec_channel_enable(Afec *const afec, const enum afec_channel_num afec_ch)
Enable the specified AFEC channel.
#define AFEC_MR_STARTUP_SUT640
(AFEC_MR) 640 periods of AFE clock
afec_startup_time
#define AFEC_EMR_RES_NO_AVERAGE
(AFEC_EMR) 12-bit resolution, AFE sample rate is maximum (no averaging).
#define AFEC_WPSR_WPVS
(AFEC_WPSR) Write Protect Violation Status
uint32_t afec_clock
static void afec_set_writeprotect(Afec *const afec, const bool is_enable)
Enable or disable write protection of AFEC registers.
static void afec_start_software_conversion(Afec *const afec)
Start analog-to-digital conversion.
#define AFEC_EMR_CMPMODE_HIGH
(AFEC_EMR) Generates an event when the converted data is higher than the high threshold of the window...
static void afec_channel_set_analog_offset(Afec *const afec, enum afec_channel_num afec_ch, uint16_t aoffset)
Set analog offset to be used for channel CSEL.
#define AFEC_EMR_RES_OSR4
(AFEC_EMR) 13-bit resolution, AFE sample rate divided by 4 (averaging).
Commonly used includes, types and macros.
#define AFEC_TEMPMR_TEMPCMPMOD_HIGH
(AFEC_TEMPMR) Generates an event when the converted data is higher than the high threshold of the win...
__O uint32_t AFEC_CHER
(Afec Offset: 0x14) AFEC Channel Enable Register
#define AFEC_MR_TRGSEL_AFEC_TRIG6
(AFEC_MR) Analog Comparator
status_code
Definition: status_codes.h:65
#define AFEC_MR_FREERUN_ON
(AFEC_MR) Free Run mode: Never wait for any trigger.
void afec_configure_sequence(Afec *const afec, const enum afec_channel_num ch_list[], const uint8_t uc_num)
Configure conversion sequence.
Definition: afec.c:610
__IO uint32_t AFEC_EMR
(Afec Offset: 0x08) AFEC Extended Mode Register
void afec_get_config_defaults(struct afec_config *const cfg)
Get the AFEC default configurations.
Definition: afec.c:239
#define AFEC_MR_TRGEN_DIS
(AFEC_MR) Hardware triggers are disabled. Starting a conversion is only possible by software...
void afec_disable(Afec *const afec)
Disable AFEC Module.
Definition: afec.c:592
static void afec_channel_disable(Afec *const afec, const enum afec_channel_num afec_ch)
Disable the specified AFEC channel.
#define AFEC_EMR_CMPMODE_IN
(AFEC_EMR) Generates an event when the converted data is in the comparison window.
#define AFEC_MR_TRGSEL_AFEC_TRIG4
(AFEC_MR) PWM0 event line 0 for AFEC0 / PWM1 event line 0 for AFEC1
static uint32_t afec_get_interrupt_status(Afec *const afec)
Get AFEC interrupt status.
#define AFEC_EMR_RES_OSR256
(AFEC_EMR) 16-bit resolution, AFE sample rate divided by 256 (averaging).
#define AFEC_EMR_CMPMODE_Msk
(AFEC_EMR) Comparison Mode
#define AFEC_MR_STARTUP_SUT896
(AFEC_MR) 896 periods of AFE clock
#define AFEC_LCDR_CHNB_Msk
(AFEC_LCDR) Channel Number
void afec_enable_interrupt(Afec *const afec, enum afec_interrupt_source interrupt_source)
Enable AFEC interrupts.
Definition: afec.c:434
void afec_disable_interrupt(Afec *const afec, enum afec_interrupt_source interrupt_source)
Disable AFEC interrupts.
Definition: afec.c:467
#define AFEC_MR_STARTUP_SUT512
(AFEC_MR) 512 periods of AFE clock
#define AFEC_TEMPMR_TEMPCMPMOD_IN
(AFEC_TEMPMR) Generates an event when the converted data is in the comparison window.
__I uint32_t AFEC_ISR
(Afec Offset: 0x30) AFEC Interrupt Status Register
#define AFEC_MR_TRGEN
(AFEC_MR) Trigger Enable
static uint32_t afec_get_overrun_status(Afec *const afec)
Get AFEC overrun error status.
#define AFEC_WPSR_WPVSRC_Msk
(AFEC_WPSR) Write Protect Violation Source
afec_power_mode
Afec hardware registers.
void(* afec_callback_t)(void)
void afec_set_callback(Afec *const afec, enum afec_interrupt_source source, afec_callback_t callback, uint8_t irq_level)
Set callback for AFEC.
Definition: afec.c:411
__I uint32_t AFEC_WPSR
(Afec Offset: 0xE8) AFEC Write Protection Status Register
#define AFEC_MR_STARTUP_SUT8
(AFEC_MR) 8 periods of AFE clock
static uint32_t afec_channel_get_value(Afec *const afec, enum afec_channel_num afec_ch)
Read the Converted Data of the selected channel.
#define AFEC_EMR_CMPMODE_OUT
(AFEC_EMR) Generates an event when the converted data is out of the comparison window.
#define AFEC_MR_STARTUP_SUT112
(AFEC_MR) 112 periods of AFE clock
#define AFEC_EMR_RES_OSR64
(AFEC_EMR) 15-bit resolution, AFE sample rate divided by 64 (averaging).
#define AFEC_MR_TRGSEL_Msk
(AFEC_MR) Trigger Selection
static void afec_set_trigger(Afec *const afec, const enum afec_trigger trigger)
Configure conversion trigger and free run mode.
#define AFEC_WPMR_WPKEY_PASSWD
(AFEC_WPMR) Writing any other value in this field aborts the write operation of the WPEN bit...
#define AFEC_MR_STARTUP_SUT24
(AFEC_MR) 24 periods of AFE clock
afec_gainvalue
__IO uint32_t AFEC_CWR
(Afec Offset: 0x50) AFEC Compare Window Register
afec_cmp_mode
#define AFEC_CWR_LOWTHRES(value)
__I uint32_t AFEC_CHSR
(Afec Offset: 0x1C) AFEC Channel Status Register
static enum afec_cmp_mode afec_get_comparison_mode(Afec *const afec)
Get comparison mode.
static uint32_t afec_get_latest_chan_num(Afec *const afec)
Get the Last Converted Channel Number.
#define AFEC0
(AFEC0 ) Base Address
Definition: same70j19.h:509
enum status_code afec_init(Afec *const afec, struct afec_config *const config)
Initialize the AFEC Module.
Definition: afec.c:315
#define AFEC_COCR_AOFF_Msk
(AFEC_COCR) Analog Offset
#define AFEC_MR_STARTUP_SUT64
(AFEC_MR) 64 periods of AFE clock
#define AFEC_CWR_HIGHTHRES(value)
#define AFEC_MR_STARTUP_SUT0
(AFEC_MR) 0 periods of AFE clock
#define AFEC_MR_STARTUP_SUT704
(AFEC_MR) 704 periods of AFE clock
#define AFEC_CR_START
(AFEC_CR) Start Conversion
#define AFEC_EMR_RES_OSR16
(AFEC_EMR) 14-bit resolution, AFE sample rate divided by 16 (averaging).
static void afec_ch_sanity_check(Afec *const afec, const enum afec_channel_num channel)
#define AFEC_MR_STARTUP_SUT576
(AFEC_MR) 576 periods of AFE clock
#define AFEC_LCDR_LDATA_Msk
(AFEC_LCDR) Last Data Converted
void afec_set_comparison_mode(Afec *const afec, const enum afec_cmp_mode mode, const enum afec_channel_num channel, uint8_t cmp_filter)
Configure comparison mode.
Definition: afec.c:351
__IO uint32_t AFEC_MR
(Afec Offset: 0x04) AFEC Mode Register
#define AFEC_MR_STARTUP_SUT768
(AFEC_MR) 768 periods of AFE clock
#define Assert(expr)
This macro is used to test fatal errors.
Definition: compiler.h:196
__O uint32_t AFEC_CR
(Afec Offset: 0x00) AFEC Control Register
__IO uint32_t AFEC_CSELR
(Afec Offset: 0x64) AFEC Channel Selection Register
#define AFEC_MR_STARTUP_SUT80
(AFEC_MR) 80 periods of AFE clock
static uint32_t afec_get_interrupt_mask(Afec *const afec)
Get AFEC interrupt mask.
#define AFEC_MR_TRGSEL_AFEC_TRIG0
(AFEC_MR) AFE0_ADTRG for AFEC0 / AFE1_ADTRG for AFEC1
static uint32_t afec_get_latest_value(Afec *const afec)
Get the Last Data Converted.
void afec_ch_set_config(Afec *const afec, const enum afec_channel_num channel, struct afec_ch_config *config)
Configure the AFEC channel.
Definition: afec.c:180
afec_trigger
__I uint32_t AFEC_CDR
(Afec Offset: 0x68) AFEC Channel Data Register
#define AFEC_WPMR_WPEN
(AFEC_WPMR) Write Protection Enable


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:08