Example #1
0
/* Calls the initialization routines */
static inline void
init(void)
{ 
    uint8_t cnf1=0x03, cnf2=0xb6, cnf3=0x04; /* Defaults to 125k */
	uint8_t can_speed = 0;

	init_spi();
 /* Set the direction for the status LEDs' */
    DDRB |= (1<<PB0);
    DDRB |= (1<<PB1);
 /* Set the CAN speed.  The values for 125k are the defaults so 0 is ignored
    and bad values also result in 125k */
    can_speed = eeprom_read_byte(EE_CAN_SPEED);
	if(can_speed==BITRATE_250) cnf1=0x01;      /* 250kbps */
	else if(can_speed==BITRATE_500) cnf1=0x00; /* 500kbps */
	else if(can_speed==BITRATE_1000) { cnf1=0x00; cnf2=0x92; cnf3=0x02; } /* 1Mbps */
    node_id = eeprom_read_byte(EE_NODE_ID);

 /* Initialize the MCP2515 */
	can_init(cnf1, cnf2, cnf3, 0x00);

 /* Set the masks and filters to listen for Node Specific Messages
    on RX 0.  We put the node specific messages in RX0 and the
    two way communication channels in RX1 */
	can_mode(CAN_MODE_CONFIG, 0);
    can_mask(0, 0x0700);
 /* This sets the filter to get a firmware update command to our
    node address.  For the bootloader this is all we care about. */
    can_filter(CAN_RXF0SIDH, 0x0700);
    can_mask(1, 0x07C0);
    can_filter(CAN_RXF2SIDH, 0x06E0);
    can_mode(CAN_MODE_NORMAL, 0);

#ifdef UART_DEBUG
	init_serial();
#endif
	TCCR1B=0x05; /* Set Timer/Counter 1 to clk/1024 */
 /* Move the Interrupt Vector table to the Bootloader section */
	MCUCR = (1<<IVCE);
	MCUCR = (1<<IVSEL);
	EICRA = 0x02; /* Set INT0 to falling edge */
}
Example #2
0
int CAN::mode(Mode mode) {
    lock();
    int ret = can_mode(&_can, (CanMode)mode);
    unlock();
    return ret;
}
Example #3
0
int CAN::mode(Mode mode) {
    return can_mode(&_can, (CanMode)mode);
}