Subversion Repositories HomeAutomation

Rev

Rev 789 | Rev 1909 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 789 Rev 869
Line 15... Line 15...
15
 */
15
 */
16
 
16
 
17
/**@{*/
17
/**@{*/
18
 
18
 
19
//#error StdCan: For discussion only! Do not use in application code.
19
//#error StdCan: For discussion only! Do not use in application code.
20
#warning StdCan: Not thourhly tested yet.
20
//#warning StdCan: Not thouroughly tested yet.
21
 
21
 
22
#ifndef STDCAN_H_
22
#ifndef STDCAN_H_
23
#define STDCAN_H_
23
#define STDCAN_H_
24
 
24
 
25
#include <config.h>
25
#include <config.h>
Line 55... Line 55...
55
 *
55
 *
56
 * Stores a CAN message frame. Flags that are unsupported have been
56
 * Stores a CAN message frame. Flags that are unsupported have been
57
 * excluded (RTR and standard id).
57
 * excluded (RTR and standard id).
58
 */
58
 */
59
typedef struct {
59
typedef struct {
-
 
60
#ifdef MODULE_APPLICATION
-
 
61
    union {
-
 
62
        uint32_t Id;    /**< CAN extended ID (29 bits). */
-
 
63
        struct {
-
 
64
            uint8_t Command;
-
 
65
            uint8_t ModuleId;
-
 
66
            uint8_t ModuleType;
-
 
67
            uint8_t ClassAndDirection;
-
 
68
        } Header;
-
 
69
    };
-
 
70
#else
60
    unsigned long Id; /**< CAN extended ID (29 bits). */
71
    unsigned long Id; /**< CAN extended ID (29 bits). */
-
 
72
#endif
61
    char Length; /**< Data length [0,8]. */
73
    char Length; /**< Data length [0,8]. */
62
    unsigned char Data[8]; /**< Data array. Only the first \c Length elements are valid. */
74
    unsigned char Data[8]; /**< Data array. Only the first \c Length elements are valid. */
63
#if (STDCAN_FILTER)
75
#if (STDCAN_FILTER)
64
    unsigned char Match; /**< Filter id that matched this message. */
76
    unsigned char Match; /**< Filter id that matched this message. */
65
#endif
77
#endif
66
} StdCan_Msg_t;
78
} StdCan_Msg_t;
-
 
79
 
-
 
80
#define StdCan_Ret_class(Header) (uint8_t)((Header.ClassAndDirection >> 1) & 0x0F)
-
 
81
#define StdCan_Set_class(Header, CLASS) Header.ClassAndDirection &= 0x01; Header.ClassAndDirection |= (CLASS << 1);
-
 
82
#define StdCan_Ret_direction(Header) (uint8_t)(Header.ClassAndDirection & 0x01)
-
 
83
#define StdCan_Set_direction(Header, DIR) Header.ClassAndDirection &= 0xfe; Header.ClassAndDirection |= DIR;
-
 
84
#define NODE_HW_ID_BYTE3 (uint8_t)((NODE_HW_ID>>24)&0xff)
-
 
85
#define NODE_HW_ID_BYTE2 (uint8_t)((NODE_HW_ID>>16)&0xff)
-
 
86
#define NODE_HW_ID_BYTE1 (uint8_t)((NODE_HW_ID>>8)&0xff)
-
 
87
#define NODE_HW_ID_BYTE0 (uint8_t)((NODE_HW_ID)&0xff)
67
 
88
 
68
/**
89
/**
69
 * @brief Node descriptor.
90
 * @brief Node descriptor.
70
 *
91
 *
71
 * Describes the node and the application running on it.
92
 * Describes the node and the application running on it.
Line 77... Line 98...
77
    unsigned char Id; /**< Node ID. */
98
    unsigned char Id; /**< Node ID. */
78
} Node_Desc_t;
99
} Node_Desc_t;
79
 
100
 
80
//(why have constats passed as parameters? they are defined at compiletime /arune)
101
//(why have constats passed as parameters? they are defined at compiletime /arune)
81
 
102
 
82
 
103
 
83
/**
104
/**
84
 * @brief Initialize StdCan.
105
 * @brief Initialize StdCan.
85
 *
106
 *
86
 * Initializes the StdCan and lower layers and sends an Application Startup
107
 * Initializes the StdCan and lower layers and sends an Application Startup
87
 * Message.
108
 * Message.
Line 89... Line 110...
89
 * @param node_desc
110
 * @param node_desc
90
 *      Pointer to node descriptor, containing information about the type and
111
 *      Pointer to node descriptor, containing information about the type and
91
 *      version of the application that should be announced in startup and
112
 *      version of the application that should be announced in startup and
92
 *      heartbeat messages.
113
 *      heartbeat messages.
93
 */
114
 */
-
 
115
#ifdef MODULE_APPLICATION
-
 
116
StdCan_Ret_t StdCan_Init(void);
-
 
117
#else 
94
StdCan_Ret_t StdCan_Init(Node_Desc_t* node_desc);
118
StdCan_Ret_t StdCan_Init(Node_Desc_t* node_desc);
95
 
119
#endif
96
/**
120
/**
97
 * @brief Get a message.
121
 * @brief Get a message.
98
 *
122
 *
99
 * Retrieves a message from the receive queue.
123
 * Retrieves a message from the receive queue.
100
 *
124
 *