00001 /* FreeEMS - the open source engine management system 00002 00003 Copyright 2008 Fred Cooke 00004 00005 This file is part of the FreeEMS project. 00006 00007 FreeEMS software is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 FreeEMS software is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00019 00020 We ask that if you make any changes to this file you email them upstream to 00021 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00022 00023 Thank you for choosing FreeEMS to run your engine! */ 00024 00025 00031 /* Header file multiple inclusion protection courtesy eclipse Header Template */ 00032 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */ 00033 #ifndef FILE_COMMS_CORE_H_SEEN 00034 #define FILE_COMMS_CORE_H_SEEN 00035 00036 00037 #ifdef EXTERN 00038 #warning "EXTERN already defined by another header, please sort it out!" 00039 #undef EXTERN /* If fail on warning is off, remove the definition such that we can redefine correctly. */ 00040 #endif 00041 00042 00043 #ifdef COMMSCORE_C 00044 #define EXTERN 00045 /* Internal use without check on buffer, purely here to place functions in paged memory. */ 00046 void sendErrorInternal(unsigned short) FPAGE_FE; 00047 void sendDebugInternal(unsigned char*) FPAGE_FE; 00048 #else 00049 #define EXTERN extern 00050 #endif 00051 00052 00053 /* Function declarations */ 00054 /* This function accesses paged flash and thus must be in linear space. Set explicitly to text. */ 00055 EXTERN void decodePacketAndRespond(void) TEXT; 00056 00057 EXTERN void sendErrorIfClear(unsigned short) FPAGE_FE; 00058 EXTERN void sendDebugIfClear(unsigned char*) FPAGE_FE; 00059 EXTERN void sendErrorBusyWait(unsigned short) FPAGE_FE; 00060 EXTERN void sendDebugBusyWait(unsigned char*) FPAGE_FE; 00061 00062 EXTERN void resetReceiveState(unsigned char) FPAGE_FE; 00063 EXTERN void sendAckIfRequired(void) FPAGE_FE; 00064 EXTERN void checksumAndSend(void) FPAGE_FE; 00065 00066 EXTERN void populateBasicDatalog(void) FPAGE_FE; 00067 00068 00069 /* Global variables for TX (one set per interface) */ 00070 EXTERN unsigned short TXPacketLengthToSendCAN0; 00071 EXTERN unsigned short TXPacketLengthToSendSCI0; 00072 EXTERN unsigned char* TXBufferCurrentPositionHandler; 00073 EXTERN unsigned char* TXBufferCurrentPositionCAN0; 00074 EXTERN unsigned char* TXBufferCurrentPositionSCI0; 00075 00076 00077 /* Buffer use and source IDs/flags */ 00078 EXTERN unsigned char TXBufferInUseFlags; 00079 EXTERN unsigned char RXBufferContentSourceID; 00080 /* Masks for TXBufferInUseFlags and RXBufferContentSourceID */ 00081 #define COM_SET_SCI0_INTERFACE_ID BIT0 00082 #define COM_SET_CAN0_INTERFACE_ID BIT1 00083 #define COM_SET_SPARE2_INTERFACE_ID BIT2 00084 #define COM_SET_SPARE3_INTERFACE_ID BIT3 00085 #define COM_SET_SPARE4_INTERFACE_ID BIT4 00086 #define COM_SET_SPARE5_INTERFACE_ID BIT5 00087 #define COM_SET_SPARE6_INTERFACE_ID BIT6 00088 #define COM_SET_SPARE7_INTERFACE_ID BIT7 00089 #define COM_CLEAR_SCI0_INTERFACE_ID NBIT0 00090 #define COM_CLEAR_CAN0_INTERFACE_ID NBIT1 00091 #define COM_CLEAR_SPARE2_INTERFACE_ID NBIT2 00092 #define COM_CLEAR_SPARE3_INTERFACE_ID NBIT3 00093 #define COM_CLEAR_SPARE4_INTERFACE_ID NBIT4 00094 #define COM_CLEAR_SPARE5_INTERFACE_ID NBIT5 00095 #define COM_CLEAR_SPARE6_INTERFACE_ID NBIT6 00096 #define COM_CLEAR_SPARE7_INTERFACE_ID NBIT7 00097 #define CLEAR_ALL_SOURCE_ID_FLAGS ZEROS 00098 00099 00100 /* Global variables for RX (one set for all) */ 00101 EXTERN unsigned char RXStateFlags; 00102 EXTERN unsigned char* RXBufferCurrentPosition; 00103 EXTERN unsigned short RXPacketLengthReceived; 00104 EXTERN unsigned short RXCalculatedPayloadLength; // why global?? 00105 /* Masks for SCIRXStateFlags */ 00106 //#define RX_BUFFER_IN_USE BIT0 00107 #define RX_READY_TO_PROCESS BIT1 00108 #define RX_SCI_ESCAPED_NEXT BIT2 00109 //#define RX_SCI_INSIDE_PACKET BIT3 00110 //#define RX_BUFFER_NOT_IN_USE NBIT0 00111 #define RX_CLEAR_READY_TO_PROCESS NBIT1 00112 #define RX_SCI_NOT_ESCAPED_NEXT NBIT2 00113 //#define RX_SCI_NOT_INSIDE_PACKET NBIT3 00114 00115 /* Global CAN specific variables */ 00116 // TODO can id filters routing etc 00117 00118 00119 /* Comms Control Enable and Disable Masks */ 00120 /* SCI masks */ 00121 #define SCICR2_RX_ENABLE BIT2 00122 #define SCICR2_TX_ENABLE BIT3 00123 #define SCICR2_RX_ISR_ENABLE BIT5 00124 #define SCICR2_TX_ISR_ENABLE BIT7 00125 #define SCICR2_RX_DISABLE NBIT2 00126 #define SCICR2_TX_DISABLE NBIT3 00127 #define SCICR2_RX_ISR_DISABLE NBIT5 00128 #define SCICR2_TX_ISR_DISABLE NBIT7 00129 /* CAN masks */ 00130 // TODO probably 8 of these too 00131 // TODO probably 8 of these too 00132 // TODO probably 8 of these too 00133 // TODO probably 8 of these too 00134 // TODO probably 8 of these too 00135 // TODO probably 8 of these too 00136 // TODO probably 8 of these too 00137 // TODO probably 8 of these too 00138 00139 00140 00141 /* Header components */ 00142 EXTERN unsigned char RXHeaderFlags; 00143 EXTERN unsigned short RXHeaderPayloadID; // why glob 00144 EXTERN unsigned char RXHeaderSourceAddress; 00145 EXTERN unsigned short RXHeaderPayloadLength; 00146 00147 00148 /* Header flag masks */ 00149 /* Always has flags (obviously) */ 00150 /* Always has payload ID so no flag */ 00151 /* Always has checksum, so no flag */ 00152 #define HEADER_IS_PROTO BIT0 00153 #define HEADER_HAS_ACK BIT1 00154 #define HEADER_IS_NACK BIT2 00155 #define HEADER_HAS_ADDRS BIT3 00156 #define HEADER_HAS_LENGTH BIT4 00157 #define HEADER_USER_BIT_A BIT5 00158 #define HEADER_USER_BIT_B BIT6 00159 #define HEADER_USER_BIT_C BIT7 00160 00161 00162 /*&&&&&&&&&&&&&&&&&&&& Payload Type ID Name Value Pairs &&&&&&&&&&&&&&&&&&&&*/ 00163 00164 /* Please note, requests use even ID numbers and their matching responses use */ 00165 /* the odd number immediately above the original request ID. There are a few */ 00166 /* examples where either a request is not required or a response not sent. In */ 00167 /* such cases the odd ID may be used for an packet asyncronously sent from */ 00168 /* the EMS to the PC. These will be well commented when present. */ 00169 00170 00171 /*&&&&&&&&&&&&&&&&&&&&&&&& Protocol Payload Type IDs &&&&&&&&&&&&&&&&&&&&&&&*/ 00172 00173 /* Firmware Independent functions */ 00174 #define requestInterfaceVersion 0 00175 #define requestFirmwareVersion 2 00176 #define requestMaxPacketSize 4 00177 #define requestEchoPacketReturn 6 00178 #define requestSoftSystemReset 8 /* System comes up fresh, so no response */ 00179 //efine replytoSoftSystemReset 9 /* This is reserved */ 00180 #define requestHardSystemReset 10 /* System comes up fresh, so no response */ 00181 //efine replytoHardSystemReset 11 /* This is reserved */ 00182 00183 00184 //efine requestAsyncErrorCode 12 /* This is reserved */ 00185 #define asyncErrorCodePacket 13 /* NOTE : Unrequested error event code packet */ 00186 //efine requestAsyncDebugInfo 14 /* This is reserved */ 00187 #define asyncDebugInfoPacket 15 /* NOTE : Unrequested debug information packet */ 00188 00189 00190 /*&&&&&&&&&&&&&&&&&&&&&&&& Firmware Payload Type IDs &&&&&&&&&&&&&&&&&&&&&&&*/ 00191 00192 /* Whole block manipulation */ 00193 #define replaceBlockInRAM 0 00194 #define replaceBlockInFlash 2 00195 #define retrieveBlockFromRAM 4 00196 #define retrieveBlockFromFlash 6 00197 #define burnBlockFromRamToFlash 8 00198 #define eraseAllBlocksFromFlash 10 00199 #define burnAllBlocksOfFlash 12 00200 00201 /* Main table manipulation */ 00202 #define adjustMainTableCell 100 00203 #define adjustMainTableRPMAxis 102 00204 #define adjustMainTableLoadAxis 104 00205 00206 /* 2d table manipulation */ 00207 #define adjust2dTableAxis 200 00208 #define adjust2dTableCell 202 00209 00210 /* Datalog request packets */ 00211 #define requestBasicDatalog 300 00212 #define responseBasicDatalog 301 00213 #define requestConfigurableDatalog 302 00214 #define responseConfigurableDatalog 303 00215 #define setAsyncDatalogType 304 00216 00217 /* Special function */ 00218 #define forwardPacketOverCAN 400 00219 #define forwardPacketOverOtherUART 402 00220 #define invalidRAMLocationID 404 00221 #define invalidFlashLocationID 406 00222 00223 /* 8 payload IDs for testing purposes */ 00224 #define testPayloadIDPacketType0 65520 00225 #define testPayloadIDPacketType1 65522 00226 #define testPayloadIDPacketType2 65524 00227 #define testPayloadIDPacketType3 65526 00228 #define testPayloadIDPacketType4 65528 00229 #define testPayloadIDPacketType5 65530 00230 #define testPayloadIDPacketType6 65532 00231 #define testPayloadIDPacketType7 65534 00232 00233 00234 #undef EXTERN 00235 00236 00237 #else 00238 /* let us know if we are being untidy with headers */ 00239 #warning "Header file COMMS_CORE_H seen before, sort it out!" 00240 /* end of the wrapper ifdef from the very top */ 00241 #endif