Subversion Repositories HomeAutomation

Rev

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

Rev 789 Rev 869
Line 80... Line 80...
80
         * message in the queue.
80
         * message in the queue.
81
         */
81
         */
82
    }
82
    }
83
}
83
}
84
 
84
 
-
 
85
#ifdef MODULE_APPLICATION
-
 
86
StdCan_Ret_t StdCan_Init(void)
-
 
87
{
-
 
88
#else
85
StdCan_Ret_t StdCan_Init(Node_Desc_t* node_desc)
89
StdCan_Ret_t StdCan_Init(Node_Desc_t* node_desc)
86
{
90
{
-
 
91
#endif
87
    StdCan_Ret_t retval;
92
    StdCan_Ret_t retval;
88
   
93
   
89
    /* Reset all queue variables. */
94
    /* Reset all queue variables. */
90
    RxQ_Rd_idx = 0;
95
    RxQ_Rd_idx = 0;
91
    RxQ_Wr_idx = 0;
96
    RxQ_Wr_idx = 0;
Line 110... Line 115...
110
   
115
   
111
    //TODO: Do something with the Node Descriptor. 
116
    //TODO: Do something with the Node Descriptor. 
112
    //(why have constats passed as parameters? they are defined at compiletime /arune)
117
    //(why have constats passed as parameters? they are defined at compiletime /arune)
113
#if defined(_AVRLIB_BIOS_)
118
#if defined(_AVRLIB_BIOS_)
114
    /* TODO: When a Tx queue is implemented, the startup message should
119
    /* TODO: When a Tx queue is implemented, the startup message should
115
     * be sent via StdCan_Put instead of directly to lower layer.
120
     * be sent via StdCan_Put instead of directly to lower layer.
116
     */
121
     */
117
    Can_Message_t Startup;
122
    Can_Message_t Startup;
118
   
123
   
119
    /* Set up Startup message format. */
124
    /* Set up Startup message format. */
120
    Startup.ExtendedFlag = 1;
125
    Startup.ExtendedFlag = 1;
121
    Startup.RemoteFlag = 0;
126
    Startup.RemoteFlag = 0;
122
    Startup.DataLength = 4;
127
    Startup.DataLength = 4;
-
 
128
#ifdef MODULE_APPLICATION
-
 
129
    Startup.Id = (CAN_NMT << CAN_SHIFT_CLASS) | (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE);
-
 
130
    Startup.Data.bytes[0] = NODE_HW_ID&0xff;
-
 
131
    Startup.Data.bytes[1] = (NODE_HW_ID>>8)&0xff;
-
 
132
    Startup.Data.bytes[2] = (NODE_HW_ID>>16)&0xff;
-
 
133
    Startup.Data.bytes[3] = (NODE_HW_ID>>24)&0xff;
-
 
134
#else
123
    Startup.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
135
    Startup.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
124
    Startup.Data.bytes[1] = APP_TYPE&0xff;
136
    Startup.Data.bytes[1] = APP_TYPE&0xff;
125
    Startup.Data.bytes[0] = (APP_TYPE>>8)&0xff;
137
    Startup.Data.bytes[0] = (APP_TYPE>>8)&0xff;
126
    Startup.Data.bytes[3] = APP_VERSION&0xff;
138
    Startup.Data.bytes[3] = APP_VERSION&0xff;
127
    Startup.Data.bytes[2] = (APP_VERSION>>8)&0xff;
139
    Startup.Data.bytes[2] = (APP_VERSION>>8)&0xff;
128
   
140
#endif
129
    /* Try to send it. */
141
    /* Try to send it. */
130
    Can_Send(&Startup);
142
    Can_Send(&Startup);
131
#endif
143
#endif
132
   
144
   
133
    return retval;
145
    return retval;
Line 154... Line 166...
154
       
166
       
155
        return StdCan_Ret_OK;
167
        return StdCan_Ret_OK;
156
    } else {
168
    } else {
157
        /* Queue is empty. */
169
        /* Queue is empty. */
158
        return StdCan_Ret_Empty;
170
        return StdCan_Ret_Empty;
159
    }
171
    }
160
}
172
}
161
 
173
 
162
unsigned char StdCan_Get_Pending(void)
174
unsigned char StdCan_Get_Pending(void)
163
{
175
{
164
    return RxQ_Len;
176
    return RxQ_Len;
165
}
177
}
166
 
178
 
Line 183... Line 195...
183
    Can_Msg.DataLength = msg->Length;
195
    Can_Msg.DataLength = msg->Length;
184
    for (n = 0; n < msg->Length; n++) {
196
    for (n = 0; n < msg->Length; n++) {
185
        Can_Msg.Data.bytes[n] = msg->Data[n];
197
        Can_Msg.Data.bytes[n] = msg->Data[n];
186
    }
198
    }
187
   
199
 
188
    if (Can_Send(&Can_Msg) == CAN_OK)
200
    if (Can_Send(&Can_Msg) == CAN_OK) {
-
 
201
#ifdef MODULE_APPLICATION
-
 
202
        Can_Process(&Can_Msg);
-
 
203
#endif
189
        return StdCan_Ret_OK;
204
        return StdCan_Ret_OK;
-
 
205
    }
190
    else
206
    else
191
        return StdCan_Ret_Full;
207
        return StdCan_Ret_Full;
192
}
208
}
193
 
209
 
194
void StdCan_SendHeartbeat(uint8_t n)
210
void StdCan_SendHeartbeat(uint8_t n)
Line 199... Line 215...
199
    Can_Message_t Heartbeat;
215
    Can_Message_t Heartbeat;
200
   
216
   
201
    /* Set up Heartbeat message format. */
217
    /* Set up Heartbeat message format. */
202
    Heartbeat.ExtendedFlag = 1;
218
    Heartbeat.ExtendedFlag = 1;
203
    Heartbeat.RemoteFlag = 0;
219
    Heartbeat.RemoteFlag = 0;
-
 
220
#ifdef MODULE_APPLICATION
-
 
221
    Heartbeat.DataLength = 4;
-
 
222
    Heartbeat.Id = (CAN_NMT << CAN_SHIFT_CLASS) | (CAN_NMT_HEARTBEAT << CAN_SHIFT_NMT_TYPE);
-
 
223
    Heartbeat.Data.bytes[0] = NODE_HW_ID&0xff;
-
 
224
    Heartbeat.Data.bytes[1] = (NODE_HW_ID>>8)&0xff;
-
 
225
    Heartbeat.Data.bytes[2] = (NODE_HW_ID>>16)&0xff;
-
 
226
    Heartbeat.Data.bytes[3] = (NODE_HW_ID>>24)&0xff;
-
 
227
#else
-
 
228
   
-
 
229
   
204
    Heartbeat.DataLength = 0;
230
    Heartbeat.DataLength = 0;
205
    Heartbeat.Id = (CAN_NMT << CAN_SHIFT_CLASS)
231
    Heartbeat.Id = (CAN_NMT << CAN_SHIFT_CLASS)
206
                 | (CAN_NMT_HEARTBEAT << CAN_SHIFT_NMT_TYPE)
232
                 | (CAN_NMT_HEARTBEAT << CAN_SHIFT_NMT_TYPE)
207
                 | (NODE_ID << CAN_SHIFT_NMT_SID);
233
                 | (NODE_ID << CAN_SHIFT_NMT_SID);
-
 
234
#endif
208
   
235
   
209
    /* Try to send it. */
236
    /* Try to send it. */
210
    Can_Send(&Heartbeat);
237
    Can_Send(&Heartbeat);
211
}
238
}
212
 
239