/******************************************************************* * CAN Test-APP * - CAN functions definded for AT90CAN * * Compiler : avr-gcc 4.3.0 / avr-libc 1.6.2 / AVR Studio 4.14 * size : 6,18KB * by : Thomas Fuchs, Wolfsburg, Germany * linux@cc-robotics.de * * License : Copyright (c) 2009 Thomas Fuchs * * Tested with AT90CAN128 *******************************************************************/ #include #include #include "utils.h" #include "at90can.h" /* to enhance the readability: * - MOb = Message Object */ // returns the mob which has the message // suchen des MOb in dem die Nachricht ist uint8_t getmob( uint32_t bitmask) { uint8_t mob; if( bitmask==0) return NOMOB; for( mob=0; (bitmask & 0x01)==0; bitmask >>= 1, ++mob); // security check if ( mob > 14 ) return NOMOB; else return mob; } // initializes CAN interface // Funktion zum Initialisieren bool initCAN( uint8_t bitrate ) { CAN_DDR |= _BV(CAN_TX); CAN_DDR &= ~_BV(CAN_RX); // security check if (bitrate >= 8) return false; // number of the MOb uint8_t mob; CANGCON |= (1<>3); // write data to MOb for (i=0; i<8; i++) CANMSG = msg.data[i]; // wait for txbsy while (CANGSTA & (1<>= 5; // get length of selected MOb recMsg.length = (CANCDMOB&0x0F); // clear memory for (i=0; i<8; i++) { recMsg.data[i] = 0; } // get data of selected MOb for (i=0; i