Intel® Quark™ Microcontroller Software Interface 1.4.0 Intel® Quark™ Microcontroller BSP

- Main Page
- Modules
- Data Structures
- Files

- File List

qm_comparator.c
1 /*
2 * {% copyright %}
3 */
4
5 #include "qm_comparator.h"
6
7 #if (HAS_SOC_CONTEXT_RETENTION)
8 #include "power_states.h"
9 #endif /* HAS_SOC_CONTEXT_RETENTION */
10
11 static void (*callback)(void *, uint32_t) = NULL;
12 static void *callback_data;
13
14 #define cmp_en cmp_en
15 #define cmp_ref_pol cmp_ref_pol
16
17 QM_ISR_DECLARE(qm_comparator_0_isr)
18 {
19 uint32_t int_status = QM_SCSS_CMP->cmp_stat_clr;
20
21 #if (HAS_SOC_CONTEXT_RETENTION)
22 if (QM_SCSS_GP->gps0 & QM_GPS0_POWER_STATES_MASK) {
23 qm_power_soc_restore();
24 }
25 #endif
26 if (callback) {
27 (*callback)(callback_data, int_status);
28 }
29
30 /* Clear all pending interrupts. */
31 QM_SCSS_CMP->cmp_stat_clr = int_status;
32
33 QM_ISR_EOI(QM_IRQ_COMPARATOR_0_INT_VECTOR);
34 }
35
36 int qm_ac_set_config(const qm_ac_config_t *const config)
37 {
38 QM_CHECK(config != NULL, -EINVAL);
39
40 uint32_t reference = 0;
41
42 reference = config->reference;
43
44 /*
45 * Avoid interrupts while configuring the comparators.
46 * This can happen when the polarity is changed
47 * compared to a previously configured interrupt.
48 */
49 QM_SCSS_CMP->cmp_en = 0;
50
51 callback = config->callback;
52 callback_data = config->callback_data;
53 QM_SCSS_CMP->cmp_ref_sel = reference;
54 QM_SCSS_CMP->cmp_ref_pol = config->polarity;
55 QM_SCSS_CMP->cmp_pwr = config->power;
56
57 /* Clear all pending interrupts before we enable. */
58 QM_SCSS_CMP->cmp_stat_clr = 0x7FFFF;
59 QM_SCSS_CMP->cmp_en = config->cmp_en;
60
61 return 0;
62 }
qm_power_soc_restore
void qm_power_soc_restore(void)
Restore system state after sleep or deep sleep.
Definition: power_states.c:402
qm_ac_config_t::power
uint32_t power
1b: Normal mode; 0b:Power-down/Shutdown mode
Definition: qm_comparator.h:32
QM_ISR_DECLARE
QM_ISR_DECLARE(qm_comparator_0_isr)
ISR for Analog Comparator 0 interrupt.
Definition: qm_comparator.c:17
qm_ac_set_config
int qm_ac_set_config(const qm_ac_config_t *const config)
Set Analog Comparator configuration.
Definition: qm_comparator.c:36
qm_ac_config_t::cmp_en
uint32_t cmp_en
Comparator enable.
Definition: qm_comparator.h:29
qm_ac_config_t::reference
uint32_t reference
Reference voltage, 1b: VREF; 0b: AR_PIN.
Definition: qm_comparator.h:30
qm_ac_config_t::callback
void(* callback)(void *data, uint32_t int_status)
Transfer callback.
Definition: qm_comparator.h:40
qm_ac_config_t::polarity
uint32_t polarity
0b: input>ref; 1b: input<ref
Definition: qm_comparator.h:31
qm_ac_config_t
Analog Comparator configuration type.
Definition: qm_comparator.h:28
qm_ac_config_t::callback_data
void * callback_data
Callback user data.
Definition: qm_comparator.h:41