@@ -60,11 +60,42 @@ void radio_reset(void)
6060 RADIO_POWER_POWER_Msk );
6161}
6262
63- void radio_phy_set (u8_t phy )
63+ void radio_phy_set (u8_t phy , u8_t flags )
6464{
65- NRF_RADIO -> MODE =
66- (((phy ) ? (u32_t )phy : RADIO_MODE_MODE_Ble_1Mbit ) <<
67- RADIO_MODE_MODE_Pos ) & RADIO_MODE_MODE_Msk ;
65+ u32_t mode ;
66+
67+ switch (phy ) {
68+ case BIT (0 ):
69+ default :
70+ mode = RADIO_MODE_MODE_Ble_1Mbit ;
71+ break ;
72+
73+ #if defined(CONFIG_SOC_SERIES_NRF51X )
74+ case BIT (1 ):
75+ mode = RADIO_MODE_MODE_Nrf_2Mbit ;
76+ break ;
77+
78+ #elif defined(CONFIG_SOC_SERIES_NRF52X )
79+ case BIT (1 ):
80+ mode = RADIO_MODE_MODE_Ble_2Mbit ;
81+ break ;
82+
83+ #else /* !CONFIG_SOC_SERIES_NRF52X */
84+ case BIT (1 ):
85+ mode = RADIO_MODE_MODE_Ble_2Mbit ;
86+ break ;
87+
88+ case BIT (2 ):
89+ if (flags & 0x01 ) {
90+ mode = RADIO_MODE_MODE_Ble_LR500Kbit ;
91+ } else {
92+ mode = RADIO_MODE_MODE_Ble_LR125Kbit ;
93+ }
94+ break ;
95+ #endif /* !CONFIG_SOC_SERIES_NRF52X */
96+ }
97+
98+ NRF_RADIO -> MODE = (mode << RADIO_MODE_MODE_Pos ) & RADIO_MODE_MODE_Msk ;
6899}
69100
70101void radio_tx_power_set (u32_t power )
@@ -96,12 +127,12 @@ void radio_aa_set(u8_t *aa)
96127
97128void radio_pkt_configure (u8_t bits_len , u8_t max_len , u8_t flags )
98129{
99- u8_t p16 = (flags >> 1 ) & 0x01 ; /* 16-bit preamble */
100130 u8_t dc = flags & 0x01 ; /* Adv or Data channel */
101131 u32_t extra ;
132+ u8_t phy ;
102133
103134#if defined(CONFIG_SOC_SERIES_NRF51X )
104- ARG_UNUSED (p16 );
135+ ARG_UNUSED (phy );
105136
106137 extra = 0 ;
107138
@@ -110,8 +141,28 @@ void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags)
110141 bits_len = 5 ;
111142 }
112143#else /* !CONFIG_SOC_SERIES_NRF51X */
113- extra = (((p16 ) ? RADIO_PCNF0_PLEN_16bit : RADIO_PCNF0_PLEN_8bit ) <<
114- RADIO_PCNF0_PLEN_Pos ) & RADIO_PCNF0_PLEN_Msk ;
144+ extra = 0 ;
145+
146+ phy = (flags >> 1 ) & 0x07 ; /* phy */
147+ switch (phy ) {
148+ case BIT (0 ):
149+ default :
150+ extra |= (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos ) &
151+ RADIO_PCNF0_PLEN_Msk ;
152+ break ;
153+
154+ case BIT (1 ):
155+ extra |= (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos ) &
156+ RADIO_PCNF0_PLEN_Msk ;
157+ break ;
158+
159+ #if !defined(CONFIG_SOC_SERIES_NRF52X )
160+ case BIT (2 ):
161+ extra |= (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos ) &
162+ RADIO_PCNF0_PLEN_Msk ;
163+ break ;
164+ #endif
165+ }
115166
116167 /* To use same Data Channel PDU structure with nRF5 specific overhead
117168 * byte, include the S1 field in radio packet configuration.
@@ -555,28 +606,7 @@ void *radio_ccm_tx_pkt_set(struct ccm *ccm, void *pkt)
555606 NRF_CCM -> EVENTS_ENDCRYPT = 0 ;
556607 NRF_CCM -> EVENTS_ERROR = 0 ;
557608
558- #if defined(CONFIG_SOC_SERIES_NRF51X )
559- /* set up PPI to enable CCM */
560- NRF_PPI -> CH [6 ].EEP = (u32_t )& (NRF_RADIO -> EVENTS_READY );
561- NRF_PPI -> CH [6 ].TEP = (u32_t )& (NRF_CCM -> TASKS_KSGEN );
562- NRF_PPI -> CHENSET = PPI_CHEN_CH6_Msk ;
563- #elif 0
564- /* encrypt tx packet */
565- NRF_CCM -> INTENSET = CCM_INTENSET_ENDCRYPT_Msk ;
566- NRF_CCM -> TASKS_KSGEN = 1 ;
567- while (NRF_CCM -> EVENTS_ENDCRYPT == 0 ) {
568- __WFE ();
569- __SEV ();
570- __WFE ();
571- }
572- NRF_CCM -> INTENCLR = CCM_INTENCLR_ENDCRYPT_Msk ;
573- NVIC_ClearPendingIRQ (CCM_AAR_IRQn );
574-
575- LL_ASSERT (NRF_CCM -> EVENTS_ERROR == 0 );
576- #else
577- /* start KSGEN early, but dont wait for ENDCRYPT */
578609 NRF_CCM -> TASKS_KSGEN = 1 ;
579- #endif
580610
581611 return _pkt_scratch ;
582612}
0 commit comments