Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
d7a_1x.h
00001 /// ====================================================================== 00002 /// 00003 /// Copyright (C) 20XX WizziLab 00004 /// All Rights Reserved 00005 /// 00006 /// ======================================================================= 00007 /// 00008 /// @file d7a_1x.h 00009 /// @brief D7A 1.x API (below ALP and FS) 00010 /// @defgroup D7A D7A 1.x API 00011 /// @{ 00012 /// ======================================================================= 00013 00014 #ifndef __D7A_1X_H__ 00015 #define __D7A_1X_H__ 00016 00017 #include "hal_types.h" 00018 #include "kal_codec.h" 00019 00020 /// @ingroup D7A_API 00021 /// @defgroup D7A_API_STR D7A API (all except APL) 00022 /// @{ 00023 00024 // ======================================================================= 00025 // d7a_buf_t 00026 // ----------------------------------------------------------------------- 00027 /// Generic D7A buffer structure 00028 // ======================================================================= 00029 typedef struct 00030 { 00031 /// Buffer payload length 00032 u8 len; 00033 /// Payload start offset (Result length) 00034 u8 pof; 00035 /// Shadow buffer payload length (snap/restore) 00036 u8 shadow_len; 00037 /// Shadow Payload start offset (snap/restore) 00038 u8 shadow_pof; 00039 /// Data 00040 u8 data[1]; 00041 00042 } d7a_buf_t; 00043 00044 //====================================================================== 00045 // D7A_BUF_R_PTR 00046 //---------------------------------------------------------------------- 00047 /// @brief Pointer to the metadata (result) 00048 /// @param buf d7a_buf_t buffer 00049 //====================================================================== 00050 #define D7A_BUF_R_PTR(buf) (void*)(((d7a_buf_t*)(buf))->data) 00051 00052 //====================================================================== 00053 // D7A_BUF_P_PTR 00054 //---------------------------------------------------------------------- 00055 /// @brief Pointer to the payload 00056 /// @param buf d7a_buf_t buffer 00057 //====================================================================== 00058 #define D7A_BUF_P_PTR(buf) (void*)(((d7a_buf_t*)(buf))->data + ((d7a_buf_t*)(buf))->pof) 00059 00060 //====================================================================== 00061 // D7A_BUF_P_LEN 00062 //---------------------------------------------------------------------- 00063 /// @brief Get the payload length 00064 /// @param buf d7a_buf_t buffer 00065 //====================================================================== 00066 #define D7A_BUF_P_LEN(buf) (((d7a_buf_t*)(buf))->len) 00067 00068 //====================================================================== 00069 // Special session identifiers 00070 //====================================================================== 00071 #define D7A_RESP_ID (0xff) 00072 00073 // ======================================================================= 00074 // d7a_id_t 00075 // ----------------------------------------------------------------------- 00076 /// Identifier types enumerator 00077 // ======================================================================= 00078 typedef enum 00079 { 00080 /// skipped Unicast identifier 00081 D7A_ID_VOID = 0, 00082 /// Void identifier (broadcast) 00083 /// with indication of number of reached devices 00084 D7A_ID_NBID = 0, 00085 /// Void identifier (broadcast) 00086 D7A_ID_NOID = 1, 00087 /// Unique Identifier 00088 D7A_ID_UID = 2, 00089 /// Virtual identifier 00090 D7A_ID_VID = 3, 00091 00092 } d7a_id_t; 00093 00094 // ======================================================================= 00095 // d7a_nls_t 00096 // ----------------------------------------------------------------------- 00097 /// Enumerator of the NWL security modes 00098 // ======================================================================= 00099 typedef enum 00100 { 00101 /// No security enabled 00102 D7A_NLS_NO = 0, 00103 /// Encryption only, Counter Mode 00104 D7A_NLS_AES_CTR, 00105 /// No encryption, Authentication, Cipher-block chaining with 128 bit MAC 00106 D7A_NLS_AES_CBC_MAC_128, 00107 /// No encryption, Authentication, Cipher-block chaining with 64 bit MAC 00108 D7A_NLS_AES_CBC_MAC_64, 00109 /// No encryption, Authentication, Cipher-block chaining with 32 bit MAC 00110 D7A_NLS_AES_CBC_MAC_32, 00111 /// Authentication with CBC-MAC-128 and Encryption with Counter Mode 00112 D7A_NLS_AES_CCM_128, 00113 /// Authentication with CBC-MAC-128 and Encryption with Counter Mode 00114 D7A_NLS_AES_CCM_64, 00115 /// Authentication with CBC-MAC-128 and Encryption with Counter Mode 00116 D7A_NLS_AES_CCM_32, 00117 /// QTY 00118 D7A_NLS_QTY 00119 00120 } d7a_nls_t; 00121 00122 //====================================================================== 00123 // ID manipulation macros 00124 //====================================================================== 00125 00126 /// Unique ID length 00127 #define D7A_UID_LEN (8) 00128 /// Virtual ID length 00129 #define D7A_VID_LEN (2) 00130 /// No identifier length 00131 #define D7A_NOID_LEN (0) 00132 /// Void (skipped) identifier length 00133 #define D7A_VOID_LEN (0) 00134 /// Void ID length with reached 00135 /// devices number indicaiton 00136 #define D7A_NBID_LEN (1) 00137 00138 /// Address is unicast (VID or UID) 00139 #define D7A_ID_IS_UCAST(ctrl) ((D7A_ID_UID == (ctrl).bf.idf) || (D7A_ID_VID == (ctrl).bf.idf)) 00140 00141 /// Address is broadcast (no identifier) 00142 #define D7A_ID_IS_BCAST(ctrl) ((D7A_ID_NOID == (ctrl).bf.idf) || (D7A_ID_NBID == (ctrl).bf.idf)) 00143 00144 /// Length of the Addressee identifier 00145 #define D7A_ID_LEN(ctrl) (((ctrl).bf.idf == D7A_ID_VID) ? D7A_VID_LEN : \ 00146 ((ctrl).bf.idf == D7A_ID_UID) ? D7A_UID_LEN : \ 00147 ((ctrl).bf.idf == D7A_ID_NBID) ? D7A_NBID_LEN : \ 00148 D7A_NOID_LEN) 00149 00150 /// Length of the DLL identifier 00151 #define D7A_DLL_ID_LEN(ctrl) (((ctrl).bf.idf == D7A_ID_VID) ? D7A_VID_LEN : \ 00152 ((ctrl).bf.idf == D7A_ID_UID) ? D7A_UID_LEN : \ 00153 ((ctrl).bf.idf == D7A_ID_VOID) ? D7A_VOID_LEN : \ 00154 D7A_NOID_LEN) 00155 /// length of the Addressee 00156 #define D7A_ADDR_LEN(ctrl) (D7A_ID_LEN(ctrl) + sizeof(d7a_addressee_t) - D7A_UID_LEN) 00157 00158 //====================================================================== 00159 // Compressed format conversions to use in declarations 00160 //====================================================================== 00161 00162 /// Decode e/m 00163 #define D7A_CTF_D(e,m) ((1 << (2*(e))) * (m)) 00164 00165 /// Encode e/m 00166 #define D7A_CTF_E(e,v) ((((e) & 0x7) << 5) | (KAL_DIV_INT((v), D7A_CTF_D(e,1)) & 0x1f)) 00167 00168 /// Encode unit to CTF 00169 #define D7A_CTF_ENCODE(v) (((v) < D7A_CTF_D(0,32)) ? D7A_CTF_E(0,(v)) : \ 00170 ((v) < D7A_CTF_D(1,32)) ? D7A_CTF_E(1,(v)) : \ 00171 ((v) < D7A_CTF_D(2,32)) ? D7A_CTF_E(2,(v)) : \ 00172 ((v) < D7A_CTF_D(3,32)) ? D7A_CTF_E(3,(v)) : \ 00173 ((v) < D7A_CTF_D(4,32)) ? D7A_CTF_E(4,(v)) : \ 00174 ((v) < D7A_CTF_D(5,32)) ? D7A_CTF_E(5,(v)) : \ 00175 ((v) < D7A_CTF_D(6,32)) ? D7A_CTF_E(6,(v)) : \ 00176 ((v) < D7A_CTF_D(7,32)) ? D7A_CTF_E(7,(v)) : \ 00177 0xff) 00178 00179 /// Decode from CTF to unit 00180 #define D7A_CTF_DECODE(ctf) D7A_CTF_D((ctf).bf.exp,(ctf).bf.mant) 00181 00182 /// Initializer for constants and variables 00183 #define D7A_CTF(v) (d7a_ctf_t){ .byte = D7A_CTF_ENCODE(v) } 00184 00185 // ======================================================================= 00186 // d7a_addressee_ctrl_t 00187 // ----------------------------------------------------------------------- 00188 /// Bitfield structure of the Addressee control byte 00189 // ======================================================================= 00190 typedef union 00191 { 00192 // bit access fields 00193 struct { 00194 /// Network security method 00195 u8 nls : 4; 00196 /// ID type 00197 u8 idf : 2; 00198 /// RFU 00199 u8 rfu_6 : 1; 00200 u8 rfu_7 : 1; 00201 } bf; 00202 00203 // byte access 00204 u8 byte; 00205 00206 } d7a_addressee_ctrl_t; 00207 00208 // ======================================================================= 00209 // d7a_xcl_t 00210 // ----------------------------------------------------------------------- 00211 /// Bitfield structure of the Addressee Access Class 00212 // ======================================================================= 00213 typedef union 00214 { 00215 // bit access fields 00216 struct { 00217 /// Subclass mask 00218 u8 m : 4; 00219 /// Specifier 00220 u8 s : 4; 00221 } bf; 00222 00223 // byte access 00224 u8 byte; 00225 00226 } d7a_xcl_t; 00227 00228 // ======================================================================= 00229 // d7a_addressee_t 00230 // ----------------------------------------------------------------------- 00231 /// Structure of the D7ATP Addressee byte 00232 // ======================================================================= 00233 TYPEDEF_STRUCT_PACKED 00234 { 00235 d7a_addressee_ctrl_t ctrl; 00236 d7a_xcl_t xcl; 00237 u8 id[D7A_UID_LEN]; 00238 00239 } d7a_addressee_t; 00240 00241 // ======================================================================= 00242 // d7a_ctf_t 00243 // ----------------------------------------------------------------------- 00244 /// DLL compressed time format 00245 // ======================================================================= 00246 typedef kal_ctf_t d7a_ctf_t; 00247 00248 // ======================================================================= 00249 // d7a_ch_header_t 00250 // ----------------------------------------------------------------------- 00251 /// Bitfield structure of the channel identifier 00252 // ======================================================================= 00253 typedef union 00254 { 00255 // bit access fields 00256 struct { 00257 /// Coding scheme 00258 u8 cs : 2; 00259 /// Channel Class 00260 u8 cl : 2; 00261 /// Channel Band 00262 u8 band : 3; 00263 /// Extension 00264 u8 ext : 1; 00265 } bf; 00266 00267 // byte access 00268 u8 byte; 00269 00270 } d7a_ch_header_t; 00271 00272 // ======================================================================= 00273 // d7a_resp_t 00274 // ----------------------------------------------------------------------- 00275 /// Enumerator of the D7ASP Response types 00276 // ======================================================================= 00277 typedef enum 00278 { 00279 /// No response requested 00280 D7A_RESP_NO = 0, 00281 /// Get all responses in response period. 00282 D7A_RESP_ALL, 00283 /// Get at least one ACK per request during response period 00284 D7A_RESP_ANY, 00285 /// Same as D7A_RESP_ALL, but responders respond only if upper layer payload is available 00286 /// It is suitable for cases when the smart addressing (queries) is used. 00287 D7A_RESP_ALL_ON_DATA, 00288 /// No response requested, repeat the number of times defined in the SEL configuration file 00289 D7A_RESP_NO_RPT, 00290 /// Same as D7A_RESP_ANY, but responders respond only if upper layer payload is available 00291 /// It is suitable for cases when the smart addressing (queries) is used. 00292 D7A_RESP_ANY_ON_DATA, 00293 /// Get at least one acknowledgement per request during response period. 00294 /// Stick to a single responder when possible 00295 D7A_RESP_PREFERRED, 00296 /// Same as D7A_RESP_PREFERRED, but responders respond only if upper layer payload is available 00297 /// It is suitable for cases when the smart addressing (queries) is used. 00298 D7A_RESP_PREFERRED_ON_DATA 00299 00300 } d7a_resp_t; 00301 00302 //====================================================================== 00303 // d7a_retry_t 00304 // ----------------------------------------------------------------------- 00305 // D7A retry policies 00306 //====================================================================== 00307 typedef enum 00308 { 00309 /// Single request, try once (context cleaned upon completion) 00310 /// Suitable for low QoS or QoS managed by the application 00311 D7A_RETRY_ONESHOT = 0, 00312 /// Single request, retry 3 times (context cleaned upon completion) 00313 /// Suitable for higher QoS or QoS managed by the application 00314 D7A_RETRY_ONESHOT_RETRY, 00315 /// FIFO mode with fast retry pattern (context kept on completion) 00316 /// Suitable for periodic frequent chart-type ActP notifications (< ~10s between messages) 00317 D7A_RETRY_FIFO_FAST, 00318 /// FIFO mode with slow retry pattern (context kept on completion) 00319 /// Suitable for periodic unfrequent chart-type ActP notifications (> ~10s between messages) 00320 D7A_RETRY_FIFO_SLOW, 00321 /// Single ("last-is-best") mode with fast retry pattern (context kept on completion) 00322 /// Suitable for periodic frequent state-type ActP notifications (< ~10s between messages) 00323 D7A_RETRY_SINGLE_FAST, 00324 /// Single ("last-is-best") mode with slow retry pattern (context kept on completion) 00325 /// Suitable for periodic unfrequent state-type ActP notifications (> ~10s between messages) 00326 D7A_RETRY_SINGLE_SLOW, 00327 /// Single request, retry 8 times or more (context cleaned upon completion) 00328 /// Suitable for rare ActP notifications with higher priority (revision, etc). 00329 /// Suitable for application requests where the QoS is managed by the stack 00330 /// or the completion is not expected synchronously (could be very long) 00331 D7A_RETRY_ONESHOT_STICKY, 00332 /// Reserved for future use 00333 D7A_RETRY_RFU_7 00334 00335 } d7a_retry_t ; 00336 00337 // ======================================================================= 00338 // d7a_qos_t 00339 // ----------------------------------------------------------------------- 00340 /// Bitfield structure of the D7ASP Quality of Service control byte 00341 // ======================================================================= 00342 typedef union 00343 { 00344 // bit access fields 00345 struct { 00346 /// Response mode 00347 u8 resp : 3; 00348 /// Retry mode 00349 u8 retry : 3; 00350 /// RFU 00351 u8 rfu : 2; 00352 } bf; 00353 00354 // byte access 00355 u8 byte; 00356 00357 } d7a_qos_t; 00358 00359 // ======================================================================= 00360 // d7a_sp_cfg_t 00361 // ----------------------------------------------------------------------- 00362 /// Structure of the D7ASP Configuration 00363 // ======================================================================= 00364 TYPEDEF_STRUCT_PACKED 00365 { 00366 /// D7ASP QoS 00367 d7a_qos_t qos; 00368 /// Session Start timeout 00369 d7a_ctf_t to; 00370 /// Response execution delay 00371 d7a_ctf_t te; 00372 /// Addressee 00373 d7a_addressee_t addressee; 00374 00375 } d7a_sp_cfg_t; 00376 00377 // ======================================================================= 00378 // d7a_sp_status_t 00379 // ----------------------------------------------------------------------- 00380 /// Bitfield structure of the D7ASP segment status byte 00381 // ======================================================================= 00382 typedef union 00383 { 00384 // bit access fields 00385 struct { 00386 /// RFU 00387 u8 rfu : 4; 00388 /// Identifier type of the received segment 00389 u8 idf : 2; 00390 /// Current seqnum was already received 00391 u8 retry : 1; 00392 /// There are not received seqnums anterior to the current seqnum 00393 u8 missed : 1; 00394 } bf; 00395 00396 // byte access 00397 u8 byte; 00398 00399 } d7a_sp_status_t; 00400 00401 // ======================================================================= 00402 // d7a_nwl_security_t 00403 // ----------------------------------------------------------------------- 00404 /// NWL Security File structure 00405 // ======================================================================= 00406 TYPEDEF_STRUCT_PACKED 00407 { 00408 /// Key counter 00409 u8 key_counter; 00410 /// Frame counter 00411 u32 frame_counter; 00412 00413 } d7a_nwl_security_t; 00414 00415 // ======================================================================= 00416 // d7a_sp_res_t 00417 // ----------------------------------------------------------------------- 00418 /// D7A specific segment metadata 00419 // ======================================================================= 00420 TYPEDEF_STRUCT_PACKED 00421 { 00422 /// channel header 00423 d7a_ch_header_t header; 00424 /// channel index 00425 u16 idx; 00426 /// RSSI in -dBm 00427 u8 rxlev; 00428 /// Link budget in dB 00429 u8 lb; 00430 /// Signal-to-noise ratio in dB 00431 s8 snr; 00432 /// D7ASP status 00433 d7a_sp_status_t status; 00434 /// D7ASP Token 00435 u8 token; 00436 /// D7ASP Sequence number 00437 u8 seq; 00438 /// Response timeout 00439 u32 resp_to; 00440 /// Addressee 00441 d7a_addressee_t addressee; 00442 /// NLS security state (optional) 00443 d7a_nwl_security_t nls_state; 00444 00445 } d7a_sp_res_t; 00446 00447 // ======================================================================= 00448 // d7a_res_t 00449 // ----------------------------------------------------------------------- 00450 /// Aggregate packet reception metadata 00451 // ======================================================================= 00452 typedef struct 00453 { 00454 /// Handle 00455 u8 id; 00456 /// End reception date 00457 u32 date; 00458 /// frequency offset (frequency error) 00459 s16 fei; 00460 /// Size of the result (depends on origin Addresse ID) 00461 u8 len; 00462 /// Target RXLEV in -dBm 00463 u8 target_rxlev; 00464 /// segment metadata 00465 d7a_sp_res_t sp; 00466 00467 } d7a_res_t; 00468 00469 // ======================================================================= 00470 // d7a_error_t 00471 // ----------------------------------------------------------------------- 00472 /// Error types enumerator for D7A 00473 // ======================================================================= 00474 typedef enum 00475 { 00476 /// No error 00477 D7A_ERROR_NO = 0, 00478 /// Resource busy 00479 D7A_ERROR_BUSY = -1, 00480 /// Bad parameter 00481 D7A_ERROR_BAD_PARAM = -2, 00482 /// Duty cycle limit overflow 00483 D7A_ERROR_DUTY_CYCLE = -3, 00484 /// CCA timeout 00485 D7A_ERROR_CCA_TO = -4, 00486 /// Security frame counter overflow 00487 D7A_ERROR_NLS_KEY = -5, 00488 /// TX stream underflow 00489 D7A_ERROR_TX_UDF = -6, 00490 /// RX stream overflow 00491 D7A_ERROR_RX_OVF = -7, 00492 /// RX checksum 00493 D7A_ERROR_RX_CRC = -8, 00494 /// Abort 00495 D7A_ERROR_ABORT = -9, 00496 /// No ACK received 00497 D7A_ERROR_NO_ACK = -10, 00498 /// RX timeout 00499 D7A_ERROR_RX_TO = -11, 00500 /// Not supported band 00501 D7A_ERROR_NOT_SUPPORTED_BAND = -12, 00502 /// Not supported channel 00503 D7A_ERROR_NOT_SUPPORTED_CHANNEL = -13, 00504 /// Not supported modulation 00505 D7A_ERROR_NOT_SUPPORTED_MODULATION = -14, 00506 /// No channels in list 00507 D7A_ERROR_VOID_CHANNEL_LIST = -15, 00508 /// Not supported packet length 00509 D7A_ERROR_NOT_SUPPORTED_LEN = -16, 00510 /// Parameter overflow 00511 D7A_ERROR_PARAM_OVF = -17, 00512 /// Qty 00513 D7A_ERROR_QTY = MAX_S16, 00514 00515 } d7a_error_t; 00516 00517 // ======================================================================= 00518 // d7a_req_status_t 00519 // ----------------------------------------------------------------------- 00520 /// D7A session request status 00521 // ======================================================================= 00522 typedef union 00523 { 00524 struct { 00525 /// Fifo identifier (handle) 00526 u32 id : 8; 00527 /// Tag of the request 00528 u32 tag : 8; 00529 /// request flush status 00530 u32 ok : 1; 00531 /// RFU 00532 u32 rfu : 7; 00533 /// D7A error 00534 u32 err : 8; 00535 } bf; 00536 00537 /// word access 00538 u32 word; 00539 00540 } d7a_req_status_t; 00541 00542 // ======================================================================= 00543 // d7a_status_t 00544 // ----------------------------------------------------------------------- 00545 /// D7A session procedure status upon termination 00546 // ======================================================================= 00547 typedef union 00548 { 00549 struct 00550 { 00551 /// Fifo identifier (handle) 00552 u32 id : 8; 00553 /// Flush status. 00554 u32 ok : 1; 00555 /// RFU 00556 u32 rfu : 15; 00557 /// D7A error 00558 u32 err : 8; 00559 } bf; 00560 00561 /// word access 00562 u32 word; 00563 00564 } d7a_status_t; 00565 00566 #endif // __D7A_1X_H__
Generated on Tue Jul 12 2022 13:52:23 by
1.7.2