Subversion Repositories HomeAutomation

Rev

Rev 1557 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1557 Rev 1910
1
 
1
 
2
#include "<template>.h"
2
#include "<template>.h"
3
 
3
 
4
#ifdef <template>_USEEEPROM
4
#ifdef <template>_USEEEPROM
5
#include "<template>_eeprom.h"
5
#include "<template>_eeprom.h"
6
struct eeprom_<template> EEMEM eeprom_<template> =
6
struct eeprom_<template> EEMEM eeprom_<template> =
7
{
7
{
8
    {
8
    {
9
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file.
9
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file.
10
        0xAB,       // x
10
        0xAB,       // x
11
        0x1234      // y
11
        0x1234      // y
12
        0x12345678  // z
12
        0x12345678  // z
13
    },
13
    },
14
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
14
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
15
};
15
};
16
#endif
16
#endif
17
 
17
 
18
void <template>_Init(void)
18
void <template>_Init(void)
19
{
19
{
20
#ifdef <template>_USEEEPROM
20
#ifdef <template>_USEEEPROM
21
    if (EEDATA_OK)
21
    if (EEDATA_OK)
22
    {
22
    {
23
      ///TODO: Use stored data to set initial values for the module
23
      ///TODO: Use stored data to set initial values for the module
24
      blablaX = eeprom_read_byte(EEDATA.x);
24
      blablaX = eeprom_read_byte(EEDATA.x);
25
      blablaY = eeprom_read_word(EEDATA16.y);
25
      blablaY = eeprom_read_word(EEDATA16.y);
26
      blablaZ = eeprom_read_dword(EEDATA32.y);
26
      blablaZ = eeprom_read_dword(EEDATA32.y);
27
    } else
27
    } else
28
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
28
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
29
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
29
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
30
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
30
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
31
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
31
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
32
      EEDATA_UPDATE_CRC;
32
      EEDATA_UPDATE_CRC;
33
    }
33
    }
34
#endif
34
#endif
35
    ///TODO: Initialize hardware etc here
35
    ///TODO: Initialize hardware etc here
36
 
36
 
37
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
37
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
38
    // Pcint_SetCallbackPin(<template>_PCINT, EXP_C , &<template>_pcint_callback);
38
    // Pcint_SetCallbackPin(<template>_PCINT, EXP_C , &<template>_pcint_callback);
39
 
39
 
40
}
40
}
41
 
41
 
42
void <template>_Process(void)
42
void <template>_Process(void)
43
{
43
{
44
    ///TODO: Stuff that needs doing is done here
44
    ///TODO: Stuff that needs doing is done here
45
}
45
}
46
 
46
 
47
void <template>_HandleMessage(StdCan_Msg_t *rxMsg)
47
void <template>_HandleMessage(StdCan_Msg_t *rxMsg)
48
{
48
{
49
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_xyz && ///TODO: Change this to the actual class type
49
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_xyz && ///TODO: Change this to the actual class type
50
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
50
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
51
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_xyz && ///TODO: Change this to the actual module type
51
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_xyz && ///TODO: Change this to the actual module type
52
        rxMsg->Header.ModuleId == <template>_ID)
52
        rxMsg->Header.ModuleId == <template>_ID)
53
    {
53
    {
54
        switch (rxMsg->Header.Command)
54
        switch (rxMsg->Header.Command)
55
        {
55
        {
56
        case CAN_CMD_MODULE_DUMMY:
56
        case CAN_CMD_MODULE_DUMMY:
57
        ///TODO: Do something dummy
57
        ///TODO: Do something dummy
58
        break;
58
        break;
59
        }
59
        }
60
    }
60
    }
61
}
61
}
62
 
62
 
63
void <template>_List(uint8_t ModuleSequenceNumber)
63
void <template>_List(uint8_t ModuleSequenceNumber)
64
{
64
{
65
    StdCan_Msg_t txMsg;
65
    StdCan_Msg_t txMsg;
66
 
66
 
67
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_xyz); ///TODO: Change this to the actual class type
67
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_xyz); ///TODO: Change this to the actual class type
68
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
68
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
69
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_xyz; ///TODO: Change this to the actual module type
69
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_xyz; ///TODO: Change this to the actual module type
70
    txMsg.Header.ModuleId = <template>_ID;
70
    txMsg.Header.ModuleId = <template>_ID;
71
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
71
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
72
    txMsg.Length = 6;
72
    txMsg.Length = 6;
73
 
73
 
-
 
74
    uint32_t HwId=BIOS_GetHwId();
74
    txMsg.Data[0] = NODE_HW_ID_BYTE0;
75
    txMsg.Data[0] = HwId&0xff;
75
    txMsg.Data[1] = NODE_HW_ID_BYTE1;
76
    txMsg.Data[1] = (HwId>>8)&0xff;
76
    txMsg.Data[2] = NODE_HW_ID_BYTE2;
77
    txMsg.Data[2] = (HwId>>16)&0xff;
77
    txMsg.Data[3] = NODE_HW_ID_BYTE3;
78
    txMsg.Data[3] = (HwId>>24)&0xff;
78
 
79
 
79
    txMsg.Data[4] = NUMBER_OF_MODULES;
80
    txMsg.Data[4] = NUMBER_OF_MODULES;
80
    txMsg.Data[5] = ModuleSequenceNumber;
81
    txMsg.Data[5] = ModuleSequenceNumber;
81
 
82
 
82
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
83
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
83
}
84
}
84
 
85