ESOS32
ESOSOn32-bitProcessors
esos_sensor.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
28 
40 #ifndef ESOS_SENSOR_H
41 #define ESOS_SENSOR_H
42 
43 /* I N C L U D E S **********************************************************/
44 #include <esos.h>
45 
46 /* E N U M S ****************************************************************/
47 
51 typedef enum {
52  ESOS_SENSOR_CH00 = 0x00,
53  ESOS_SENSOR_CH01,
54  ESOS_SENSOR_CH02,
55  ESOS_SENSOR_CH03,
56  ESOS_SENSOR_CH04,
57  ESOS_SENSOR_CH05,
58  ESOS_SENSOR_CH06,
59  ESOS_SENSOR_CH07,
60  ESOS_SENSOR_CH08,
61  ESOS_SENSOR_CH09,
62  ESOS_SENSOR_CH0A,
63  ESOS_SENSOR_CH0B,
64  ESOS_SENSOR_CH0C,
65  ESOS_SENSOR_CH0D,
66  ESOS_SENSOR_CH0E,
67  ESOS_SENSOR_CH0F,
69 
73 typedef enum {
74  ESOS_SENSOR_VREF_1V0 = 0x00,
75  ESOS_SENSOR_VREF_1V024,
76  ESOS_SENSOR_VREF_2V0,
77  ESOS_SENSOR_VREF_2V048,
78  ESOS_SENSOR_VREF_3V0,
79  ESOS_SENSOR_VREF_3V3,
80  ESOS_SENSOR_VREF_4V0,
81  ESOS_SENSOR_VREF_4V096,
82  ESOS_SENSOR_VREF_5V0,
84 
88 typedef enum {
89  ESOS_SENSOR_ONE_SHOT = 0x00,
90  ESOS_SENSOR_AVG2 = 0x01, // arithmetic average
91  ESOS_SENSOR_AVG4 = 0x02,
92  ESOS_SENSOR_AVG8 = 0x03,
93  ESOS_SENSOR_AVG16 = 0x04,
94  ESOS_SENSOR_AVG32 = 0x05,
95  ESOS_SENSOR_AVG64 = 0x06,
96  ESOS_SENSOR_MIN2 = 0x21, // minimum
97  ESOS_SENSOR_MIN4 = 0x22,
98  ESOS_SENSOR_MIN8 = 0x23,
99  ESOS_SENSOR_MIN16 = 0x24,
100  ESOS_SENSOR_MIN32 = 0x25,
101  ESOS_SENSOR_MIN64 = 0x26,
102  ESOS_SENSOR_MAX2 = 0x41, // maximum
103  ESOS_SENSOR_MAX4 = 0x42,
104  ESOS_SENSOR_MAX8 = 0x43,
105  ESOS_SENSOR_MAX16 = 0x44,
106  ESOS_SENSOR_MAX32 = 0x45,
107  ESOS_SENSOR_MAX64 = 0x46,
108  ESOS_SENSOR_MEDIAN2 = 0x81, // median
109  ESOS_SENSOR_MEDIAN4 = 0x82,
110  ESOS_SENSOR_MEDIAN8 = 0x83,
111  ESOS_SENSOR_MEDIAN16 = 0x84,
112  ESOS_SENSOR_MEDIAN32 = 0x85,
113  ESOS_SENSOR_MEDIAN64 = 0x86,
115 
119 typedef enum {
120  ESOS_SENSOR_FORMAT_BITS = 0x00, // Return the ADC "raw" bitset
121  ESOS_SENSOR_FORMAT_VOLTAGE = 0x80, // Return the ADC value as an integer representating the number of 0.1mV
122  ESOS_SENSOR_FORMAT_PERCENT = 0x40, // Return the ADC value as an integer percentage 0-100% of full scale
124 
125 /* C H I L D T A S K S ****************************************************/
126 
127 ESOS_CHILD_TASK(_WAIT_ON_AVAILABLE_SENSOR, esos_sensor_ch_t, esos_sensor_vref_t);
128 ESOS_CHILD_TASK(_WAIT_SENSOR_QUICK_READ, uint16_t *u16_data);
129 ESOS_CHILD_TASK(_WAIT_SENSOR_READ, uint16_t *u16_data, uint8_t, esos_sensor_format_t);
130 BOOL ESOS_SENSOR_CLOSE(void);
131 
132 /* D E F I N E S ************************************************************/
133 
134 #define SIGNAL_ADC_BUSY esos_SetSystemFlag(__ESOS_SYS_ADC_IS_BUSY)
135 
136 #define ESOS_TASK_WAIT_WHILE_ADC_BUSY do { \
137  esos_ClearSystemFlag(__ESOS_SYS_ADC_IS_BUSY); \
138  ESOS_TASK_WAIT_UNTIL(esos_IsSystemFlagSet(__ESOS_SYS_ADC_IS_BUSY)); \
139 } while(0)
140 
141 static ESOS_TASK_HANDLE th_child;
142 
143 #define ESOS_TASK_WAIT_ON_AVAILABLE_SENSOR(CHCONST, VREFCONST) do { \
144  ESOS_ALLOCATE_CHILD_TASK(th_child); \
145  ESOS_TASK_SPAWN_AND_WAIT(th_child, _WAIT_ON_AVAILABLE_SENSOR, CHCONST, VREFCONST); \
146 } while(0)
147 
148 #define ESOS_TASK_WAIT_SENSOR_QUICK_READ(u16_data) do { \
149  ESOS_ALLOCATE_CHILD_TASK(th_child); \
150  ESOS_TASK_SPAWN_AND_WAIT(th_child, _WAIT_SENSOR_QUICK_READ, &u16_data); \
151 } while(0)
152 
153 #define ESOS_TASK_WAIT_SENSOR_READ(u16_data, PROCESSCONST, FMTCONST) do { \
154  ESOS_ALLOCATE_CHILD_TASK(th_child); \
155  ESOS_TASK_SPAWN_AND_WAIT(th_child, _WAIT_SENSOR_READ, &u16_data, PROCESSCONST, FMTCONST); \
156 } while(0)
157 
158 #endif
esos_sensor_ch_t
esos_sensor_ch_t
Definition: esos_sensor.h:51
esos_sensor_vref_t
esos_sensor_vref_t
Definition: esos_sensor.h:73
ESOS_TASK_HANDLE
esos_sensor_format_t
esos_sensor_format_t
Definition: esos_sensor.h:119
esos_sensor_process_t
esos_sensor_process_t
Definition: esos_sensor.h:88
esos.h
ESOS_CHILD_TASK
#define ESOS_CHILD_TASK(taskname,...)
Definition: esos_task.h:246
BOOL
enum _BOOL BOOL
ESOS_SENSOR_CLOSE
BOOL ESOS_SENSOR_CLOSE(void)
Definition: esos_sensor.c:390