void CAN_send(struct canchip_t *chip, canmsg_t* msg);
void CAN_recv(struct canchip_t *chip, canmsg_t* msg);
void CAN_IRQHandler(void);
+void CAN_set_bittiming(struct canchip_t *chip, uint32_t brp, uint32_t sjw, uint32_t tseg1, uint32_t tseg2);
//----------------------------------
int flags;
};
+#define CAN_LMC1_CHIP_CANBTR_SET (1<<1)
+
// board can-lmc1 specific functions:
int can_lmc1_register(struct hwspecops_t *hwspecops);
int can_lmc1_init_hw_data(struct candevice_t *candev);
}
+void CAN_set_bittiming(struct canchip_t *chip, uint32_t brp, uint32_t sjw, uint32_t tseg1, uint32_t tseg2){
+
+ uint8_t SAM = 0; // 0 = the bus is sampled once
+
+ brp--;
+ sjw--;
+ tseg1--;
+ tseg2--;
+
+ can_disable_irq(chip->chip_irq);
+ // enter reset mode
+ can_write_reg(chip, 1, CAN_MOD_o);
+
+
+ can_write_reg(chip, ((SAM<<23)|(tseg2<<20)|(tseg1<<16)|(sjw<<14)|(brp<<0)), CAN_BTR_o);
+
+
+ // return to normal operating
+ can_write_reg(chip, 0, CAN_MOD_o);
+
+ can_enable_irq(chip->chip_irq);
+}
+
void CAN_setBusTiming(struct canchip_t *chip){
uint32_t PCLK_CAN;
#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;