Ejemplo n.º 1
0
void can_monitor(can_t *obj, int silent) {
    uint32_t mod_mask = can_disable(obj);
    if (silent) {
        obj->dev->MOD |= (1 << 1);
    } else {
        obj->dev->MOD &= ~(1 << 1);
    }
    if (!(mod_mask & 1)) {
        can_enable(obj);
    }
}
Ejemplo n.º 2
0
Archivo: can.c Proyecto: gedare/rtems
/**
 * @brief Enables the interrupt type passed to the desired CAN device.
 *
 * @param number The CAN device to enable the interrupts.
 * @param type The type of interrupt to enable.
 */
static inline void can_enable_interrupt(
  const lpc176x_can_number number,
  const can_irq_type       type
)
{
  const can_driver_entry *const driver = &can_driver_table[ number ];
  const uint32_t                ier = 1 << type;

  can_disable( driver );
  driver->device->IER |= ier;
  can_enable( driver );
}
Ejemplo n.º 3
0
int can_frequency(can_t *obj, int f) {
    int pclk = PeripheralClock;

    int btr = can_speed(pclk, (unsigned int)f, 1);

    if (btr > 0) {
        uint32_t modmask = can_disable(obj);
        obj->dev->BTR = btr;
        obj->dev->MOD = modmask;
        return 1;
    } else {
        return 0;
    }
}
Ejemplo n.º 4
0
Archivo: can.c Proyecto: gedare/rtems
/**
 * @brief Configures the desired CAN device with the desired frequency.
 *
 * @param obj The can device to configure.
 * @param f The desired frequency.
 *
 * @return RTEMS_SUCCESSFUL if could be set, RTEMS_INVALID_NUMBER otherwise.
 */
static rtems_status_code can_frequency(
  const can_driver_entry *const obj,
  const can_freq            freq
)
{
  rtems_status_code sc = RTEMS_INVALID_NUMBER;
  const uint32_t    btr = can_speed( LPC176X_CCLK, LPC176X_PCLKDIV, freq, 1 );

  if ( btr != WRONG_BTR_VALUE ) {
    sc = RTEMS_SUCCESSFUL;
    uint32_t modmask = can_disable( obj );
    obj->device->BTR = btr;
    obj->device->MOD = modmask;
  } /*else couldnt found a good timing for the desired frequency,
      return RTEMS_INVALID_NUMBER.*/

  return sc;
}
Ejemplo n.º 5
0
Archivo: can_api.c Proyecto: pan-/mbed
int can_mode(can_t *obj, CanMode mode) {
    int success = 0;
    switch (mode) {
        case MODE_RESET:
            LPC_C_CAN0->CANCNTL &=~CANCNTL_TEST;
            can_disable(obj);
            success = 1;
            break;
        case MODE_NORMAL:
            LPC_C_CAN0->CANCNTL &=~CANCNTL_TEST;
            can_enable(obj);
            success = 1;
            break;
        case MODE_SILENT:
            LPC_C_CAN0->CANCNTL |= CANCNTL_TEST;
            LPC_C_CAN0->CANTEST |= CANTEST_SILENT;
            LPC_C_CAN0->CANTEST &=~ CANTEST_LBACK;
            success = 1;
            break;
        case MODE_TEST_LOCAL:
            LPC_C_CAN0->CANCNTL |= CANCNTL_TEST;
            LPC_C_CAN0->CANTEST &=~CANTEST_SILENT;
            LPC_C_CAN0->CANTEST |= CANTEST_LBACK;
            success = 1;
            break;
        case MODE_TEST_SILENT:
            LPC_C_CAN0->CANCNTL |= CANCNTL_TEST;
            LPC_C_CAN0->CANTEST |= (CANTEST_LBACK | CANTEST_SILENT);
            success = 1;
            break;
        case MODE_TEST_GLOBAL:
        default:
            success = 0;
            break;
    }
    
    return success;
}
Ejemplo n.º 6
0
void can_reset(can_t *obj) {
    can_disable(obj);
    obj->dev->GSR = 0; // Reset error counter when CAN1MOD is in reset
}
Ejemplo n.º 7
0
Archivo: can.c Proyecto: gedare/rtems
/**
 * @brief Resets the error count.
 *
 * @param obj which device reset.
 */
static inline void can_reset( const can_driver_entry *const obj )
{
  can_disable( obj );
  obj->device->GSR = 0;   /* Reset error counter when CANxMOD is in reset*/
}
Ejemplo n.º 8
0
/**
 *  \brief can_example application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t ul_sysclk;
	uint8_t uc_char;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Initialize CAN0 Transceiver. */
	sn65hvd234_set_rs(&can0_transceiver, PIN_CAN0_TR_RS_IDX);
	sn65hvd234_set_en(&can0_transceiver, PIN_CAN0_TR_EN_IDX);
	/* Enable CAN0 Transceiver. */
	sn65hvd234_disable_low_power(&can0_transceiver);
	sn65hvd234_enable(&can0_transceiver);

	/* Initialize CAN1 Transceiver. */
	sn65hvd234_set_rs(&can1_transceiver, PIN_CAN1_TR_RS_IDX);
	sn65hvd234_set_en(&can1_transceiver, PIN_CAN1_TR_EN_IDX);
	/* Enable CAN1 Transceiver. */
	sn65hvd234_disable_low_power(&can1_transceiver);
	sn65hvd234_enable(&can1_transceiver);

	/* Enable CAN0 & CAN1 clock. */
	pmc_enable_periph_clk(ID_CAN0);
	pmc_enable_periph_clk(ID_CAN1);

	ul_sysclk = sysclk_get_cpu_hz();
	if (can_init(CAN0, ul_sysclk, CAN_BPS_1000K) &&
		can_init(CAN1, ul_sysclk, CAN_BPS_1000K)) {
		puts("CAN initialization is completed." STRING_EOL);

		/* Disable all CAN0 & CAN1 interrupts. */
		can_disable_interrupt(CAN0, CAN_DISABLE_ALL_INTERRUPT_MASK);
		can_disable_interrupt(CAN1, CAN_DISABLE_ALL_INTERRUPT_MASK);

		/* Configure and enable interrupt of CAN1, as the tests will use receiver interrupt. */
		NVIC_EnableIRQ(CAN1_IRQn);

		/* Run tests. */
		puts("Press any key to start test" STRING_EOL);
		while (uart_read(CONSOLE_UART, &uc_char)) {
		}
		test_1();
		g_ul_recv_status = 0;

		puts("Press any key to continue..." STRING_EOL);
		while (uart_read(CONSOLE_UART, &uc_char)) {
		}
		test_2();
		g_ul_recv_status = 0;

		puts("Press any key to continue..." STRING_EOL);
		while (uart_read(CONSOLE_UART, &uc_char)) {
		}
		test_3();
		g_ul_recv_status = 0;

		puts("Press any key to continue..." STRING_EOL);
		while (uart_read(CONSOLE_UART, &uc_char)) {
		}
		test_4();
		g_ul_recv_status = 0;

		/* Disable CAN0 Controller */
		can_disable(CAN0);
		/* Disable CAN0 Transceiver */
		sn65hvd234_enable_low_power(&can0_transceiver);
		sn65hvd234_disable(&can0_transceiver);

		/* Disable CAN1 Controller */
		can_disable(CAN1);
		/* Disable CAN1 Transceiver */
		sn65hvd234_enable_low_power(&can1_transceiver);
		sn65hvd234_disable(&can1_transceiver);

		puts("End of all tests" STRING_EOL);
	} else {
		puts("CAN initialization (sync) ERROR" STRING_EOL);
	}

	while (1) {
	}
}