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