Subversion Repositories HomeAutomation

Rev

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

Rev 693 Rev 789
Line 107... Line 107...
107
    else
107
    else
108
        retval = StdCan_Ret_Fail;
108
        retval = StdCan_Ret_Fail;
109
#endif
109
#endif
110
   
110
   
111
    //TODO: Do something with the Node Descriptor.
111
    //TODO: Do something with the Node Descriptor. 
-
 
112
    //(why have constats passed as parameters? they are defined at compiletime /arune)
-
 
113
#if defined(_AVRLIB_BIOS_)
-
 
114
    /* TODO: When a Tx queue is implemented, the startup message should
-
 
115
     * be sent via StdCan_Put instead of directly to lower layer.
-
 
116
     */
-
 
117
    Can_Message_t Startup;
-
 
118
   
-
 
119
    /* Set up Startup message format. */
-
 
120
    Startup.ExtendedFlag = 1;
-
 
121
    Startup.RemoteFlag = 0;
-
 
122
    Startup.DataLength = 4;
-
 
123
    Startup.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
-
 
124
    Startup.Data.bytes[1] = APP_TYPE&0xff;
-
 
125
    Startup.Data.bytes[0] = (APP_TYPE>>8)&0xff;
-
 
126
    Startup.Data.bytes[3] = APP_VERSION&0xff;
-
 
127
    Startup.Data.bytes[2] = (APP_VERSION>>8)&0xff;
-
 
128
   
-
 
129
    /* Try to send it. */
-
 
130
    Can_Send(&Startup);
-
 
131
#endif
112
   
132
   
113
    return retval;
133
    return retval;
114
}
134
}
115
 
135
 
116
StdCan_Ret_t StdCan_Get(StdCan_Msg_t* msg)
136
StdCan_Ret_t StdCan_Get(StdCan_Msg_t* msg)
117
{
137
{
118
    unsigned char n;
138
    unsigned char n;
119
   
139
   
120
    /* Check if there's a message waiting. */
140
    /* Check if there's a message waiting. */
121
    if (RxQ_Len) {
141
    if (RxQ_Len) {
122
       
142
       
123
        /* Copy message to user buffer. */
143
        /* Copy message to user buffer. */
124
        msg->Id     = RxQ[RxQ_Rd_idx].Id;
144
        msg->Id     = RxQ[RxQ_Rd_idx].Id;
125
        msg->Length = RxQ[RxQ_Rd_idx].Length;
145
        msg->Length = RxQ[RxQ_Rd_idx].Length;
126
        //TODO: Consider a mempcy() of the entire message.
146
        //TODO: Consider a mempcy() of the entire message.
127
        for (n = 0; n < RxQ[RxQ_Rd_idx].Length; n++) {
147
        for (n = 0; n < RxQ[RxQ_Rd_idx].Length; n++) {
128
            msg->Data[n] = RxQ[RxQ_Rd_idx].Data[n];
148
            msg->Data[n] = RxQ[RxQ_Rd_idx].Data[n];
129
        }
149
        }
130
       
150
       
131
        /* Increment read index and decrease queue length. */
151
        /* Increment read index and decrease queue length. */
132
        if (++RxQ_Rd_idx >= STDCAN_RX_QUEUE_SIZE) RxQ_Rd_idx = 0;
152
        if (++RxQ_Rd_idx >= STDCAN_RX_QUEUE_SIZE) RxQ_Rd_idx = 0;
133
        RxQ_Len--;
153
        RxQ_Len--;
134
       
154
       
135
        return StdCan_Ret_OK;
155
        return StdCan_Ret_OK;
136
    } else {
156
    } else {
137
        /* Queue is empty. */
157
        /* Queue is empty. */
138
        return StdCan_Ret_Empty;
158
        return StdCan_Ret_Empty;
139
    }
159
    }
-
 
160
}
-
 
161
 
-
 
162
unsigned char StdCan_Get_Pending(void)
-
 
163
{
-
 
164
    return RxQ_Len;
140
}
165
}
141
 
166
 
142
StdCan_Ret_t StdCan_Put(StdCan_Msg_t* msg)
167
StdCan_Ret_t StdCan_Put(StdCan_Msg_t* msg)
143
{
168
{
144
    Can_Message_t Can_Msg;
169
    Can_Message_t Can_Msg;