コード例 #1
0
ファイル: CAN_MHS.cpp プロジェクト: JiteshPatel/busmaster
/**
* \brief         Sends STCAN_MSG structure from the client dwClientID.
* \param[in]     dwClientID is the client ID
* \param[in]     sMessage is the application specific CAN message structure
* \return        S_OK for success, S_FALSE for failure
*/
HRESULT CDIL_CAN_MHS::CAN_SendMsg(DWORD dwClientID, const STCAN_MSG& sMessage)
{
    struct TCanMsg msg;
    static SACK_MAP sAckMap;
    HRESULT hResult;

    VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE);

    hResult = S_FALSE;
    if (bClientIdExist(dwClientID))
    {
        if (sMessage.m_ucChannel <= sg_nNoOfChannels)
        {
            // msg Variable Initialisieren
            msg.MsgFlags = 0L;   // Alle Flags löschen, Stanadrt Frame Format,
            // keine RTR, Datenlänge auf 0
            if (sMessage.m_ucEXTENDED == 1)
            {
                msg.MsgEFF = 1;    // Nachricht im EFF (Ext. Frame Format) versenden
            }
            if (sMessage.m_ucRTR == 1)
            {
                msg.MsgRTR = 1;    // Nachricht als RTR Frame versenden
            }
            msg.Id = sMessage.m_unMsgID;
            msg.MsgLen = sMessage.m_ucDataLen;
            memcpy(msg.MsgData, &sMessage.m_ucData, msg.MsgLen);
            sAckMap.m_ClientID = dwClientID;
            sAckMap.m_Channel  = sMessage.m_ucChannel;
            sAckMap.m_MsgID    = msg.Id;
            vMarkEntryIntoMap(sAckMap);
            if (CanTransmit(0, &msg, 1) >= 0)
            {
                hResult = S_OK;
            }
            else
            {
                hResult = S_FALSE;
                sg_pIlog->vLogAMessage(A2T(__FILE__), __LINE__, _T(_("could not write can data into bus")));
            }
        }
        else
        {
            hResult = ERR_INVALID_CHANNEL;
        }
    }
    else
    {
        hResult = ERR_NO_CLIENT_EXIST;
    }
    return(hResult);
}
コード例 #2
0
ファイル: can.c プロジェクト: BitThunder/bitthunder
/**
 *	Note, this doesn't implement ulFlags specific options yet!
 **/
static BT_ERROR canWrite(BT_HANDLE hCan, BT_CAN_MESSAGE *pCanMessage) {
	volatile LPC17xx_CAN_REGS *pRegs = hCan->pRegs;
	BT_CAN_MESSAGE oMessage;

	BT_ERROR Error = BT_ERR_NONE;

	switch(hCan->eMode) {
	case BT_CAN_MODE_POLLED:
	{
		BT_u32 ulIndex;
		while ((ulIndex = canFindFreeBuffer(hCan)) == LPC17xx_CAN_NO_FREE_BUFFER) {
			BT_ThreadYield();
		}
		CanTransmit(hCan, pCanMessage);
		break;
	}

	case BT_CAN_MODE_BUFFERED:
	{
		BT_FifoWrite(hCan->hTxFifo, 1, pCanMessage, &Error);

		while (!BT_FifoIsEmpty(hCan->hTxFifo, &Error) && (canFindFreeBuffer(hCan) != LPC17xx_CAN_NO_FREE_BUFFER)) {
			BT_FifoRead(hCan->hTxFifo, 1, &oMessage, &Error);
			CanTransmit(hCan, &oMessage);
		}

		pRegs->CANIER |= LPC17xx_CAN_IER_TIE;	// Enable the interrupt

		break;
	}

	default:
		break;
	}
	return Error;
}
コード例 #3
0
ファイル: CAN_applCan.c プロジェクト: Timb00/Test
void ApplCanInitPowerOn(void)
{
   /* CAN driver */
   CanInitPowerOn();
   /* IL */

   CanOnline(CANChannel_0_XCP);
   CanTransmit(CanTxTxXCP);

   IlInitPowerOn();

   IlRxStart(CANChannel_0_XCP);
   IlTxStart(CANChannel_0_XCP);
   IlRxStart(CANChannel_1_PrivateCAN);
   IlTxStart(CANChannel_1_PrivateCAN);
}
コード例 #4
0
ファイル: can.c プロジェクト: BitThunder/bitthunder
void isr_CAN(BT_HANDLE hCan) {
	volatile LPC17xx_CAN_REGS *pRegs = hCan->pRegs;
	BT_ERROR Error;
	BT_CAN_MESSAGE oMessage;

	BT_u32 ulICR = pRegs->CANICR;

	if (ulICR & LPC17xx_CAN_ICR_RI) {
		CanReceive(g_CAN_HANDLES[0], &oMessage);
		BT_FifoWrite(hCan->hRxFifo, 1, &oMessage, &Error);
	}
	if (ulICR & LPC17xx_CAN_ICR_TI) {
		while (!BT_FifoIsEmpty(hCan->hTxFifo, &Error) && (canFindFreeBuffer(hCan) != LPC17xx_CAN_NO_FREE_BUFFER)) {
			BT_FifoRead(hCan->hTxFifo, 1, &oMessage, &Error);
			CanTransmit(hCan, &oMessage);
		}
	}
	if (BT_FifoIsEmpty(hCan->hTxFifo, &Error)) {
		pRegs->CANIER &= ~LPC17xx_CAN_IER_TIE;	// Disable the interrupt
	}
}