- if ((usb_device.ep_events & MASK_EP1RX)&&(usb_can_send)) { //EP1RX
- int size;
- uint8_t *data;
- uint8_t val;
- size=usb_udev_read_endpoint(&eps[0],ep1_rx_buff,USB_MAX_PACKET);
- data=(uint8_t *)ep1_rx_buff;
- if (size==2){
- if (((*data)&CAN_OP_MASK)==CAN_OP_READ){ // Get data from CAN device and return to caller
- can_read((*data) & 0x7F,&val);
+ if (!(IO0PIN&P0_SJA1000_INT_PIN)) //INT PIN is inverted
+ chip->chipspecops->irq_handler(0,chip);
+
+ if (usb_device.ep_events & MASK_EP1RX) { //EP1RX - data waiting to receive
+ if (canque_get_inslot(qends, &qedge, &slot, 0)>=0){ //Free slot obtained
+ size=usb_udev_read_endpoint(&eps[0],ep1_rx_buff,16);
+ if (size==16){
+ uint16_t msgflags;
+ uint32_t msgid;
+ canmsg.cob=0;
+ 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;
+ /* has been dependent on "extended" option */
+ slot->msg=canmsg;
+ canque_put_inslot(qends, qedge, slot);
+ }
+ else
+ canque_abort_inslot(qends,qedge,slot);
+ timer_rx_off=50; //rosviceni diody pri prijmu
+ CLR_OUT_PIN(LED_PORT,LED2_BIT);
+ usb_device.ep_events &= ~MASK_EP1RX;
+ }
+
+
+/* if (size==2){
+ uint8_t val;
+ if ((data[0]&CAN_OP_MASK)==CAN_OP_READ){ // Get data from CAN device and return to caller
+ val = can_read(data[0] & ~CAN_OP_MASK);