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 /* See memory.x provides and commsCore.c */
00036 extern void hardReset(void);
00037 
00038 /* Global variables for TX (one set per interface) */
00039 EXTERN unsigned short   TXPacketLengthToSendCAN0;
00040 EXTERN unsigned short   TXPacketLengthToSendSCI0;
00041 EXTERN unsigned char*   TXBufferCurrentPositionHandler;
00042 EXTERN unsigned char*   TXBufferCurrentPositionCAN0;
00043 EXTERN unsigned char*   TXBufferCurrentPositionSCI0;
00044 
00045 
00046 /* Buffer use and source IDs/flags */
00047 EXTERN unsigned char    TXBufferInUseFlags;
00048 EXTERN unsigned char    RXBufferContentSourceID;
00049 /* Masks for TXBufferInUseFlags and RXBufferContentSourceID */
00050 #define COM_SET_SCI0_INTERFACE_ID               BIT0
00051 #define COM_SET_CAN0_INTERFACE_ID               BIT1
00052 #define COM_SET_SPARE2_INTERFACE_ID             BIT2
00053 #define COM_SET_SPARE3_INTERFACE_ID             BIT3
00054 #define COM_SET_SPARE4_INTERFACE_ID             BIT4
00055 #define COM_SET_SPARE5_INTERFACE_ID             BIT5
00056 #define COM_SET_SPARE6_INTERFACE_ID             BIT6
00057 #define COM_SET_SPARE7_INTERFACE_ID             BIT7
00058 #define COM_CLEAR_SCI0_INTERFACE_ID             NBIT0
00059 #define COM_CLEAR_CAN0_INTERFACE_ID             NBIT1
00060 #define COM_CLEAR_SPARE2_INTERFACE_ID   NBIT2
00061 #define COM_CLEAR_SPARE3_INTERFACE_ID   NBIT3
00062 #define COM_CLEAR_SPARE4_INTERFACE_ID   NBIT4
00063 #define COM_CLEAR_SPARE5_INTERFACE_ID   NBIT5
00064 #define COM_CLEAR_SPARE6_INTERFACE_ID   NBIT6
00065 #define COM_CLEAR_SPARE7_INTERFACE_ID   NBIT7
00066 #define CLEAR_ALL_SOURCE_ID_FLAGS               ZEROS
00067 
00068 
00069 /* Global variables for RX (one set for all) */
00070 EXTERN unsigned char    RXStateFlags;
00071 EXTERN unsigned char*   RXBufferCurrentPosition;
00072 EXTERN unsigned short   RXPacketLengthReceived;
00073 EXTERN unsigned short   RXCalculatedPayloadLength; // why global??
00074 /* Masks for SCIRXStateFlags */
00075 //#define RX_BUFFER_IN_USE                      BIT0
00076 #define RX_READY_TO_PROCESS                     BIT1
00077 #define RX_SCI_ESCAPED_NEXT                     BIT2
00078 //#define RX_SCI_INSIDE_PACKET          BIT3
00079 //#define RX_BUFFER_NOT_IN_USE          NBIT0
00080 #define RX_CLEAR_READY_TO_PROCESS       NBIT1
00081 #define RX_SCI_NOT_ESCAPED_NEXT         NBIT2
00082 //#define RX_SCI_NOT_INSIDE_PACKET      NBIT3
00083 
00084 /* Global CAN specific variables */
00085 // TODO can id filters routing etc
00086 
00087 
00088 /* Comms Control Enable and Disable Masks */
00089 /* SCI masks */
00090 #define SCICR2_RX_ENABLE                BIT2
00091 #define SCICR2_TX_ENABLE                BIT3
00092 #define SCICR2_RX_ISR_ENABLE    BIT5
00093 #define SCICR2_TX_ISR_ENABLE    BIT7
00094 #define SCICR2_RX_DISABLE               NBIT2
00095 #define SCICR2_TX_DISABLE               NBIT3
00096 #define SCICR2_RX_ISR_DISABLE   NBIT5
00097 #define SCICR2_TX_ISR_DISABLE   NBIT7
00098 /* CAN masks */
00099 // TODO probably 8 of these too
00100 // TODO probably 8 of these too
00101 // TODO probably 8 of these too
00102 // TODO probably 8 of these too
00103 // TODO probably 8 of these too
00104 // TODO probably 8 of these too
00105 // TODO probably 8 of these too
00106 // TODO probably 8 of these too
00107 
00108 
00109 /* Function declarations */
00110 EXTERN void decodePacketAndBuildResponse(void);
00111 //EXTERN void sendError(unsigned short);
00112 //EXTERN void sendDebug(unsigned char*);
00113 EXTERN void resetReceiveState(unsigned char);
00114 EXTERN void lookupBlockDetails(unsigned short, blockDetails*);
00115 //EXTERN unsigned short operateOnBlock(unsigned char, blockDetails*);
00116 
00117 /* Header components */
00118 EXTERN unsigned char    RXHeaderFlags;
00119 EXTERN unsigned short   RXHeaderPayloadID; // why glob
00120 EXTERN unsigned char    RXHeaderSourceAddress;
00121 EXTERN unsigned short   RXHeaderPayloadLength;
00122 
00123 
00124 /* Header flag masks */
00125 /* Always has flags (obviously)                 */
00126 /* Always has payload ID so no flag             */
00127 /* Always has checksum, so no flag              */
00128 #define HEADER_IS_PROTO         BIT0
00129 #define HEADER_HAS_ACK          BIT1
00130 #define HEADER_IS_NACK          BIT2
00131 #define HEADER_HAS_ADDRS        BIT3
00132 #define HEADER_HAS_LENGTH       BIT4
00133 #define HEADER_USER_BIT_A       BIT5
00134 #define HEADER_USER_BIT_B       BIT6
00135 #define HEADER_USER_BIT_C       BIT7
00136 
00137 
00138 /*&&&&&&&&&&&&&&&&&&&&  Payload Type ID Name Value Pairs  &&&&&&&&&&&&&&&&&&&&*/
00139 
00140 /* Please note, requests use even ID numbers and their matching responses use */
00141 /* the odd number immediately above the original request ID. There are a few  */
00142 /* examples where either a request is not required or a response not sent. In */
00143 /* such cases the odd ID may be used for an packet asyncronously sent from    */
00144 /* the EMS to the PC. These will be well commented when present.                          */
00145 
00146 /*&&&&&&&&&&&&&&&&&&&&&&&&  Protocol Payload Type IDs  &&&&&&&&&&&&&&&&&&&&&&&*/
00147 
00148 /* Firmware Independent functions */
00149 #define requestInterfaceVersion           0
00150 #define requestFirmwareVersion            2
00151 #define requestMaxPacketSize              4
00152 #define requestEchoPacketReturn           6
00153 #define requestSoftSystemReset            8     /* System comes up fresh, so no response */
00154 //efine replytoSoftSystemReset            9     /* This is reserved */
00155 #define requestHardSystemReset           10     /* System comes up fresh, so no response */
00156 //efine replytoHardSystemReset           11     /* This is reserved */
00157 
00158 
00159 //efine requestAsyncErrorCode            12     /* This is reserved */
00160 #define asyncErrorCodePacket             13     /* NOTE : Unrequested error event code packet */
00161 //efine requestAsyncDebugInfo            14     /* This is reserved */
00162 #define asyncDebugInfoPacket             15     /* NOTE : Unrequested debug information packet */
00163 
00164 
00165 /*&&&&&&&&&&&&&&&&&&&&&&&&  Firmware Payload Type IDs  &&&&&&&&&&&&&&&&&&&&&&&*/
00166 
00167 /* Whole block manipulation */
00168 #define replaceBlockInRAM                         0
00169 #define replaceBlockInFlash                       2
00170 #define retrieveBlockFromRAM              4
00171 #define retrieveBlockFromFlash            6
00172 #define burnBlockFromRamToFlash           8
00173 
00174 /* Main table manipulation */
00175 #define adjustMainTableCell                     100
00176 #define adjustMainTableRPMAxis          102
00177 #define adjustMainTableLoadAxis         104
00178 
00179 /* 2d table manipulation */
00180 #define adjust2dTableAxis                       200
00181 #define adjust2dTableCell                       202
00182 #define replace2dTableInRAM                     204
00183 
00184 /* Datalog request packets */
00185 #define requestBasicDatalog                     300
00186 #define requestAdjustableDatalog        302
00187 
00188 /* Special function */
00189 #define forwardPacketOverCAN            400
00190 #define forwardPacketOverUART           402
00191 #define invalidRAMLocationID            404
00192 #define invalidFlashLocationID          406
00193 
00194 
00195 /* Fueling blocks */
00196 #define VETableMainFlashLocationID                                              0
00197 #define VETableMainFlash2LocationID                                             1
00198 #define VETableSecondaryFlashLocationID                                 2
00199 #define VETableSecondaryFlash2LocationID                                3
00200 #define VETableTertiaryFlashLocationID                                  4
00201 #define VETableTertiaryFlash2LocationID                                 5
00202 #define LambdaTableFlashLocationID                                              6
00203 #define LambdaTableFlash2LocationID                                             7
00204 /* Timing blocks */
00205 #define IgnitionAdvanceTableMainFlashLocationID                 8
00206 #define IgnitionAdvanceTableMainFlash2LocationID                9
00207 #define IgnitionAdvanceTableSecondaryFlashLocationID    10
00208 #define IgnitionAdvanceTableSecondaryFlash2LocationID   11
00209 #define InjectionAdvanceTableMainFlashLocationID                12
00210 #define InjectionAdvanceTableMainFlash2LocationID               13
00211 #define InjectionAdvanceTableSecondaryFlashLocationID   14
00212 #define InjectionAdvanceTableSecondaryFlash2LocationID  15
00213 /* Tuable blocks */
00214 #define SmallTablesAFlashLocationID                                             16
00215 #define SmallTablesAFlash2LocationID                                    17
00216 #define SmallTablesBFlashLocationID                                             18
00217 #define SmallTablesBFlash2LocationID                                    19
00218 #define SmallTablesCFlashLocationID                                             20
00219 #define SmallTablesCFlash2LocationID                                    21
00220 #define SmallTablesDFlashLocationID                                             22
00221 #define SmallTablesDFlash2LocationID                                    23
00222 /* Flash ONLY blocks */
00223 #define FixedConfigLocationID                                                   24
00224 #define FixedConfig2LocationID                                                  25
00225 #define IATTransferTableLocationID                                              26 /* 2k */
00226 #define CHTTransferTableLocationID                                              27 /* 2k */
00227 #define MAFTransferTableLocationID                                              28 /* 2k */
00228 /* Small tables */
00229 //#define
00230 
00231 
00232 #undef EXTERN
00233 
00234 #else
00235         /* let us know if we are being untidy with headers */
00236         #warning "Header file COMMS_CORE_H seen before, sort it out!"
00237 /* end of the wrapper ifdef from the very top */
00238 #endif

Generated on Mon Nov 10 21:18:50 2008 for freeems by  doxygen 1.5.2