diff options
Diffstat (limited to 'chip/nrf51')
-rw-r--r-- | chip/nrf51/bluetooth_le.c | 22 | ||||
-rw-r--r-- | chip/nrf51/bluetooth_le.h | 21 | ||||
-rw-r--r-- | chip/nrf51/radio_test.h | 2 |
3 files changed, 22 insertions, 23 deletions
diff --git a/chip/nrf51/bluetooth_le.c b/chip/nrf51/bluetooth_le.c index 077f3317f3..08a4a26b5f 100644 --- a/chip/nrf51/bluetooth_le.c +++ b/chip/nrf51/bluetooth_le.c @@ -74,33 +74,31 @@ struct nrf51_ble_packet_t on_air_packet; struct ble_pdu rcv_packet; -int ble_radio_init(void) +int ble_radio_init(uint32_t access_address, uint32_t crc_init_val) { int rv = radio_init(BLE_1MBIT); if (rv) return rv; - NRF51_RADIO_CRCCNF = 3 | NRF51_RADIO_CRCCNF_SKIP_ADDR; /* 3-byte CRC */ /* x^24 + x^10 + x^9 + x^6 + x^4 + x^3 + x + 1 */ /* 0x1_0000_0000_0000_0110_0101_1011 */ NRF51_RADIO_CRCPOLY = 0x100065B; - NRF51_RADIO_CRCINIT = 0x555555; - NRF51_RADIO_TXPOWER = NRF51_RADIO_TXPOWER_0_DBM; + NRF51_RADIO_CRCINIT = crc_init_val; - NRF51_RADIO_BASE0 = BLE_ADV_ACCESS_ADDRESS << 8; + NRF51_RADIO_TXPOWER = NRF51_RADIO_TXPOWER_0_DBM; - NRF51_RADIO_PREFIX0 = BLE_ADV_ACCESS_ADDRESS >> 24; + NRF51_RADIO_BASE0 = access_address << 8; + NRF51_RADIO_PREFIX0 = access_address >> 24; NRF51_RADIO_TXADDRESS = 0; NRF51_RADIO_RXADDRESSES = 1; - - NRF51_RADIO_PCNF0 = NRF51_RADIO_PCNF0_ADV; - - NRF51_RADIO_PCNF1 = NRF51_RADIO_PCNF1_ADV; + NRF51_RADIO_PCNF0 = NRF51_RADIO_PCNF0_ADV_DATA; + NRF51_RADIO_PCNF1 = NRF51_RADIO_PCNF0_ADV_DATA; return rv; + } static struct nrf51_ble_packet_t tx_packet; @@ -380,7 +378,7 @@ static int command_ble_adv(int argc, char **argv) CPRINTS("type DIRECT needs to have a length of 12"); } - rv = ble_radio_init(); + rv = ble_radio_init(BLE_ADV_ACCESS_ADDRESS, BLE_ADV_CRCINIT); CPRINTS("ADV @%p", &adv_packet); @@ -436,7 +434,7 @@ static int command_ble_adv_scan(int argc, char **argv) addr_lsbyte = -1; } - rv = ble_radio_init(); + rv = ble_radio_init(BLE_ADV_ACCESS_ADDRESS, BLE_ADV_CRCINIT); /* Change channel */ NRF51_RADIO_FREQUENCY = NRF51_RADIO_FREQUENCY_VAL(chan2freq(chan)); diff --git a/chip/nrf51/bluetooth_le.h b/chip/nrf51/bluetooth_le.h index 8a746f39d7..d438259aac 100644 --- a/chip/nrf51/bluetooth_le.h +++ b/chip/nrf51/bluetooth_le.h @@ -13,20 +13,21 @@ #define NRF51_BLE_S0_BYTES 1 #define NRF51_BLE_S1_BITS 0 /* no s1 field */ -#define NRF51_RADIO_PCNF0_ADV NRF51_RADIO_PCNF0_VAL(NRF51_BLE_LENGTH_BITS, \ - NRF51_BLE_S0_BYTES, \ - NRF51_BLE_S1_BITS) - #define BLE_ACCESS_ADDRESS_BYTES 4 #define EXTRA_RECEIVE_BYTES 0 #define BLE_ADV_WHITEN 1 -#define NRF51_RADIO_PCNF1_ADV \ - NRF51_RADIO_PCNF1_VAL(BLE_MAX_ADV_PAYLOAD_OCTETS, \ - EXTRA_RECEIVE_BYTES, \ - BLE_ACCESS_ADDRESS_BYTES - 1, \ - BLE_ADV_WHITEN) +/* Data and Advertisements have the same PCNF values */ +#define NRF51_RADIO_PCNF0_ADV_DATA \ + NRF51_RADIO_PCNF0_VAL(NRF51_BLE_LENGTH_BITS, \ + NRF51_BLE_S0_BYTES, \ + NRF51_BLE_S1_BITS) +#define NRF51_RADIO_PCNF1_ADV_DATA \ + NRF51_RADIO_PCNF1_VAL(BLE_MAX_ADV_PAYLOAD_OCTETS, \ + EXTRA_RECEIVE_BYTES, \ + BLE_ACCESS_ADDRESS_BYTES - 1, \ + BLE_ADV_WHITEN) struct nrf51_ble_packet_t { uint8_t s0; /* First byte */ @@ -41,7 +42,7 @@ struct nrf51_ble_config_t { }; /* Initialize the nRF51 radio for BLE */ -int ble_radio_init(void); +int ble_radio_init(uint32_t access_address, uint32_t crc_init_val); /* Transmit pdu on the radio */ void ble_tx(struct ble_pdu *pdu); diff --git a/chip/nrf51/radio_test.h b/chip/nrf51/radio_test.h index b70a22d69a..591b78a78c 100644 --- a/chip/nrf51/radio_test.h +++ b/chip/nrf51/radio_test.h @@ -17,7 +17,7 @@ #define BLE_MAX_TEST_CHANNEL 39 #define BLE_MIN_TEST_CHANNEL 0 -#define NRF51_RADIO_PCNF0_TEST NRF51_RADIO_PCNF0_ADV +#define NRF51_RADIO_PCNF0_TEST NRF51_RADIO_PCNF0_ADV_DATA #define BLE_TEST_WHITEN 0 |