/**
* CAN Test. This program immediately echoes back all received CAN messages to
* the bus, but increases ID with 1 before doing so.
*
* @date 2006-11-21
* @author Jimmy Myhrman
*
*/
/*-----------------------------------------------------------------------------
* Includes
*---------------------------------------------------------------------------*/
/* system files */
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <stdio.h>
/* lib files */
#include <can.h>
#include <serial.h>
#include <timebase.h>
/*-----------------------------------------------------------------------------
* Main Program
*---------------------------------------------------------------------------*/
int main(void) {
Timebase_Init();
Serial_Init();
sei();
printf("\n------------------------------------------------------------\n");
printf( "------------------------------------------------------------\n");
if (Can_Init() != CAN_OK) {
}
else {
}
uint32_t timeStamp = 0;
Can_Message_t txMsg;
Can_Message_t rxMsg;
txMsg.DataLength = 8;
txMsg.Data.bytes[0] = 7;
txMsg.Id = 0;
txMsg.RemoteFlag = 0;
txMsg.ExtendedFlag = 1;
/* main loop */
while (1) {
/* service the CAN routines */
Can_Service();
/* send CAN message and check for CAN errors once every second */
if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
timeStamp = Timebase_CurrentTime();
}
/* check if any messages have been received */
while (Can_Receive(&rxMsg) == CAN_OK) {
/* echo back with increased Id */
rxMsg.Id++;
while (Can_Send(&rxMsg) != CAN_OK);
}
}
return 0;
}