-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathccp.h
591 lines (489 loc) · 17.2 KB
/
ccp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
/*****************************************************************************
| Project Name: C C P - Driver
| File Name: CCP.H
|
| Description:
| CCP driver example.
| CANape CAN Calibration Tool.
|
|-----------------------------------------------------------------------------
| C O P Y R I G H T
|-----------------------------------------------------------------------------
| Copyright (c) 2001-2003 by Vector Informatik GmbH. All rights reserved.
|-----------------------------------------------------------------------------
| A U T H O R I D E N T I T Y
|-----------------------------------------------------------------------------
| Initials Name Company
| -------- --------------------- -------------------------------------
| Bus Sabine Bücherl Vector Informatik GmbH
| Ds Sven Deckardt Vector Informatik GmbH
| Hp Armin Happel Vector Informatik GmbH
| Tri Frank Triem Vector Informatik GmbH
| Za Rainer Zaiser Vector Informatik GmbH
|-----------------------------------------------------------------------------
| R E V I S I O N H I S T O R Y
|-----------------------------------------------------------------------------
| Date Version Author Description
| ---------- ------- ------ -----------------------------------------------
| 2000-24-09 1.29.00 Za - New define CCP_CHECKSUM_BLOCKSIZE
| 2000-29-11 1.30.00 Za - #ifndef CCP_EXTERNAL_STATION_ID
| 2001-08-02 1.31.00 Za - new define CCP_DAQ_BASE_ADDR
| - new function ccpGetDaqPointer
| 2001-30-05 1.32.00 Za - Reserved word "data" in KEIL Compiler for C5x5
| - Prefix CCP_ for all #defines
| 2001-14-09 1.33.00 Za - #define CCP_ODT_ENTRY_SIZE
| - #define CCP_INTEL,CCP_MOTOROLA
| 2001-28-10 1.34.00 Za - ccpSend return value removed
| - Transmission error handling should be done by the user
| 2002-08-04 1.35.00 Za - #define CCP_CPUTYPE_32BIT
| - Max checksum block size is DWORD on 32 bit CPUs
| 2002-02-06 1.36.00 Za - #undef CCP_DAQ for drivers without DAQ fixed
| - double - float conversion for SHORT_UPLOAD, DNLOAD and DAQ
| 2002-17-07 1.37.00 Ds - Fixed the version nr. because the version was in
| the comment 1.36 but 135 was define.
| - Set #define CCP_DRIVER_VERSION to 137
| 2002-14-11 1.37.01 Hp - define CCP_MAX_DAQ only if CCP_DAQ is defined
| 2002-27-11 1.37.02 Ds - delete the query of extended id
| 2003-05-28 1.37.02 Bus - added V_MEMROM0
| 2003-08-11 1.37.03 Tri - implemented P_MEM_ROM and P_MEM_RAM to support M16C Mitsubishi.
| 2003-10-14 1.38.00 Tri - version skipped due to special version for TMS320
| 2003-10-14 1.39.00 Tri - version skipped due to special version for TMS320
| 2003-10-14 1.40.00 Tri - merge of versions: 1.37.03, 1.37.02
| 2003-10-16 1.41.00 Ds - minor bugfix set ROM to CCP_ROM
| 2003-10-16 1.41.01 Ds - change the position of CCP_ROM
| 2003-10-21 1.42.00 Tri - change the position of CCP_ROM
|***************************************************************************/
#ifndef __CCP_H_
#define __CCP_H_
#include "ccppar.h"
#ifndef C_DISABLE_CCP
/* Declare CCP-protocol version */
#define CCP_VERSION_MAJOR 0x02
#define CCP_VERSION_MINOR 0x01
/* Declare module implementation version number */
#define CCP_DRIVER_VERSION 142
#define CCP_DRIVER_BUGFIX_VERSION 0
/* Basic */
#define CC_CONNECT 0x01
#define CC_SET_MTA 0x02
#define CC_DNLOAD 0x03
#define CC_UPLOAD 0x04
#define CC_TEST 0x05 /* V2.1 */
#define CC_START_STOP 0x06
#define CC_DISCONNECT 0x07
#define CC_START_STOP_ALL 0x08 /* V2.1 */
#define CC_SHORT_UPLOAD 0x0F
#define CC_GET_DAQ_SIZE 0x14
#define CC_SET_DAQ_PTR 0x15
#define CC_WRITE_DAQ 0x16
#define CC_EXCHANGE_ID 0x17
#define CC_GET_CCP_VERSION 0x1B /* V2.1 */
#define CC_DNLOAD6 0x23
/* Optional */
#define CC_GET_CAL_PAGE 0x09
#define CC_SET_S_STATUS 0x0C
#define CC_GET_S_STATUS 0x0D
#define CC_BUILD_CHKSUM 0x0E
#define CC_CLEAR_MEMORY 0x10
#define CC_SET_CAL_PAGE 0x11
#define CC_GET_SEED 0x12
#define CC_UNLOCK 0x13
#define CC_PROGRAM 0x18
#define CC_MOVE_MEMORY 0x19
#define CC_DIAG_SERVICE 0x20
#define CC_ACTION_SERVICE 0x21
#define CC_PROGRAM6 0x22
/* Vector extensions */
#define CC_PROGRAM_PREPARE 0x1E /* Prepare for flash kernel download */
#define CC_PROGRAM_START 0x1F /* Start flash kernel at MTA[0] */
/* Returncodes */
#define CRC_OK 0x00
/* C1 */
#define CRC_CMD_BUSY 0x10
#define CRC_DAQ_BUSY 0x11
#define CRC_KEY_REQUEST 0x18
#define CRC_STATUS_REQUEST 0x19
/* C2 */
#define CRC_COLD_START_REQUEST 0x20
#define CRC_CAL_INIT_REQUEST 0x21
#define CRC_DAQ_INIT_REQUEST 0x22
#define CRC_CODE_REQUEST 0x23
/* C3 (Errors) */
#define CRC_CMD_UNKNOWN 0x30
#define CRC_CMD_SYNTAX 0x31
#define CRC_OUT_OF_RANGE 0x32
#define CRC_ACCESS_DENIED 0x33
#define CRC_OVERLOAD 0x34
#define CRC_ACCESS_LOCKED 0x35
/* Session Status */
#define SS_CAL 0x01
#define SS_DAQ 0x02
#define SS_RESUME 0x04
#define SS_TMP_DISCONNECTED 0x10
#define SS_CONNECTED 0x20
#define SS_STORE 0x40
#define SS_RUN 0x80
/* Priviledge Level */
#define PL_CAL 0x01
#define PL_DAQ 0x02
#define PL_PGM 0x40
/* Broadcast Station Address */
#define CCP_BROADCAST_STATION_ADDR 0
/*--------------------------------------------------------------------------*/
/* Datatypes */
/*--------------------------------------------------------------------------*/
/*
The types CCP_BYTE, CCP_WORD and CCP_DWORD should be defined in ccppar.h
*/
#ifndef CCP_BYTE
#ifdef BYTE
#define CCP_BYTE BYTE
#else
#define CCP_BYTE unsigned char
#endif
#endif
#ifndef CCP_WORD
#ifdef WORD
#define CCP_WORD WORD
#else
#define CCP_WORD unsigned short
#endif
#endif
#ifndef CCP_DWORD
#ifdef DWORD
#define CCP_DWORD DWORD
#else
#define CCP_DWORD unsigned long
#endif
#endif
#ifndef CCP_BYTEPTR
#ifdef BYTEPTR
#define CCP_BYTEPTR BYTEPTR
#else
#define CCP_BYTEPTR unsigned char *
#endif
#endif
#ifndef CCP_MTABYTEPTR
#ifdef MTABYTEPTR
#define CCP_MTABYTEPTR MTABYTEPTR
#else
#define CCP_MTABYTEPTR CCP_BYTE CCP_MEM_ROM *
#endif
#endif
#ifndef CCP_DAQBYTEPTR
#ifdef DAQBYTEPTR
#define CCP_DAQBYTEPTR DAQBYTEPTR
#else
#define CCP_DAQBYTEPTR CCP_BYTE CCP_MEM_ROM *
#endif
#endif
#ifndef CCP_RAM
#ifdef RAM
#define CCP_RAM RAM
#else
#define CCP_RAM
#endif
#endif
#ifndef CCP_ROM
#ifdef ROM
#define CCP_ROM ROM
#else
#define CCP_ROM
#endif
#endif
/* Vector CAN Driver Intel/Motorola */
#ifdef C_CPUTYPE_BIGENDIAN
#define CCP_MOTOROLA
#endif
#ifdef C_CPUTYPE_LITTLEENDIAN
#define CCP_INTEL
#endif
#ifndef CCP_INTEL
#ifndef CCP_MOTOROLA
#error Please #define CCP_INTEL or CCP_MOTOROLA as the target system byte order
#endif
#endif
/* pointer to ROM/RAM */
#if defined (CCP_MEM_ROM)
#else
#if defined (P_MEM_ROM)
#define CCP_MEM_ROM P_MEM_ROM
#else
#define CCP_MEM_ROM
#endif
#endif
#if defined (CCP_MEM_RAM)
#else
#if defined (P_MEM_RAM)
#define CCP_MEM_RAM P_MEM_RAM
#else
#define CCP_MEM_RAM
#endif
#endif
/* Memory qualifier, which always remains in first position. */
/* Can be used e.g. for compiler/linker which don't place constants into the ROM */
#if defined (CCP_MEMROM0)
#else
#if defined (V_MEMROM0)
#define CCP_MEMROM0 V_MEMROM0
#else
#define CCP_MEMROM0
#endif
#endif
/*--------------------------------------------------------------------------*/
/* DAQ Lists, Type Definition */
/*--------------------------------------------------------------------------*/
/* Note:
- Adressextensions are not used in this example
- Object size > 1 are not used in this example and must be handled in
the calibration system
*/
/* The maximum number of ODTs is restricted
PID=0xFE,0xFF is reserved
*/
#ifdef CCP_DAQ
#ifndef CCP_SEND_QUEUE_OVERRUN_INDICATION
#if CCP_MAX_DAQ*CCP_MAX_ODT>254
#error Too many ODTs, maximum is CCP_MAX_DAQ*CCP_MAX_ODT = 254
#endif
#else
#if CCP_MAX_DAQ*CCP_MAX_ODT>126
#error Too many ODTs, maximum is CCP_MAX_DAQ*CCP_MAX_ODT = 126
#endif
#endif
#endif
/* CCP_DAQBYTEPTR and CCP_MTABYTEPTR may be defined different to CCP_BYTEPTR to save memory
Example:
#define CCP_BYTEPTR unsigned char *
#define CCP_MTABYTEPTR huge unsigned char *
#define CCP_DAQBYTEPTR unsigned char *
*/
#ifndef CCP_DAQBYTEPTR
#ifdef CCP_DAQ_BASE_ADDR /* CCP_DAQBYTEPTR required, if CCP_DAQ_BASE_ADDR is defined */
#error Please define CCP_DAQBYTEPTR, which is the type of ODT entries
#else
#define CCP_DAQBYTEPTR CCP_BYTEPTR
#endif
#endif
#ifndef CCP_MTABYTEPTR
#define CCP_MTABYTEPTR CCP_BYTEPTR
#endif
#ifdef CCP_DAQ
/* ODT entry */
typedef struct ccpOdtEntry {
CCP_DAQBYTEPTR ptr;
#ifdef CCP_ODT_ENTRY_SIZE
CCP_BYTE siz;
#endif
} ccpOdtEntry_t;
/* ODT */
typedef ccpOdtEntry_t ccpODT_t[7];
/* DAQ list */
#define DAQ_FLAG_START 0x01
#define DAQ_FLAG_SEND 0x02
#define DAQ_FLAG_PREPARED 0x04
#define DAQ_FLAG_OVERRUN 0x80
typedef struct ccpDaqList {
ccpODT_t odt[CCP_MAX_ODT];
CCP_WORD prescaler;
CCP_WORD cycle;
CCP_BYTE eventChannel;
CCP_BYTE last;
CCP_BYTE flags;
} ccpDaqList_t;
#else
#undef CCP_SEND_QUEUE
#undef CCP_SEND_SINGLE
#endif
/*--------------------------------------------------------------------------*/
/* Transmit Queue, Type Definition */
/*--------------------------------------------------------------------------*/
#ifdef CCP_SEND_QUEUE
/* Checks */
#ifndef CCP_SEND_QUEUE_SIZE
#define CCP_SEND_QUEUE_SIZE (CCP_MAX_ODT*CCP_MAX_DAQ)
#endif
#ifdef CCP_SEND_SINGLE
#error Do not use CCP_SEND_SINGLE together with CCP_SEND_QUEUE
#endif
#if CCP_MAX_ODT > CCP_SEND_QUEUE_SIZE
#error CCP_SEND_QUEUE_SIZE is too small
#endif
typedef struct {
CCP_BYTE b[8];
} ccpMsg_t;
typedef struct {
CCP_BYTE len;
CCP_BYTE rp;
ccpMsg_t msg[CCP_SEND_QUEUE_SIZE];
} ccpQueue_t;
#endif
/*--------------------------------------------------------------------------*/
/* CCP Driver Variables, Type Definition */
/*--------------------------------------------------------------------------*/
#define CCP_MAX_MTA 2
#define CCP_INTERNAL_MTA (CCP_MAX_MTA-1)
/* Return values for ccpWriteMTA and ccpCheckWriteEEPROM */
#define CCP_WRITE_DENIED 0
#define CCP_WRITE_OK 1
#define CCP_WRITE_PENDING 2
#define CCP_WRITE_ERROR 3
/* Bitmasks for ccp.SendStatus */
#define CCP_CRM_REQUEST 0x01
#define CCP_DTM_REQUEST 0x02
#define CCP_USR_REQUEST 0x04
#define CCP_CMD_PENDING 0x08
#define CCP_CRM_PENDING 0x10
#define CCP_DTM_PENDING 0x20
#define CCP_USR_PENDING 0x40
#define CCP_TX_PENDING 0x80
#define CCP_SEND_PENDING (CCP_DTM_PENDING|CCP_CRM_PENDING|CCP_USR_PENDING)
struct ccp {
CCP_BYTE Crm[8]; /* CRM Command Return Message buffer */
CCP_BYTE SessionStatus;
CCP_BYTE SendStatus;
CCP_MTABYTEPTR MTA[CCP_MAX_MTA]; /* Memory Transfer Address */
#ifdef CCP_DAQ
#ifdef CCP_SEND_QUEUE
ccpQueue_t Queue;
#else
CCP_BYTE Dtm[8]; /* DTM Data Transmission Message buffer */
#endif
#ifdef CCP_SEND_SINGLE
CCP_BYTE CurrentDaq;
CCP_BYTE CurrentOdt;
#endif
ccpOdtEntry_t *DaqListPtr; /* Pointer for SET_DAQ_PTR, make it near to save RAM */
ccpDaqList_t DaqList[CCP_MAX_DAQ]; /* DAQ list */
#endif
CCP_BYTE UserSessionStatus; /* Used for GET/SET_SESSION_STATUS */
#ifdef CCP_SEED_KEY
CCP_BYTE ProtectionStatus; /* Resource Protection Status */
#endif
#ifdef CCP_CHECKSUM
#if defined( CCP_CPUTYPE_32BIT )
CCP_DWORD CheckSumSize; /* Counter for checksum calculation */
#else
CCP_WORD CheckSumSize; /* Counter for checksum calculation */
#endif
#endif
};
extern CCP_RAM struct ccp ccp;
/*--------------------------------------------------------------------------*/
/* Prototypes */
/*--------------------------------------------------------------------------*/
/* Functions from ccp.c */
/*----------------------*/
/* Initialize */
extern void ccpInit( void );
/* DAQ processor */
extern void ccpDaq( CCP_BYTE eventChannel );
/* Command processor */
extern void ccpCommand( CCP_BYTEPTR msg );
/* Transmit Notification */
/* Returns 0 when the CCP driver is idle */
extern CCP_BYTE ccpSendCallBack( void );
/* Send a pending CRM */
void ccpSendCrm( void );
/* Background Loop */
/* Return 1 (TRUE) when still pending */
/* Used only if Checksum Calculation or EEPROM Programming is required */
extern CCP_BYTE ccpBackground( void );
/* Functions provided externally */
/*-------------------------------*/
/* Transmit a message */
/* Returns 1 (TRUE) when successfull */
extern void ccpSend( CCP_BYTEPTR msg );
/* Background calculation */
#ifndef ccpUserBackground
extern void ccpUserBackground( void );
#endif
/* Generate a pointer from addr_ext and addr */
#if !defined(ccpGetPointer) || defined(__BOOT_H__) /* Not defined as macro */
extern CCP_MTABYTEPTR ccpGetPointer( CCP_BYTE addr_ext, CCP_DWORD addr );
#endif
#ifdef CCP_DAQ_BASE_ADDR
extern CCP_DAQBYTEPTR ccpGetDaqPointer( CCP_BYTE addr_ext, CCP_DWORD addr );
#endif
#ifdef CCP_STANDARD
extern void ccpGetMTA0( CCP_BYTE *e, CCP_DWORD *a);
#endif
/* Check addresses for valid write access */
/* Returns 0 (false) if access denied */
/* Used only, if write protection of memory areas is required */
#ifdef CCP_WRITE_PROTECTION
#ifndef ccpCheckWriteAccess /* Not defined as macro */
extern CCP_BYTE ccpCheckWriteAccess( CCP_MTABYTEPTR a, CCP_BYTE size );
#endif
#endif
/* Flash Kernel Download */
/* Used only of Download of the Flash Kernel is required */
#ifdef CCP_BOOTLOADER_DOWNLOAD
extern CCP_BYTE ccpDisableNormalOperation( CCP_MTABYTEPTR a, CCP_WORD size );
typedef void (*ccpBootLoader_t)(struct ccp *, CCP_BYTEPTR);
#endif
/* Flash Programming */
/* Used only if Flash Programming is required */
#ifdef CCP_PROGRAM
#define CCP_CALPAGE
/* If Flash Programming is performed by a special loader, */
/* the following function will be called on CLEAR_MEMORY command */
#ifdef CCP_BOOTLOADER
extern void ccpBootLoaderStartup( struct ccp *ccp, CCP_BYTEPTR com );
#else
extern void ccpFlashClear( CCP_MTABYTEPTR a, CCP_DWORD size );
extern CCP_BYTE ccpFlashProgramm( CCP_BYTEPTR data, CCP_MTABYTEPTR a, CCP_BYTE size );
/* Returns:
CCP_WRITE_OK - FLASH written
CCP_WRITE_PENDING - FLASH write in progress, call ccpSendCrm when done
*/
#endif
#endif
/* RAM/ROM Switching */
#ifdef CCP_CALPAGE
extern void ccpInitCalPage( void );
extern CCP_DWORD ccpGetCalPage( void );
extern void ccpSetCalPage( CCP_DWORD a );
#endif
/* Seed&Key*/
#ifdef CCP_SEED_KEY
extern CCP_DWORD ccpGetSeed( CCP_BYTE resourceMask );
extern CCP_BYTE ccpUnlock( CCP_BYTE *key );
#endif
/* EEPROM Programing */
#ifdef CCP_WRITE_EEPROM
/* Return values for ccpCheckWriteEEPROM:
CCP_WRITE_OK - EEPROM written
CCP_WRITE_DENIED - This is not EEPROM
CCP_WRITE_PENDING - EEPROM write in progress, call ccpSendCrm when done
*/
CCP_BYTE ccpCheckWriteEEPROM( CCP_MTABYTEPTR addr, CCP_BYTE size, CCP_BYTEPTR data );
#endif
#ifdef CCP_READ_EEPROM
/* Return values for ccpCheckReadEEPROM:
0 (FALSE) - This is not EEPROM
1 (TRUE) - EEPROM read
*/
CCP_BYTE ccpCheckReadEEPROM( CCP_MTABYTEPTR addr, CCP_BYTE size, CCP_BYTEPTR data );
#endif
/*--------------------------------------------------------------------------*/
/* Special Features */
/* Please contact Vector for details */
/*--------------------------------------------------------------------------*/
/* ECU Timestamping */
#ifdef CCP_TIMESTAMPING
#ifndef ccpGetTimestamp /* Not defined as macro */
CCP_WORD ccpGetTimestamp( void );
#endif
#ifndef ccpClearTimestamp /* Not defined as macro */
void ccpClearTimestamp( void );
#endif
#endif
/*--------------------------------------------------------------------------*/
/* Test */
/*--------------------------------------------------------------------------*/
#ifdef CCP_TESTMODE
extern unsigned char gDebugLevel;
#endif
#endif
#endif