1 // *********************************************************************
    2 //   General public DPA header file                                    *
    3 // *********************************************************************
    4 // Copyright (c) MICRORISC s.r.o.
    5 //
    6 // File:    $RCSfile: DPA.h,v $
    7 // Version: $Revision: 1.336 $
    8 // Date:    $Date: 2025/06/27 15:47:48 $
    9 //
   10 // Revision history:
   11 //   2025/05/30  Release for DPA 4.33
   12 //   2024/11/05  Release for DPA 4.32
   13 //   2024/04/17  Release for DPA 4.31
   14 //   2023/03/07  Release for DPA 4.30
   15 //   2022/10/05  Release for DPA 4.18
   16 //   2022/02/24  Release for DPA 4.17
   17 //   2021/08/20  Release for DPA 4.16
   18 //   2020/09/03  Release for DPA 4.15
   19 //   2020/04/03  Release for DPA 4.14
   20 //   2020/02/27  Release for DPA 4.13
   21 //   2020/01/09  Release for DPA 4.12
   22 //   2019/12/11  Release for DPA 4.11
   23 //   2019/10/09  Release for DPA 4.10
   24 //   2019/06/12  Release for DPA 4.03
   25 //   2019/06/03  Release for DPA 4.02
   26 //   2019/03/07  Release for DPA 4.01
   27 //   2019/01/10  Release for DPA 4.00
   28 //   2018/10/25  Release for DPA 3.03
   29 //   2017/11/16  Release for DPA 3.02
   30 //   2017/08/14  Release for DPA 3.01
   31 //   2017/03/13  Release for DPA 3.00
   32 //   2016/09/12  Release for DPA 2.28
   33 //   2016/04/14  Release for DPA 2.27
   34 //   2016/03/03  Release for DPA 2.26
   35 //   2016/01/21  Release for DPA 2.25
   36 //   2015/12/01  Release for DPA 2.24
   37 //   2015/10/23  Release for DPA 2.23
   38 //   2015/09/25  Release for DPA 2.22
   39 //   2015/09/03  Release for DPA 2.21
   40 //   2015/08/05  Release for DPA 2.20
   41 //   2014/10/31  Release for DPA 2.10
   42 //   2014/04/30  Release for DPA 2.00
   43 //   2013/10/03  Release for DPA 1.00
   44 //
   45 // *********************************************************************
   46 
   47 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/
   48 // IQRF Standards documentation https://doc.iqrf.org/
   49 
   50 #ifndef _DPA_HEADER_
   51 #define _DPA_HEADER_
   52 
   53 //############################################################################################
   54 
   55 // DPA version
   56 #define DPA_VERSION_MASTER          0x0433
   57 
   58 #if defined( __CC5X__ ) && !defined( CC5XnotDPA )
   59 // Compiled only at CC5X
   60 #if __CC5X__ < 3800
   61 #error Insufficient CC5X compiler version, V3.8 is minimum
   62 #endif
   63 
   64 #if IQRFOS < 406
   65 #error IQRF OS 4.06+ is required
   66 #endif
   67 
   68 // Bank for custom variables
   69 #pragma rambank = UserBank_01
   70 
   71 // Main DPA API entry address (also start of the licensed FLASH)
   72 #define DPA_API_ADDRESS             __LICENSED_FLASH
   73 
   74 // Main DPA entry address
   75 #define MAIN_DPA_ADDRESS            ( DPA_API_ADDRESS + 4 )
   76 
   77 // Main DPA API entry address stub
   78 #define DPA_API_ADDRESS_ENTRY       0x3A08
   79 
   80 // Address of the DPA Custom Handler
   81 #define CUSTOM_HANDLER_ADDRESS      0x3A20
   82 
   83 // Address of the DPA Custom Handler end + 1
   84 #if defined TR7xD
   85 #define CUSTOM_HANDLER_ADDRESS_END  0x3D80
   86 #else
   87 #define CUSTOM_HANDLER_ADDRESS_END  __USER_INTERRUPT
   88 #endif
   89 
   90 // DPA API entry function
   91 uns8 DpaApiEntry( uns8 par1, uns8 par2, uns8 apiIndex );
   92 
   93 // DPA API codes
   94 #define DPA_API_RFTX_DPAPACKET              0
   95 #define DPA_API_READ_CONFIG_BYTE            1
   96 #define DPA_API_SEND_TO_IFACEMASTER         2
   97 #define DPA_API_COORDINATOR_RFTX_DPAPACKET  3
   98 #define DPA_API_LOCAL_REQUEST               4
   99 #define DPA_API_SET_PERIPHERAL_ERROR        5
  100 #define DPA_API_SET_RF_DEFAULTS             6
  101 #define DPA_API_LOCAL_FRC                   7
  102 #define DPA_API_CRC8                        8
  103 #define DPA_API_AGGREGATE_FRC               9
  104 #define DPA_API_SET_OTK                     10
  105 #define DPA_API_I2C_INIT                    11
  106 #define DPA_API_I2C_START                   12
  107 #define DPA_API_I2C_WRITE                   13
  108 #define DPA_API_I2C_READ                    14
  109 #define DPA_API_I2C_STOP                    15
  110 #define DPA_API_I2C_WAIT_FOR_ACK            16
  111 #define DPA_API_I2C_SHUTDOWN                17
  112 #define DPA_API_I2C_WAIT_FOR_IDLE           18
  113 #define DPA_API_SLEEP                       19
  114 #define DPA_API_AFTER_SLEEP                 20
  115 #define DPA_API_RANDOM                      21
  116 #if !defined( TR7xD )
  117 #define DPA_API_MENU                        22
  118 #define DPA_API_MENU_INDICATE_RESULT        23
  119 #define DPA_API_MENU_EXECUTE                24
  120 #define DPA_API_DEEP_SLEEP                  25
  121 #endif
  122 
  123 // Used buffer size symbols
  124 #define sizeofBufferRF                      sizeof( bufferRF )
  125 #define sizeofBufferAUX                     sizeof( bufferAUX )
  126 #define sizeofBufferCOM                     sizeof( bufferCOM )
  127 #define sizeofBufferINFO                    sizeof( bufferINFO )
  128 
  129 // Converts conventional address to the linear one at PIC16LF1938
  130 // Note: This is workaround of CC5X preprocessor bug "No '#endif' detected"
  131 #define error_ #error Address cannot be linearized
  132 #define LINEARIZE_ADDRESS( a ) \
  133 #if ( ((uns16)(a)) - ( ((uns16)(a)) / 0x80 ) * 0x80 ) >= 0x20 && ( ((uns16)(a)) - ( ((uns16)(a)) / 0x80 ) * 0x80 ) <= 0x6F && ( ((uns16)(a)) / 0x80 ) <= 12 \
  134 ( ( ( ((uns16)(a)) / 0x80 ) * 0x50 ) + ( ((uns16)(a)) - 0x20 - ( ((uns16)(a)) / 0x80 ) * 0x80 ) + 0x2000 ) \
  135 #else \
  136 error_ \
  137 #endif
  138 #undef error_
  139 
  140 #define STRUCTATTR
  141 
  142 #else // __CC5X__
  143 // Not compiled at CC5X
  144 
  145 #if !defined( CC5XnotDPA )
  146 // Define CC5X types
  147 typedef int8_t int8;
  148 typedef int16_t int16;
  149 typedef int32_t int32;
  150 typedef uint8_t uns8;
  151 typedef uint16_t uns16;
  152 typedef uint32_t uns32;
  153 // Disables alignment of members of structures
  154 #define STRUCTATTR  __attribute__((packed))
  155 #else
  156 #define STRUCTATTR
  157 #endif
  158 
  159 // Fake buffer sizes
  160 #define sizeofBufferRF    64
  161 #define sizeofBufferAUX   64
  162 #define sizeofBufferCOM   64
  163 #define sizeofBufferINFO  64
  164 
  165 #endif  // __CC5X__
  166 
  167 // Indexes of configuration bytes used by DpaApiReadConfigByte( index )
  168 // Checksum
  169 #define CFGIND_CHECKSUM         0x00
  170 // Embedded peripherals
  171 #define CFGIND_DPA_PERIPHERALS  0x01
  172 // DPA configuration flags #0
  173 #define CFGIND_DPA_FLAGS0       0x05
  174 // Main RF channel, used by the subordinate network
  175 #define CFGIND_CHANNEL_2ND_A    0x06
  176 // Second RF channel, used by the subordinate network
  177 #define CFGIND_CHANNEL_2ND_B    0x07
  178 // TX power
  179 #define CFGIND_TXPOWER          0x08
  180 // RX filter used by checkRF()
  181 #define CFGIND_RXFILTER         0x09
  182 // toutRF for LP mode
  183 #define CFGIND_DPA_LP_TOUTRF    0x0A
  184 // UART interface baud rate
  185 #define CFGIND_DPA_UART_SPEED   0x0B
  186 // Alternate DSM channel
  187 #define CFGIND_ALTERNATE_DSM_CHANNEL 0x0C
  188 // DPA configuration flags #1
  189 #define CFGIND_DPA_FLAGS1       0x0D
  190 // Main RF channel
  191 #define CFGIND_CHANNEL_A        0x11
  192 // Second RF channel
  193 #define CFGIND_CHANNEL_B        0x12
  194 
  195 // 0: checks only mandatory precondition in order to prevent critical side-effects
  196 // 1: as above plus checks meaningful parameter conditions
  197 // 2: full implemented parameter checking (default)
  198 #ifndef PARAM_CHECK_LEVEL
  199 #define PARAM_CHECK_LEVEL 2
  200 #endif
  201 
  202 // "foursome" at IFace structure
  203 
  204 typedef struct
  205 {
  206   // Node address low byte
  207   uns8 NADRlow;
  208   // Node address high byte
  209   uns8 NADRhigh;
  210   // Peripheral number
  211   uns8 PNUM;
  212   // Peripheral command
  213   uns8 PCMD;
  214   // HWPID
  215   uns16 HWPID;
  216 } STRUCTATTR TDpaIFaceHeader;
  217 
  218 // Maximum command PCMD value (except reserved 0x3F = CMD_GET_PER_INFO)
  219 #define PCMD_MAX                    0x7f
  220 // Bit mask at PCMD that indicates DPA Response message
  221 #define RESPONSE_FLAG               0x80
  222 
  223 // IQMESH coordinator address
  224 #define COORDINATOR_ADDRESS         0x00
  225 // IQMESH broadcast address
  226 #define BROADCAST_ADDRESS           0xff
  227 // IQMESH temporary address, assigned by pre-bonding before authorization is done
  228 #define TEMPORARY_ADDRESS           0xfe
  229 // Address of the local device addressed by IFace
  230 #define LOCAL_ADDRESS               0xfc
  231 // Maximum IQMESH network device address
  232 #define MAX_ADDRESS                 ( 240 - 1 )
  233 
  234 // Time slots lengths in 10 ms
  235 #define MIN_STD_TIMESLOT    4
  236 #define MAX_STD_TIMESLOT    6
  237 
  238 #define MIN_LP_TIMESLOT     8
  239 #define MAX_LP_TIMESLOT     10
  240 
  241 // Maximum number of DPA PData bytes ( minus 8 = 6B foursome + 8b error code + 8b DpaValue )
  242 #define DPA_MAX_DATA_LENGTH         ( sizeofBufferCOM - sizeof( TDpaIFaceHeader ) - 2 * sizeof( uns8 ) )
  243 
  244 // Maximum number of peripherals info that can fit in the message
  245 #define MAX_PERIPHERALS_PER_BLOCK_INFO  ( DPA_MAX_DATA_LENGTH / sizeof( TPeripheralInfoAnswer ) )
  246 
  247 // Embedded peripheral numbers
  248 #define PNUM_COORDINATOR    0x00
  249 #define PNUM_NODE           0x01
  250 #define PNUM_OS             0x02
  251 #define PNUM_EEPROM         0x03
  252 #define PNUM_EEEPROM        0x04
  253 #define PNUM_RAM            0x05
  254 #define PNUM_LEDR           0x06
  255 #define PNUM_LEDG           0x07
  256 #define PNUM_IO             0x09
  257 #define PNUM_THERMOMETER    0x0A
  258 #define PNUM_UART           0x0C
  259 #define PNUM_FRC            0x0D
  260 
  261 // Number of the 1st user peripheral
  262 #define PNUM_USER           0x20
  263 // Number of the last user peripheral
  264 #define PNUM_USER_MAX       0x3E
  265 // Maximum peripheral number
  266 #define PNUM_MAX            0x7F
  267 
  268 // Fake peripheral number used to flag DPA response with error sent by RF
  269 #define PNUM_ERROR_FLAG     0xFE
  270 // Special peripheral used for enumeration
  271 #define PNUM_ENUMERATION    0xFF
  272 
  273 // DPA Commands for embedded peripherals
  274 #define CMD_COORDINATOR_ADDR_INFO  0
  275 #define CMD_COORDINATOR_DISCOVERED_DEVICES 1
  276 #define CMD_COORDINATOR_BONDED_DEVICES 2
  277 #define CMD_COORDINATOR_CLEAR_ALL_BONDS 3
  278 #define CMD_COORDINATOR_BOND_NODE 4
  279 #define CMD_COORDINATOR_REMOVE_BOND 5
  280 #define CMD_COORDINATOR_DISCOVERY 7
  281 #define CMD_COORDINATOR_SET_DPAPARAMS 8
  282 #define CMD_COORDINATOR_SET_HOPS 9
  283 #define CMD_COORDINATOR_BACKUP 11
  284 #define CMD_COORDINATOR_RESTORE 12
  285 #define CMD_COORDINATOR_AUTHORIZE_BOND 13
  286 #define CMD_COORDINATOR_BRIDGE 14
  287 #define CMD_COORDINATOR_SMART_CONNECT 18
  288 #define CMD_COORDINATOR_SET_MID 19
  289 
  290 #define CMD_NODE_READ 0
  291 #define CMD_NODE_REMOVE_BOND 1
  292 #define CMD_NODE_BACKUP 6
  293 #define CMD_NODE_RESTORE 7
  294 #define CMD_NODE_VALIDATE_BONDS 8
  295 #if !defined( TR7xD )
  296 #define CMD_NODE_GET_DPA_MENU_INFO  9
  297 #define CMD_NODE_EXE_DPA_MENU_ITEM  10
  298 #endif
  299 
  300 #define CMD_OS_READ 0
  301 #define CMD_OS_RESET 1
  302 #define CMD_OS_READ_CFG 2
  303 #define CMD_OS_RFPGM 3
  304 #define CMD_OS_SLEEP 4
  305 #define CMD_OS_BATCH 5
  306 #define CMD_OS_SET_SECURITY 6
  307 #define CMD_OS_INDICATE 7
  308 #define CMD_OS_RESTART 8
  309 #define CMD_OS_WRITE_CFG_BYTE 9
  310 #define CMD_OS_LOAD_CODE 10
  311 #define CMD_OS_SELECTIVE_BATCH 11
  312 #define CMD_OS_TEST_RF_SIGNAL 12
  313 #define CMD_OS_FACTORY_SETTINGS 13
  314 #define CMD_OS_WRITE_CFG 15
  315 
  316 #define CMD_RAM_READ 0
  317 #define CMD_RAM_WRITE 1
  318 #define CMD_RAM_READ_ANY    15
  319 
  320 #define CMD_EEPROM_READ CMD_RAM_READ
  321 #define CMD_EEPROM_WRITE CMD_RAM_WRITE
  322 
  323 #define CMD_EEEPROM_XREAD ( CMD_RAM_READ + 2 )
  324 #define CMD_EEEPROM_XWRITE ( CMD_RAM_WRITE + 2 )
  325 
  326 #define CMD_LED_SET_OFF 0
  327 #define CMD_LED_SET_ON 1
  328 #define CMD_LED_PULSE 3
  329 #define CMD_LED_FLASHING 4
  330 
  331 #define CMD_IO_DIRECTION  0
  332 #define CMD_IO_SET  1
  333 #define CMD_IO_GET  2
  334 
  335 #define CMD_THERMOMETER_READ 0
  336 
  337 #define CMD_UART_OPEN 0
  338 #define CMD_UART_CLOSE 1
  339 #define CMD_UART_WRITE_READ 2
  340 #define CMD_UART_CLEAR_WRITE_READ 3
  341 
  342 #define CMD_FRC_SEND 0
  343 #define CMD_FRC_EXTRARESULT 1
  344 #define CMD_FRC_SEND_SELECTIVE 2
  345 #define CMD_FRC_SET_PARAMS 3
  346 
  347 #define CMD_GET_PER_INFO  0x3f
  348 
  349 // DPA peripheral type
  350 
  351 typedef enum
  352 {
  353   PERIPHERAL_TYPE_DUMMY = 0x00,
  354   PERIPHERAL_TYPE_COORDINATOR = 0x01,
  355   PERIPHERAL_TYPE_NODE = 0x02,
  356   PERIPHERAL_TYPE_OS = 0x03,
  357   PERIPHERAL_TYPE_EEPROM = 0x04,
  358   PERIPHERAL_TYPE_BLOCK_EEPROM = 0x05,
  359   PERIPHERAL_TYPE_RAM = 0x06,
  360   PERIPHERAL_TYPE_LED = 0x07,
  361   PERIPHERAL_TYPE_SPI = 0x08,
  362   PERIPHERAL_TYPE_IO = 0x09,
  363   PERIPHERAL_TYPE_UART = 0x0a,
  364   PERIPHERAL_TYPE_THERMOMETER = 0x0b,
  365   PERIPHERAL_TYPE_ADC = 0x0c,
  366   PERIPHERAL_TYPE_PWM = 0x0d,
  367   PERIPHERAL_TYPE_FRC = 0x0e,
  368   // Starts peripheral type number interval for user peripherals
  369   PERIPHERAL_TYPE_USER_AREA = 0x80
  370 } TDpaPeripheralType;
  371 
  372 // Peripheral extended information
  373 
  374 typedef enum
  375 {
  376   PERIPHERAL_TYPE_EXTENDED_DEFAULT = 0x00,
  377   PERIPHERAL_TYPE_EXTENDED_READ = 0x01,
  378   PERIPHERAL_TYPE_EXTENDED_WRITE = 0x02,
  379   PERIPHERAL_TYPE_EXTENDED_READ_WRITE = PERIPHERAL_TYPE_EXTENDED_READ | PERIPHERAL_TYPE_EXTENDED_WRITE
  380 } TDpaPeripheralTypeExtended;
  381 
  382 // Response packet error codes
  383 
  384 typedef enum
  385 {
  386   // No error
  387   STATUS_NO_ERROR = 0,
  388 
  389   // General fail
  390   ERROR_FAIL = 1,
  391   // Incorrect PCMD
  392   ERROR_PCMD = 2,
  393   // Incorrect PNUM or PCMD
  394   ERROR_PNUM = 3,
  395   // Incorrect Address value when addressing memory type peripherals
  396   ERROR_ADDR = 4,
  397   // Incorrect Data length
  398   ERROR_DATA_LEN = 5,
  399   // Incorrect Data
  400   ERROR_DATA = 6,
  401   // Incorrect HWPID used
  402   ERROR_HWPID = 7,
  403   // Incorrect NADR
  404   ERROR_NADR = 8,
  405   // IFACE data consumed by Custom DPA Handler
  406   ERROR_IFACE_CUSTOM_HANDLER = 9,
  407   // Custom DPA Handler is missing
  408   ERROR_MISSING_CUSTOM_DPA_HANDLER = 10,
  409   // Usually refused for security reasons
  410   ERROR_DENIED = 11,
  411 
  412   // Beginning of the user code error interval
  413   ERROR_USER_FROM = 0x20,
  414   // End of the user code error interval
  415   ERROR_USER_TO = 0x3f,
  416 
  417   // Bit/flag reserved for a future use
  418   STATUS_RESERVED_FLAG = 0x40,
  419   // Bit to flag asynchronous DPA Response from [N]
  420   STATUS_ASYNC_RESPONSE = 0x80,
  421   // Error code used to mark DPA Confirmation
  422   STATUS_CONFIRMATION = 0xff
  423 } TErrorCodes;
  424 
  425 // Embedded FRC commands
  426 
  427 typedef enum
  428 {
  429   // 2 bits
  430   FRC_Ping = 0x00,
  431   FRC_AcknowledgedBroadcastBits = 0x02,
  432   FRC_PrebondedAlive = 0x03,
  433   FRC_SupplyVoltage = 0x04,
  434   FRC_PrebondedMemoryCompare2B = 0x05,
  435   // 1 byte
  436   FRC_Temperature = 0x80,
  437   FRC_AcknowledgedBroadcastBytes = 0x81,
  438   FRC_MemoryRead = 0x82,
  439   FRC_MemoryReadPlus1 = 0x83,
  440   FRC_FrcResponseTime = 0x84,
  441   FRC_TestRFsignal = 0x85,
  442   // 4 bytes
  443   FRC_PrebondedMemoryRead4BPlus1 = 0xF8,
  444   FRC_MemoryRead4B = 0xFA
  445 } TFRCommands;
  446 
  447 // Intervals of user FRC codes
  448 #define FRC_USER_BIT_FROM     0x40
  449 #define FRC_USER_BIT_TO       0x7F
  450 #define FRC_USER_BYTE_FROM    0xC0
  451 #define FRC_USER_BYTE_TO      0xDF
  452 #define FRC_USER_2BYTE_FROM   0xF0
  453 #define FRC_USER_2BYTE_TO     0xF7
  454 #define FRC_USER_4BYTE_FROM   0xFC
  455 #define FRC_USER_4BYTE_TO     0xFF
  456 
  457 // No HWPID specified
  458 #define HWPID_Default         0x0000
  459 // Use this type to override HWPID check
  460 #define HWPID_DoNotCheck      0xFfFf
  461 
  462 // RAM peripheral block definitions
  463 #ifdef TR7xD
  464 #define PERIPHERAL_RAM_LENGTH 48
  465 #else
  466 #define PERIPHERAL_RAM_LENGTH 80
  467 #endif
  468 
  469 // Start address of EEPROM peripheral in the real EEPROM
  470 #ifndef COORDINATOR_CUSTOM_HANDLER // Node
  471 #define PERIPHERAL_EEPROM_START     ( (uns8)0x00 )
  472 #else // Coordinator
  473 #define PERIPHERAL_EEPROM_START     ( (uns8)0x80 )
  474 #endif
  475 
  476 // Length of the internal EEPROM peripheral array
  477 #define PERIPHERAL_EEPROM_LENGTH            ( (uns8)( 0xC0 - PERIPHERAL_EEPROM_START ) )
  478 
  479 // Length of the readable area of serial EEEPROM from the EEEPROM DPA peripheral write point of view.
  480 #define EEEPROM_READ_LENGTH                 0x8000
  481 // Length of the writable area of serial EEEPROM from the EEEPROM DPA peripheral write point of view.
  482 #define EEEPROM_WRITE_LENGTH                0x4000
  483 
  484 // Starting address of the IO Setup DPA storage at external EEPROM
  485 #define IOSETUP_EEEPROM_ADDR                ( 0x0000 + sizeofBufferAUX )
  486 // Length of the IO setup memory block
  487 #define IOSETUP_LENGTH                      sizeofBufferAUX
  488 
  489 #if !defined( TR7xD )
  490 // Parameter at [_]DpaApi[Deep]Sleep() for not using Watchdog timer wakeup
  491 #define DpaApiSleep_WdtOff                  0b000000
  492 #endif
  493 
  494 // ---------------------------------------------------------
  495 
  496 // Enumerate peripherals structure
  497 
  498 typedef struct
  499 {
  500   uns16 DpaVersion;
  501   uns8 UserPerNr;
  502   uns8 EmbeddedPers[PNUM_USER / 8];
  503   uns16 HWPID;
  504   uns16 HWPIDver;
  505   uns8 Flags;
  506   uns8 UserPer[(PNUM_MAX - PNUM_USER + 1 + 7) / 8];
  507 } STRUCTATTR TEnumPeripheralsAnswer;
  508 
  509 #define FlagUserPer(UserPersArray,UserPerNumber)    UserPersArray[((UserPerNumber)-PNUM_USER) / 8] |= (uns8)0x01 << (((UserPerNumber)-PNUM_USER) % 8);
  510 
  511 // Get peripheral info structure (CMD_GET_PER_INFO)
  512 
  513 typedef struct
  514 {
  515   uns8 PerTE;
  516   uns8 PerT;
  517   uns8 Par1;
  518   uns8 Par2;
  519 } STRUCTATTR TPeripheralInfoAnswer;
  520 
  521 // Error DPA response (PNUM_ERROR_FLAG)
  522 
  523 typedef struct
  524 {
  525   uns8 ErrN;
  526   uns8 PNUMoriginal;
  527 } STRUCTATTR TErrorAnswer;
  528 
  529 // Structure returned by CMD_COORDINATOR_ADDR_INFO
  530 
  531 typedef struct
  532 {
  533   uns8 DevNr;
  534   uns8 DID;
  535 } STRUCTATTR TPerCoordinatorAddrInfo_Response;
  536 
  537 // Structure for CMD_COORDINATOR_BOND_NODE
  538 
  539 typedef struct
  540 {
  541   uns8 ReqAddr;
  542   uns8 BondingTestRetries;
  543 } STRUCTATTR TPerCoordinatorBondNode_Request;
  544 
  545 // Structure returned by CMD_COORDINATOR_BOND_NODE or CMD_COORDINATOR_SMART_CONNECT
  546 
  547 typedef struct
  548 {
  549   uns8 BondAddr;
  550   uns8 DevNr;
  551 } STRUCTATTR TPerCoordinatorBondNodeSmartConnect_Response;
  552 
  553 // Structure for CMD_COORDINATOR_REMOVE_BOND
  554 
  555 typedef struct
  556 {
  557   uns8 BondAddr;
  558 } STRUCTATTR TPerCoordinatorRemoveBond_Request;
  559 
  560 // Structure returned by CMD_COORDINATOR_REMOVE_BOND
  561 
  562 typedef struct
  563 {
  564   uns8 DevNr;
  565 } STRUCTATTR TPerCoordinatorRemoveBond_Response;
  566 
  567 // Structure for CMD_COORDINATOR_DISCOVERY
  568 
  569 typedef struct
  570 {
  571   uns8 TxPower;
  572   uns8 MaxAddr;
  573 } STRUCTATTR TPerCoordinatorDiscovery_Request;
  574 
  575 // Structure returned by CMD_COORDINATOR_DISCOVERY
  576 
  577 typedef struct
  578 {
  579   uns8 DiscNr;
  580 } STRUCTATTR TPerCoordinatorDiscovery_Response;
  581 
  582 // Structure for and also returned by CMD_COORDINATOR_SET_DPAPARAMS
  583 
  584 typedef struct
  585 {
  586   uns8 DpaParam;
  587 } STRUCTATTR TPerCoordinatorSetDpaParams_Request_Response;
  588 
  589 // Structure for and also returned by CMD_COORDINATOR_SET_HOPS
  590 
  591 typedef struct
  592 {
  593   uns8 RequestHops;
  594   uns8 ResponseHops;
  595 } STRUCTATTR TPerCoordinatorSetHops_Request_Response;
  596 
  597 // Structure for CMD_COORDINATOR_BACKUP and CMD_NODE_BACKUP
  598 
  599 typedef struct
  600 {
  601   uns8 Index;
  602 } STRUCTATTR TPerCoordinatorNodeBackup_Request;
  603 
  604 // Structure returned by CMD_COORDINATOR_BACKUP and CMD_NODE_BACKUP
  605 
  606 typedef struct
  607 {
  608   uns8 NetworkData[49];
  609 } STRUCTATTR TPerCoordinatorNodeBackup_Response;
  610 
  611 // Structure for CMD_COORDINATOR_RESTORE and CMD_NODE_RESTORE
  612 
  613 typedef struct
  614 {
  615   uns8 NetworkData[49];
  616 } STRUCTATTR TPerCoordinatorNodeRestore_Request;
  617 
  618 // Structure for CMD_COORDINATOR_AUTHORIZE_BOND
  619 
  620 typedef struct
  621 {
  622   uns8 ReqAddr;
  623   uns8 MID[4];
  624 } STRUCTATTR TPerCoordinatorAuthorizeBond_Request;
  625 
  626 // Structure returned by CMD_COORDINATOR_AUTHORIZE_BOND
  627 
  628 typedef struct
  629 {
  630   uns8 BondAddr;
  631   uns8 DevNr;
  632 } STRUCTATTR TPerCoordinatorAuthorizeBond_Response;
  633 
  634 // Structure for CMD_COORDINATOR_BRIDGE
  635 
  636 typedef struct
  637 {
  638   TDpaIFaceHeader subHeader;
  639   uns8 subPData[DPA_MAX_DATA_LENGTH - sizeof ( TDpaIFaceHeader)];
  640 } STRUCTATTR TPerCoordinatorBridge_Request;
  641 
  642 // Structure returned by CMD_COORDINATOR_BRIDGE
  643 
  644 typedef struct
  645 {
  646   TDpaIFaceHeader subHeader;
  647   uns8 subRespCode;
  648   uns8 subDpaValue;
  649   uns8 subPData[DPA_MAX_DATA_LENGTH - sizeof ( TDpaIFaceHeader) - 2 * sizeof ( uns8)];
  650 } STRUCTATTR TPerCoordinatorBridge_Response;
  651 
  652 // Structure for CMD_COORDINATOR_SMART_CONNECT
  653 
  654 typedef struct
  655 {
  656   uns8 ReqAddr;
  657   uns8 BondingTestRetries;
  658   uns8 IBK[16];
  659   uns8 MID[4];
  660   uns8 reserved0;
  661   uns8 VirtualDeviceAddress;
  662   uns8 UserData[4];
  663   uns8 reserved1[10];
  664 } STRUCTATTR TPerCoordinatorSmartConnect_Request;
  665 
  666 // Structure for CMD_COORDINATOR_SET_MID
  667 
  668 typedef struct
  669 {
  670   uns8 MID[4];
  671   uns8 BondAddr;
  672 } STRUCTATTR TPerCoordinatorSetMID_Request;
  673 
  674 // Structure returned by CMD_NODE_READ
  675 
  676 typedef struct
  677 {
  678   uns8 ntwADDR;
  679   uns8 ntwVRN;
  680   uns8 ntwZIN;
  681   uns8 ntwDID;
  682   uns8 ntwPVRN;
  683   uns16 ntwUSERADDRESS;
  684   uns16 ntwID;
  685   uns8 ntwVRNFNZ;
  686   uns8 ntwCFG;
  687   uns8 Flags;
  688 } STRUCTATTR TPerNodeRead_Response;
  689 
  690 // Structures for CMD_NODE_VALIDATE_BONDS
  691 
  692 typedef struct
  693 {
  694   uns8 Address;
  695   uns8 MID[4];
  696 } STRUCTATTR TPerNodeValidateBondsItem;
  697 
  698 // Structure for CMD_NODE_VALIDATE_BONDS
  699 
  700 typedef struct
  701 {
  702   TPerNodeValidateBondsItem Bonds[DPA_MAX_DATA_LENGTH / sizeof ( TPerNodeValidateBondsItem)];
  703 } STRUCTATTR TPerNodeValidateBonds_Request;
  704 
  705 #if !defined( TR7xD )
  706 // Structure returned by CMD_NODE_GET_DPA_MENU_INFO
  707 
  708 typedef struct
  709 {
  710   uns8 Menu;
  711   uns8 Flags;
  712   uns8 FlagsExt;
  713   char User1Name[21];
  714   char User2Name[21];
  715 } STRUCTATTR TPerNodeGetDpaMenuInfo_Response;
  716 
  717 // Structure for CMD_NODE_EXE_DPA_MENU_ITEM
  718 
  719 typedef struct
  720 {
  721   uns8 MenuAndItem;
  722   uns8 Flags;
  723 } STRUCTATTR TPerNodeExeDpaMenuItem_Request;
  724 
  725 // Structure returned by CMD_NODE_EXE_DPA_MENU_ITEM
  726 
  727 typedef struct
  728 {
  729   uns8 Result;
  730 } STRUCTATTR TPerNodeExeDpaMenuItem_Response;
  731 #endif
  732 
  733 // Structure returned by CMD_OS_READ
  734 
  735 typedef struct
  736 {
  737   uns8 MID[4];
  738   uns8 OsVersion;
  739   uns8 TrType;
  740   uns16 OsBuild;
  741   uns8 Rssi;
  742   uns8 SupplyVoltage;
  743   uns8 Flags;
  744   uns8 SlotLimits;
  745   uns8 IBK[16];
  746   // Enumerate peripherals part, variable length because of UserPer field
  747   uns16 DpaVersion;
  748   uns8 UserPerNr;
  749   uns8 EmbeddedPers[PNUM_USER / 8];
  750   uns16 HWPID;
  751   uns16 HWPIDver;
  752   uns8 FlagsEnum;
  753   uns8 UserPer[(PNUM_MAX - PNUM_USER + 1 + 7) / 8];
  754 } STRUCTATTR TPerOSRead_Response;
  755 
  756 // Structure returned by CMD_OS_READ_CFG
  757 
  758 typedef struct
  759 {
  760   uns8 Checksum;
  761   uns8 Configuration[31];
  762   uns8 RFPGM;
  763   uns8 Undocumented[1];
  764 } STRUCTATTR TPerOSReadCfg_Response;
  765 
  766 // Structure for CMD_OS_WRITE_CFG
  767 
  768 typedef struct
  769 {
  770   uns8 Undefined;
  771   uns8 Configuration[31];
  772   uns8 RFPGM;
  773 } STRUCTATTR TPerOSWriteCfg_Request;
  774 
  775 // Structures for CMD_OS_WRITE_CFG_BYTE
  776 
  777 typedef struct
  778 {
  779   uns8 Address;
  780   uns8 Value;
  781   uns8 Mask;
  782 } STRUCTATTR TPerOSWriteCfgByteTriplet;
  783 
  784 // Structure for CMD_OS_WRITE_CFG_BYTE
  785 
  786 typedef struct
  787 {
  788   TPerOSWriteCfgByteTriplet Triplets[DPA_MAX_DATA_LENGTH / sizeof ( TPerOSWriteCfgByteTriplet)];
  789 } STRUCTATTR TPerOSWriteCfgByte_Request;
  790 
  791 // Structure for CMD_OS_SET_SECURITY
  792 
  793 typedef struct
  794 {
  795   uns8 Type;
  796   uns8 Data[16];
  797 } STRUCTATTR TPerOSSetSecurity_Request;
  798 
  799 // Structure for CMD_OS_LOAD_CODE
  800 
  801 typedef struct
  802 {
  803   uns8 Flags;
  804   uns16 Address;
  805   uns16 Length;
  806   uns16 CheckSum;
  807 } STRUCTATTR TPerOSLoadCode_Request;
  808 
  809 // Structure for CMD_OS_SLEEP
  810 
  811 typedef struct
  812 {
  813   uns16 Time;
  814   uns8 Control;
  815 } STRUCTATTR TPerOSSleep_Request;
  816 
  817 // Structure for CMD_OS_SELECTIVE_BATCH
  818 
  819 typedef struct
  820 {
  821   uns8 SelectedNodes[30];
  822   uns8 Requests[DPA_MAX_DATA_LENGTH - 30];
  823 } STRUCTATTR TPerOSSelectiveBatch_Request;
  824 
  825 // Structure for CMD_OS_TEST_RF_SIGNAL request
  826 
  827 typedef struct
  828 {
  829   uns8 Channel;
  830   uns8 RXfilter;
  831   uns16 Time;
  832 } STRUCTATTR TPerOSTestRfSignal_Request;
  833 
  834 // Structure for CMD_OS_TEST_RF_SIGNAL response
  835 
  836 typedef struct
  837 {
  838   uns8 Counter;
  839 } STRUCTATTR TPerOSTestRfSignal_Response;
  840 
  841 // Structure for CMD_OS_INDICATE request
  842 
  843 typedef struct
  844 {
  845   uns8 Control;
  846 } STRUCTATTR TPerOSIndicate_Request;
  847 
  848 // Structure for general memory request
  849 
  850 typedef struct
  851 {
  852   // Address of data to write or read
  853   uns8 Address;
  854 
  855   union
  856   {
  857     // Memory read request
  858 
  859     struct
  860     {
  861       // Length of data to read
  862       uns8 Length;
  863     } Read;
  864 
  865     // Size of Address field
  866 #define MEMORY_WRITE_REQUEST_OVERHEAD   ( sizeof( uns8 ) )
  867 
  868     // Memory write request
  869 
  870     struct
  871     {
  872       uns8 PData[DPA_MAX_DATA_LENGTH - MEMORY_WRITE_REQUEST_OVERHEAD];
  873     } Write;
  874 
  875   } ReadWrite;
  876 } STRUCTATTR TPerMemoryRequest;
  877 
  878 // Structure for general extended memory request
  879 
  880 typedef struct
  881 {
  882   // Address of data to write or read
  883   uns16 Address;
  884 
  885   union
  886   {
  887     // Memory read request
  888 
  889     struct
  890     {
  891       // Length of data to read
  892       uns8 Length;
  893     } Read;
  894 
  895     // Size of Address field
  896 #define XMEMORY_WRITE_REQUEST_OVERHEAD  ( sizeof( uns16 ) )
  897 
  898     // Memory write request
  899 
  900     struct
  901     {
  902       uns8 PData[DPA_MAX_DATA_LENGTH - XMEMORY_WRITE_REQUEST_OVERHEAD];
  903     } Write;
  904 
  905   } ReadWrite;
  906 } STRUCTATTR TPerXMemoryRequest;
  907 
  908 // Structure for CMD_IO requests
  909 
  910 typedef struct
  911 {
  912   uns8 Port;
  913   uns8 Mask;
  914   uns8 Value;
  915 } STRUCTATTR TPerIOTriplet;
  916 
  917 typedef struct
  918 {
  919   uns8 Header; // == PNUM_IO_DELAY
  920   uns16 Delay;
  921 } STRUCTATTR TPerIODelay;
  922 
  923 // Union for CMD_IO_SET and CMD_IO_DIRECTION requests
  924 
  925 typedef union
  926 {
  927   TPerIOTriplet Triplets[DPA_MAX_DATA_LENGTH / sizeof ( TPerIOTriplet)];
  928   TPerIODelay Delays[DPA_MAX_DATA_LENGTH / sizeof ( TPerIODelay)];
  929 } STRUCTATTR TPerIoDirectionAndSet_Request;
  930 
  931 // Structure returned by CMD_THERMOMETER_READ
  932 
  933 typedef struct
  934 {
  935   int8 IntegerValue;
  936   int16 SixteenthValue;
  937 } STRUCTATTR TPerThermometerRead_Response;
  938 
  939 // Structure for CMD_UART_OPEN
  940 
  941 typedef struct
  942 {
  943   uns8 BaudRate;
  944 } STRUCTATTR TPerUartOpen_Request;
  945 
  946 // Structure for CMD_UART_[CLEAR_]WRITE_READ
  947 
  948 typedef struct
  949 {
  950   uns8 ReadTimeout;
  951   uns8 WrittenData[DPA_MAX_DATA_LENGTH - sizeof ( uns8)];
  952 } STRUCTATTR TPerUartWriteRead_Request;
  953 
  954 // Structure for CMD_FRC_SEND
  955 
  956 typedef struct
  957 {
  958   uns8 FrcCommand;
  959   uns8 UserData[30];
  960 } STRUCTATTR TPerFrcSend_Request;
  961 
  962 // Structure for CMD_FRC_SEND_SELECTIVE
  963 
  964 typedef struct
  965 {
  966   uns8 FrcCommand;
  967   uns8 SelectedNodes[30];
  968   uns8 UserData[25];
  969 } STRUCTATTR TPerFrcSendSelective_Request;
  970 
  971 // Structure returned by CMD_FRC_SEND and CMD_FRC_SEND_SELECTIVE
  972 
  973 typedef struct
  974 {
  975   uns8 Status;
  976   uns8 FrcData[DPA_MAX_DATA_LENGTH - sizeof ( uns8)];
  977 } STRUCTATTR TPerFrcSend_Response;
  978 
  979 // Structure for request and response of CMD_FRC_SET_PARAMS
  980 
  981 typedef struct
  982 {
  983   uns8 FrcParams;
  984 } STRUCTATTR TPerFrcSetParams_RequestResponse;
  985 
  986 // Interface and CMD_COORDINATOR_BRIDGE confirmation structure
  987 
  988 typedef struct
  989 {
  990   // Number of hops
  991   uns8 Hops;
  992   // Time slot length in 10ms
  993   uns8 TimeSlotLength;
  994   // Number of hops for response
  995   uns8 HopsResponse;
  996 } STRUCTATTR TIFaceConfirmation;
  997 
  998 // ---------------------------------------------------------
  999 
 1000 // DPA Message data structure (packet w/o NADR, PNUM, PCMD, HWPID)
 1001 
 1002 typedef union
 1003 {
 1004   // General DPA request
 1005 
 1006   struct
 1007   {
 1008     uns8 PData[DPA_MAX_DATA_LENGTH];
 1009   } Request;
 1010 
 1011   // General DPA response
 1012 
 1013   struct
 1014   {
 1015     uns8 PData[DPA_MAX_DATA_LENGTH];
 1016   } Response;
 1017 
 1018   // Enumerate peripherals structure
 1019   TEnumPeripheralsAnswer EnumPeripheralsAnswer;
 1020 
 1021   // Get peripheral info structure (CMD_GET_PER_INFO)
 1022   TPeripheralInfoAnswer PeripheralInfoAnswer;
 1023 
 1024   // Get peripheral info structure (CMD_GET_PER_INFO) for more peripherals
 1025   TPeripheralInfoAnswer PeripheralInfoAnswers[MAX_PERIPHERALS_PER_BLOCK_INFO];
 1026 
 1027   // Error DPA response (PNUM_ERROR_FLAG)
 1028   TErrorAnswer ErrorAnswer;
 1029 
 1030   // Structure returned by CMD_COORDINATOR_ADDR_INFO
 1031   TPerCoordinatorAddrInfo_Response PerCoordinatorAddrInfo_Response;
 1032 
 1033   // Structure for CMD_COORDINATOR_BOND_NODE
 1034   TPerCoordinatorBondNode_Request PerCoordinatorBondNode_Request;
 1035 
 1036   // Structure returned by CMD_COORDINATOR_BOND_NODE or CMD_COORDINATOR_SMART_CONNECT
 1037   TPerCoordinatorBondNodeSmartConnect_Response PerCoordinatorBondNodeSmartConnect_Response;
 1038 
 1039   // Structure for CMD_COORDINATOR_REMOVE_BOND
 1040   TPerCoordinatorRemoveBond_Request PerCoordinatorRemoveBond_Request;
 1041 
 1042   // Structure returned by CMD_COORDINATOR_REMOVE_BOND
 1043   TPerCoordinatorRemoveBond_Response PerCoordinatorRemoveBond_Response;
 1044 
 1045   // Structure for CMD_COORDINATOR_DISCOVERY
 1046   TPerCoordinatorDiscovery_Request PerCoordinatorDiscovery_Request;
 1047 
 1048   // Structure returned by CMD_COORDINATOR_DISCOVERY
 1049   TPerCoordinatorDiscovery_Response PerCoordinatorDiscovery_Response;
 1050 
 1051   // Structure for and also returned by CMD_COORDINATOR_SET_DPAPARAMS
 1052   TPerCoordinatorSetDpaParams_Request_Response PerCoordinatorSetDpaParams_Request_Response;
 1053 
 1054   // Structure for and also returned by CMD_COORDINATOR_SET_HOPS
 1055   TPerCoordinatorSetHops_Request_Response PerCoordinatorSetHops_Request_Response;
 1056 
 1057   // Structure for CMD_COORDINATOR_BACKUP and CMD_NODE_BACKUP
 1058   TPerCoordinatorNodeBackup_Request PerCoordinatorNodeBackup_Request;
 1059 
 1060   // Structure returned by CMD_COORDINATOR_BACKUP and CMD_NODE_BACKUP
 1061   TPerCoordinatorNodeBackup_Response PerCoordinatorNodeBackup_Response;
 1062 
 1063   // Structure for CMD_COORDINATOR_RESTORE and CMD_NODE_RESTORE
 1064   TPerCoordinatorNodeRestore_Request PerCoordinatorNodeRestore_Request;
 1065 
 1066   // Structure for CMD_COORDINATOR_AUTHORIZE_BOND
 1067   TPerCoordinatorAuthorizeBond_Request PerCoordinatorAuthorizeBond_Request;
 1068 
 1069   // Structure returned by CMD_COORDINATOR_AUTHORIZE_BOND
 1070   TPerCoordinatorAuthorizeBond_Response PerCoordinatorAuthorizeBond_Response;
 1071 
 1072   // Structure for CMD_COORDINATOR_BRIDGE
 1073   TPerCoordinatorBridge_Request PerCoordinatorBridge_Request;
 1074 
 1075   // Structure returned by CMD_COORDINATOR_BRIDGE
 1076   TPerCoordinatorBridge_Response PerCoordinatorBridge_Response;
 1077 
 1078   // Structure for CMD_COORDINATOR_SMART_CONNECT
 1079   TPerCoordinatorSmartConnect_Request PerCoordinatorSmartConnect_Request;
 1080 
 1081   // Structure for CMD_COORDINATOR_SET_MID
 1082   TPerCoordinatorSetMID_Request PerCoordinatorSetMID_Request;
 1083 
 1084   // Structure returned by CMD_NODE_READ
 1085   TPerNodeRead_Response PerNodeRead_Response;
 1086 
 1087   // Structure for CMD_NODE_VALIDATE_BONDS
 1088   TPerNodeValidateBonds_Request PerNodeValidateBonds_Request;
 1089 
 1090 #if !defined( TR7xD )
 1091   // Structure returned by CMD_NODE_GET_DPA_MENU_INFO
 1092   TPerNodeGetDpaMenuInfo_Response PerNodeGetDpaMenuInfo_Response;
 1093 
 1094   // Structure for CMD_NODE_EXE_DPA_MENU_ITEM
 1095   TPerNodeExeDpaMenuItem_Request PerNodeExeDpaMenuItem_Request;
 1096 
 1097   // Structure returned by CMD_NODE_EXE_DPA_MENU_ITEM
 1098   TPerNodeExeDpaMenuItem_Response PerNodeExeDpaMenuItem_Response;
 1099 #endif
 1100 
 1101   // Structure returned by CMD_OS_READ
 1102   TPerOSRead_Response PerOSRead_Response;
 1103 
 1104   // Structure returned by CMD_OS_READ_CFG
 1105   TPerOSReadCfg_Response PerOSReadCfg_Response;
 1106 
 1107   // Structure for CMD_OS_WRITE_CFG
 1108   TPerOSWriteCfg_Request PerOSWriteCfg_Request;
 1109 
 1110   // Structure for CMD_OS_WRITE_CFG_BYTE
 1111   TPerOSWriteCfgByte_Request PerOSWriteCfgByte_Request;
 1112 
 1113   // Structure for CMD_OS_SET_SECURITY
 1114   TPerOSSetSecurity_Request PerOSSetSecurity_Request;
 1115 
 1116   // Structure for CMD_OS_LOAD_CODE
 1117   TPerOSLoadCode_Request PerOSLoadCode_Request;
 1118 
 1119   // Structure for CMD_OS_SLEEP
 1120   TPerOSSleep_Request PerOSSleep_Request;
 1121 
 1122   // Structure for CMD_OS_SELECTIVE_BATCH
 1123   TPerOSSelectiveBatch_Request PerOSSelectiveBatch_Request;
 1124 
 1125   // Structure for CMD_OS_TEST_RF_SIGNAL request
 1126   TPerOSTestRfSignal_Request PerOSTestRfSignal_Request;
 1127 
 1128   // Structure for CMD_OS_INDICATE request
 1129   TPerOSIndicate_Request PerOSIndicate_Request;
 1130 
 1131   // Structure for CMD_OS_TEST_RF_SIGNAL response
 1132   TPerOSTestRfSignal_Response PerOSTestRfSignal_Response;
 1133 
 1134   // Structure for general memory request
 1135   TPerMemoryRequest MemoryRequest;
 1136 
 1137   // Structure for general extended memory request
 1138   TPerXMemoryRequest XMemoryRequest;
 1139 
 1140   // Structure for CMD_IO requests
 1141   TPerIoDirectionAndSet_Request PerIoDirectionAndSet_Request;
 1142 
 1143   // Structure returned by CMD_THERMOMETER_READ
 1144   TPerThermometerRead_Response PerThermometerRead_Response;
 1145 
 1146   // Structure for CMD_UART_OPEN
 1147   TPerUartOpen_Request PerUartOpen_Request;
 1148 
 1149   // Structure for CMD_UART_[CLEAR_]WRITE_READ
 1150   TPerUartWriteRead_Request PerUartWriteRead_Request;
 1151 
 1152   // Structure for CMD_FRC_SEND
 1153   TPerFrcSend_Request PerFrcSend_Request;
 1154 
 1155   // Structure returned by CMD_FRC_SEND and CMD_FRC_SEND_SELECTIVE
 1156   TPerFrcSend_Response PerFrcSend_Response;
 1157 
 1158   // Structure for CMD_FRC_SEND_SELECTIVE
 1159   TPerFrcSendSelective_Request PerFrcSendSelective_Request;
 1160 
 1161   // Structure for request and response of CMD_FRC_SET_PARAMS
 1162   TPerFrcSetParams_RequestResponse PerFrcSetParams_RequestResponse;
 1163 
 1164   // Interface and CMD_COORDINATOR_BRIDGE confirmation structure
 1165   TIFaceConfirmation IFaceConfirmation;
 1166 } TDpaMessage;
 1167 
 1168 // Custom DPA Handler events
 1169 #define DpaEvent_DpaRequest               0
 1170 #define DpaEvent_Interrupt                1
 1171 #define DpaEvent_Idle                     2
 1172 #define DpaEvent_Init                     3
 1173 #define DpaEvent_Notification             4
 1174 #define DpaEvent_AfterRouting             5
 1175 #define DpaEvent_BeforeSleep              6
 1176 #define DpaEvent_AfterSleep               7
 1177 #define DpaEvent_Reset                    8
 1178 #define DpaEvent_DisableInterrupts        9
 1179 #define DpaEvent_FrcValue                 10
 1180 #define DpaEvent_ReceiveDpaResponse       11
 1181 #define DpaEvent_IFaceReceive             12
 1182 #define DpaEvent_ReceiveDpaRequest        13
 1183 #define DpaEvent_BeforeSendingDpaResponse 14
 1184 #define DpaEvent_PeerToPeer               15
 1185 #define DpaEvent_UserDpaValue             17
 1186 #define DpaEvent_FrcResponseTime          18
 1187 #if defined( TR7xD )
 1188 #define DpaEvent_BondingButton            19
 1189 #endif
 1190 #define DpaEvent_Indicate                 20
 1191 #define DpaEvent_VerifyLocalFrc           21
 1192 #if !defined( TR7xD )
 1193 #define DpaEvent_MenuActivated            22
 1194 #define DpaEvent_MenuItemSelected         23
 1195 #define DpaEvent_MenuItemFinalize         24
 1196 #define DpaEvent_InStandby                25
 1197 #define DpaEvent_AsyncRequest             26
 1198 #define DpaEvent_AsyncResponse            27
 1199 #endif
 1200 
 1201 #if defined( TR7xD )
 1202 #define DpaEvent_LAST                     DpaEvent_VerifyLocalFrc
 1203 #else
 1204 #define DpaEvent_LAST                     DpaEvent_AsyncResponse
 1205 #endif
 1206 
 1207 // Types of the diagnostic DPA Value that is returned inside DPA response
 1208 
 1209 typedef enum
 1210 {
 1211   DpaValueType_RSSI = 0,
 1212   DpaValueType_SupplyVoltage = 1,
 1213   DpaValueType_System = 2,
 1214   DpaValueType_User = 3
 1215 } TDpaValueType;
 1216 
 1217 // Type (color) of LED peripheral
 1218 
 1219 typedef enum
 1220 {
 1221   LED_COLOR_RED = 0,
 1222   LED_COLOR_GREEN = 1,
 1223   LED_COLOR_BLUE = 2,
 1224   LED_COLOR_YELLOW = 3,
 1225   LED_COLOR_WHITE = 4,
 1226   LED_COLOR_UNKNOWN = 0xff
 1227 } TLedColor;
 1228 
 1229 // Baud rates
 1230 
 1231 typedef enum
 1232 {
 1233   DpaBaud_1200 = 0x00,
 1234   DpaBaud_2400 = 0x01,
 1235   DpaBaud_4800 = 0x02,
 1236   DpaBaud_9600 = 0x03,
 1237   DpaBaud_19200 = 0x04,
 1238   DpaBaud_38400 = 0x05,
 1239   DpaBaud_57600 = 0x06,
 1240   DpaBaud_115200 = 0x07,
 1241   DpaBaud_230400 = 0x08
 1242 } TBaudRates;
 1243 
 1244 // Useful PNUM_IO definitions
 1245 
 1246 typedef enum
 1247 {
 1248   PNUM_IO_PORTA = 0x00,
 1249   PNUM_IO_TRISA = 0x00,
 1250 
 1251   PNUM_IO_PORTB = 0x01,
 1252   PNUM_IO_TRISB = 0x01,
 1253 
 1254   PNUM_IO_PORTC = 0x02,
 1255   PNUM_IO_TRISC = 0x02,
 1256 
 1257   PNUM_IO_PORTE = 0x04,
 1258   PNUM_IO_TRISE = 0x04,
 1259 
 1260   PNUM_IO_WPUB = 0x11,
 1261 #if !defined( TR7xD )
 1262   PNUM_IO_WPUA = 0x10,
 1263   PNUM_IO_WPUC = 0x12,
 1264   PNUM_IO_WPUE = 0x14,
 1265 #endif
 1266   PNUM_IO_DELAY = 0xff,
 1267 } PNUM_IO_Definitions;
 1268 
 1269 // To test for enumeration peripherals request
 1270 #define IsDpaEnumPeripheralsRequestNoSize() ( _PNUM == PNUM_ENUMERATION && _PCMD == CMD_GET_PER_INFO )
 1271 
 1272 #if PARAM_CHECK_LEVEL >= 2
 1273 #define IsDpaEnumPeripheralsRequest() ( IsDpaEnumPeripheralsRequestNoSize() && _DpaDataLength == 0 )
 1274 #else
 1275 #define IsDpaEnumPeripheralsRequest() IsDpaEnumPeripheralsRequestNoSize()
 1276 #endif
 1277 
 1278 // To test for peripherals information request
 1279 #define IsDpaPeripheralInfoRequestNoSize()  ( _PNUM != PNUM_ENUMERATION && _PCMD == CMD_GET_PER_INFO )
 1280 
 1281 #if PARAM_CHECK_LEVEL >= 2
 1282 #define IsDpaPeripheralInfoRequest()  ( IsDpaPeripheralInfoRequestNoSize() && _DpaDataLength == 0 )
 1283 #else
 1284 #define IsDpaPeripheralInfoRequest()  IsDpaPeripheralInfoRequestNoSize()
 1285 #endif
 1286 
 1287 // Optimized macro for both testing enumeration peripherals ELSE peripherals information. See examples
 1288 #define IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequestNoSize() if ( _PCMD == CMD_GET_PER_INFO ) if ( _PNUM == PNUM_ENUMERATION )
 1289 
 1290 #if PARAM_CHECK_LEVEL >= 2
 1291 #define IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() if ( _DpaDataLength == 0 && _PCMD == CMD_GET_PER_INFO ) if ( _PNUM == PNUM_ENUMERATION )
 1292 #else
 1293 #define IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequestNoSize()
 1294 #endif
 1295 
 1296 #ifndef TR7xD
 1297 
 1298 // Menus
 1299 #define DMENU_Online                                  0x0
 1300 #define DMENU_ReadyToBond                             0x1
 1301 #define DMENU_Beaming                                 0x2
 1302 #define DMENU_Standby                                 0x3
 1303 
 1304 // Menu items
 1305 #define DMENU_Item_None                               0x0
 1306 #define DMENU_Item_Beaming                            ( DMENU_Online + 1 ) // 1
 1307 #define DMENU_Item_BondRequest                        ( DMENU_ReadyToBond + 1 ) // 2
 1308 #define DMENU_Item_ConnectivityCheck                  ( DMENU_Beaming + 1 ) // 3
 1309 #define DMENU_Item_ExitStandby                        ( DMENU_Standby + 1 ) // 4
 1310 #define DMENU_Item_StateIndication                    ( DMENU_Item_ExitStandby + 1 ) // 5
 1311 #define DMENU_Item_User1                              ( DMENU_Item_StateIndication + 1 ) // 6
 1312 #define DMENU_Item_User2                              ( DMENU_Item_User1 + 1 ) // 7
 1313 #define DMENU_Item_Standby                            ( DMENU_Item_User2 + 1 ) // 8
 1314 #define DMENU_Item_Reset                              ( DMENU_Item_Standby + 1 ) // 9
 1315 #define DMENU_Item_UnbondAndRestart                   ( DMENU_Item_Reset + 2 ) // 11
 1316 #define DMENU_Item_UnbondFactorySettingsAndRestart    ( DMENU_Item_UnbondAndRestart + 1 ) // 12
 1317 
 1318 // Flags for enabling/disabling menu items at event DpaEvent_MenuActivated (when TRUE is returned) and at DpaApiMenu call
 1319 #define DMENU_Item_Implemented_Beaming                            0b00000001
 1320 #define DMENU_Item_Implemented_User1                              0b00000100
 1321 #define DMENU_Item_Implemented_User1Confirmed                     ( DMENU_Item_Implemented_User1 | DMENU_Item_Confirm_User1 )
 1322 #define DMENU_Item_Implemented_User2                              0b00001000
 1323 #define DMENU_Item_Implemented_User2Confirmed                     ( DMENU_Item_Implemented_User2 | DMENU_Item_Confirm_User2 )
 1324 
 1325 #define DMENU_Item_Unimplemented_Standby                          0b00010000
 1326 #define DMENU_Item_Unimplemented_UnbondAndRestart                 0b01000000
 1327 #define DMENU_Item_Unimplemented_UnbondFactorySettingsAndRestart  0b10000000
 1328 
 1329 #define DMENU_Item_Confirm_User1                                  0b00000010
 1330 #define DMENU_Item_Confirm_User2                                  0b00100000
 1331 
 1332 // Extended flags
 1333 #define DMENU_Ext_Item_Unimplemented_Reset                        0b00000001
 1334 #define DMENU_Ext_DoNotOpen                                       0b10000000
 1335 
 1336 // Macro to construct value containing both menu and item values
 1337 #define MakeDMenuAndItem( menu, menuItem )            ( ((menu) << 4 ) | (menuItem) )
 1338 // Macro to get menu from menu&item value
 1339 #define GetDMenu( menuAndItem )                       ( (menuAndItem) >> 4 )
 1340 // Macro to get menu item from menu&item value
 1341 #define GetDMenuItem( menuAndItem )                   ( (menuAndItem) & 0x0F )
 1342 
 1343 #endif
 1344 
 1345 #if defined( __CC5X__ ) && !defined( CC5XnotDPA )
 1346 
 1347 // DPA message at bufferRF
 1348 TDpaMessage DpaRfMessage @bufferRF;
 1349 
 1350 // Note: Works only, because _DpaMessage.Request.PData is at the same location as bufferRF!
 1351 #define _FSR_DPA    _FSR_RF
 1352 
 1353 // Actual allocation of the RAM Peripheral memory block @ UserBank_02
 1354 bank12 uns8 PeripheralRam[PERIPHERAL_RAM_LENGTH] @ 0x620;
 1355 
 1356 // Actual DPA message parameters at memory
 1357 #define _NADR           RX
 1358 #define _NADRhigh       RTAUX
 1359 #define _PNUM           PNUM
 1360 #define _PCMD           PCMD
 1361 #define _DpaDataLength  DLEN
 1362 #define _DpaMessage     DpaRfMessage
 1363 
 1364 // Return actual DPA user routine event
 1365 #define GetDpaEvent()   userReg0
 1366 
 1367 // Stores DPA Params inside DPA request/response
 1368 #define _DpaParams      PPAR
 1369 // Get DPA Value type out of the DPA Params
 1370 #define DpaValueType()  ( _DpaParams & 0b11 )
 1371 
 1372 // When TRUE then encryptBufferRF/decryptBufferRF is done by AccessPassord
 1373 bit encryptByAccessPassword @ usedBank0[0x23].7;
 1374 
 1375 // DP2P response time-slot time in 10 ms
 1376 #define DP2P_TIMESLOT   11
 1377 
 1378 // DP2P request packet. Fills out the whole bufferRF.
 1379 
 1380 typedef struct
 1381 {
 1382   uns8 Header[3]; // 0x000000
 1383   uns8 SelectedNodes[30];
 1384   uns8 SlotLength;
 1385   uns8 ResponseTxPower;
 1386   uns8 Reserved;
 1387   uns16 HWPID;
 1388   uns8 PDATA[sizeofBufferRF - (3 + 30 + 1 + 1 + 1) * sizeof ( uns8) - (1) * sizeof ( uns16)]; // size is 26 bytes
 1389 } STRUCTATTR TDP2Prequest;
 1390 
 1391 // DP2P invite packet.
 1392 
 1393 typedef struct
 1394 {
 1395   uns8 Header[3]; // 0x000001
 1396   uns8 NADR;
 1397   uns8 Rand[12];
 1398 } STRUCTATTR TDP2Invite;
 1399 
 1400 // DP2P confirm packet.
 1401 
 1402 typedef struct
 1403 {
 1404   uns8 Header[3]; // 0x000003
 1405   uns8 NADR;
 1406   uns8 Rand[12];
 1407 } STRUCTATTR TDP2Confirm;
 1408 
 1409 // DP2P response packet.
 1410 
 1411 typedef struct
 1412 {
 1413   uns8 Header[3]; // 0xFfFfFf
 1414   uns8 NADR;
 1415   uns8 PDATA[DPA_MAX_DATA_LENGTH];
 1416 } STRUCTATTR TDP2Presponse;
 1417 
 1418 // Include assembler definitions
 1419 #include "HexCodes.h"
 1420 // CC5X fix
 1421 #if __CC5X__ <= 3800 && _16LF18877 == 1
 1422 #undef  __MOVLB
 1423 #define __MOVLB(k)    (0x0140+((k)&0x3F))
 1424 #endif
 1425 
 1426 // Next code must start at the IQRF APPLICATION routine entry point
 1427 #pragma origin __APPLICATION_ADDRESS
 1428 
 1429 #endif  // __CC5X__
 1430 #endif  // _DPA_HEADER_
 1431 //############################################################################################