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