commsCore.h

Go to the documentation of this file.
00001 /*      commsCore.h
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 send them upstream to us at admin@diyefi.org
00021 
00022         Thank you for choosing FreeEMS to run your engine! */
00023 
00024 /* Header file multiple inclusion protection courtesy eclipse Header Template   */
00025 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual              */
00026 #ifndef FILE_COMMS_CORE_H_SEEN
00027 #define FILE_COMMS_CORE_H_SEEN
00028 
00029 #ifdef COMMSCORE_C
00030 #define EXTERN
00031 #else
00032 #define EXTERN extern
00033 #endif
00034 
00035 
00036 /* Function declarations */
00037 /* This function accesses paged flash and thus must be in linear space. Set explicitly to text. */
00038 EXTERN void decodePacketAndRespond(void) TEXT;
00039 
00040 EXTERN void sendErrorIfClear(unsigned short) FPAGE_FE;
00041 EXTERN void sendDebugIfClear(unsigned char*) FPAGE_FE;
00042 EXTERN void sendErrorBusyWait(unsigned short) FPAGE_FE;
00043 EXTERN void sendDebugBusyWait(unsigned char*) FPAGE_FE;
00044 
00045 EXTERN void resetReceiveState(unsigned char) FPAGE_FE;
00046 EXTERN void sendAckIfRequired(void) FPAGE_FE;
00047 EXTERN void checksumAndSend(void) FPAGE_FE;
00048 
00049 EXTERN void populateBasicDatalog(void) FPAGE_FE;
00050 
00051 
00052 /* Global variables for TX (one set per interface) */
00053 EXTERN unsigned short   TXPacketLengthToSendCAN0;
00054 EXTERN unsigned short   TXPacketLengthToSendSCI0;
00055 EXTERN unsigned char*   TXBufferCurrentPositionHandler;
00056 EXTERN unsigned char*   TXBufferCurrentPositionCAN0;
00057 EXTERN unsigned char*   TXBufferCurrentPositionSCI0;
00058 
00059 
00060 /* Buffer use and source IDs/flags */
00061 EXTERN unsigned char    TXBufferInUseFlags;
00062 EXTERN unsigned char    RXBufferContentSourceID;
00063 /* Masks for TXBufferInUseFlags and RXBufferContentSourceID */
00064 #define COM_SET_SCI0_INTERFACE_ID               BIT0
00065 #define COM_SET_CAN0_INTERFACE_ID               BIT1
00066 #define COM_SET_SPARE2_INTERFACE_ID             BIT2
00067 #define COM_SET_SPARE3_INTERFACE_ID             BIT3
00068 #define COM_SET_SPARE4_INTERFACE_ID             BIT4
00069 #define COM_SET_SPARE5_INTERFACE_ID             BIT5
00070 #define COM_SET_SPARE6_INTERFACE_ID             BIT6
00071 #define COM_SET_SPARE7_INTERFACE_ID             BIT7
00072 #define COM_CLEAR_SCI0_INTERFACE_ID             NBIT0
00073 #define COM_CLEAR_CAN0_INTERFACE_ID             NBIT1
00074 #define COM_CLEAR_SPARE2_INTERFACE_ID   NBIT2
00075 #define COM_CLEAR_SPARE3_INTERFACE_ID   NBIT3
00076 #define COM_CLEAR_SPARE4_INTERFACE_ID   NBIT4
00077 #define COM_CLEAR_SPARE5_INTERFACE_ID   NBIT5
00078 #define COM_CLEAR_SPARE6_INTERFACE_ID   NBIT6
00079 #define COM_CLEAR_SPARE7_INTERFACE_ID   NBIT7
00080 #define CLEAR_ALL_SOURCE_ID_FLAGS               ZEROS
00081 
00082 
00083 /* Global variables for RX (one set for all) */
00084 EXTERN unsigned char    RXStateFlags;
00085 EXTERN unsigned char*   RXBufferCurrentPosition;
00086 EXTERN unsigned short   RXPacketLengthReceived;
00087 EXTERN unsigned short   RXCalculatedPayloadLength; // why global??
00088 /* Masks for SCIRXStateFlags */
00089 //#define RX_BUFFER_IN_USE                      BIT0
00090 #define RX_READY_TO_PROCESS                     BIT1
00091 #define RX_SCI_ESCAPED_NEXT                     BIT2
00092 //#define RX_SCI_INSIDE_PACKET          BIT3
00093 //#define RX_BUFFER_NOT_IN_USE          NBIT0
00094 #define RX_CLEAR_READY_TO_PROCESS       NBIT1
00095 #define RX_SCI_NOT_ESCAPED_NEXT         NBIT2
00096 //#define RX_SCI_NOT_INSIDE_PACKET      NBIT3
00097 
00098 /* Global CAN specific variables */
00099 // TODO can id filters routing etc
00100 
00101 
00102 /* Comms Control Enable and Disable Masks */
00103 /* SCI masks */
00104 #define SCICR2_RX_ENABLE                BIT2
00105 #define SCICR2_TX_ENABLE                BIT3
00106 #define SCICR2_RX_ISR_ENABLE    BIT5
00107 #define SCICR2_TX_ISR_ENABLE    BIT7
00108 #define SCICR2_RX_DISABLE               NBIT2
00109 #define SCICR2_TX_DISABLE               NBIT3
00110 #define SCICR2_RX_ISR_DISABLE   NBIT5
00111 #define SCICR2_TX_ISR_DISABLE   NBIT7
00112 /* CAN masks */
00113 // TODO probably 8 of these too
00114 // TODO probably 8 of these too
00115 // TODO probably 8 of these too
00116 // TODO probably 8 of these too
00117 // TODO probably 8 of these too
00118 // TODO probably 8 of these too
00119 // TODO probably 8 of these too
00120 // TODO probably 8 of these too
00121 
00122 
00123 
00124 /* Header components */
00125 EXTERN unsigned char    RXHeaderFlags;
00126 EXTERN unsigned short   RXHeaderPayloadID; // why glob
00127 EXTERN unsigned char    RXHeaderSourceAddress;
00128 EXTERN unsigned short   RXHeaderPayloadLength;
00129 
00130 
00131 /* Header flag masks */
00132 /* Always has flags (obviously)                 */
00133 /* Always has payload ID so no flag             */
00134 /* Always has checksum, so no flag              */
00135 #define HEADER_IS_PROTO         BIT0
00136 #define HEADER_HAS_ACK          BIT1
00137 #define HEADER_IS_NACK          BIT2
00138 #define HEADER_HAS_ADDRS        BIT3
00139 #define HEADER_HAS_LENGTH       BIT4
00140 #define HEADER_USER_BIT_A       BIT5
00141 #define HEADER_USER_BIT_B       BIT6
00142 #define HEADER_USER_BIT_C       BIT7
00143 
00144 
00145 /*&&&&&&&&&&&&&&&&&&&&  Payload Type ID Name Value Pairs  &&&&&&&&&&&&&&&&&&&&*/
00146 
00147 /* Please note, requests use even ID numbers and their matching responses use */
00148 /* the odd number immediately above the original request ID. There are a few  */
00149 /* examples where either a request is not required or a response not sent. In */
00150 /* such cases the odd ID may be used for an packet asyncronously sent from    */
00151 /* the EMS to the PC. These will be well commented when present.                          */
00152 
00153 
00154 /*&&&&&&&&&&&&&&&&&&&&&&&&  Protocol Payload Type IDs  &&&&&&&&&&&&&&&&&&&&&&&*/
00155 
00156 /* Firmware Independent functions */
00157 #define requestInterfaceVersion           0
00158 #define requestFirmwareVersion            2
00159 #define requestMaxPacketSize              4
00160 #define requestEchoPacketReturn           6
00161 #define requestSoftSystemReset            8     /* System comes up fresh, so no response */
00162 //efine replytoSoftSystemReset            9     /* This is reserved */
00163 #define requestHardSystemReset           10     /* System comes up fresh, so no response */
00164 //efine replytoHardSystemReset           11     /* This is reserved */
00165 
00166 
00167 //efine requestAsyncErrorCode            12     /* This is reserved */
00168 #define asyncErrorCodePacket             13     /* NOTE : Unrequested error event code packet */
00169 //efine requestAsyncDebugInfo            14     /* This is reserved */
00170 #define asyncDebugInfoPacket             15     /* NOTE : Unrequested debug information packet */
00171 
00172 
00173 /*&&&&&&&&&&&&&&&&&&&&&&&&  Firmware Payload Type IDs  &&&&&&&&&&&&&&&&&&&&&&&*/
00174 
00175 /* Whole block manipulation */
00176 #define replaceBlockInRAM                         0
00177 #define replaceBlockInFlash                       2
00178 #define retrieveBlockFromRAM              4
00179 #define retrieveBlockFromFlash            6
00180 #define burnBlockFromRamToFlash           8
00181 #define eraseAllBlocksFromFlash          10
00182 #define burnAllBlocksOfFlash             12
00183 
00184 /* Main table manipulation */
00185 #define adjustMainTableCell                     100
00186 #define adjustMainTableRPMAxis          102
00187 #define adjustMainTableLoadAxis         104
00188 
00189 /* 2d table manipulation */
00190 #define adjust2dTableAxis                       200
00191 #define adjust2dTableCell                       202
00192 
00193 /* Datalog request packets */
00194 #define requestBasicDatalog                     300
00195 #define responseBasicDatalog            301
00196 #define requestConfigurableDatalog      302
00197 #define responseConfigurableDatalog     303
00198 #define setAsyncDatalogType                     304
00199 
00200 /* Special function */
00201 #define forwardPacketOverCAN            400
00202 #define forwardPacketOverOtherUART      402
00203 #define invalidRAMLocationID            404
00204 #define invalidFlashLocationID          406
00205 
00206 /* 8 payload IDs for testing purposes */
00207 #define testPayloadIDPacketType0        65520
00208 #define testPayloadIDPacketType1        65522
00209 #define testPayloadIDPacketType2        65524
00210 #define testPayloadIDPacketType3        65526
00211 #define testPayloadIDPacketType4        65528
00212 #define testPayloadIDPacketType5        65530
00213 #define testPayloadIDPacketType6        65532
00214 #define testPayloadIDPacketType7        65534
00215 
00216 
00217 #undef EXTERN
00218 
00219 #else
00220         /* let us know if we are being untidy with headers */
00221         #warning "Header file COMMS_CORE_H seen before, sort it out!"
00222 /* end of the wrapper ifdef from the very top */
00223 #endif

Generated on Mon Dec 22 21:29:17 2008 for freeems by  doxygen 1.5.2