Serial Wombat 4A and 4B Firmware
serialWombat.h
Go to the documentation of this file.
1 /*
2 Copyright 2020-2021 Broadwell Consulting Inc.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 
23 /* Serial Wombat is a trademark of Broadwell Consulting Inc. registered
24  * in the United States. */
25 
26 
27 #ifndef SERIALWOMBAT_H
28 #define SERIALWOMBAT_H
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include "pinModes.h"
32 #include "deviceSpecific.h"
33 #include "pinRegisters.h"
34 #include "protocol.h"
35 #include "queue.h"
36 #include "serialWombatErrors.h"
37 
38 extern uint8_t CurrentPin;
39 
41 
42 extern bool RunForeground;
43 
44 #define RXBUFFER_LENGTH 8
45 extern uint8_t Rxbuffer[RXBUFFER_LENGTH];
46 
47 #define TXBUFFER_LENGTH 8
48 extern uint8_t Txbuffer[TXBUFFER_LENGTH];
49 
50 #if SIZE_OF_USER_BUFFER > 0
51 extern uint8_t UserBuffer[SIZE_OF_USER_BUFFER];
52 #endif
53 
54 #define CLOCK_STRETCHING_MAX 10
55 #define DIGITAL_LOW 0
56 #define DIGITAL_HIGH 1
57 #define DIGITAL_INPUT 2
58 uint8_t CurrentPinPort(void);
59 uint16_t CurrentPinBitmap(void);
60 bool CurrentPinRead(void);
61 bool ReadPin(uint8_t pin);
62 void ConfigurePinAnalog(uint8_t pin, bool makeAnalog);
63 void CurrentPinAnalog(void);
64 void CurrentPinNotAnalog(void);
65 void CurrentPinPullUp(void);
66 void CurrentPinNoPullUp(void);
67 
68 void PinInput(uint8_t pin);
69 void PinOutput(uint8_t pin);
70 void PinHigh(uint8_t pin);
71 void PinLow(uint8_t pin);
72 void SetPin(uint8_t pin, uint8_t pinState);
73 void CurrentPinInput(void);
74 void CurrentPinOutput(void);
75 void CurrentPinHigh(void);
76 void CurrentPinLow(void);
77 void SetCurrentPin(uint8_t pinState);
78 void CurrentPinPullup(void);
79 void CurrentPinNoPullup(void);
80 void PinPullUp(uint8_t pin);
81 void PinNoPullUp(uint8_t pin);
82 bool ReadPin(uint8_t pin);
83 void CurrentPinOpenDrain(void);
84 void CurrentPinNotOpenDrain(void);
85 
86 void ProcessRx(void);
87 void ProcessPins(void);
88 void reset(void);
89 
90 
91 typedef enum {
92 
113 // SW_DATA_SOURCE_PIN_20 = 20,
114 // SW_DATA_SOURCE_PIN_21 = 21,
115 // SW_DATA_SOURCE_PIN_22 = 22,
116 // SW_DATA_SOURCE_PIN_23 = 23,
117 // SW_DATA_SOURCE_PIN_24 = 24,
118 // SW_DATA_SOURCE_PIN_25 = 25,
119 // SW_DATA_SOURCE_PIN_26 = 26,
120 // SW_DATA_SOURCE_PIN_27 = 27,
121 // SW_DATA_SOURCE_PIN_28 = 28,
122 // SW_DATA_SOURCE_PIN_29 = 29,
123 // SW_DATA_SOURCE_PIN_30 = 30,
124 // SW_DATA_SOURCE_PIN_31 = 31,
125 // SW_DATA_SOURCE_PIN_32 = 32,
126 // SW_DATA_SOURCE_PIN_33 = 33,
127 // SW_DATA_SOURCE_PIN_34 = 34,
128 // SW_DATA_SOURCE_PIN_35 = 35,
129 // SW_DATA_SOURCE_PIN_36 = 36,
130 // SW_DATA_SOURCE_PIN_37 = 37,
131 // SW_DATA_SOURCE_PIN_38 = 38,
132 // SW_DATA_SOURCE_PIN_39 = 39,
133 // SW_DATA_SOURCE_PIN_40 = 40,
134 // SW_DATA_SOURCE_PIN_41 = 41,
135 // SW_DATA_SOURCE_PIN_42 = 42,
136 // SW_DATA_SOURCE_PIN_43 = 43,
137 // SW_DATA_SOURCE_PIN_44 = 44,
138 // SW_DATA_SOURCE_PIN_45 = 45,
139 // SW_DATA_SOURCE_PIN_46 = 46,
140 // SW_DATA_SOURCE_PIN_47 = 47,
141 // SW_DATA_SOURCE_PIN_48 = 48,
142 // SW_DATA_SOURCE_PIN_49 = 49,
143 // SW_DATA_SOURCE_PIN_50 = 50,
144 // SW_DATA_SOURCE_PIN_51 = 51,
145 // SW_DATA_SOURCE_PIN_52 = 52,
146 // SW_DATA_SOURCE_PIN_53 = 53,
147 // SW_DATA_SOURCE_PIN_54 = 54,
148 // SW_DATA_SOURCE_PIN_55 = 55,
149 // SW_DATA_SOURCE_PIN_56 = 56,
150 // SW_DATA_SOURCE_PIN_57 = 57,
151 // SW_DATA_SOURCE_PIN_58 = 58,
152 // SW_DATA_SOURCE_PIN_59 = 59,
153 // SW_DATA_SOURCE_PIN_60 = 60,
154 // SW_DATA_SOURCE_PIN_61 = 61,
155 // SW_DATA_SOURCE_PIN_62 = 62,
156 // SW_DATA_SOURCE_PIN_63 = 63,
176 //NOT ANALOG SW_DATA_SOURCE_PIN_5_MV = 105,
177 //NOT ANALOG SW_DATA_SOURCE_PIN_6_MV = 106,
178 //NOT ANALOG SW_DATA_SOURCE_PIN_7_MV = 107,
179 //NOT ANALOG SW_DATA_SOURCE_PIN_8_MV = 108,
180 //NOT ANALOG SW_DATA_SOURCE_PIN_9_MV = 109,
181 //NOT ANALOG SW_DATA_SOURCE_PIN_10_MV = 110,
182 //NOT ANALOG SW_DATA_SOURCE_PIN_11_MV = 111,
183 //NOT ANALOG SW_DATA_SOURCE_PIN_12_MV = 112,
184 //NOT ANALOG SW_DATA_SOURCE_PIN_13_MV = 113,
185 //NOT ANALOG SW_DATA_SOURCE_PIN_14_MV = 114,
186 //NOT ANALOG SW_DATA_SOURCE_PIN_15_MV = 115,
191 
194 // SW_DATA_SOURCE_2HZ_SIN = 166,
197  // SW_DATA_SOURCE_1HZ_SIN = 169,
200  // SW_DATA_SOURCE_2SEC_SIN = 172,
203  // SW_DATA_SOURCE_8SEC_SIN = 175,
206  // SW_DATA_SOURCE_65SEC_SIN = 178,
208 
209 
210 
211 void error (SW_ERROR_t errorCode);
212 
213 extern uint32_t FramesRun;
214 
215 #endif
216 
pinModes.h
PinPullUp
void PinPullUp(uint8_t pin)
Definition: pinDigitalHwSpecific.c:115
SW_DATA_SOURCE_8SEC_SAW
@ SW_DATA_SOURCE_8SEC_SAW
Sawtooth wave that goes from 0 to 65535 to 0 every 8192 frames.
Definition: serialWombat.h:202
SW_DATA_SOURCE_PIN_4_MV
@ SW_DATA_SOURCE_PIN_4_MV
The public data of Pin 4 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:175
SW_ERROR_t
SW_ERROR_t
Definition: serialWombatErrors.h:24
SetPin
void SetPin(uint8_t pin, uint8_t pinState)
Definition: pinDigitalHwSpecific.c:49
deviceSpecific.h
SW_DATA_SOURCE_VCC_mVOLTS
@ SW_DATA_SOURCE_VCC_mVOLTS
The system source voltage in mV.
Definition: serialWombat.h:167
SW_DATA_SOURCE_PIN_10
@ SW_DATA_SOURCE_PIN_10
Definition: serialWombat.h:103
SW_DATA_SOURCE_PIN_4
@ SW_DATA_SOURCE_PIN_4
Definition: serialWombat.h:97
PinLow
void PinLow(uint8_t pin)
SW_DATA_SOURCE_PIN_18
@ SW_DATA_SOURCE_PIN_18
Definition: serialWombat.h:111
CurrentPinNoPullUp
void CurrentPinNoPullUp(void)
Definition: pinDigitalHwSpecific.c:110
SW_DATA_SOURCE_PIN_0_MV
@ SW_DATA_SOURCE_PIN_0_MV
The public data of Pin 0 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:171
SW_DATA_SOURCE_PIN_17
@ SW_DATA_SOURCE_PIN_17
Definition: serialWombat.h:110
CurrentPinRead
bool CurrentPinRead(void)
Definition: pinDigitalHwSpecific.c:88
RXBUFFER_LENGTH
#define RXBUFFER_LENGTH
Definition: serialWombat.h:44
SW_DATA_SOURCE_PIN_3_MV
@ SW_DATA_SOURCE_PIN_3_MV
The public data of Pin 3 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:174
FramesRun
uint32_t FramesRun
Definition: main.c:52
SW_DATA_SOURCE_PIN_0
@ SW_DATA_SOURCE_PIN_0
Definition: serialWombat.h:93
SW_DATA_SOURCE_2HZ_SAW
@ SW_DATA_SOURCE_2HZ_SAW
Sawtooth wave that goes from 0 to 65535 to 0 every 512 frames.
Definition: serialWombat.h:193
SW_DATA_SOURCE_PIN_2
@ SW_DATA_SOURCE_PIN_2
Definition: serialWombat.h:95
SIZE_OF_USER_BUFFER
#define SIZE_OF_USER_BUFFER
Definition: deviceSpecific.h:47
SW_DATA_SOURCE_PIN_19
@ SW_DATA_SOURCE_PIN_19
Definition: serialWombat.h:112
SW_DATA_SOURCE_PIN_5
@ SW_DATA_SOURCE_PIN_5
Definition: serialWombat.h:98
ProcessPins
void ProcessPins(void)
Definition: processPins.c:33
SW_DATA_SOURCE_TEMPERATURE
@ SW_DATA_SOURCE_TEMPERATURE
The internal core temperature expressed in 100ths deg C.
Definition: serialWombat.h:162
PinNoPullUp
void PinNoPullUp(uint8_t pin)
Definition: pinDigitalHwSpecific.c:120
PinUpdateRegisters
pinRegister_t PinUpdateRegisters[NUMBER_OF_TOTAL_PINS]
Definition: pinRegisters.c:28
RunForeground
bool RunForeground
Definition: main.c:49
SW_DATA_SOURCE_PIN_7
@ SW_DATA_SOURCE_PIN_7
Definition: serialWombat.h:100
SW_DATA_SOURCE_FRAMES_RUN_LSW
@ SW_DATA_SOURCE_FRAMES_RUN_LSW
The number of frames run since reset, least significant 16 bits.
Definition: serialWombat.h:159
Rxbuffer
uint8_t Rxbuffer[RXBUFFER_LENGTH]
A buffer for incoming commands from the host.
Definition: protocol.c:37
CurrentPinLow
void CurrentPinLow(void)
Definition: pinDigitalHwSpecific.c:45
SW_DATA_SOURCE_PIN_3
@ SW_DATA_SOURCE_PIN_3
Definition: serialWombat.h:96
PinOutput
void PinOutput(uint8_t pin)
CurrentPinNotAnalog
void CurrentPinNotAnalog(void)
Definition: pinDigitalHwSpecific.c:125
ProcessRx
void ProcessRx(void)
Definition: protocol.c:1049
SW_DATA_SOURCE_PIN_6
@ SW_DATA_SOURCE_PIN_6
Definition: serialWombat.h:99
ReadPin
bool ReadPin(uint8_t pin)
Definition: pinDigitalHwSpecific.c:93
SW_DATA_SOURCE_1HZ_SQUARE
@ SW_DATA_SOURCE_1HZ_SQUARE
Square wave that alternates between 0 and 65535 every 512 frames.
Definition: serialWombat.h:195
protocol.h
SW_DATA_SOURCE_LFSR
@ SW_DATA_SOURCE_LFSR
A Linear FeedBack Shift register (32,7,5,3,2,1) based pseudo-random number generator.
Definition: serialWombat.h:170
SW_DATA_SOURCE_PIN_16
@ SW_DATA_SOURCE_PIN_16
Definition: serialWombat.h:109
SW_DATA_SOURCE_PIN_15
@ SW_DATA_SOURCE_PIN_15
Definition: serialWombat.h:108
SW_DATA_SOURCE_OVERRUN_FRAMES
@ SW_DATA_SOURCE_OVERRUN_FRAMES
The number of frames that ran more than 1mS.
Definition: serialWombat.h:161
CurrentPinOpenDrain
void CurrentPinOpenDrain(void)
Definition: pinDigitalHwSpecific.c:130
SW_DATA_SOURCE_PIN_2_MV
@ SW_DATA_SOURCE_PIN_2_MV
The public data of Pin 2 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:173
CurrentPinBitmap
uint16_t CurrentPinBitmap(void)
SW_DATA_SOURCE_1HZ_SAW
@ SW_DATA_SOURCE_1HZ_SAW
Sawtooth wave that goes from 0 to 65535 to 0 every 1024 frames.
Definition: serialWombat.h:196
SW_DATA_SOURCE_8SEC_SQUARE
@ SW_DATA_SOURCE_8SEC_SQUARE
Square wave that alternates between 0 and 65535 every 4096 frames.
Definition: serialWombat.h:201
SW_DATA_SOURCE_PIN_14
@ SW_DATA_SOURCE_PIN_14
Definition: serialWombat.h:107
SW_DATA_SOURCE_PIN_19_MV
@ SW_DATA_SOURCE_PIN_19_MV
The public data of Pin 19 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:190
NUMBER_OF_TOTAL_PINS
#define NUMBER_OF_TOTAL_PINS
Definition: deviceSpecific.h:36
CurrentPinHigh
void CurrentPinHigh(void)
Definition: pinDigitalHwSpecific.c:40
_pin_register_t
Definition: pinRegisters.h:40
SW_DATA_SOURCE_PIN_13
@ SW_DATA_SOURCE_PIN_13
Definition: serialWombat.h:106
CurrentPinInput
void CurrentPinInput(void)
Definition: pinDigitalHwSpecific.c:34
CurrentPinNoPullup
void CurrentPinNoPullup(void)
SW_DATA_SOURCE_2SEC_SAW
@ SW_DATA_SOURCE_2SEC_SAW
Sawtooth wave that goes from 0 to 65535 to 0 every 2048 frames.
Definition: serialWombat.h:199
SW_DATA_SOURCE_65SEC_SAW
@ SW_DATA_SOURCE_65SEC_SAW
Sawtooth wave that goes from 0 to 65535 to 0 every 65536 frames.
Definition: serialWombat.h:205
SW_DATA_SOURCE_PIN_9
@ SW_DATA_SOURCE_PIN_9
Definition: serialWombat.h:102
SW_DATA_SOURCE_PIN_16_MV
@ SW_DATA_SOURCE_PIN_16_MV
The public data of Pin 16 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:187
PinHigh
void PinHigh(uint8_t pin)
SetCurrentPin
void SetCurrentPin(uint8_t pinState)
Definition: pinDigitalHwSpecific.c:61
queue.h
CurrentPin
uint8_t CurrentPin
Definition: processPins.c:25
SW_DATA_SOURCE_65SEC_SQUARE
@ SW_DATA_SOURCE_65SEC_SQUARE
Square wave that alternates between 0 and 65535 every 32768 frames.
Definition: serialWombat.h:204
CurrentPinPullUp
void CurrentPinPullUp(void)
Definition: pinDigitalHwSpecific.c:105
SW_DATA_SOURCE_PACKETS_RECEIVED
@ SW_DATA_SOURCE_PACKETS_RECEIVED
The nubmer of incoming command packets that have been processed since reset (rolls over at 65535)
Definition: serialWombat.h:163
serialWombatErrors.h
PinInput
void PinInput(uint8_t pin)
SW_DATA_SOURCE_FRAMES_DROPPED
@ SW_DATA_SOURCE_FRAMES_DROPPED
The number of times since reset that a frame ran so far behind that it crossed two subsequent 1ms bou...
Definition: serialWombat.h:165
SW_DATA_SOURCE_SYSTEM_UTILIZATION
@ SW_DATA_SOURCE_SYSTEM_UTILIZATION
A number between 0 and 65535 that scales to the average length of pin processing frames between 0 and...
Definition: serialWombat.h:166
SW_DATA_SOURCE_PIN_17_MV
@ SW_DATA_SOURCE_PIN_17_MV
The public data of Pin 17 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:188
reset
void reset(void)
Definition: main.c:54
SW_DATA_SOURCE_t
SW_DATA_SOURCE_t
Definition: serialWombat.h:91
SW_DATA_SOURCE_PIN_8
@ SW_DATA_SOURCE_PIN_8
Definition: serialWombat.h:101
CurrentPinPullup
void CurrentPinPullup(void)
Txbuffer
uint8_t Txbuffer[TXBUFFER_LENGTH]
A buffer for outgoing commands to the host.
Definition: protocol.c:40
CurrentPinPort
uint8_t CurrentPinPort(void)
ConfigurePinAnalog
void ConfigurePinAnalog(uint8_t pin, bool makeAnalog)
SW_DATA_SOURCE_ERRORS
@ SW_DATA_SOURCE_ERRORS
The number of incoming packets that have caused errors since reset (rolls over at 65535)
Definition: serialWombat.h:164
SW_DATA_SOURCE_PIN_1
@ SW_DATA_SOURCE_PIN_1
Definition: serialWombat.h:94
SW_DATA_SOURCE_PIN_12
@ SW_DATA_SOURCE_PIN_12
Definition: serialWombat.h:105
SW_DATA_SOURCE_PIN_1_MV
@ SW_DATA_SOURCE_PIN_1_MV
The public data of Pin 1 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:172
CurrentPinNotOpenDrain
void CurrentPinNotOpenDrain(void)
Definition: pinDigitalHwSpecific.c:135
SW_DATA_SOURCE_INCREMENTING_NUMBER
@ SW_DATA_SOURCE_INCREMENTING_NUMBER
An number that increments each time it is accessed.
Definition: serialWombat.h:157
SW_DATA_SOURCE_PIN_18_MV
@ SW_DATA_SOURCE_PIN_18_MV
The public data of Pin 18 expressed as mV. Only applicable to Analog Input mode.
Definition: serialWombat.h:189
SW_DATA_SOURCE_1024mvCounts
@ SW_DATA_SOURCE_1024mvCounts
The number of ADC counts that result from a 1.024V reading.
Definition: serialWombat.h:158
error
void error(SW_ERROR_t errorCode)
CurrentPinAnalog
void CurrentPinAnalog(void)
Definition: pinDigitalHwSpecific.c:98
SW_DATA_SOURCE_FRAMES_RUN_MSW
@ SW_DATA_SOURCE_FRAMES_RUN_MSW
The number of frames run since reset, most significant 16 bits.
Definition: serialWombat.h:160
pinRegisters.h
CurrentPinOutput
void CurrentPinOutput(void)
Definition: pinDigitalHwSpecific.c:37
SW_DATA_SOURCE_RESET_REGISTER
@ SW_DATA_SOURCE_RESET_REGISTER
Hardware dependent reset reason register contents.
Definition: serialWombat.h:169
SW_DATA_SOURCE_2HZ_SQUARE
@ SW_DATA_SOURCE_2HZ_SQUARE
Square wave that alternates between 0 and 65535 every 256 frames.
Definition: serialWombat.h:192
SW_DATA_SOURCE_2SEC_SQUARE
@ SW_DATA_SOURCE_2SEC_SQUARE
Square wave that alternates between 0 and 65535 every 1024 frames.
Definition: serialWombat.h:198
SW_DATA_SOURCE_PIN_11
@ SW_DATA_SOURCE_PIN_11
Definition: serialWombat.h:104
SW_DATA_SOURCE_VBG_COUNTS_VS_VREF
@ SW_DATA_SOURCE_VBG_COUNTS_VS_VREF
A/D conversion of VBG against VRef . Used for mfg calibration.
Definition: serialWombat.h:168
TXBUFFER_LENGTH
#define TXBUFFER_LENGTH
Definition: serialWombat.h:47