#include <lpciap.h>
#include <lpciap_kvpb.h>
+#include <endian.h>
+#if __BYTE_ORDER == __BIG_ENDIAN
+ #include <byteswap.h>
+#endif
+
#include "./can/can.h"
#include "./can/sja1000p.h"
#include "./can/main.h"
#include "./can/ul_usb1.h"
//#include "./can/setup.h"
+#include "./usb/usb_vend.h"
+
#define MASK_EP1RX 0x01
#define MASK_EP1TX 0x02
struct canchip_t *chips_p[MAX_TOT_CHIPS];
struct msgobj_t *objects_p[MAX_TOT_MSGOBJS];
+struct canuser_t *canuser;
+
/***********************************************************************
* SOMETHING BAD HAPPENED
struct candevice_t *candev;
struct canchip_t *chip=NULL;
struct msgobj_t *obj;
- struct canuser_t *canuser;
struct canque_ends_t *qends;
struct canque_edge_t *edge,*qedge;
struct canque_slot_t *slot;
if (canque_get_inslot(qends, &qedge, &slot, 0)>=0){ //Free slot obtained
size=usb_udev_read_endpoint(&eps[0],ep1_rx_buff,USB_MAX_PACKET);
if (size==16){
+ uint16_t msgflags;
+ uint32_t msgid;
canmsg.cob=0;
- canmsg.id=*((uint32_t*)ep1_rx_buff);
- canmsg.flags=(*((uint32_t*)(ep1_rx_buff+4)))>>8;
- canmsg.length=(*((uint16_t*)(ep1_rx_buff+6)))&0x00FF;
- for (i=0;i<CAN_MSG_LENGTH;i++){
- canmsg.data[i]=*((unsigned char*)(ep1_rx_buff+8+i));
+ canmsg.length=*(uint8_t *)(ep1_rx_buff+1);
+ if (canmsg.length > CAN_MSG_LENGTH)
+ canmsg.length=CAN_MSG_LENGTH;
+ msgflags=*(uint16_t *)(ep1_rx_buff+2);
+ msgid=*(uint32_t *)(ep1_rx_buff+4);
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ msgflags = bswap_16( msgflags);
+ msgid = bswap_32( msgid);
+ #endif
+ canmsg.flags=msgflags;
+ canmsg.id=msgid;
+
+ for (i=0;i<canmsg.length;i++){
+ canmsg.data[i]=*(unsigned char*)(ep1_rx_buff+8+i);
+ }
+ for (;i<CAN_MSG_LENGTH;i++){
+ canmsg.data[i]=0;
}
/* Automatic selection of extended format if ID>2047 */
if (canmsg.id & ~0x7ffl & MSG_ID_MASK ) canmsg.flags |= MSG_EXT;
if(usb_device.ep_events & MASK_EP1TX){ //EP1TX - data transmitted
if(canque_test_outslot(qends, &qedge, &slot)>=0){
- (*((uint32_t*)ep1_tx_buff))=slot->msg.id;
- (*((uint32_t*)(ep1_tx_buff+4)))=slot->msg.flags<<8 | (slot->msg.length&0xFF);
- for (i=0;i<CAN_MSG_LENGTH;i++){
- (*((uint32_t*)(ep1_tx_buff+8+i)))=slot->msg.data[i];
+ uint16_t msgflags;
+ uint32_t msgid;
+
+ *(uint8_t *)(ep1_tx_buff)=0;
+ *(uint8_t *)(ep1_tx_buff+1)=slot->msg.length;
+
+ msgflags=slot->msg.flags;
+ msgid=slot->msg.id;
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ msgflags = bswap_16( msgflags);
+ msgid = bswap_32( msgid);
+ #endif
+
+ *(uint16_t *)(ep1_tx_buff+2)=msgflags;
+ *(uint32_t *)(ep1_tx_buff+4)=msgid;
+ for (i=0;i<slot->msg.length;i++){
+ *(uint8_t *)(ep1_tx_buff+8+i)=slot->msg.data[i];
+ }
+ for (;i<CAN_MSG_LENGTH;i++){
+ *(uint8_t *)(ep1_tx_buff+8+i)=0;
}
usb_udev_write_endpoint(&eps[1],ep1_tx_buff,USB_MAX_PACKET);