#include <stdio.h>
#include <system_def.h>
-#include <hal_intr.h>
+//#include <hal_intr.h>
#include "./can/can.h"
#include "./can/can_sysdep.h"
#include "./can/main.h"
#include <byteswap.h>
#endif
+// lpc17xx debug
+#include "./can/lpc17xx_can.h"
+// lpc17xx debug - end
+
extern struct canuser_t *canuser;
extern uint8_t vendor_ret;
return -1;
}
+int set_canbtr_complete_fnc(struct usb_ep_t *ep, int status){
+ int dest_chip;
+
+// int32_t rate,sjw,sampl_pt,flags;
+ uint32_t brp, sjw, tseg1, tseg2;
+
+ struct can_lmc1_chip_data *chip_data=NULL;
+
+ usb_device_t *udev=ep->udev;
+ unsigned char *data=ep->ptr - ep->actual;
+
+ if (udev->request.bRequest==USBCAN_VENDOR_SET_CANBTR){
+ dest_chip=(udev->request.wIndex);
+ if ((dest_chip>=MAX_TOT_CHIPS)||(dest_chip<0))
+ goto error;
+ if (!chips_p[dest_chip])
+ goto error;
+ if ((chip_data=((struct can_lmc1_chip_data*)(chips_p[dest_chip]->chip_data)))==NULL)
+ goto nodata;
+
+ brp=*(uint32_t *)(data);
+ sjw=*(uint32_t *)(data+4);
+ tseg1=*(uint32_t *)(data+8);
+ tseg2=*(uint32_t *)(data+12);
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ brp = bswap_32(brp);
+ sjw = bswap_32(sjw);
+ tseg1 = bswap_32(tseg1);
+ tseg2 = bswap_32(tseg2);
+ #endif
+
+
+ printf("BRP: %d, SJW: %d, TSEG1: %d, TSEG2: %d \n", brp, sjw, tseg1, tseg2);
+ CAN_set_bittiming(chips_p[dest_chip], brp, sjw, tseg1, tseg2);
+
+// if (chips_p[dest_chip]->chipspecops->baud_rate(chips_p[dest_chip], rate, chips_p[dest_chip]->clock, sjw, sampl_pt, flags)<0)
+// goto error;
+ chip_data->flags |= CAN_LMC1_CHIP_CANBTR_SET;
+ }
+ return 0;
+error:
+ chip_data->flags &= ~CAN_LMC1_CHIP_CANBTR_SET;
+nodata:
+ return -1;
+}
+
int usbcan_vendor(usb_device_t *udev)
{
// wIndex, wValue, bRequest, wLength
return -1; // Should look like ok (0) or stall (-1)?
switch ( udev->request.bRequest) {
+
+ //lpc17xx debug
+ case USBCAN_VENDOR_SET_CANBTR:
+ udev->ep0.complete_fnc=set_canbtr_complete_fnc;
+ return 1;
+ //lpc17xx debug - end
+
case USBCAN_VENDOR_EXT_MASK_SET:
udev->ep0.complete_fnc=set_ext_mask_complete_fnc;
return 1;