Fixed ugly header
[freeems-vanilla.git] / src / inc / commsCore.h
blob6c22413f78af9dbbd7533fc2e730c10abc007e41
1 /* commsCore.h
3 Copyright 2008 Fred Cooke
5 This file is part of the FreeEMS project.
7 FreeEMS software is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 FreeEMS software is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
20 We ask that if you make any changes to this file you send them upstream to us at admin@diyefi.org
22 Thank you for choosing FreeEMS to run your engine! */
24 /* Header file multiple inclusion protection courtesy eclipse Header Template */
25 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
26 #ifndef FILE_COMMS_CORE_H_SEEN
27 #define FILE_COMMS_CORE_H_SEEN
29 #ifdef COMMSCORE_C
30 #define EXTERN
31 #else
32 #define EXTERN extern
33 #endif
36 /* Function declarations */
37 /* This function accesses paged flash and thus must be in linear space. Set explicitly to text. */
38 EXTERN void decodePacketAndRespond(void) TEXT;
40 EXTERN void sendErrorIfClear(unsigned short) FPAGE_FE;
41 EXTERN void sendDebugIfClear(unsigned char*) FPAGE_FE;
42 EXTERN void sendErrorBusyWait(unsigned short) FPAGE_FE;
43 EXTERN void sendDebugBusyWait(unsigned char*) FPAGE_FE;
45 EXTERN void resetReceiveState(unsigned char) FPAGE_FE;
46 EXTERN void sendAckIfRequired(void) FPAGE_FE;
47 EXTERN void checksumAndSend(void) FPAGE_FE;
49 EXTERN void populateBasicDatalog(void) FPAGE_FE;
52 /* Global variables for TX (one set per interface) */
53 EXTERN unsigned short TXPacketLengthToSendCAN0;
54 EXTERN unsigned short TXPacketLengthToSendSCI0;
55 EXTERN unsigned char* TXBufferCurrentPositionHandler;
56 EXTERN unsigned char* TXBufferCurrentPositionCAN0;
57 EXTERN unsigned char* TXBufferCurrentPositionSCI0;
60 /* Buffer use and source IDs/flags */
61 EXTERN unsigned char TXBufferInUseFlags;
62 EXTERN unsigned char RXBufferContentSourceID;
63 /* Masks for TXBufferInUseFlags and RXBufferContentSourceID */
64 #define COM_SET_SCI0_INTERFACE_ID BIT0
65 #define COM_SET_CAN0_INTERFACE_ID BIT1
66 #define COM_SET_SPARE2_INTERFACE_ID BIT2
67 #define COM_SET_SPARE3_INTERFACE_ID BIT3
68 #define COM_SET_SPARE4_INTERFACE_ID BIT4
69 #define COM_SET_SPARE5_INTERFACE_ID BIT5
70 #define COM_SET_SPARE6_INTERFACE_ID BIT6
71 #define COM_SET_SPARE7_INTERFACE_ID BIT7
72 #define COM_CLEAR_SCI0_INTERFACE_ID NBIT0
73 #define COM_CLEAR_CAN0_INTERFACE_ID NBIT1
74 #define COM_CLEAR_SPARE2_INTERFACE_ID NBIT2
75 #define COM_CLEAR_SPARE3_INTERFACE_ID NBIT3
76 #define COM_CLEAR_SPARE4_INTERFACE_ID NBIT4
77 #define COM_CLEAR_SPARE5_INTERFACE_ID NBIT5
78 #define COM_CLEAR_SPARE6_INTERFACE_ID NBIT6
79 #define COM_CLEAR_SPARE7_INTERFACE_ID NBIT7
80 #define CLEAR_ALL_SOURCE_ID_FLAGS ZEROS
83 /* Global variables for RX (one set for all) */
84 EXTERN unsigned char RXStateFlags;
85 EXTERN unsigned char* RXBufferCurrentPosition;
86 EXTERN unsigned short RXPacketLengthReceived;
87 EXTERN unsigned short RXCalculatedPayloadLength; // why global??
88 /* Masks for SCIRXStateFlags */
89 //#define RX_BUFFER_IN_USE BIT0
90 #define RX_READY_TO_PROCESS BIT1
91 #define RX_SCI_ESCAPED_NEXT BIT2
92 //#define RX_SCI_INSIDE_PACKET BIT3
93 //#define RX_BUFFER_NOT_IN_USE NBIT0
94 #define RX_CLEAR_READY_TO_PROCESS NBIT1
95 #define RX_SCI_NOT_ESCAPED_NEXT NBIT2
96 //#define RX_SCI_NOT_INSIDE_PACKET NBIT3
98 /* Global CAN specific variables */
99 // TODO can id filters routing etc
102 /* Comms Control Enable and Disable Masks */
103 /* SCI masks */
104 #define SCICR2_RX_ENABLE BIT2
105 #define SCICR2_TX_ENABLE BIT3
106 #define SCICR2_RX_ISR_ENABLE BIT5
107 #define SCICR2_TX_ISR_ENABLE BIT7
108 #define SCICR2_RX_DISABLE NBIT2
109 #define SCICR2_TX_DISABLE NBIT3
110 #define SCICR2_RX_ISR_DISABLE NBIT5
111 #define SCICR2_TX_ISR_DISABLE NBIT7
112 /* CAN masks */
113 // TODO probably 8 of these too
114 // TODO probably 8 of these too
115 // TODO probably 8 of these too
116 // TODO probably 8 of these too
117 // TODO probably 8 of these too
118 // TODO probably 8 of these too
119 // TODO probably 8 of these too
120 // TODO probably 8 of these too
124 /* Header components */
125 EXTERN unsigned char RXHeaderFlags;
126 EXTERN unsigned short RXHeaderPayloadID; // why glob
127 EXTERN unsigned char RXHeaderSourceAddress;
128 EXTERN unsigned short RXHeaderPayloadLength;
131 /* Header flag masks */
132 /* Always has flags (obviously) */
133 /* Always has payload ID so no flag */
134 /* Always has checksum, so no flag */
135 #define HEADER_IS_PROTO BIT0
136 #define HEADER_HAS_ACK BIT1
137 #define HEADER_IS_NACK BIT2
138 #define HEADER_HAS_ADDRS BIT3
139 #define HEADER_HAS_LENGTH BIT4
140 #define HEADER_USER_BIT_A BIT5
141 #define HEADER_USER_BIT_B BIT6
142 #define HEADER_USER_BIT_C BIT7
145 /*&&&&&&&&&&&&&&&&&&&& Payload Type ID Name Value Pairs &&&&&&&&&&&&&&&&&&&&*/
147 /* Please note, requests use even ID numbers and their matching responses use */
148 /* the odd number immediately above the original request ID. There are a few */
149 /* examples where either a request is not required or a response not sent. In */
150 /* such cases the odd ID may be used for an packet asyncronously sent from */
151 /* the EMS to the PC. These will be well commented when present. */
154 /*&&&&&&&&&&&&&&&&&&&&&&&& Protocol Payload Type IDs &&&&&&&&&&&&&&&&&&&&&&&*/
156 /* Firmware Independent functions */
157 #define requestInterfaceVersion 0
158 #define requestFirmwareVersion 2
159 #define requestMaxPacketSize 4
160 #define requestEchoPacketReturn 6
161 #define requestSoftSystemReset 8 /* System comes up fresh, so no response */
162 //efine replytoSoftSystemReset 9 /* This is reserved */
163 #define requestHardSystemReset 10 /* System comes up fresh, so no response */
164 //efine replytoHardSystemReset 11 /* This is reserved */
167 //efine requestAsyncErrorCode 12 /* This is reserved */
168 #define asyncErrorCodePacket 13 /* NOTE : Unrequested error event code packet */
169 //efine requestAsyncDebugInfo 14 /* This is reserved */
170 #define asyncDebugInfoPacket 15 /* NOTE : Unrequested debug information packet */
173 /*&&&&&&&&&&&&&&&&&&&&&&&& Firmware Payload Type IDs &&&&&&&&&&&&&&&&&&&&&&&*/
175 /* Whole block manipulation */
176 #define replaceBlockInRAM 0
177 #define replaceBlockInFlash 2
178 #define retrieveBlockFromRAM 4
179 #define retrieveBlockFromFlash 6
180 #define burnBlockFromRamToFlash 8
181 #define eraseAllBlocksFromFlash 10
182 #define burnAllBlocksOfFlash 12
184 /* Main table manipulation */
185 #define adjustMainTableCell 100
186 #define adjustMainTableRPMAxis 102
187 #define adjustMainTableLoadAxis 104
189 /* 2d table manipulation */
190 #define adjust2dTableAxis 200
191 #define adjust2dTableCell 202
193 /* Datalog request packets */
194 #define requestBasicDatalog 300
195 #define responseBasicDatalog 301
196 #define requestConfigurableDatalog 302
197 #define responseConfigurableDatalog 303
198 #define setAsyncDatalogType 304
200 /* Special function */
201 #define forwardPacketOverCAN 400
202 #define forwardPacketOverOtherUART 402
203 #define invalidRAMLocationID 404
204 #define invalidFlashLocationID 406
206 /* 8 payload IDs for testing purposes */
207 #define testPayloadIDPacketType0 65520
208 #define testPayloadIDPacketType1 65522
209 #define testPayloadIDPacketType2 65524
210 #define testPayloadIDPacketType3 65526
211 #define testPayloadIDPacketType4 65528
212 #define testPayloadIDPacketType5 65530
213 #define testPayloadIDPacketType6 65532
214 #define testPayloadIDPacketType7 65534
217 #undef EXTERN
219 #else
220 /* let us know if we are being untidy with headers */
221 #warning "Header file COMMS_CORE_H seen before, sort it out!"
222 /* end of the wrapper ifdef from the very top */
223 #endif