@@ -68,16 +68,31 @@ void radio_phy_set(u8_t phy, u8_t flags)
6868 case BIT (0 ):
6969 default :
7070 mode = RADIO_MODE_MODE_Ble_1Mbit ;
71+
72+ #if defined(CONFIG_SOC_NRF52840 )
73+ /* Workaround: nRF52840 Engineering A Errata ID 164 */
74+ * (volatile u32_t * )0x4000173c &= ~0x80000000 ;
75+ #endif /* CONFIG_SOC_NRF52840 */
7176 break ;
7277
7378#if defined(CONFIG_SOC_SERIES_NRF51X )
7479 case BIT (1 ):
7580 mode = RADIO_MODE_MODE_Nrf_2Mbit ;
81+
82+ #if defined(CONFIG_SOC_NRF52840 )
83+ /* Workaround: nRF52840 Engineering A Errata ID 164 */
84+ * (volatile u32_t * )0x4000173c &= ~0x80000000 ;
85+ #endif /* CONFIG_SOC_NRF52840 */
7686 break ;
7787
7888#elif defined(CONFIG_SOC_SERIES_NRF52X )
7989 case BIT (1 ):
8090 mode = RADIO_MODE_MODE_Ble_2Mbit ;
91+
92+ #if defined(CONFIG_SOC_NRF52840 )
93+ /* Workaround: nRF52840 Engineering A Errata ID 164 */
94+ * (volatile u32_t * )0x4000173c &= ~0x80000000 ;
95+ #endif /* CONFIG_SOC_NRF52840 */
8196 break ;
8297
8398#if defined(CONFIG_SOC_NRF52840 )
@@ -87,6 +102,12 @@ void radio_phy_set(u8_t phy, u8_t flags)
87102 } else {
88103 mode = RADIO_MODE_MODE_Ble_LR500Kbit ;
89104 }
105+
106+ /* Workaround: nRF52840 Engineering A Errata ID 164 */
107+ * (volatile u32_t * )0x4000173c |= 0x80000000 ;
108+ * (volatile u32_t * )0x4000173c =
109+ ((* (volatile u32_t * )0x4000173c ) & 0xFFFFFF00 ) |
110+ 0x5C ;
90111 break ;
91112#endif /* CONFIG_SOC_NRF52840 */
92113#endif /* CONFIG_SOC_SERIES_NRF52X */
@@ -115,6 +136,10 @@ void radio_freq_chan_set(u32_t chan)
115136void radio_whiten_iv_set (u32_t iv )
116137{
117138 NRF_RADIO -> DATAWHITEIV = iv ;
139+
140+ NRF_RADIO -> PCNF1 &= ~RADIO_PCNF1_WHITEEN_Msk ;
141+ NRF_RADIO -> PCNF1 |= ((1UL ) << RADIO_PCNF1_WHITEEN_Pos ) &
142+ RADIO_PCNF1_WHITEEN_Msk ;
118143}
119144
120145void radio_aa_set (u8_t * aa )
@@ -187,17 +212,17 @@ void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags)
187212 RADIO_PCNF0_S1LEN_Msk ) |
188213 extra ;
189214
190- NRF_RADIO -> PCNF1 = (((((u32_t )max_len ) << RADIO_PCNF1_MAXLEN_Pos ) &
215+ NRF_RADIO -> PCNF1 &= ~(RADIO_PCNF1_MAXLEN_Msk | RADIO_PCNF1_STATLEN_Msk |
216+ RADIO_PCNF1_BALEN_Msk | RADIO_PCNF1_ENDIAN_Msk );
217+ NRF_RADIO -> PCNF1 |= ((((u32_t )max_len ) << RADIO_PCNF1_MAXLEN_Pos ) &
191218 RADIO_PCNF1_MAXLEN_Msk ) |
192- (((0UL ) << RADIO_PCNF1_STATLEN_Pos ) &
193- RADIO_PCNF1_STATLEN_Msk ) |
194- (((3UL ) << RADIO_PCNF1_BALEN_Pos ) &
195- RADIO_PCNF1_BALEN_Msk ) |
196- (((RADIO_PCNF1_ENDIAN_Little ) <<
197- RADIO_PCNF1_ENDIAN_Pos ) &
198- RADIO_PCNF1_ENDIAN_Msk ) |
199- (((1UL ) << RADIO_PCNF1_WHITEEN_Pos ) &
200- RADIO_PCNF1_WHITEEN_Msk ));
219+ (((0UL ) << RADIO_PCNF1_STATLEN_Pos ) &
220+ RADIO_PCNF1_STATLEN_Msk ) |
221+ (((3UL ) << RADIO_PCNF1_BALEN_Pos ) &
222+ RADIO_PCNF1_BALEN_Msk ) |
223+ (((RADIO_PCNF1_ENDIAN_Little ) <<
224+ RADIO_PCNF1_ENDIAN_Pos ) &
225+ RADIO_PCNF1_ENDIAN_Msk );
201226}
202227
203228void radio_pkt_rx_set (void * rx_packet )
@@ -657,6 +682,25 @@ u32_t radio_tmr_start(u8_t trx, u32_t ticks_start, u32_t remainder)
657682 return remainder ;
658683}
659684
685+ void radio_tmr_start_us (u8_t trx , u32_t us )
686+ {
687+ if (trx ) {
688+ NRF_PPI -> CH [0 ].EEP =
689+ (u32_t )& (NRF_TIMER0 -> EVENTS_COMPARE [0 ]);
690+ NRF_PPI -> CH [0 ].TEP =
691+ (u32_t )& (NRF_RADIO -> TASKS_TXEN );
692+ } else {
693+ NRF_PPI -> CH [0 ].EEP =
694+ (u32_t )& (NRF_TIMER0 -> EVENTS_COMPARE [0 ]);
695+ NRF_PPI -> CH [0 ].TEP =
696+ (u32_t )& (NRF_RADIO -> TASKS_RXEN );
697+ }
698+ NRF_PPI -> CHENSET = PPI_CHEN_CH0_Msk ;
699+
700+ NRF_TIMER0 -> CC [0 ] = us ;
701+ NRF_TIMER0 -> EVENTS_COMPARE [0 ] = 0 ;
702+ }
703+
660704void radio_tmr_stop (void )
661705{
662706 NRF_TIMER0 -> TASKS_STOP = 1 ;
@@ -689,6 +733,11 @@ void radio_tmr_aa_capture(void)
689733 NRF_PPI -> CHENSET = (PPI_CHEN_CH2_Msk | PPI_CHEN_CH3_Msk );
690734}
691735
736+ u32_t radio_tmr_ready_get (void )
737+ {
738+ return NRF_TIMER0 -> CC [0 ];
739+ }
740+
692741u32_t radio_tmr_aa_get (void )
693742{
694743 return (NRF_TIMER0 -> CC [1 ] - NRF_TIMER0 -> CC [0 ]);
0 commit comments