ECU/GSM/dist/src/CAN.c
void CAN_rdMsg_0 (CAN_msg *msg)  {
	// Read identifier information
	if ((CAN1->sFIFOMailBox[0].RIR & CAN_ID_EXT) == 0) { // Standard ID

		msg->format = STANDARD_FORMAT;


		msg->id     = (u32)0x000007FF & (CAN1->sFIFOMailBox[0].RIR >> 21);
	}  else  {                                          // Extended ID
		msg->format = EXTENDED_FORMAT;

		msg->id     = (u32)0x0003FFFF & (CAN1->sFIFOMailBox[0].RIR >> 3);
	}
	// Read type information
	if ((CAN1->sFIFOMailBox[0].RIR & CAN_RTR_REMOTE) == 0) {

		msg->type =   DATA_FRAME;                     // DATA   FRAME

	}  else  {
		msg->type = REMOTE_FRAME;                   // REMOTE FRAME
	}
	// Read length (number of received bytes)
	msg->len = (u8)0x0000000F & CAN1->sFIFOMailBox[0].RDTR;
	// Read data bytes
	msg->data[0] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR);
	msg->data[1] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR >> 8);
	msg->data[2] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR >> 16);
	msg->data[3] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR >> 24);

	msg->data[4] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR);
	msg->data[5] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR >> 8);
	msg->data[6] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR >> 16);
	msg->data[7] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR >> 24);
	CAN_vidReleaseMessage();
}
/*----------------------------------------------------------------------------
  read a message from CAN peripheral and release it
 *----------------------------------------------------------------------------*/
read a message from CAN peripheral and release it
read a message from CAN peripheral and release it
void CAN_rdMsg_0 (CAN_msg *msg)  {
	if ((CAN1->sFIFOMailBox[0].RIR & CAN_ID_EXT) == 0) { 
		msg->format = STANDARD_FORMAT;
		msg->id     = (u32)0x000007FF & (CAN1->sFIFOMailBox[0].RIR >> 21);
	}  else  {                                          
		msg->format = EXTENDED_FORMAT;
		msg->id     = (u32)0x0003FFFF & (CAN1->sFIFOMailBox[0].RIR >> 3);
	}
	if ((CAN1->sFIFOMailBox[0].RIR & CAN_RTR_REMOTE) == 0) {
		msg->type =   DATA_FRAME;                     
	}  else  {
		msg->type = REMOTE_FRAME;                   
	}
	msg->len = (u8)0x0000000F & CAN1->sFIFOMailBox[0].RDTR;
	msg->data[0] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR);
	msg->data[1] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR >> 8);
	msg->data[2] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR >> 16);
	msg->data[3] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDLR >> 24);
	msg->data[4] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR);
	msg->data[5] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR >> 8);
	msg->data[6] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR >> 16);
	msg->data[7] = (u32)0x000000FF & (CAN1->sFIFOMailBox[0].RDHR >> 24);
	CAN_vidReleaseMessage();
}
void CAN_rdMsg_0 ( CAN_msg * msg ) { if ( ( CAN1 -> sFIFOMailBox [ 0 ] . RIR & CAN_ID_EXT ) == 0 ) { msg -> format = STANDARD_FORMAT ; msg -> id = ( u32 ) 0x000007FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RIR >> 21 ) ; } else { msg -> format = EXTENDED_FORMAT ; msg -> id = ( u32 ) 0x0003FFFF & ( CAN1 -> sFIFOMailBox [ 0 ] . RIR >> 3 ) ; } if ( ( CAN1 -> sFIFOMailBox [ 0 ] . RIR & CAN_RTR_REMOTE ) == 0 ) { msg -> type = DATA_FRAME ; } else { msg -> type = REMOTE_FRAME ; } msg -> len = ( u8 ) 0x0000000F & CAN1 -> sFIFOMailBox [ 0 ] . RDTR ; msg -> data [ 0 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDLR ) ; msg -> data [ 1 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDLR >> 8 ) ; msg -> data [ 2 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDLR >> 16 ) ; msg -> data [ 3 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDLR >> 24 ) ; msg -> data [ 4 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDHR ) ; msg -> data [ 5 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDHR >> 8 ) ; msg -> data [ 6 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDHR >> 16 ) ; msg -> data [ 7 ] = ( u32 ) 0x000000FF & ( CAN1 -> sFIFOMailBox [ 0 ] . RDHR >> 24 ) ; CAN_vidReleaseMessage ( ) ; }
read a message from CAN peripheral and release it
read a message from CAN peripheral and release it
// Read identifier information // Standard ID // Extended ID // Read type information // DATA   FRAME // REMOTE FRAME // Read length (number of received bytes) // Read data bytes