hondartp-1.2.0/src/main.c

135 lines
3.1 KiB
C

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/***************************************************************************
* INCLUDES
***************************************************************************/
#include "config.h"
#include "comm.h"
#include "io.h"
#include "main.h"
#include "memory.h"
#include "sync_timer.h"
#include "usart.h"
/***************************************************************************
* FUNCTIONS
***************************************************************************/
/* ----------------------------------------------------------------------- */
int main()
{
UINT8 ui8_sync_timer_10 = 0;
UINT8 ui8_sync_timer_100 = 0;
/* do initialization - both leds light*/
init();
/* test memory and exit if write operation failed */
if (!memoryTest())
{
SET_BIT(LED_G_PORT, LED_G, !LED_G_ACT);
return (0);
}
/* set default state of all cells to 0xFF */
if (!memoryClear())
{
SET_BIT(LED_G_PORT, LED_G, !LED_G_ACT);
return (0);
}
/* if tests passed ok then, only green led blinks */
SET_BIT(LED_R_PORT, LED_R, !LED_R_ACT);
b_status_ready = true;
/* set default state to: read by ECU available */
setMemoryAccessEcuRead();
/* start infinite loop */
while (1)
{
/* code execuded 100 times a second */
if (sync())
{
exec100();
ui8_sync_timer_10++;
/* code executed 10 times a second */
if (ui8_sync_timer_10 == 10)
{
exec10();
ui8_sync_timer_10 = 0;
ui8_sync_timer_100++;
/* code executed once a second */
if (ui8_sync_timer_100 == 10)
{
exec1();
ui8_sync_timer_100 = 0;
}
}
}
/* code executed in each pass */
exec();
}
}
/* ----------------------------------------------------------------------- */
void init()
{
/* initialize peripherials */
initIoPorts();
initSyncTimer();
/* default settings supported by CROME 1.5.3 and above */
initUsart(USART_BAUD_920000, false, true, USART_PARITY_EVEN);
/* enable interrupts */
sei();
}
/* ----------------------------------------------------------------------- */
void exec()
{
if (usartUnreadBytes())
pcCommand();
setMemoryAccessEcuRead();
b_status_ready = true;
}
/* ----------------------------------------------------------------------- */
void exec1()
{
TOGGLE_BIT(LED_G_PORT, LED_G);
}
/* ----------------------------------------------------------------------- */
void exec10()
{
}
/* ----------------------------------------------------------------------- */
void exec100()
{
}
/* END */