1 /* FreeEMS - the open source engine management system
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 email them upstream to
21 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 Thank you for choosing FreeEMS to run your engine! */
31 /* Header file multiple inclusion protection courtesy eclipse Header Template */
32 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
33 #ifndef FILE_COMMS_CORE_H_SEEN
34 #define FILE_COMMS_CORE_H_SEEN
38 #warning "EXTERN already defined by another header, please sort it out!"
39 #undef EXTERN /* If fail on warning is off, remove the definition such that we can redefine correctly. */
45 /* Internal use without check on buffer, purely here to place functions in paged memory. */
46 void sendErrorInternal(unsigned short) FPAGE_FE
;
47 void sendDebugInternal(unsigned char*) FPAGE_FE
;
53 /* Function declarations */
54 /* This function accesses paged flash and thus must be in linear space. Set explicitly to text. */
55 EXTERN
void decodePacketAndRespond(void) TEXT
;
57 EXTERN
void sendErrorIfClear(unsigned short) FPAGE_FE
;
58 EXTERN
void sendDebugIfClear(unsigned char*) FPAGE_FE
;
59 EXTERN
void sendErrorBusyWait(unsigned short) FPAGE_FE
;
60 EXTERN
void sendDebugBusyWait(unsigned char*) FPAGE_FE
;
62 EXTERN
void resetReceiveState(unsigned char) FPAGE_FE
;
63 EXTERN
void sendAckIfRequired(void) FPAGE_FE
;
64 EXTERN
void checksumAndSend(void) FPAGE_FE
;
66 EXTERN
void populateBasicDatalog(void) FPAGE_FE
;
69 /* Global variables for TX (one set per interface) */
70 EXTERN
unsigned short TXPacketLengthToSendCAN0
;
71 EXTERN
unsigned short TXPacketLengthToSendSCI0
;
72 EXTERN
unsigned char* TXBufferCurrentPositionHandler
;
73 EXTERN
unsigned char* TXBufferCurrentPositionCAN0
;
74 EXTERN
unsigned char* TXBufferCurrentPositionSCI0
;
77 /* Buffer use and source IDs/flags */
78 EXTERN
unsigned char TXBufferInUseFlags
;
79 EXTERN
unsigned char RXBufferContentSourceID
;
80 /* Masks for TXBufferInUseFlags and RXBufferContentSourceID */
81 #define COM_SET_SCI0_INTERFACE_ID BIT0
82 #define COM_SET_CAN0_INTERFACE_ID BIT1
83 #define COM_SET_SPARE2_INTERFACE_ID BIT2
84 #define COM_SET_SPARE3_INTERFACE_ID BIT3
85 #define COM_SET_SPARE4_INTERFACE_ID BIT4
86 #define COM_SET_SPARE5_INTERFACE_ID BIT5
87 #define COM_SET_SPARE6_INTERFACE_ID BIT6
88 #define COM_SET_SPARE7_INTERFACE_ID BIT7
89 #define COM_CLEAR_SCI0_INTERFACE_ID NBIT0
90 #define COM_CLEAR_CAN0_INTERFACE_ID NBIT1
91 #define COM_CLEAR_SPARE2_INTERFACE_ID NBIT2
92 #define COM_CLEAR_SPARE3_INTERFACE_ID NBIT3
93 #define COM_CLEAR_SPARE4_INTERFACE_ID NBIT4
94 #define COM_CLEAR_SPARE5_INTERFACE_ID NBIT5
95 #define COM_CLEAR_SPARE6_INTERFACE_ID NBIT6
96 #define COM_CLEAR_SPARE7_INTERFACE_ID NBIT7
97 #define CLEAR_ALL_SOURCE_ID_FLAGS ZEROS
100 /* Global variables for RX (one set for all) */
101 EXTERN
unsigned char RXStateFlags
;
102 EXTERN
unsigned char* RXBufferCurrentPosition
;
103 EXTERN
unsigned short RXPacketLengthReceived
;
104 EXTERN
unsigned short RXCalculatedPayloadLength
; // why global??
105 /* Masks for SCIRXStateFlags */
106 //#define RX_BUFFER_IN_USE BIT0
107 #define RX_READY_TO_PROCESS BIT1
108 #define RX_SCI_ESCAPED_NEXT BIT2
109 //#define RX_SCI_INSIDE_PACKET BIT3
110 //#define RX_BUFFER_NOT_IN_USE NBIT0
111 #define RX_CLEAR_READY_TO_PROCESS NBIT1
112 #define RX_SCI_NOT_ESCAPED_NEXT NBIT2
113 //#define RX_SCI_NOT_INSIDE_PACKET NBIT3
115 /* Global CAN specific variables */
116 // TODO can id filters routing etc
119 /* Comms Control Enable and Disable Masks */
121 #define SCICR2_RX_ENABLE BIT2
122 #define SCICR2_TX_ENABLE BIT3
123 #define SCICR2_RX_ISR_ENABLE BIT5
124 #define SCICR2_TX_ISR_ENABLE BIT7
125 #define SCICR2_RX_DISABLE NBIT2
126 #define SCICR2_TX_DISABLE NBIT3
127 #define SCICR2_RX_ISR_DISABLE NBIT5
128 #define SCICR2_TX_ISR_DISABLE NBIT7
130 // TODO probably 8 of these too
131 // TODO probably 8 of these too
132 // TODO probably 8 of these too
133 // TODO probably 8 of these too
134 // TODO probably 8 of these too
135 // TODO probably 8 of these too
136 // TODO probably 8 of these too
137 // TODO probably 8 of these too
141 /* Header components */
142 EXTERN
unsigned char RXHeaderFlags
;
143 EXTERN
unsigned short RXHeaderPayloadID
; // why glob
144 EXTERN
unsigned char RXHeaderSourceAddress
;
145 EXTERN
unsigned short RXHeaderPayloadLength
;
148 /* Header flag masks */
149 /* Always has flags (obviously) */
150 /* Always has payload ID so no flag */
151 /* Always has checksum, so no flag */
152 #define HEADER_IS_PROTO BIT0
153 #define HEADER_HAS_ACK BIT1
154 #define HEADER_IS_NACK BIT2
155 #define HEADER_HAS_ADDRS BIT3
156 #define HEADER_HAS_LENGTH BIT4
157 #define HEADER_USER_BIT_A BIT5
158 #define HEADER_USER_BIT_B BIT6
159 #define HEADER_USER_BIT_C BIT7
162 /*&&&&&&&&&&&&&&&&&&&& Payload Type ID Name Value Pairs &&&&&&&&&&&&&&&&&&&&*/
164 /* Please note, requests use even ID numbers and their matching responses use */
165 /* the odd number immediately above the original request ID. There are a few */
166 /* examples where either a request is not required or a response not sent. In */
167 /* such cases the odd ID may be used for an packet asyncronously sent from */
168 /* the EMS to the PC. These will be well commented when present. */
171 /*&&&&&&&&&&&&&&&&&&&&&&&& Protocol Payload Type IDs &&&&&&&&&&&&&&&&&&&&&&&*/
173 /* Firmware Independent functions */
174 #define requestInterfaceVersion 0
175 #define requestFirmwareVersion 2
176 #define requestMaxPacketSize 4
177 #define requestEchoPacketReturn 6
178 #define requestSoftSystemReset 8 /* System comes up fresh, so no response */
179 //efine replytoSoftSystemReset 9 /* This is reserved */
180 #define requestHardSystemReset 10 /* System comes up fresh, so no response */
181 //efine replytoHardSystemReset 11 /* This is reserved */
184 //efine requestAsyncErrorCode 12 /* This is reserved */
185 #define asyncErrorCodePacket 13 /* NOTE : Unrequested error event code packet */
186 //efine requestAsyncDebugInfo 14 /* This is reserved */
187 #define asyncDebugInfoPacket 15 /* NOTE : Unrequested debug information packet */
190 /*&&&&&&&&&&&&&&&&&&&&&&&& Firmware Payload Type IDs &&&&&&&&&&&&&&&&&&&&&&&*/
192 /* Whole block manipulation */
193 #define replaceBlockInRAM 0
194 #define replaceBlockInFlash 2
195 #define retrieveBlockFromRAM 4
196 #define retrieveBlockFromFlash 6
197 #define burnBlockFromRamToFlash 8
198 #define eraseAllBlocksFromFlash 10
199 #define burnAllBlocksOfFlash 12
201 /* Main table manipulation */
202 #define adjustMainTableCell 100
203 #define adjustMainTableRPMAxis 102
204 #define adjustMainTableLoadAxis 104
206 /* 2d table manipulation */
207 #define adjust2dTableAxis 200
208 #define adjust2dTableCell 202
210 /* Datalog request packets */
211 #define requestBasicDatalog 300
212 #define responseBasicDatalog 301
213 #define requestConfigurableDatalog 302
214 #define responseConfigurableDatalog 303
215 #define setAsyncDatalogType 304
217 /* Special function */
218 #define forwardPacketOverCAN 400
219 #define forwardPacketOverOtherUART 402
220 #define invalidRAMLocationID 404
221 #define invalidFlashLocationID 406
223 /* 8 payload IDs for testing purposes */
224 #define testPayloadIDPacketType0 65520
225 #define testPayloadIDPacketType1 65522
226 #define testPayloadIDPacketType2 65524
227 #define testPayloadIDPacketType3 65526
228 #define testPayloadIDPacketType4 65528
229 #define testPayloadIDPacketType5 65530
230 #define testPayloadIDPacketType6 65532
231 #define testPayloadIDPacketType7 65534
238 /* let us know if we are being untidy with headers */
239 #warning "Header file COMMS_CORE_H seen before, sort it out!"
240 /* end of the wrapper ifdef from the very top */