Serial Wombat 4A and 4B Firmware
pinRegisters.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 PIN_TYPES_H
28 #define PIN_TYPES_H
29 
30 #include <stdint.h>
31 
32 #ifdef _PIC14EX
33 #define BYTES_PER_PIN_REGISTER 20
34 #else
35 #define BYTES_PER_PIN_REGISTER 64
36 #define BYTES_AVAIALABLE_OUTPUT_PULSE 50
37 #define BYTES_AVAILABLE_INPUT_DMA (BYTES_PER_PIN_REGISTER - 5)
38 #endif
39 
40 typedef union _pin_register_t{
43 
46  struct generic_n {
47  uint16_t pinUwords[(BYTES_PER_PIN_REGISTER / 2) - 2];
51  uint16_t buffer;
52 
55  uint8_t mode; // Do not move
56  } generic;
57 #ifndef _PIC14EX
58  struct pulse_output_n
59  {
60  uint8_t bytes[BYTES_AVAIALABLE_OUTPUT_PULSE];
61  uint8_t resource;
62  uint8_t lastDMA;
63  uint16_t highRemaining;
64  uint16_t lowRemaining;
65  uint16_t highReload;
66  uint16_t lowReload;
67  uint16_t buffer;
68  uint16_t mode;
69  } pulse_output;
70 
71  struct pulse_input_n
72  {
73  uint8_t bytes[BYTES_AVAILABLE_INPUT_DMA];
74  uint8_t lastDMA;
75  uint16_t buffer;
76  uint16_t mode;
77  }pulse_input;
78 
79 #endif
81 
82 
86 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
87 
88 
90 
91 #ifdef _PIC14EX
92 #define USE_BUFFERED_PIN_REGISTER
93 #endif
94 
95 #ifdef USE_BUFFERED_PIN_REGISTER
97 void CopyFromArrayToPinBuffer(void);
98 void CopyFromPinBufferToArray(void);
99 #define CurrentPinRegister (&pinRegisterBuffer)
102 #else
104 #endif
105 
106 
107 void SetBuffer(uint8_t pin, uint16_t value);
108 uint16_t GetBuffer(uint8_t pin);
109 void SetMode(uint8_t pin, uint8_t mode);
110 uint8_t GetMode(uint8_t pin);
111 #endif
_pin_register_t::bytes
uint8_t bytes[BYTES_PER_PIN_REGISTER]
Definition: pinRegisters.h:41
PinUpdateRegisters
pinRegister_t PinUpdateRegisters[NUMBER_OF_TOTAL_PINS]
Definition: pinRegisters.c:28
CopyFromPinBufferToArray
void CopyFromPinBufferToArray(void)
Definition: pinRegisters.c:37
_pin_register_t::generic_n::buffer
uint16_t buffer
A 16 bit 'public' variable which is in the same location for every pin.
Definition: pinRegisters.h:51
BYTES_PER_PIN_REGISTER
#define BYTES_PER_PIN_REGISTER
Definition: pinRegisters.h:33
SetBuffer
void SetBuffer(uint8_t pin, uint16_t value)
Definition: pinRegisters.c:46
GetMode
uint8_t GetMode(uint8_t pin)
Definition: pinRegisters.c:102
pinRegister_t
union _pin_register_t pinRegister_t
pinRegisterBuffer
pinRegister_t pinRegisterBuffer
Definition: main.c:62
NUMBER_OF_TOTAL_PINS
#define NUMBER_OF_TOTAL_PINS
Definition: deviceSpecific.h:36
_pin_register_t
Definition: pinRegisters.h:40
_pin_register_t::generic_n::mode
uint8_t mode
The mode of the current pin.
Definition: pinRegisters.h:55
SetMode
void SetMode(uint8_t pin, uint8_t mode)
Definition: pinRegisters.c:94
_pin_register_t::uwords
uint16_t uwords[BYTES_PER_PIN_REGISTER/2]
Definition: pinRegisters.h:42
CurrentPinRegister
#define CurrentPinRegister
Definition: pinRegisters.h:99
_pin_register_t::generic_n::pinUwords
uint16_t pinUwords[(BYTES_PER_PIN_REGISTER/2) - 2]
Definition: pinRegisters.h:47
CopyFromArrayToPinBuffer
void CopyFromArrayToPinBuffer(void)
Definition: pinRegisters.c:32
GetBuffer
uint16_t GetBuffer(uint8_t pin)
Definition: pinRegisters.c:54
_pin_register_t::generic_n
A generic descriptor, typically used to access the buffer and mode variables.
Definition: pinRegisters.h:46