Subversion Repositories HomeAutomation

Rev

Rev 1909 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

#include <inttypes.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <string.h>
#include <drivers/can/stdcan.h>
#include <config.h> // All configuration parameters
#include <bios.h>   // BIOS interface declarations, including CAN structure and ID defines.
#include <drivers/timer/timer.h>

#include <drivers/can/canprintf.h>

%INCLUDE

int main(void)
{
    StdCan_Msg_t rxMsg; // Message storage

    // Enable interrupts as early as possible
    sei();
    
    Timer_Init();

    StdCan_Init();

#if CAN_PRINTF==1
    #warning can_printf in use
    CanPrintf_Init();
#endif
    
    Timer_SetTimeout(APP_HEARTBEAT_TIMER, STDCAN_HEARTBEAT_PERIOD, TimerTypeFreeRunning, StdCan_SendHeartbeat);

    %INIT

    while (1)
    {
        %PROCESS
    
        if (StdCan_Get(&rxMsg) == StdCan_Ret_OK)
        {
            uint32_t HwId=BIOS_GetHwId();
            if (    StdCan_Ret_class(rxMsg.Header) == CAN_MODULE_CLASS_MNMT &&
                StdCan_Ret_direction(rxMsg.Header) == DIRECTIONFLAG_TO_OWNER &&
                rxMsg.Header.Command == CAN_MODULE_CMD_GLOBAL_LIST &&
                rxMsg.Data[0] == (HwId&0xff) &&
                rxMsg.Data[1] == ((HwId>>8)&0xff) &&
                rxMsg.Data[2] == ((HwId>>16)&0xff) &&
                rxMsg.Data[3] == ((HwId>>24)&0xff))
            {
                %LIST
            }
            else
            {
                %HANDLEMSG
            }
        }
    }
    
    return 0;
}