Esempio n. 1
0
//------------------------------------------------------------------------------
//  @fn can_init
//!
//! CAN macro initialization. Reset the CAN peripheral, initialize the bit
//! timing, initialize all the registers mapped in SRAM to put MObs in
//! inactive state and enable the CAN macro.
//!
//! @warning The CAN macro will be enable after seen on CAN bus a receceive
//!          level as long as of an inter frame (hardware feature).
//!
//! @param  Mode (for "can_fixed_baudrate" param not used)
//!         ==0: start CAN bit timing evaluation from faster baudrate
//!         ==1: start CAN bit timing evaluation with CANBTx registers
//!              contents
//!
//! @return Baudrate Status
//!         ==0: research of bit timing configuration failed
//!         ==1: baudrate performed 
//!
//------------------------------------------------------------------------------
U8 can_init(U8 mode)
{
    if ((Can_bit_timing(mode))==0) return (0);  // c.f. macro in "can_drv.h"
    can_clear_all_mob();                        // c.f. function in "can_drv.c"
    Can_enable();                               // c.f. macro in "can_drv.h" 
    return (1);
}
Esempio n. 2
0
//------------------------------------------------------------------------------
//  @fn can_init
//!
//! CAN macro initialization. Reset the CAN peripheral, initialize the bit
//! timing, initialize all the registers mapped in SRAM to put MObs in
//! inactive state and enable the CAN macro.
//!
//! @warning The CAN macro will be enable after seen on CAN bus a receceive
//!          level as long as of an inter frame (hardware feature).
//!
//! @param  Mode (for "can_fixed_baudrate" param not used)
//!         ==0: start CAN bit timing evaluation from faster baudrate
//!         ==1: start CAN bit timing evaluation with CANBTx registers
//!              contents
//!
//! @return Baudrate Status
//!         ==0: research of bit timing configuration failed
//!         ==1: baudrate performed 
//!
//------------------------------------------------------------------------------
U8 can_init(U8 mode)
{
		
//	PIND |= (1<<PD5);	//Setzen auf High um CAN-Bus Nicht zu blockieren
//	DDRD |= (1<<PD5);	//Pin6 := Output (Can_Tx)
//	PIND |= (1<<PD5);	//Setzen auf High um CAN-Bus Nicht zu blockieren

    if ((Can_bit_timing(mode))==0) return (0);  // c.f. macro in "can_drv.h"
    can_clear_all_mob();                        // c.f. function in "can_drv.c"
    Can_enable();                               // c.f. macro in "can_drv.h" 
    return (1);
}
//******************************************************************************
//  @fn main
//!
//! Core of "main_can_boot_loader.c".
//!
//! @brief: This application performs a CAN boot loader for AT90CAN128/64/32
//!         with aut-bitrate, IAP (In Application Programming) and API
//!         (Application Programming Interface).
//!
//! @warning: Don't forget to full locate the boot loader in "Boot Loader
//!           Flash Section".
//!           xxx_HWCB defined in "board.h" file
//!
//! @param none.
//!
//! @return Integer 0
//!
//******************************************************************************
int main (void)
{
    //U8      hwcb = FALSE;
    Bool    auto_b = 1;

    if(eeprom_rd_byte( (U16) ENNB  )  != 254)
      eeprom_wr_byte((U16) ENNB, 254);
       
    //DDRA = 0xFF;
	//PORTA = 0x00;

        //boot_conf[6] = 0x05;
		
    //uint8_t NNB;
    //NNB = eeprom_read_byte( (uint8_t*) 0 );
    //eeprom_update_byte((uint8_t*)0, NNB);
    
    
    //U8 mup = get_conf_byte(NNB);
    //U8 mupp[64];
    //------
    //put_conf_byte(NNB, 0x02);	//set node id
    //put_conf_byte(BSB, 0xFF);	//start programming
    //eeprom_wr_byte(NNB, 0x03);
    
    //------
    
    
//! --- First of all, disabling the Global Interrupt
    Disable_interrupt();

    
//! --- If comming from RESET then test of the HardWare Condition Bit
    if (MCUSR != 0)
    {
      //- Clear all reset flags
      MCUSR = 0;
    }
      if(eeprom_rd_byte( (U16) EBSB ) != 0xFF){
        // Start application
        //PORTA = 0xFF;
        isp_jump_to( (((U16)SA_H)<<8) | ((U16)SA_L));
      }
    

//! --- Open CAN communication

    can_communication_opened = 0;   // Not opened

    //- Pull-up on TxCAN & RxCAN one by one to use bit-addressing
    CAN_PORT_DIR &= ~(1<<CAN_INPUT_PIN );
    CAN_PORT_DIR &= ~(1<<CAN_OUTPUT_PIN);
    CAN_PORT_OUT |=  (1<<CAN_INPUT_PIN );
    CAN_PORT_OUT |=  (1<<CAN_OUTPUT_PIN);

    while (1)
    {
        auto_b = ((~auto_b)&0x01);      // Flip of "auto_b"

        //- Wait until activity on RxCAN
        while ((CAN_PORT_IN & (1<<CAN_INPUT_PIN)) != 0);

        //- Reset CAN peripheral
	    Can_reset();

	    //- Set CAN Bit-timming
        if (EB != 0xFF)
        {
//            CANBT1 = get_conf_byte(BTC1);
//            CANBT2 = get_conf_byte(BTC2);
//            CANBT3 = get_conf_byte(BTC3);
            
            CANBT1 = BTC1;
            CANBT2 = BTC2;
            CANBT3 = BTC3;

        }
        else
        //- Loop on auto-bitrate until it is performed
        {
            while ((Can_bit_timing(auto_b))==0);        // c.f. macro in "can_drv.h"
        }

	    //- Enable CAN peripheral
        can_clear_all_mob();                        // c.f. function in "can_drv.c"
        Can_enable();                               // c.f. macro in "can_drv.h"

//! --- CAN ISP protocol execution
        //- Initialization of CAN ISP PROTOCOL only when CAN communication NOT opened
        if(!can_communication_opened) can_isp_protocol_init();

        //- Exit with "0" only if CAN hardware error occurs
        while(can_isp_protocol_task());
    }
}   // End of "main"