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