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