Subversion Repositories HomeAutomation

Rev

Rev 299 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 299 Rev 315
1
#ifndef CAN_H_
1
#ifndef CAN_H_
2
#define CAN_H_
2
#define CAN_H_
3
 
3
 
4
/*-----------------------------------------------------------------------------
4
/*-----------------------------------------------------------------------------
5
 * Includes
5
 * Includes
6
 *---------------------------------------------------------------------------*/
6
 *---------------------------------------------------------------------------*/
7
#include <inttypes.h>
7
#include <inttypes.h>
8
 
8
 
9
 
9
 
10
/*-----------------------------------------------------------------------------
10
/*-----------------------------------------------------------------------------
11
 * Type Definitions
11
 * Type Definitions
12
 *---------------------------------------------------------------------------*/
12
 *---------------------------------------------------------------------------*/
13
 
13
 
14
 
14
 
15
/**
15
/**
16
 * CAN Return Type. Most CAN functions return one of these.
16
 * CAN Return Type. Most CAN functions return one of these.
17
 */
17
 */
18
typedef enum {
18
typedef enum {
19
    CAN_FAIL = -1,                  /* The function failed */
19
    CAN_FAIL = -1,                  /* The function failed */
20
    CAN_OK = 1,                     /* The function succeeded */
20
    CAN_OK = 1,                     /* The function succeeded */
21
   
21
   
22
    CAN_MSG_AVAILABLE = 2,          /* Messsages are available */
22
    CAN_MSG_AVAILABLE = 2,          /* Messsages are available */
23
    CAN_NO_MSG_AVAILABLE = -2,      /* Messages are NOT available */
23
    CAN_NO_MSG_AVAILABLE = -2,      /* Messages are NOT available */
24
   
24
   
25
    //CAN_CTRLERROR = -4
25
    //CAN_CTRLERROR = -4
26
} Can_Return_t;
26
} Can_Return_t;
27
 
27
 
28
 
28
 
29
/**
29
/**
30
 * CAN Message Type. Stores a complete CAN frame.
30
 * CAN Message Type. Stores a complete CAN frame.
31
 */
31
 */
32
typedef struct {
32
typedef struct {
33
    /*
33
    /*
34
     * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
34
     * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
35
     */
35
     */
36
    uint32_t Id;
36
    uint32_t Id;
37
   
37
   
38
    /*
38
    /*
39
     * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
39
     * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
40
     */
40
     */
41
    uint8_t DataLength;
41
    uint8_t DataLength;
42
   
42
   
43
    /**
43
    /**
44
     * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit.
44
     * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit.
45
     */
45
     */
46
    uint8_t ExtendedFlag;
46
    uint8_t ExtendedFlag;
47
   
47
   
48
    /**
48
    /**
49
     * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise.
49
     * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise.
50
     */
50
     */
51
    uint8_t RemoteFlag;
51
    uint8_t RemoteFlag;
52
   
52
   
53
    /*
53
    /*
54
     * DATA section. Contains the 8 data bytes.
54
     * DATA section. Contains the 8 data bytes.
55
     */
55
     */
56
    union {
56
    union {
57
        /* read as 8bit unsigned data */
57
        /* read as 8bit unsigned data */
58
        uint8_t bytes[8];
58
        uint8_t bytes[8];
59
       
59
       
60
        /* read as 16bit unsigned data */
60
        /* read as 16bit unsigned data */
61
        uint16_t words[4];
61
        uint16_t words[4];
62
       
62
       
63
        /* read as 32bit unsigned data */
63
        /* read as 32bit unsigned data */
64
        uint32_t dwords[2];
64
        uint32_t dwords[2];
65
    } Data;
65
    } Data;
66
} Can_Message_t;
66
} Can_Message_t;
67
 
67
 
68
//---------------------------------------------------------------------------
68
//---------------------------------------------------------------------------
69
// CAN ID definitions
69
// CAN ID definitions
70
 
70
 
71
#define CAN_MASK_CLASS      0x1E000000
71
#define CAN_MASK_CLASS      0x1E000000
72
#define CAN_SHIFT_CLASS     25
72
#define CAN_SHIFT_CLASS     25
73
//------------------------------------
73
//------------------------------------
74
#define CAN_NMT             0x00UL
74
#define CAN_NMT             0x00UL
75
#define CAN_MASK_NMT_TYPE   0x00FF0000
75
#define CAN_MASK_NMT_TYPE   0x00FF0000
76
#define CAN_SHIFT_NMT_TYPE  16
76
#define CAN_SHIFT_NMT_TYPE  16
77
#define CAN_MASK_NMT_SID    0x0000FF00
77
#define CAN_MASK_NMT_SID    0x0000FF00
78
#define CAN_SHIFT_NMT_SID   8
78
#define CAN_SHIFT_NMT_SID   8
79
#define CAN_MASK_NMT_RID    0x000000FF
79
#define CAN_MASK_NMT_RID    0x000000FF
80
#define CAN_SHIFT_NMT_RID   0
80
#define CAN_SHIFT_NMT_RID   0
-
 
81
#define CAN_NMT_TIME        0x00UL  //D0:3 UNIX_TIME, D4:7 {YY:6, MM:4, DD:5, hh:5, mm:6, ss:6}
81
#define CAN_NMT_RESET       0x00UL
82
#define CAN_NMT_RESET       0x04UL
82
#define CAN_NMT_BIOS_START  0x01UL  //D0: VER7:0, D1:VER15:8, D2: 0 if no app, >0 if app
83
#define CAN_NMT_BIOS_START  0x08UL  //D0: VER7:0, D1:VER15:8, D2: 0 if no app, >0 if app
83
#define CAN_NMT_PGM_START   0x02UL  //D0: ADR7:0, D1:ADR15:8, D2:ADR23:16, D3:ADR31:24
84
#define CAN_NMT_PGM_START   0x0CUL  //D0: ADR7:0, D1:ADR15:8, D2:ADR23:16, D3:ADR31:24
84
#define CAN_NMT_PGM_DATA    0x03UL  //D0: OFS7:0, D1: OFS15:8, D(n+2): DATAn7:0 [n=0..x] [x=0..5]
85
#define CAN_NMT_PGM_DATA    0x10UL  //D0: OFS7:0, D1: OFS15:8, D(n+2): DATAn7:0 [n=0..x] [x=0..5]
85
#define CAN_NMT_PGM_END     0x04UL  //D0: CRC7:0, D1: CRC15:8
86
#define CAN_NMT_PGM_END     0x14UL  //D0: CRC7:0, D1: CRC15:8
-
 
87
#define CAN_NMT_PGM_COPY    0x18UL  //D0: SRC7:0, D1:SRC15:8, D0: DST7:0, D1:DST15:8, D0: LEN7:0, D1:LEN15:8
86
#define CAN_NMT_PGM_ACK     0x05UL  //D0: OFS7:0, D1: OFS15:8
88
#define CAN_NMT_PGM_ACK     0x1CUL  //D0: OFS7:0, D1: OFS15:8
87
#define CAN_NMT_PGM_NACK    0x06UL  //D0: OFS7:0, D1: OFS15:8
89
#define CAN_NMT_PGM_NACK    0x20UL  //D0: OFS7:0, D1: OFS15:8
88
#define CAN_NMT_START_APP   0x07UL
90
#define CAN_NMT_START_APP   0x24UL
89
#define CAN_NMT_APP_START   0x08UL  //D0: ID7:0, D1:ID15:8, D2: VER7:0, D3:VER15:8
91
#define CAN_NMT_APP_START   0x28UL  //D0: ID7:0, D1:ID15:8, D2: VER7:0, D3:VER15:8
90
#define CAN_NMT_HEARTBEAT   0x09UL
92
#define CAN_NMT_HEARTBEAT   0x2CUL
91
#define CAN_NMT_PGM_COPY    0x0FUL  //D0: SRC7:0, D1:SRC15:8, D0: DST7:0, D1:DST15:8, D0: LEN7:0, D1:LEN15:8
-
 
92
//------------------------------------
93
//------------------------------------
93
#define CAN_SNS             0x02UL
94
#define CAN_SNS             0x02UL
94
#define CAN_MASK_SNS_FUNCC  0x01FF8000
95
#define CAN_MASK_SNS_FUNCC  0x01FF8000
95
#define CAN_SHIFT_SNS_FUNCC 15
96
#define CAN_SHIFT_SNS_FUNCC 15
96
#define CAN_MASK_SNS_NID    0x00007E00
97
#define CAN_MASK_SNS_NID    0x00007E00
97
#define CAN_SHIFT_SNS_NID   9
98
#define CAN_SHIFT_SNS_NID   9
98
#define CAN_MASK_SNS_SID    0x000001FF
99
#define CAN_MASK_SNS_SID    0x000001FF
99
#define CAN_SHIFT_SNS_SID   0
100
#define CAN_SHIFT_SNS_SID   0
100
//------------------------------------
101
//------------------------------------
101
#define CAN_PKT             0x06UL
102
#define CAN_PKT             0x06UL
102
//------------------------------------
103
//------------------------------------
103
#define CAN_CON             0x08UL
104
#define CAN_CON             0x08UL
104
//------------------------------------
105
//------------------------------------
105
#define CAN_TST             0x0FUL
106
#define CAN_TST             0x0FUL
106
//------------------------------------
107
//------------------------------------
107
 
108
 
108
#endif
109
#endif
109
 
110