Subversion Repositories HomeAutomation

Rev

Rev 905 | Rev 986 | Go to most recent revision | 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
 
905 arune 10
#include <drivers/can/canprintf.h>
11
 
801 linlun 12
%INCLUDE
13
 
14
int main(void)
15
{
819 migan 16
	StdCan_Msg_t rxMsg; // Message storage
801 linlun 17
 
18
	// Enable interrupts as early as possible
19
	sei();
20
 
21
	Timer_Init();
22
 
23
	StdCan_Init();
905 arune 24
 
25
#if CAN_PRINTF==1
26
	#warning can_printf in use
27
	CanPrintf_Init();
28
#endif
801 linlun 29
 
30
	Timer_SetTimeout(APP_HEARTBEAT_TIMER, STDCAN_HEARTBEAT_PERIOD, TimerTypeFreeRunning, StdCan_SendHeartbeat);
905 arune 31
 
801 linlun 32
	%INIT
33
 
819 migan 34
	while (1)
35
	{
801 linlun 36
		%PROCESS
37
 
819 migan 38
		if (StdCan_Get(&rxMsg) == StdCan_Ret_OK)
39
		{
948 runge 40
			if (	StdCan_Ret_class(rxMsg.Header) == CAN_MODULE_CLASS_NMT &&
41
				StdCan_Ret_direction(rxMsg.Header) == DIRECTIONFLAG_TO_OWNER &&
42
				rxMsg.Header.Command == CAN_MODULE_CMD_GLOBAL_LIST &&
819 migan 43
				rxMsg.Data[0] == NODE_HW_ID_BYTE0 &&
44
				rxMsg.Data[1] == NODE_HW_ID_BYTE1 &&
45
				rxMsg.Data[2] == NODE_HW_ID_BYTE2 &&
46
				rxMsg.Data[3] == NODE_HW_ID_BYTE3)
47
			{
48
				%LIST
801 linlun 49
			}
819 migan 50
			else
51
			{
52
				%HANDLEMSG
801 linlun 53
			}
819 migan 54
		}
801 linlun 55
	}
56
 
57
	return 0;
58
}