This allows to use same CAN-USB converter code for other chips as well.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
bin_PROGRAMS = usbcan
usbcan_SOURCES = main.c can_queue.c sja1000p.c devcommon.c setup.c finish.c
usbcan_SOURCES += usb_vend.c can_quesysless.c sysdep_sysless.c
+ifeq ($(MACH),lpc17xx)
usbcan_SOURCES += lpc17xx_can.c
+else #MACH
#usbcan_SOURCES += can_lpcbusemu.c ul_usb1.c
+endif #MACH
#usbtest_SOURCES += ul_idstr.c
#lib_LOADLIBES = bspbase ul_drv lpciap keyval lpciap_kvpb mach_hal uldy
--- /dev/null
+#ifndef _CAN_BITTIMING_H
+#define _CAN_BITTIMING_H
+
+#include "./can_sysdep.h"
+
+/*
+ * CAN harware-dependent bit-timing constant
+ *
+ * Used for calculating and checking bit-timing parameters
+ */
+
+struct can_bittiming_const {
+ char name[16]; /* Name of the CAN controller hardware */
+ uint32_t tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */
+ uint32_t tseg1_max;
+ uint32_t tseg2_min; /* Time segement 2 = phase_seg2 */
+ uint32_t tseg2_max;
+ uint32_t sjw_max; /* Synchronisation jump width */
+ uint32_t brp_min; /* Bit-rate prescaler */
+ uint32_t brp_max;
+ uint32_t brp_inc;
+};
+
+#endif /*_CAN_BITTIMING_H*/
#include "can/can.h"
#include "can/canmsg.h"
+#include "can/can_bittiming.h"
#ifdef __cplusplus
extern "C"
void CAN_send(struct canchip_t *chip, canmsg_t* msg);
void CAN_recv(struct canchip_t *chip, canmsg_t* msg);
-
-/*
- * CAN harware-dependent bit-timing constant
- *
- * Used for calculating and checking bit-timing parameters
- */
-
-struct can_bittiming_const {
- char name[16]; /* Name of the CAN controller hardware */
- uint32_t tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */
- uint32_t tseg1_max;
- uint32_t tseg2_min; /* Time segement 2 = phase_seg2 */
- uint32_t tseg2_max;
- uint32_t sjw_max; /* Synchronisation jump width */
- uint32_t brp_min; /* Bit-rate prescaler */
- uint32_t brp_max;
- uint32_t brp_inc;
-};
-
struct can_lmc1_chip_data
{
int flags;
- struct can_bittiming_const btc;
};
#include "./ul_listbase.h"
#include "./can_sysdep.h"
#include "./can_queue.h"
+#include "./can_bittiming.h"
#include "./errno.h"
#ifdef CAN_DEBUG
* @irq_accept: optional fast irq accept routine responsible for blocking further interrupts
*
* @set_bittiming: set bittiming parameters
+ * @get_bittiming_const: get chip specific constants for bittiming computation
*/
struct chipspecops_t {
int (*chip_config)(struct canchip_t *chip);
int (*irq_accept)(int irq, struct canchip_t *chip);
int (*set_bittiming)(struct canchip_t *chip, int brp, int sjw, int tseg1, int tseg2);
+ int (*get_bittiming_const)(struct canchip_t *chip, struct can_bittiming_const *btc);
};
struct mem_addr {
int can_lmc1_init_chip_data(struct candevice_t *candev, int chipnr){
- struct can_bittiming_const *btc;
struct can_lmc1_chip_data *chip_data;
// used CAN1 peripherial -> CAN1 registers base
chip_data = (struct can_lmc1_chip_data*) candev->chip[chipnr]->chip_data;
-
- btc = &chip_data->btc;
-
- // set bittiming constants
- btc->tseg1_min = 1;
- btc->tseg1_max = 16;
- btc->tseg2_min = 1;
- btc->tseg2_max = 8;
- btc->sjw_max = 4;
- btc->brp_min = 1;
- btc->brp_max = 1024;
- btc->brp_inc = 1;
+ chip_data->flags = 0;
return 0;
}
int best_tseg=0, best_brp=0, best_rate=0, brp=0;
int tseg=0, tseg1=0, tseg2=0;
- struct can_lmc1_chip_data *chip_data = (struct can_lmc1_chip_data*) chip->chip_data;
+ struct can_bittiming_const btc_buff;
+ struct can_bittiming_const *btc = &btc_buff;
- struct can_bittiming_const *btc = &chip_data->btc;
+ chip->chipspecops->get_bittiming_const(chip, btc);
/* tseg even = round down, odd = round up */
for (tseg=(0+0+2)*2; tseg<=(btc->tseg2_max+btc->tseg1_max+2)*2+1; tseg++) {
return 0;
}
+int lpc17xx_get_bittiming_const(struct canchip_t *chip, struct can_bittiming_const *btc) {
+ btc->tseg1_min = 1;
+ btc->tseg1_max = 16;
+ btc->tseg2_min = 1;
+ btc->tseg2_max = 8;
+ btc->sjw_max = 4;
+ btc->brp_min = 1;
+ btc->brp_max = 1024;
+ btc->brp_inc = 1;
+
+ return 0;
+}
+
+
int lpc17xx_fill_chipspecops(struct canchip_t *chip){
chip->max_objects=1;
chipspecops->irq_handler = lpc17xx_irq_handler;
chipspecops->set_bittiming = lpc17xx_set_bittiming;
+ chipspecops->get_bittiming_const = lpc17xx_get_bittiming_const;
return 0;
#include "./usb/usb_defs.h"
#include "./usb/usb_vend.h"
-
-#include "can/lpc17xx_can.h"
+extern int can_lmc1_register(struct hwspecops_t *hwspecops);
#define MASK_EP1RX 0x01
#define MASK_EP1TX 0x02
}
- //***********************************************************************
+ // ***********************************************************************
// * CAN device initialization - device side (adapted from LinCAN setup.c)
// ***********************************************************************
#include <byteswap.h>
#endif
-#include "./can/lpc17xx_can.h"
+#include "./can/can_bittiming.h"
extern struct canuser_t *canuser;
extern uint8_t vendor_ret;
return -1;
}
-int get_bittiming_const_complete_fnc(usb_device_t *udev){
-
+int usbcan_get_bittiming_const_reply(usb_device_t *udev){
int dest_chip;
+ struct canchip_t *chip;
- struct can_lmc1_chip_data *chip_data=NULL;
- struct can_bittiming_const *btc;
+ struct can_bittiming_const btc_buff;
+ struct can_bittiming_const *btc = &btc_buff;
uint8_t buffer[USBCAN_BITTIMING_CONST_SIZE];
uint32_t *ptr;
dest_chip=(udev->request.wIndex);
if ((dest_chip>=MAX_TOT_CHIPS)||(dest_chip<0))
goto error;
- if (!chips_p[dest_chip])
+ if ((chip = chips_p[dest_chip]) == NULL)
goto error;
- if ((chip_data=((struct can_lmc1_chip_data*)(chips_p[dest_chip]->chip_data)))==NULL){
+ if (chip->chipspecops->get_bittiming_const == NULL){
goto error;
}
- btc = &chip_data->btc;
-
+ chip->chipspecops->get_bittiming_const(chip, btc);
ptr = (uint32_t*) buffer;
#if __BYTE_ORDER == __BIG_ENDIAN
return 1;
case USBCAN_VENDOR_GET_BITTIMING_CONST:
- get_bittiming_const_complete_fnc(udev);
+ usbcan_get_bittiming_const_reply(udev);
return 1;
//lpc17xx - end