WISP ERT (Client)  1.0.0
The WISP Extended Runtime (WISP side)
globals.h
Go to the documentation of this file.
1 
12 #ifndef GLOBALS_H_
13 #define GLOBALS_H_
14 
15 #include <msp430.h>
16 #include "config/pin-assign.h" /* low level pinDefs, IDs, etc. */
17 
18 /* Global constants */
19 #define FOREVER (1)
20 #define NEVER (0)
21 
22 #define TRUE (1)
23 #define FALSE (0)
24 
25 #define HIGH (1)
26 #define LOW (0)
27 
28 #define FAIL (0)
29 #define SUCCESS (1)
30 
32 #define EPC_WORDS (6) /* length of EPC value in words, 0 <= n <= 31 */
33 
34 #define CMDBUFF_SIZE (30) /* ? */
35 #define DATABUFF_SIZE (2+(EPC_WORDS<<1)+2) /* first2/last2 are reserved. put data into B2..B13 */
36  /* format: [storedPC|EPC|CRC16] */
37 #define RFIDBUFF_SIZE (1+16+2+2+50) /* longest command handled is the read command for 8 wds*/
38 
39 #define USRBANK_SIZE (32) /* ? */
40 
41 #define RFID_SEED (0x1234) //change this to change the RN16 selection behavior. if using multiple tags make sure to put a
42  //different value on each one!! /** @todo: maybe have this generated in INFO Mems during cal*/
43 
44 #define CMD_PARSE_AS_QUERY_REP (0x00)
45 #define CMD_PARSE_AS_OVF (0xFF)
46 #define ENOUGH_BITS_TO_FORCE_EXECUTION (200)
47 
48 #define RESET_BITS_VAL (-2) /* this is the value which will reset the TA1_SM if found in 'bits (R5)' by rfid_sm */
49 
50 // RFID TIMINGS (Taken a bit more liberately to support both R420 and R1000).
51 #define RTCAL_MIN (200) // strictly calculated it should be 2.5*TARI = 2.5*6.25 = 15.625 us = 250 cycles
52 #define RTCAL_MAX (300) // 3*TARI = 3*6.25 = 18.75 us = 300 cycles
53 #define TRCAL_MIN (220) // We don't have time to do a MUL instruction, so we do 1.1*RTCAL_MIN instead of 1.1*RTCAL.
54 #define TRCAL_MAX (900) // We don't have time to do a MUL instruction, so we do 3*RTCAL_MAX instead of 3*RTCAL.
55 
56 //TIMING----------------------------------------------------------------------------------------------------------------------------//
57 //Goal is 56.125/62.500/68.875us. Trying to shoot for the lower to save (a little) power.
58 //Note: 1 is minVal here due to the way decrement timing loop works. 0 will act like (0xFFFF+1)!
59 #define TX_TIMING_QUERY (24)/*53.5-60us (depends on which Q value is loaded). */
60 #define TX_TIMING_ACK (20)/*60.0us*/ //(14,58.6us)
61 
62 #define TX_TIMING_QR (52)//58.8us
63 #define TX_TIMING_QA (48)//60.0us
64 #define TX_TIMING_REQRN (33)//60.4us
65 #define TX_TIMING_READ (29)//58.0us
66 #define TX_TIMING_WRITE (31)//60.4us
67 
68 #define QUERY_TIMEOUT_PERIOD (65535)
69 
70 //PROTOCOL DEFS---------------------------------------------------------------------------------------------------------------------//
71 //(if # is rounded to 8 that is so cmd[n] was finished being shifted in)
72 #define NUM_SEL_BITS (48) /* only need to parse through mask: (4+3+3+2+8+8+16 = 44 -> round to 48) */
73 #define NUM_QUERY_BITS (22)
74 #define NUM_ACK_BITS (18)
75 #define NUM_REQRN_BITS (40)
76 #define NUM_WRITE_BITS (66)
77 
78 #define EPC_LENGTH (EPC_WORDS) /* 10h..14h EPC Length in Words. (6 is 96bit std) */
79 #define UMI (0x01) /* 15h User-Memory Indicator. '1' means the tag has user memory available. */
80 #define XI (0x00) /* 16h XPC_W1 indicator. '0' means the tag does not support this feature. */
81 #define NSI (0x00) /* 17h..1Fh Numbering System Identifier. */
82  /* all zeros means it isn't supported and is recommended default */
83 
84 #define TREXT_ON (1) /* Tag should use TRext format for backscatter */
85 #define TREXT_OFF (0) /* Tag shouldn't use TRext format for backscatter */
86 #define WRITE_DATA_BLINK_LED (0x00)
87 #define WRITE_DATA_NEW_ID (0x01)
88 
89 #ifndef __ASSEMBLER__
90 #include <stdint.h> /* use xintx_t good var defs (e.g. uint8_t) */
91 #include "config/wispGuts.h"
92 
93 //TYPEDEFS------------------------------------------------------------------------------------------------------------------------
94 //THE RFID STRUCT FOR INVENTORY STATE VARS
95 typedef struct {
96  uint8_t TRext;
97  uint16_t handle;
98  uint16_t slotCount;
99  uint8_t Q;
101  uint8_t mode;
102  uint8_t abortOn; /* List of command responses which cause the main RFID loop to return */
103  uint8_t abortFlag;
104  uint8_t isSelected; /* state of being selected via the select command. Zero if not selected */
105 
106  uint8_t rn8_ind; /* using our RN values in INFO_MEM, this points to the current one to use next */
107 
108  uint16_t edge_capture_prev_ccr; /* Previous value of CCR register, used to compute delta in edge capture ISRs */
109 
112 }RFIDstruct; /* in MODE_USES_SEL!! */
113 
114 extern RFIDstruct rfid;
115 
116 //THE RW STRUCT FOR ACCESS STATE VARS
117 typedef struct {
118  //Parsed Cmd Fields
119  uint8_t memBank; /* for Rd/Wr, this will hold memBank parsed from cmd when hook is called */
120  uint8_t wordPtr; /* for Rd/Wr, this will hold wordPtr parsed from cmd when hook is called */
121  uint16_t wrData; /* for Write this will hold the 16-bit Write Data value when hook is called */
122  uint16_t bwrByteCount; /* for BlockWrite this will hold the number of BYTES received */
123  uint16_t* bwrBufPtr; /* for BlockWrite this will hold a pointer to the data buffer containing write data */
124 
125  //Function Hooks
126  void* *akHook; /* this function is called with no params or return after an ack command response */
127  void* *wrHook; /* this function is called with no params or return after a write command response */
128  void* *bwrHook; /* this function is called with no params or return after a write command response */
129  void* *rdHook; /* this function is called with no params or return after a read command response */
130 
131  //Memory Map Bank Ptrs
132  uint8_t* RESBankPtr; /* for read command, this is a pointer to the virtual, mapped Reserved Bank */
133  uint8_t* EPCBankPtr; /* "" mapped EPC Bank */
134  uint8_t* TIDBankPtr; /* "" mapped TID Bank */
135  uint8_t* USRBankPtr; /* "" mapped USR Bank */
136 }RWstruct;
137 
138 // Boolean type
139 typedef uint8_t BOOL;
140 
141 extern RWstruct RWData;
142 
143 //Memory Banks
144 extern uint8_t cmd [CMDBUFF_SIZE];
145 extern uint8_t dataBuf [DATABUFF_SIZE];
146 extern uint8_t rfidBuf [RFIDBUFF_SIZE];
147 
148 
149 extern uint8_t usrBank [USRBANK_SIZE];
150 extern uint16_t wisp_ID;
151 extern volatile uint8_t isDoingLowPwrSleep;
152 
153 //Register Macros
154 #define bits _get_R5_register()
155 #define dest _get_R4_register()
156 #define setBits(x) _set_R5_register(x)
157 #define setDest(x) _set_R4_register(x)
158 
159 //FUNCTION PROTOTYPES---------------------------------------------------------------------------------------------------------------//
160 extern void WISP_doRFID(void);
161 extern void TxFM0(volatile uint8_t *data, uint8_t numBytes, uint8_t numBits, uint8_t TRext); //sends out MSB first...
162 
163 // Linker hack: We need to reference assembly ISRs directly somewhere to force linker to include them in binary.
164 extern void RX_ISR(void);
165 extern void Timer0A0_ISR(void);
166 extern void Timer0A1_ISR(void);
167 extern void Timer1A0_ISR(void);
168 
169 extern void handleQuery (void);
170 extern void handleAck (void);
171 extern void handleQR (void);
172 extern void handleQA (void);
173 extern void handleReq_RN (void);
174 extern void handleRead (void);
175 extern void handleWrite (void);
176 extern void handleBlockWrite(void);
177 
178 //MACROS----------------------------------------------------------------------------------------------------------------------------//
179 #define BITSET(port,pin) port |= (pin)
180 #define BITCLR(port,pin) port &= ~(pin)
181 #define BITTOG(port,pin) port ^= (pin)
182 
183 //RFID DEFINITIONS------------------------------------------------------------------------------------------------------------------//
184 
185 #define STORED_PC ( ((EPC_LENGTH&0x001F)<<11) | ((UMI&0x0001)<<10) | ((XI&0x0001)<<9) | (NSI&0x01FF)<<01 )
186 //**per EPC Spec would be:
187 //#define STORED_PC_GRR (uint16_t) ( ((NSI&0x01FF)<<7) | ((XI&0x01)<<6) | ((UMI&0x01)<<5) | (EPC_LENGTH&0x1F) )
188 
189 //This is the ugliest, non-portable code ever BUT it allows the compiler to setup the memory at compile time.
190 #define STORED_PC1 ( (STORED_PC&0xFF00)>>8 )
191 #define STORED_PC0 ( (STORED_PC&0x00FF)>>0 )
192 
193 #endif /* __ASSEMBLER__ */
194 #endif /* GLOBALS_H_ */
uint16_t bwrByteCount
Definition: globals.h:122
uint8_t usrBank[USRBANK_SIZE]
Definition: interface.c:12
void handleQR(void)
uint8_t rfidBuf[RFIDBUFF_SIZE]
Definition: wisp-init.c:18
void WISP_doRFID(void)
void RX_ISR(void)
uint8_t * RESBankPtr
Definition: globals.h:132
void Timer0A0_ISR(void)
uint8_t rn8_ind
Definition: globals.h:106
uint16_t wrData
Definition: globals.h:121
uint16_t * bwrBufPtr
Definition: globals.h:123
Definition: globals.h:95
void ** rdHook
Definition: globals.h:129
void ** akHook
Definition: globals.h:126
uint16_t wisp_ID
void Timer1A0_ISR(void)
void handleQuery(void)
void handleWrite(void)
uint8_t isSelected
Definition: globals.h:104
void handleAck(void)
#define USRBANK_SIZE
Definition: globals.h:39
#define RFIDBUFF_SIZE
Definition: globals.h:37
uint16_t edge_capture_prev_ccr
Definition: globals.h:108
uint8_t cmd[CMDBUFF_SIZE]
Definition: wisp-init.c:16
uint8_t * EPCBankPtr
Definition: globals.h:133
void Timer0A1_ISR(void)
void ** wrHook
Definition: globals.h:127
uint8_t * USRBankPtr
Definition: globals.h:135
uint8_t TRext
Definition: globals.h:96
Definition: globals.h:117
uint8_t abortFlag
Definition: globals.h:103
#define DATABUFF_SIZE
Definition: globals.h:35
#define CMDBUFF_SIZE
Definition: globals.h:34
uint16_t handle
Definition: globals.h:97
void TxFM0(volatile uint8_t *data, uint8_t numBytes, uint8_t numBits, uint8_t TRext)
uint8_t mode
Definition: globals.h:101
uint8_t wordPtr
Definition: globals.h:120
uint8_t * TIDBankPtr
Definition: globals.h:134
RWstruct RWData
Definition: wisp-init.c:13
void handleBlockWrite(void)
uint8_t memBank
Definition: globals.h:119
uint8_t BOOL
Definition: globals.h:139
uint8_t dataBuf[DATABUFF_SIZE]
Definition: wisp-init.c:17
RFIDstruct rfid
Definition: wisp-init.c:12
void handleRead(void)
void handleQA(void)
uint8_t abortOn
Definition: globals.h:102
void ** bwrHook
Definition: globals.h:128
uint8_t Q
Definition: globals.h:99
void handleReq_RN(void)
volatile uint8_t isDoingLowPwrSleep
Definition: wisp-init.c:24
uint16_t slotCount
Definition: globals.h:98