ECU/GSM/dist/src/CAN.c
void CAN_wrMsg (CAN_msg *msg, u8 u8MailBox)  {

	CAN1->sTxMailBox[u8MailBox].TIR  = (u32)0;      // Reset TIR register
	// Setup identifier information
	if (msg->format == STANDARD_FORMAT)
	{
		CAN1->sTxMailBox[u8MailBox].TIR |= (u32)(msg->id << 21) | (CAN_ID_STD);
	}
	else
	{    // Extended ID

		CAN1->sTxMailBox[u8MailBox].TIR |= (u32)(msg->id <<  3) | (CAN_ID_EXT);
	}
	// Setup type information
	if (msg->type == DATA_FRAME)
	{                 // DATA FRAME
		CAN1->sTxMailBox[u8MailBox].TIR |= (CAN_RTR_DATA);
		CAN1->sTxMailBox[u8MailBox].TDLR = (((u32)msg->data[3] << 24) |
				((u32)msg->data[2] << 16) |
				((u32)msg->data[1] <<  8) |
				((u32)msg->data[0])        );
		CAN1->sTxMailBox[u8MailBox].TDHR = (((u32)msg->data[7] << 24) |
				((u32)msg->data[6] << 16) |
				((u32)msg->data[5] <<  8) |
				((u32)msg->data[4])        );
	}
	else
	{                  // REMOTE FRAME
		CAN1->sTxMailBox[u8MailBox].TIR |= (CAN_RTR_REMOTE);
	}
	// Setup length
	CAN1->sTxMailBox[u8MailBox].TDTR &= ~CAN_TDTxR_DLC;
	CAN1->sTxMailBox[u8MailBox].TDTR |=  (msg->len & CAN_TDTxR_DLC);

	CAN1->IER |= CAN_IER_TMEIE;                      // enable  TME interrupt                     // enable  TME interrupt
	CAN1->sTxMailBox[u8MailBox].TIR |=  CAN_TIxR_TXRQ;       // transmit message
}
/*----------------------------------------------------------------------------
  wite a message to CAN peripheral and transmit it
 *----------------------------------------------------------------------------*/
wite a message to CAN peripheral and transmit it
wite a message to CAN peripheral and transmit it
void CAN_wrMsg (CAN_msg *msg, u8 u8MailBox)  {
	CAN1->sTxMailBox[u8MailBox].TIR  = (u32)0;      
	if (msg->format == STANDARD_FORMAT)
	{
		CAN1->sTxMailBox[u8MailBox].TIR |= (u32)(msg->id << 21) | (CAN_ID_STD);
	}
	else
	{    
		CAN1->sTxMailBox[u8MailBox].TIR |= (u32)(msg->id <<  3) | (CAN_ID_EXT);
	}
	if (msg->type == DATA_FRAME)
	{                 
		CAN1->sTxMailBox[u8MailBox].TIR |= (CAN_RTR_DATA);
		CAN1->sTxMailBox[u8MailBox].TDLR = (((u32)msg->data[3] << 24) |
				((u32)msg->data[2] << 16) |
				((u32)msg->data[1] <<  8) |
				((u32)msg->data[0])        );
		CAN1->sTxMailBox[u8MailBox].TDHR = (((u32)msg->data[7] << 24) |
				((u32)msg->data[6] << 16) |
				((u32)msg->data[5] <<  8) |
				((u32)msg->data[4])        );
	}
	else
	{                  
		CAN1->sTxMailBox[u8MailBox].TIR |= (CAN_RTR_REMOTE);
	}
	CAN1->sTxMailBox[u8MailBox].TDTR &= ~CAN_TDTxR_DLC;
	CAN1->sTxMailBox[u8MailBox].TDTR |=  (msg->len & CAN_TDTxR_DLC);
	CAN1->IER |= CAN_IER_TMEIE;                      
	CAN1->sTxMailBox[u8MailBox].TIR |=  CAN_TIxR_TXRQ;       
}
void CAN_wrMsg ( CAN_msg * msg , u8 u8MailBox ) { CAN1 -> sTxMailBox [ u8MailBox ] . TIR = ( u32 ) 0 ; if ( msg -> format == STANDARD_FORMAT ) { CAN1 -> sTxMailBox [ u8MailBox ] . TIR |= ( u32 ) ( msg -> id << 21 ) | ( CAN_ID_STD ) ; } else { CAN1 -> sTxMailBox [ u8MailBox ] . TIR |= ( u32 ) ( msg -> id << 3 ) | ( CAN_ID_EXT ) ; } if ( msg -> type == DATA_FRAME ) { CAN1 -> sTxMailBox [ u8MailBox ] . TIR |= ( CAN_RTR_DATA ) ; CAN1 -> sTxMailBox [ u8MailBox ] . TDLR = ( ( ( u32 ) msg -> data [ 3 ] << 24 ) | ( ( u32 ) msg -> data [ 2 ] << 16 ) | ( ( u32 ) msg -> data [ 1 ] << 8 ) | ( ( u32 ) msg -> data [ 0 ] ) ) ; CAN1 -> sTxMailBox [ u8MailBox ] . TDHR = ( ( ( u32 ) msg -> data [ 7 ] << 24 ) | ( ( u32 ) msg -> data [ 6 ] << 16 ) | ( ( u32 ) msg -> data [ 5 ] << 8 ) | ( ( u32 ) msg -> data [ 4 ] ) ) ; } else { CAN1 -> sTxMailBox [ u8MailBox ] . TIR |= ( CAN_RTR_REMOTE ) ; } CAN1 -> sTxMailBox [ u8MailBox ] . TDTR &= ~ CAN_TDTxR_DLC ; CAN1 -> sTxMailBox [ u8MailBox ] . TDTR |= ( msg -> len & CAN_TDTxR_DLC ) ; CAN1 -> IER |= CAN_IER_TMEIE ; CAN1 -> sTxMailBox [ u8MailBox ] . TIR |= CAN_TIxR_TXRQ ; }
wite a message to CAN peripheral and transmit it
wite a message to CAN peripheral and transmit it
// Reset TIR register // Setup identifier information // Extended ID // Setup type information // DATA FRAME // REMOTE FRAME // Setup length // enable  TME interrupt                     // enable  TME interrupt // transmit message