00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #ifndef GZLL_H__
00019 #define GZLL_H__
00020
00021 #include <stdint.h>
00022 #include <stdbool.h>
00023 #include "gzll_macros.h"
00024 #include "gzll_params.h"
00025 #include "hal_nrf.h"
00026 #include "assertions.h"
00027
00032 #define GZLL_TYP_TX_PAYLOAD_LENGTH 15
00033
00038 #define GZLL_TYP_TX_PERIOD (130+((GZLL_CONST_BYTES_PR_PACKET+GZLL_TYP_TX_PAYLOAD_LENGTH) * GZLL_US_PR_BYTE) + GZLL_AUTO_RETR_DELAY)
00039
00043 typedef enum
00044 {
00045 GZLL_PARAM_DEVICE_MODE,
00046 GZLL_PARAM_TX_TIMEOUT,
00047 GZLL_PARAM_TX_ATTEMPTS_PR_CHANNEL_WHEN_SYNC_ON,
00048 GZLL_PARAM_TX_ATTEMPTS_PR_CHANNEL_WHEN_SYNC_OFF,
00049 GZLL_PARAM_HOST_MODE,
00050 GZLL_PARAM_RX_PIPES,
00051 GZLL_PARAM_RX_TIMEOUT,
00052 GZLL_PARAM_HOST_MODE_1_CYCLE_PERIOD,
00053 GZLL_PARAM_RX_PERIOD,
00054 GZLL_PARAM_RX_PERIOD_MODIFIER,
00055 GZLL_PARAM_RX_CHANNEL_HOLD_PERIODS,
00056 GZLL_PARAM_CRYPT_PIPES,
00057 GZLL_PARAM_OUTPUT_POWER,
00058 GZLL_PARAM_POWER_DOWN_IDLE_ENABLE,
00059 GZLL_PARAM_MAX_SYNC_PERIOD,
00060 GZLL_PARAM_COLLISION_CHANNEL_SWITCH_LIMIT,
00061 GZLL_DYN_PARAM_SIZE
00062 } gzll_dyn_params_t;
00063
00067 #define GZLL_PARAMS_MAX {4, 0xffff, 0xffff, 0xffff, 1, 0x3f, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3f, 0x03, 1, 0xffff, 0xffff}
00068
00072 typedef enum
00073 {
00074 GZLL_IDLE,
00075 GZLL_DEVICE_ACTIVE,
00076 GZLL_HOST_ACTIVE
00077 }gzll_states_t;
00078
00082 typedef enum
00083 {
00084 GZLL_HOST_MODE_0,
00085 GZLL_HOST_MODE_1,
00086 }gzll_rx_modes_t;
00087
00091 typedef enum
00092 {
00093 GZLL_DEVICE_MODE_0,
00094 GZLL_DEVICE_MODE_1,
00095 GZLL_DEVICE_MODE_2,
00096 GZLL_DEVICE_MODE_3,
00097 GZLL_DEVICE_MODE_4,
00098 }gzll_device_modes_t;
00099
00100
00101 #define GZLL_DR_1MBPS 0
00102 #define GZLL_DR_2MBPS 1
00103 #define GZLL_DR_250KBPS 2
00104
00105
00106
00107
00108
00109
00110
00111
00112 #define GZLL_CRC HAL_NRF_CRC_16BIT
00113
00114
00115
00116
00117 #define GZLL_ADDRESS_WIDTH HAL_NRF_AW_5BYTES
00118
00119
00120
00121
00122
00123 #define GZLL_CONST_BYTES_PR_PACKET (1 + 2 + 5 + 1)
00124
00125
00141 void gzll_init(void);
00142
00163 void gzll_set_address(hal_nrf_address_t pipe, const uint8_t *address);
00164
00180 void gzll_set_channels(uint8_t *channels, uint8_t size);
00181
00205 void gzll_set_param(gzll_dyn_params_t param, uint16_t value);
00206
00233 uint16_t gzll_get_param_max(gzll_dyn_params_t param);
00234
00260 uint16_t gzll_get_param(gzll_dyn_params_t param);
00261
00274 gzll_states_t gzll_get_state(void);
00275
00287 bool gzll_radio_active();
00288
00296 void gzll_goto_idle(void);
00297
00315 bool gzll_rx_data_ready(uint8_t pipe);
00316
00330 uint8_t gzll_get_rx_data_ready_pipe_number(void);
00331
00355 bool gzll_rx_fifo_read(uint8_t *dst, uint8_t *length, uint8_t *pipe);
00356
00368 bool gzll_rx_power_high(void);
00369
00375 uint8_t gzll_get_channel_tab_size();
00376
00382 void gzll_get_channels(uint8_t *channels);
00383
00395 void gzll_get_address(uint8_t pipe, uint8_t* address);
00396
00403 void gzll_tx_fifo_flush(void);
00404
00411 void gzll_rx_fifo_flush(void);
00412
00431 void gzll_set_crypt_key(uint8_t pipe, uint8_t* key128);
00432
00443 void gzll_get_crypt_key(uint8_t pipe, uint8_t* key128);
00444
00449 void gzll_radio_isr_function(void);
00450
00455 void gzll_timer_isr_function(void);
00456
00476 bool gzll_dev_mode2_rx_channel_match(void);
00477
00514 bool gzll_tx_data(const uint8_t *src, uint8_t length, uint8_t pipe);
00515
00527 bool gzll_tx_success(void);
00528
00543 uint16_t gzll_get_tx_attempts(void);
00544
00558 uint16_t gzll_get_tx_channel_switches(void);
00559
00578 void gzll_rx_start(void);
00579
00583 #define gzll_rx_stop() gzll_goto_idle()
00584
00610 bool gzll_ack_payload_write(const uint8_t *src, uint8_t length, uint8_t pipe);
00611
00627 void gzll_set_timer_period(uint16_t period);
00628
00631
00632
00633
00634
00635 #define GZLL_CRYPT_PAYLOAD_OVERHEAD 5
00636 #define GZLL_MAX_INTERNAL_PAYLOAD_LENGTH 32
00637 #define GZLL_MAX_CRYPT_PAYLOAD_LENGTH (GZLL_MAX_INTERNAL_PAYLOAD_LENGTH - GZLL_CRYPT_PAYLOAD_OVERHEAD)
00638
00639 #if(GZLL_MAX_FW_PAYLOAD_LENGTH > GZLL_MAX_ACK_PAYLOAD_LENGTH)
00640 #define GZLL_MAX_PAYLOAD_LENGTH GZLL_MAX_FW_PAYLOAD_LENGTH
00641 #else
00642 #define GZLL_MAX_PAYLOAD_LENGTH GZLL_MAX_ACK_PAYLOAD_LENGTH
00643 #endif
00644
00645 #if(GZLL_MAX_FW_PAYLOAD_LENGTH > GZLL_MAX_INTERNAL_PAYLOAD_LENGTH)
00646 {
00647 #error "GZLL_MAX_FW_PAYLOAD_LENGTH is limited to 32"
00648 }
00649 #endif
00650
00651 #if(GZLL_MAX_ACK_PAYLOAD_LENGTH > GZLL_MAX_INTERNAL_PAYLOAD_LENGTH)
00652 {
00653 #error "GZLL_MAX_ACK_PAYLOAD_LENGTH is limited to 32"
00654 }
00655 #endif
00656
00657 #define GZLL_INTERNAL_FW_PAYLOAD_LENGTH GZLL_MAX_FW_PAYLOAD_LENGTH
00658 #define GZLL_INTERNAL_ACK_PAYLOAD_LENGTH GZLL_MAX_ACK_PAYLOAD_LENGTH
00659
00660
00661 #if(GZLL_MAX_CRYPT_PIPES == 0)
00662 #define GZLL_MAX_CRYPT_PIPES_VAL 0x00
00663 #elif (GZLL_MAX_CRYPT_PIPES == 1)
00664 #define GZLL_MAX_CRYPT_PIPES_VAL 0x01
00665 #elif (GZLL_MAX_CRYPT_PIPES == 2)
00666 #define GZLL_MAX_CRYPT_PIPES_VAL 0x03
00667 #elif (GZLL_MAX_CRYPT_PIPES == 3)
00668 #define GZLL_MAX_CRYPT_PIPES_VAL 0x07
00669 #elif (GZLL_MAX_CRYPT_PIPES == 4)
00670 #define GZLL_MAX_CRYPT_PIPES_VAL 0x0f
00671 #elif (GZLL_MAX_CRYPT_PIPES == 5)
00672 #define GZLL_MAX_CRYPT_PIPES_VAL 0x1f
00673 #elif (GZLL_MAX_CRYPT_PIPES == 6)
00674 #define GZLL_MAX_CRYPT_PIPES_VAL 0x3f
00675 #else
00676 #error GZLL_MAX_CRYPT_PIPES can not exceed 6.
00677 #endif
00678
00679 #if(GZLL_DEFAULT_PARAM_CRYPT_PIPES > GZLL_MAX_CRYPT_PIPES_VAL)
00680 #error GZLL_MAX_CRYPT_PIPES not in accordance with GZLL_DEFAULT_PARAM_CRYPT_PIPES.
00681 #endif
00682
00683 #if(GZLL_INTERNAL_FW_PAYLOAD_LENGTH > GZLL_INTERNAL_ACK_PAYLOAD_LENGTH)
00684 #define GZLL_INTERNAL_PAYLOAD_LENGTH GZLL_INTERNAL_FW_PAYLOAD_LENGTH
00685 #else
00686 #define GZLL_INTERNAL_PAYLOAD_LENGTH GZLL_INTERNAL_ACK_PAYLOAD_LENGTH
00687 #endif
00688
00689 #if(GZLL_DATARATE == GZLL_DR_2MBPS)
00690 #define GZLL_US_PR_BYTE 4
00691 #define GZLL_HAL_DATARATE HAL_NRF_2MBPS
00692 #define GZLL_HOST_CE_LOW_IDLE_DELAY 15 // Host cative -> Idle delay. 9 * 50us = 500 us.
00693 #if(GZLL_INTERNAL_ACK_PAYLOAD_LENGTH > 15)
00694 #define GZLL_AUTO_RETR_DELAY 500
00695 #else
00696 #define GZLL_AUTO_RETR_DELAY 250
00697 #endif
00698 #endif
00699
00700 #if(GZLL_DATARATE == GZLL_DR_1MBPS)
00701 #define GZLL_US_PR_BYTE 8
00702 #define GZLL_HAL_DATARATE HAL_NRF_1MBPS
00703 #define GZLL_HOST_CE_LOW_IDLE_DELAY 14 // Host cative -> Idle delay. 13 * 50us = 700 us.
00704 #if(GZLL_INTERNAL_ACK_PAYLOAD_LENGTH > 5)
00705 #define GZLL_AUTO_RETR_DELAY 500
00706 #else
00707 #define GZLL_AUTO_RETR_DELAY 250
00708 #endif
00709 #endif
00710
00711 #if(GZLL_DATARATE == GZLL_DR_250KBPS)
00712 #define GZLL_US_PR_BYTE 32
00713 #define GZLL_HAL_DATARATE HAL_NRF_250KBPS
00714 #define GZLL_HOST_CE_LOW_IDLE_DELAY 37 // Host cative -> Idle delay. 36 * 50us = 1850 us.
00715
00716 #if(GZLL_INTERNAL_ACK_PAYLOAD_LENGTH == 0)
00717 #define GZLL_AUTO_RETR_DELAY 500
00718 #elif(GZLL_INTERNAL_ACK_PAYLOAD_LENGTH < 8)
00719 #define GZLL_AUTO_RETR_DELAY 750
00720 #elif(GZLL_INTERNAL_ACK_PAYLOAD_LENGTH < 16)
00721 #define GZLL_AUTO_RETR_DELAY 1000
00722 #elif(GZLL_INTERNAL_ACK_PAYLOAD_LENGTH < 24)
00723 #define GZLL_AUTO_RETR_DELAY 1250
00724 #else
00725 #define GZLL_AUTO_RETR_DELAY 1500
00726 #endif
00727 #endif
00728
00729 #ifndef GZLL_CRYPT_ENABLE
00730 #if(GZLL_MAX_CRYPT_PIPES > 0)
00731 #warning GZLL_MAX_CRYPT_PIPES > 0 but GZLL_CRYPT_ENABLE is not defined.
00732 #endif
00733 #endif
00734
00735 #endif // GZLL_H__
00736