X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/26fbfa454cdb986c0e18b41bda3a0e8ec54128ba..f9522530e37184c3dcfb818a35f55ec3f177406f:/embedded/app/usbcan/main.c diff --git a/embedded/app/usbcan/main.c b/embedded/app/usbcan/main.c index 97d9785..b9271e3 100644 --- a/embedded/app/usbcan/main.c +++ b/embedded/app/usbcan/main.c @@ -15,6 +15,11 @@ #include #include +#include +#if __BYTE_ORDER == __BIG_ENDIAN + #include +#endif + #include "./can/can.h" #include "./can/sja1000p.h" #include "./can/main.h" @@ -26,6 +31,8 @@ #include "./can/ul_usb1.h" //#include "./can/setup.h" +#include "./usb/usb_vend.h" + #define MASK_EP1RX 0x01 #define MASK_EP1TX 0x02 @@ -83,6 +90,8 @@ struct canhardware_t *hardware_p=&canhardware; struct canchip_t *chips_p[MAX_TOT_CHIPS]; struct msgobj_t *objects_p[MAX_TOT_MSGOBJS]; +struct canuser_t *canuser; + /*********************************************************************** * SOMETHING BAD HAPPENED @@ -134,7 +143,6 @@ int main(void) 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; @@ -312,12 +320,26 @@ int main(void) 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) + 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;i2047 */ if (canmsg.id & ~0x7ffl & MSG_ID_MASK ) canmsg.flags |= MSG_EXT; @@ -352,10 +374,26 @@ int main(void) 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;imsg.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;imsg.length;i++){ + *(uint8_t *)(ep1_tx_buff+8+i)=slot->msg.data[i]; + } + for (;i