Esempio n. 1
0
File: main.c Progetto: mabl/ChibiOS
struct can_instance {
  CANDriver     *canp;
  ioline_t      led;
};

static const struct can_instance can1 = {&CAND1, LINE_LED_GREEN};

/*
 * Internal loopback mode, 500KBaud, automatic wakeup, automatic recover
 * from abort mode.
 * See section 42.7.7 on the STM32 reference manual.
 */
static const CANConfig cancfg = {
  CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
  CAN_BTR_LBKM | CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
  CAN_BTR_TS1(12) | CAN_BTR_BRP(9)
};

/*
 * Receiver thread.
 */
static THD_WORKING_AREA(can_rx1_wa, 256);
static THD_FUNCTION(can_rx, p) {
  struct can_instance *cip = p;
  event_listener_t el;
  CANRxFrame rxmsg;

  (void)p;
  chRegSetThreadName("receiver");
  chEvtRegister(&cip->canp->rxfull_event, &el, 0);
  while(!chThdShouldTerminateX()) {
Esempio n. 2
0
static THD_WORKING_AREA(canTreadStack, UTILITY_THREAD_STACK_SIZE);

/*
 * 500KBaud
 * automatic wakeup
 * automatic recover from abort mode
 * See section 22.7.7 on the STM32 reference manual.
 *
 * speed = 42000000 / (BRP + 1) / (1 + TS1 + 1 + TS2 + 1)
 * 42000000 / 7 / 12 = 500000
 *
 *
 */
static const CANConfig canConfig = {
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
CAN_BTR_SJW(0) | CAN_BTR_TS2(1) | CAN_BTR_TS1(8) | CAN_BTR_BRP(6) };

static CANRxFrame rxBuffer;
CANTxFrame txmsg;

// todo: we would need a data structure here
static int engine_rpm = 0;
static float engine_clt = 0;

static int rand = 1212321311;

//static CANDriver *getCanDevice() {
//	if(board)
//}

static void printPacket(CANRxFrame *rx) {
Esempio n. 3
0
{
  SERIAL_DEFAULT_BITRATE,
  0,
  USART_CR2_STOP1_BITS,
  0
};

/*
 * 500KBaud, automatic wakeup, automatic recover
 * from abort mode.
 * See section 22.7.7 on the STM32 reference manual.
 */
static const CANConfig cancfg = {
  CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
  CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
  CAN_BTR_TS1(8) | CAN_BTR_BRP(4)
  //| CAN_BTR_LBKM
};

void BoardDriverInit(void)
{
    mod_led_init(&LED_BMS_HEARTBEAT, &ledCfg1);
    mod_led_init(&LED_CAN_RX, &ledCfg2);
    mod_led_init(&LED_BOARDHEARTBEAT, &ledCfg3);
}

void BoardDriverStart(void)
{
	canStart(&CAND1, &cancfg);

	/*CAN1 RX and TX*/
Esempio n. 4
0
  50,      /* Initial PWM period 10mS.       */
  NULL,
  {
   {PWM_OUTPUT_ACTIVE_HIGH, NULL},
   {PWM_OUTPUT_ACTIVE_HIGH, NULL},
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL}
  },
  0,
  0
};

const CANConfig cancfg = {
  CAN_MCR_ABOM   | CAN_MCR_AWUM   | CAN_MCR_TXFP,
  CAN_BTR_SJW(1) | CAN_BTR_TS2(4) |
  CAN_BTR_TS1(5) | CAN_BTR_BRP(5)
};

/*===========================================================================*/
/* Threads                                                                   */
/*===========================================================================*/

THD_WORKING_AREA(waThreadCAN, 256);
CCM_FUNC static THD_FUNCTION(ThreadCAN, arg)
{
  event_listener_t el;
  CANTxFrame txmsg;
  CANRxFrame rxmsg;
  uint16_t i;
  bool pidserved;
Esempio n. 5
0
    the source code for any proprietary components. See the file exception.txt
    for full details of how and when the exception can be applied.
*/

#include "ch.h"
#include "hal.h"

/*
 * Internal loopback mode, 500KBaud, automatic wakeup, automatic recover
 * from abort mode.
 * See section 22.7.7 on the STM32 reference manual.
 */
static const CANConfig cancfg = {
  CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
  CAN_BTR_LBKM | CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
  CAN_BTR_TS1(8) | CAN_BTR_BRP(6),
  0,
  NULL
};

/*
 * Receiver thread.
 */
static WORKING_AREA(can_rx_wa, 256);
static msg_t can_rx(void *p) {
  EventListener el;
  CANRxFrame rxmsg;

  (void)p;
  chRegSetThreadName("receiver");
  chEvtRegister(&CAND1.rxfull_event, &el, 0);
Esempio n. 6
0
 */

/*
 ******************************************************************************
 * GLOBAL VARIABLES
 ******************************************************************************
 */
/*
 * Internal loopback mode, 250KBaud, automatic wakeup, automatic recover
 * from abort mode.
 * See section 22.7.7 on the STM32 reference manual.
 */
static const CANConfig cancfg = {
  CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
  //CAN_BTR_LBKM | CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(11) | CAN_BTR_BRP(5),
  CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(11) | CAN_BTR_BRP(5),
  0,
  NULL
};

static Thread *can_tp;

/*
 ******************************************************************************
 ******************************************************************************
 * LOCAL FUNCTIONS
 ******************************************************************************
 ******************************************************************************
 */
/*
 * Transmitter thread.