Exemplo n.º 1
0
MUST_CHECK s32
nu__Can__tx(const struct nu__Can *c, CAN_CHANNEL chn, enum nu__Can__id_type id_type,
        u16 sid, u32 eid, u32 rtr, const void *data, size_t n)
{
    s32 err;

    CANTxMessageBuffer *message = CANGetTxMessageBuffer(c->module, chn);

    if (n > 8)
        return -EINVAL;

    if ((err = go_normal_mode(c)) < 0)
        return err;

    /* clear message data */
    memset(message, 0, sizeof(CANTxMessageBuffer));

    /* insert SID/EID information */
    message->msgEID.IDE = (NU_CAN_EXTENDED_ID == id_type);
    message->msgSID.SID = BITFIELD_CAST(sid, 11);  /* 11   bits */
    message->msgEID.DLC = BITFIELD_CAST(n, 4);   /* 4    bits */
    message->msgEID.RTR = BITFIELD_CAST(rtr, 1);   /* 1    bit; 1 = remote transmission request enabled */
    if (NU_CAN_EXTENDED_ID == id_type) /* EID is indicated by IDTypeExtended = 1 */
        message->msgEID.EID = BITFIELD_CAST(eid, 18);    /* 18 bits */

    if (n)
        memcpy(message->data, (const byte *)data, n);

    CANUpdateChannel(c->module, chn);
    CANFlushTxChannel(c->module, chn);

    return 0;
}
Exemplo n.º 2
0
void CAN1TxSendLEDMsg(BYTE data0)
{
    /* This function will send a message to
     * CAN2 with SID 202. The data payload
     * size is 1 byte. The value of the LED5Status
     * will be toggled and then sent as
     * the payload. CAN1 Channel 0 is used
    * to send the message*/

    CANTxMessageBuffer * message;

    /* Get a pointer to the next buffer in the channel
    * check if the returned value is null. */

    message = CANGetTxMessageBuffer(CAN1,CAN_CHANNEL0);

    if(message != NULL)
    {

        /* Form a Standard ID CAN message.
         * Start by clearing the buffer.
         * Send message to CAN2.
         * IDE = 0 means Standard ID message.
         * Send one byte of data.
         * This is the payload.					*/


        message->messageWord[0] = 0;
        message->messageWord[1] = 0;
        message->messageWord[2] = 0;
        message->messageWord[3] = 0;

        message->msgSID.SID 	= 0x202;
        message->msgEID.IDE 	= 0;
        message->msgEID.DLC 	= 1;
        message->data[0]        = data0;

        /* This function lets the CAN module
         * know that the message processing is done
         * and message is ready to be processed. */

        CANUpdateChannel(CAN1,CAN_CHANNEL0);

        /* Direct the CAN module to flush the
         * TX channel. This will send any pending
         * message in the TX channel. */

        CANFlushTxChannel(CAN1,CAN_CHANNEL0);

    }
}