Subversion Repositories HomeAutomation

Rev

Rev 819 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
801 linlun 1
#include <inttypes.h>
2
#include <avr/interrupt.h>
3
#include <stdio.h>
4
#include <string.h>
819 migan 5
#include <drivers/can/stdcan.h>
801 linlun 6
#include <config.h> // All configuration parameters
7
#include <bios.h>   // BIOS interface declarations, including CAN structure and ID defines.
8
#include <drivers/timer/timer.h>
9
 
10
%INCLUDE
11
 
12
int main(void)
13
{
819 migan 14
	StdCan_Msg_t rxMsg; // Message storage
801 linlun 15
 
16
	// Enable interrupts as early as possible
17
	sei();
18
 
19
	Timer_Init();
20
 
21
	StdCan_Init();
22
 
23
	Timer_SetTimeout(APP_HEARTBEAT_TIMER, STDCAN_HEARTBEAT_PERIOD, TimerTypeFreeRunning, StdCan_SendHeartbeat);
24
 
25
	%INIT
26
 
819 migan 27
	while (1)
28
	{
801 linlun 29
		%PROCESS
30
 
819 migan 31
		if (StdCan_Get(&rxMsg) == StdCan_Ret_OK)
32
		{
827 migan 33
			if (	StdCan_Ret_class(rxMsg.Header) == CAN_CLASS_MODULE_NMT &&
34
				StdCan_Ret_direction(rxMsg.Header) == DIR_TO_OWNER &&
819 migan 35
				rxMsg.Header.Command == CAN_CMD_MODULE_NMT_LIST &&
36
				rxMsg.Data[0] == NODE_HW_ID_BYTE0 &&
37
				rxMsg.Data[1] == NODE_HW_ID_BYTE1 &&
38
				rxMsg.Data[2] == NODE_HW_ID_BYTE2 &&
39
				rxMsg.Data[3] == NODE_HW_ID_BYTE3)
40
			{
41
				%LIST
801 linlun 42
			}
819 migan 43
			else
44
			{
45
				%HANDLEMSG
801 linlun 46
			}
819 migan 47
		}
801 linlun 48
	}
49
 
50
	return 0;
51
}