X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/ad1d46af5c8562e90a3f8564cf511213ff1f1745..a9296605ae899d82c9e8f682eafe63d999c4a57b:/embedded/app/usbcan/main.c diff --git a/embedded/app/usbcan/main.c b/embedded/app/usbcan/main.c index 4b91631..71fb5e7 100644 --- a/embedded/app/usbcan/main.c +++ b/embedded/app/usbcan/main.c @@ -62,14 +62,13 @@ //#include "./can/ul_usb1.h" -//#include "./can/setup.h" +#include "./can/setup.h" #include "./usb/usb_defs.h" #include "./usb/usb_vend.h" -// DEBUG CAN + #include "can/lpc17xx_can.h" -// DEBUG CAN - end #define MASK_EP1RX 0x01 #define MASK_EP1TX 0x02 @@ -106,12 +105,10 @@ LT_TIMER_IMP(lt_2sec) typedef void (*FNC)(); //function ptr - /*********************************************************************** * global variables ***********************************************************************/ - usb_device_t usb_device; usb_ep_t eps[NUM_ENDPOINTS]; @@ -211,7 +208,6 @@ int main(void) int i,size,m=0; CANMSG("Starting USBCAN module firmware...\n"); - // volatile int i=0; bootloader_run=0; @@ -230,22 +226,13 @@ int main(void) sys_err(); } -// !!! DEBUG - first version, only transmitting CAN messages withnout usage of queue system from LinCAN - - // CAN - CAN_init(1000000); - // CAN end - -/* //*********************************************************************** // * CAN device initialization - device side (adapted from LinCAN setup.c) // *********************************************************************** - // DEBUG - //can_init(); // only for successful compiling (defined in can_lpcbusemu.c) - - +// useless with lpc17xx (defined in can_lpcbusemu.c) +// can_init(); DEBUGMSG("Initiating CAN device initialization\n"); @@ -274,8 +261,13 @@ int main(void) } memset(candev->hwspecops, 0, sizeof(struct hwspecops_t)); + + // DEBUG - //ul_usb1_register(candev->hwspecops); // only for successful compiling (defined in ul_usb1.c) + //ul_usb1_register(candev->hwspecops); //(defined in ul_usb1.c) + // register for another board: + can_lmc1_register(candev->hwspecops); + bd=baudrate[0]; @@ -283,6 +275,7 @@ int main(void) CANMSG("HW data could not be initialized\n"); sys_err(); } + // Alocate and initialize the chip structures for (chipnr=0; chipnr < candev->nr_all_chips; chipnr++) { // if(chipnrnr_all_chips; chipnr++) { struct canchip_t *chip=candev->chip[chipnr]; int objnr; @@ -303,11 +299,17 @@ int main(void) if(m>=0) m++; } } + + if (candev->hwspecops->request_io(candev)) sys_err(); candev->flags|=CANDEV_IO_RESERVED; + + if (candev->hwspecops->reset(candev)) sys_err(); + + for(chipnr=0; chipnrnr_all_chips; chipnr++) { if((chip=candev->chip[chipnr])==NULL) continue; @@ -319,11 +321,12 @@ int main(void) chip->flags |= CHIP_ATTACHED; -// Interrupts from chip are served in main cycle -// if(can_chip_setup_irq(chip)<0) { -// CANMSG("Error to setup chip IRQ\n"); -// sys_err(); -// } + // used with lpc17xx: + if(can_chip_setup_irq(chip)<0) { + CANMSG("Error to setup chip IRQ\n"); + sys_err(); + } + } if (candev->flags & CANDEV_PROGRAMMABLE_IRQ) @@ -336,6 +339,7 @@ int main(void) // * CAN device initialization - client side (adapted from LinCAN open.c) // *********************************************************************** + chip=candev->chip[0]; obj=chip->msgobj[0]; atomic_inc(&obj->obj_used); @@ -354,6 +358,7 @@ int main(void) } // End of chip configuration + canuser = (struct canuser_t *)malloc(sizeof(struct canuser_t)); if(canuser == NULL) sys_err(); canuser->flags=0; @@ -381,7 +386,7 @@ int main(void) canque_edge_decref(canuser->rx_edge0); canque_edge_decref(edge); -*/ + /*********************************************************************** * USB Init @@ -424,14 +429,13 @@ int main(void) usb_check_events(&usb_device); usb_control_response(&usb_device); -// DEBUG +// useless with lpc17xx: // 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 - // DEBUG - unused queue system (yet) - //if (canque_get_inslot(qends, &qedge, &slot, 0)>=0){ //Free slot obtained + 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){ @@ -459,24 +463,22 @@ int main(void) /* 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); - // DEBUG - unused queue system (yet) - //slot->msg=canmsg; - //canque_put_inslot(qends, qedge, slot); - CAN_send(&canmsg); } - - // DEBUG - unused queue system (yet) - //else - // canque_abort_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; - // DEBUG - //} - + + } + /* if (size==2){ uint8_t val; @@ -496,8 +498,7 @@ int main(void) }*/ } - // DEBUG - only transmitting CAN messages, no reading (yet) - /* + if(usb_device.ep_events & MASK_EP1TX){ //EP1TX - data transmitted if(canque_test_outslot(qends, &qedge, &slot)>=0){ DEBUGMSG("CAN message ready to send over usb\n"); @@ -528,9 +529,11 @@ int main(void) timer_tx_off=50; //rozsviceni diod pri vysilani CLR_OUT_PIN(LED_PORT,LED1_BIT); usb_device.ep_events &= ~MASK_EP1TX; + } + } - */ + //if (usb_can_send && )