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