Rev 141 | Rev 341 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 141 | Rev 339 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 |
|
1 | /********************************************************************* |
| 2 | * |
2 | * |
| 3 | * Defines functs and funccs and other global definitions. |
3 | * Defines functs and funccs and other global definitions. |
| 4 | * |
4 | * |
| 5 | ********************************************************************* |
5 | ********************************************************************* |
| 6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/Include/funcdefs.h $ |
6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/Include/funcdefs.h $ |
| 7 | * Last changed: $LastChangedDate: |
7 | * Last changed: $LastChangedDate: 2007-02-25 20:51:08 +0100 (Sun, 25 Feb 2007) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 339 $ |
| 10 | ********************************************************************/ |
10 | ********************************************************************/ |
| 11 | 11 | ||
| - | 12 | #include <typedefs.h> |
|
| 12 | 13 | ||
| 13 | - | ||
| 14 | //<FUNCT> |
- | |
| 15 | #define FUNCT_BOOTLOADER 0x00 |
- | |
| 16 | #define FUNCT_SENSORS 0x01 |
- | |
| 17 | - | ||
| 18 | //<FUNCC> configuration packet |
- | |
| 19 | #define FUNCC_BOOT_INIT 0b0000000001 //Start programmring and/or resseting user program to go into bootloader mode. |
- | |
| 20 | #define FUNCC_BOOT_ADDR 0b0000000010 //Change programming address. |
- | |
| 21 | #define FUNCC_BOOT_SET_ID 0b0000000110 //Change ID and NID. |
- | |
| 22 | #define FUNCC_BOOT_DONE 0b0000000101 //End programming, start user program. |
- | |
| 23 | - | ||
| 24 | #define FUNCC_BOOT_HEARTBEAT 0b0000001000 // Heartbeat |
- | |
| 25 | - | ||
| 26 | //<FUNCC> program packet |
- | |
| 27 | #define FUNCC_BOOT_PGM 0b0000000011 //To indicate programming data packet. |
- | |
| 28 | - | ||
| 29 | //<FUNCC> ack packet 10 bits, 0x3FF |
- | |
| 30 | #define FUNCC_BOOT_ACK 0b0000000100 //Ack packet |
- | |
| 31 | - | ||
| 32 | - | ||
| 33 | //<FUNCC> 10 bits, 0x3FF |
- | |
| 34 | #define FUNCC_SENSORS_IR 0x001 |
- | |
| 35 | - | ||
| 36 | #define FUNCC_SENSORS_TEMPERATURE_INSIDE 0x010 |
- | |
| 37 | #define FUNCC_SENSORS_TEMPERATURE_OUTSIDE 0x011 |
- | |
| 38 | #define FUNCC_SENSORS_TEMPERATURE_FREEZER 0x012 |
- | |
| 39 | #define FUNCC_SENSORS_TEMPERATURE_REFRIGERATOR 0x013 |
- | |
| 40 | - | ||
| 41 | #define FUNCC_SENSORS_DOORS_FREEZER 0x020 |
- | |
| 42 | #define FUNCC_SENSORS_DOORS_REFRIGERATOR 0x021 |
- | |
| 43 | - | ||
| 44 | #define DEFAULT_ID 0x78 // Default ID for bootloader/node when no id is set. |
14 | #define DEFAULT_ID 0x78 // Default ID for bootloader/node when no id is set. |
| 45 | #define DEFAULT_NID 0x00 // Default ID for bootloader/node when no nid is set. |
- | |
| 46 | - | ||
| 47 | - | ||
| 48 | #define NODE_ID_EE 0x00 // EEPROM first index where to look for ID and NID. |
15 | #define NODE_ID_EE 0x00 // EEPROM first index where to look for ID and NID. |
| 49 | // NODE_ID_EE = NODE_HAS_ID if has correct ID, otherwise use DEFAULT_ID and DEFAULT_NID |
16 | // NODE_ID_EE = NODE_HAS_ID if has correct ID, otherwise use DEFAULT_ID and DEFAULT_NID |
| 50 | // NODE_ID_EE + 1 = ID[1] |
- | |
| 51 | // NODE_ID_EE + 2 = ID[0] |
- | |
| 52 | // NODE_ID_EE + |
17 | // NODE_ID_EE + 1 = ID |
| 53 | - | ||
| 54 | #define NODE_HAS_ID 0x2A // Value which indicate valid ID and NID. |
18 | #define NODE_HAS_ID 0x2A // Value which indicate valid ID and NID. |
| 55 | 19 | ||
| 56 | 20 | ||
| 57 | // Definitions for BOOT packets. Which index in data where things are. |
- | |
| 58 | #define BOOT_DATA_ADDRL_INDEX 0 |
- | |
| 59 | #define BOOT_DATA_ADDRH_INDEX 1 |
- | |
| 60 | #define BOOT_DATA_ADDRU_INDEX 2 |
- | |
| 61 | #define BOOT_DATA_RID_LOW_INDEX 4 |
- | |
| 62 | #define BOOT_DATA_RID_HIGH_INDEX 5 |
- | |
| 63 | #define BOOT_DATA_ERR_INDEX 4 |
- | |
| 64 | #define BOOT_DATA_NEW_ID_LOW_INDEX 0 |
- | |
| 65 | #define BOOT_DATA_NEW_ID_HIGH_INDEX 1 |
- | |
| 66 | #define BOOT_DATA_NEW_NID_INDEX 2 |
- | |
| 67 | #define BOOT_DATA_HEARTBEAT_INDEX 0 |
- | |
| 68 | 21 | ||
| - | 22 | typedef enum _PACKET_TYPE {ptBOOT=0x0,ptPGM=0x1} PACKET_TYPE; |
|
| - | 23 | typedef enum _BOOT_TYPE {btADDR=0x0,btPGM=0x1,btDONE=0x2,btACK=0x4,btNACK=0x5,btCRC=0x6,btCHANGEID=0x7} BOOT_TYPE; |
|
| - | 24 | typedef enum _PGM_CLASS {pcCTRL=0x0,pcSENSOR=0x1,pcACTUATOR=0x2} PGM_CLASS; |
|
| - | 25 | ||
| - | 26 | typedef struct _CAN_BOOT_PACKET |
|
| - | 27 | { |
|
| - | 28 | BOOT_TYPE type; //3 |
|
| - | 29 | BYTE offset; //8 |
|
| - | 30 | BYTE rid; //8 |
|
| - | 31 | } CAN_BOOT_PACKET; |
|
| - | 32 | ||
| - | 33 | ||
| - | 34 | typedef struct _CAN_PGM_PACKET |
|
| - | 35 | { |
|
| - | 36 | PGM_CLASS class; //4 |
|
| - | 37 | WORD id; //15 |
|
| - | 38 | } CAN_PGM_PACKET; |
|
| - | 39 | ||
| - | 40 | typedef struct _CAN_PACKET |
|
| - | 41 | { |
|
| - | 42 | PACKET_TYPE type; |
|
| - | 43 | CAN_PGM_PACKET pgm; |
|
| - | 44 | CAN_BOOT_PACKET boot; |
|
| - | 45 | BYTE sid; //8 |
|
| - | 46 | BYTE length; |
|
| - | 47 | BYTE data[8]; |
|
| - | 48 | } CAN_PACKET; |
|
| - | 49 | ||
| - | 50 | ||
| - | 51 | ||
| - | 52 | // When CAN_BOOT_PACKET.type==btADDR |
|
| - | 53 | // data[2] = ADDRU |
|
| - | 54 | // data[1] = ADDRH |
|
| 69 | // |
55 | // data[0] = ADDRL |
| - | 56 | ||
| 70 | // |
57 | // When CAN_BOOT_PACKET.type==btCRC |
| - | 58 | // data[4] = CRCH |
|
| - | 59 | // data[3] = CRCL |
|
| - | 60 | // data[2] = ADDRU |
|
| - | 61 | // data[1] = ADDRH |
|
| - | 62 | // data[0] = ADDRL |
|
| - | 63 | ||
| 71 |
|
64 | // When CAN_BOOT_PACKET.type==btCHANGEID |
| - | 65 | // data[0] = new id |
|
| - | 66 | ||
| - | 67 | typedef enum _PGM_CTRL_TYPE {pctBOOTBOOT=0x0,pctAPPBOOT=0x1,pctHEARTBEAT=0x2} PGM_CTRL_TYPE; |
|
| - | 68 | // When CAN_PGM_PACKET.type==pcCTRL |
|
| - | 69 | // When CAN_PGM_PACKET.id==pctBOOTBOOT |
|
| - | 70 | // data[0] = startup reason |
|
| - | 71 | ||
| 72 |
|
72 | typedef enum _PGM_SENSOR_TYPE { |
| - | 73 | pstIR=0x0, |
|
| - | 74 | pstTEMP_INSIDE=0x1, pstTEMP_OUTSIDE=0x2, pstTEMP_FREEZER=0x3, pstTEMP_REFRIGERATOR=0x4, |
|
| - | 75 | pstDOOR_FREEZER=0x5, pstDOOR_REFRIGERATOR=0x6, |
|
| - | 76 | pstBLIND_TR=0x7 |
|
| - | 77 | } PGM_SENSOR_TYPE; |
|
| - | 78 | // When CAN_PGM_PACKET.type==pcSENSOR |
|
| - | 79 | // When CAN_PGM_PACKET.id==pstIR |
|
| - | 80 | // data[0]... |
|
| - | 81 | // When CAN_PGM_PACKET.id==pstTEMP_* |
|
| - | 82 | // data[1] = integer value -127 to 127 |
|
| - | 83 | // data[0] = decimal value 0-9 |
|
| - | 84 | // When CAN_PGM_PACKET.id==pstBLIND_* |
|
| - | 85 | // data[0] = Precent value 0-100 |
|
| - | 86 | ||
| - | 87 | typedef enum _PGM_ACTUATOR_TYPE { |
|
| - | 88 | patBLIND_TR=0x7 |
|
| - | 89 | } PGM_ACTUATOR_TYPE; |
|
| - | 90 | // When CAN_PGM_PACKET.type==pcACTUATOR |
|
| - | 91 | // When CAN_PGM_PACKET.id==pstBLIND_* |
|
| - | 92 | // data[0] = Precent value 0-100 |
|
| - | 93 | ||
| - | 94 | ||
| - | 95 | ||
| - | 96 | ||
| 73 | 97 | ||
| 74 | //<HEART> |
- | |
| 75 | #define HEARTBEAT_BOOT_STARTUP 0x00 |
- | |
| 76 | #define HEARTBEAT_USER_STARTUP 0x01 |
- | |
| 77 | #define HEARTBEAT_ALIVE 0x02 |
- | |
| 78 | 98 | ||
| 79 | 99 | ||