Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a7a1ce7
Merge pull request #9 from PisterLab/develop
lydia-lee Oct 18, 2019
7910426
Merge branch 'master' of github.com:PisterLab/scum-test-code
lydia-lee Oct 18, 2019
5dea454
Merge branch 'master' of https://github.com/PisterLab/scum-test-code …
tryuan99 Feb 12, 2020
ce43424
Add BLE files with BLE TX/15.4 RX application
tryuan99 Feb 13, 2020
fc17706
Allow BLE packet customization
tryuan99 Feb 13, 2020
9f3fb4c
Add BLE TX application
tryuan99 Feb 13, 2020
752a525
Add delay for DIV to turn on
tryuan99 Feb 16, 2020
dfeb12a
Fix BLE packet generation code
tryuan99 Feb 16, 2020
0e22546
Modify BLE TX and 15.4 RX application code
tryuan99 Feb 16, 2020
6ef0d71
Fix LC and IF calibration
tryuan99 Feb 17, 2020
ae36d69
Stop sweeping with 15.4 RX and repeat packet 5 times
tryuan99 Feb 18, 2020
ff2841c
Add a variable for number of repeats
tryuan99 Feb 19, 2020
a831a27
Reduce busy wait time when transmitting from FIFO
tryuan99 Feb 19, 2020
85df9c7
Turn on IF before LC calibration
tryuan99 Feb 19, 2020
39daf94
Remove unnecessary bin and hex files
tryuan99 Feb 19, 2020
73b5cfc
Change data GAP code
tryuan99 Feb 20, 2020
36e61d4
Adjust RX frequency and period
tryuan99 Feb 21, 2020
48f1db2
Merge branch 'develop' of https://github.com/PisterLab/scum-test-code…
tryuan99 Feb 21, 2020
d3b5ad4
Merge branch 'develop' into titan/SW-19
tryuan99 Feb 21, 2020
04f541e
Change RX frequency with divider on
tryuan99 Feb 23, 2020
8720c88
More code cleanup
tryuan99 Feb 26, 2020
c5d0f48
Fix typos in the other projects
tryuan99 Feb 26, 2020
1b082ec
Change target LC frequency to 2.40175GHz
tryuan99 Feb 27, 2020
f3328e3
Add initial test file for BLE TX and BLE TX 15.4 RX projects
tryuan99 Feb 27, 2020
1a84419
Add basic logger and parser that reads UART output
tryuan99 Feb 27, 2020
9e61ee0
Merge branch 'develop' of https://github.com/PisterLab/scum-test-code…
tryuan99 Mar 2, 2020
7491024
Merge branch 'develop' into titan/SW-19
tryuan99 Mar 2, 2020
82ce392
Merge remote-tracking branch 'remotes/upstream/develop' into titan/SW-19
changtengfei Aug 11, 2020
9f9bb87
SW-19. Fix test for ble projects.
changtengfei Aug 11, 2020
7d1726f
SW-19. fix quick_cal project
changtengfei Aug 11, 2020
8c2f990
SW-19. update continuously_cal project
changtengfei Aug 13, 2020
a798701
SW-19. add ble_freq_sweep project
changtengfei Aug 24, 2020
f1fa69c
SW-19. make crc calculation and data whitening as functions.
changtengfei Aug 24, 2020
0d85a83
SW-19. sweep settings in application file.
changtengfei Aug 24, 2020
126b81b
SW-19. reduce sweeping range to send ibeacon frequently
changtengfei Aug 24, 2020
d1d00ce
SW-19. increasing interval of sending packet.
changtengfei Aug 24, 2020
e37319f
SW-19. update ble_freq_sweep project.
changtengfei Oct 1, 2020
a63e499
df. sweep 3 mid settings (96 settings)
changtengfei Oct 13, 2020
bf0ff9d
sweep 4 mid
changtengfei Oct 14, 2020
b98346a
SW-19. add macro settings for different hornet slayer boards.
changtengfei Oct 26, 2020
0b165ed
SW-19. Update parser.py for CoCa paper.
changtengfei Apr 25, 2021
9943acf
Update scripts and add failed log_data.txt
changtengfei Apr 25, 2021
99fe0da
Merge remote-tracking branch 'remotes/upstream/develop' into titan/SW-19
changtengfei May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
380 changes: 380 additions & 0 deletions scm_v3c/applications/ble_freq_sweep/ble_freq_sweep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,380 @@
/**
\brief This program lets SCuM transmit BLE packets over a range of
frequency settings.
*/

#include <string.h>

#include "scm3c_hw_interface.h"
#include "memory_map.h"
#include "rftimer.h"
#include "radio.h"
#include "ble.h"
#include "optical.h"

//=========================== defines =========================================

#define CRC_VALUE (*((unsigned int *) 0x0000FFFC))
#define CODE_LENGTH (*((unsigned int *) 0x0000FFF8))

#define CHANNEL 0 // ble channel

#define TXPOWER 0xC5 // used for ibeacon pkt

#define NUMPKT_PER_CFG 1
#define STEPS_PER_CONFIG 32
#define TIMER_PERIOD 2000 // 500 = 1ms@500kHz

// only this coarse settings are swept,
// channel 37 and 0 are known within the setting scope of coarse=24
#define CFG_COARSE 24

#define HS_3

#ifdef TEST
#define MID_START 0
#define MID_END 32
#endif

#ifdef HS_2
#define MID_START 15
#define MID_END 20
#endif

#ifdef HS_1
#define MID_START 0
#define MID_END 32
#endif

#ifdef HS_3
#define MID_START 17
#define MID_END 22
#endif


const static uint8_t ble_device_addr[6] = {
0xaa, 0xbb, 0xcc, 0xcc, 0xbb, 0xaa
};

const static uint8_t ble_uuid[16] = {

0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf,
0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf
};

//=========================== variables =======================================

typedef struct {
uint8_t tx_coarse;
uint8_t tx_mid;
uint8_t tx_fine;

bool sendDone;

uint8_t pdu[PDU_LENGTH+CRC_LENGTH]; // protocol data unit
uint8_t pdu_len;
} app_vars_t;

app_vars_t app_vars;

//=========================== prototypes ======================================

void cb_endFrame_tx(uint32_t timestamp);
void cb_timer(void);

uint8_t prepare_pdu_nordic_aoa_beacon(void);
uint8_t prepare_pdu_ibeacon(void);
uint8_t prepare_pdu_cte_inline(void);
uint8_t prepare_freq_setting_pdu(uint8_t coarse, uint8_t mid, uint8_t fine);
void delay_tx(void);
void delay_lc_setup(void);

//=========================== main ============================================

int main(void) {

uint32_t calc_crc;

uint8_t cfg_mid;
uint8_t cfg_fine;

uint8_t i;
uint8_t j;
uint8_t offset;

uint32_t t;

memset(&app_vars, 0, sizeof(app_vars_t));

printf("Initializing...");

// Set up mote configuration
// This function handles all the analog scan chain setup
initialize_mote();
ble_init_tx();

radio_setEndFrameTxCb(cb_endFrame_tx);
rftimer_set_callback(cb_timer);

// Disable interrupts for the radio and rftimer
radio_disable_interrupts();
rftimer_disable_interrupts();

// Check CRC to ensure there were no errors during optical programming
printf("\r\n-------------------\r\n");
printf("Validating program integrity...");

calc_crc = crc32c(0x0000,CODE_LENGTH);

if (calc_crc == CRC_VALUE) {
printf("CRC OK\r\n");
} else {
printf("\r\nProgramming Error - CRC DOES NOT MATCH - Halting Execution\r\n");
while(1);
}

// After bootloading the next thing that happens is frequency calibration using optical
printf("Calibrating frequencies...\r\n");

// Initial frequency calibration will tune the frequencies for HCLK, the RX/TX chip clocks, and the LO

optical_enableLCCalibration();

// Turn on LO, DIV, PA, and IF
ANALOG_CFG_REG__10 = 0x78;

// Turn off polyphase and disable mixer
ANALOG_CFG_REG__16 = 0x6;

#if CHANNEL==37
// For TX, LC target freq = 2.402G - 0.25M = 2.40175 GHz.
optical_setLCTarget(250182);
#elif CHANNEL==0

// For TX, LC target freq = 2.404G - 0.25M = 2.40375 GHz.
optical_setLCTarget(250390);
#endif

// For the LO, calibration for RX channel 11, so turn on AUX, IF, and LO LDOs
// by calling radio rxEnable
radio_rxEnable();

// Enable optical SFD interrupt for optical calibration
optical_enable();

// Wait for optical cal to finish
while(!optical_getCalibrationFinished());

printf("Cal complete\r\n");

// Enable interrupts for the radio FSM (Not working for ble)
radio_enable_interrupts();

radio_rfOff();

ble_set_channel(CHANNEL);

while (1) {

// loop through all configuration

// customize coarse, mid, fine values to change the sweeping range
for (cfg_mid=MID_START;cfg_mid<MID_END;cfg_mid++) {
for (cfg_fine=0;cfg_fine<32;cfg_fine+=1) {

printf(
"coarse=%d, middle=%d, fine=%d\r\n",
CFG_COARSE,cfg_mid,cfg_fine
);

for (i=0;i<NUMPKT_PER_CFG;i++) {

radio_rfOff();

app_vars.pdu_len = prepare_freq_setting_pdu(CFG_COARSE, cfg_mid, cfg_fine);
ble_prepare_packt(&app_vars.pdu[0], app_vars.pdu_len);

LC_FREQCHANGE(CFG_COARSE, cfg_mid, cfg_fine);

delay_lc_setup();

ble_load_tx_arb_fifo();
radio_txEnable();

delay_tx();

ble_txNow_tx_arb_fifo();

// need to make sure the tx is done before
// starting a new transmission

rftimer_setCompareIn(rftimer_readCounter()+TIMER_PERIOD);
app_vars.sendDone = false;
while (app_vars.sendDone==false);
}
}
}
}
}

//=========================== public ==========================================

//=========================== private =========================================

//==== callback

void cb_timer(void) {
app_vars.sendDone = true;
}

void cb_endFrame_tx(uint32_t timestamp){

printf("this is end of tx \r\n");

}

//==== delay

// 0x07ff roughly corresponds to 2.8ms
#define TX_DELAY 0x07ff

void delay_tx(void) {
uint16_t i;
for (i=0;i<TX_DELAY;i++);
}

#define LC_SETUP_DELAY 0x02ff

void delay_lc_setup(void) {
uint16_t i;
for (i=0;i<LC_SETUP_DELAY;i++);
}

//==== pdu related

uint8_t prepare_freq_setting_pdu(uint8_t coarse, uint8_t mid, uint8_t fine) {

uint8_t i;
uint8_t j;

uint8_t field_len;

memset(app_vars.pdu, 0, sizeof(app_vars.pdu));

// adv head (to be explained)
i = 0;
field_len = 0;

app_vars.pdu[i++] = flipChar(0x20);
app_vars.pdu[i++] = flipChar(0x03);
app_vars.pdu[i++] = flipChar(coarse);
app_vars.pdu[i++] = flipChar(mid);
app_vars.pdu[i++] = flipChar(fine);

field_len += 5;

return field_len;
}

uint8_t prepare_pdu_cte_inline(void) {

uint8_t i;
uint8_t j;

uint8_t field_len;

memset(app_vars.pdu, 0, sizeof(app_vars.pdu));

// adv head (to be explained)
i = 0;
field_len = 0;

app_vars.pdu[i++] = flipChar(0x20);
app_vars.pdu[i++] = flipChar(0x02);

app_vars.pdu[i++] = flipChar(0x03);
app_vars.pdu[i++] = flipChar(0xdd);
app_vars.pdu[i++] = flipChar(0xff);

field_len += 3;

// the pdu length = field_len plus 2 bytes header
return (field_len+2);
}

uint8_t prepare_pdu_ibeacon(void) {

uint8_t i;
uint8_t j;

uint8_t field_len;

memset(app_vars.pdu, 0, sizeof(app_vars.pdu));

// adv head (to be explained)
i = 0;
field_len = 0;

app_vars.pdu[i++] = flipChar(0x42);
i++; // skip the length field, fill it at last

// adv address

for (j=6; j>0; j--) {
app_vars.pdu[i++] = flipChar(ble_device_addr[j-1]);
}

field_len += 6;

app_vars.pdu[i++] = flipChar(0x1a);
app_vars.pdu[i++] = flipChar(0xff);
app_vars.pdu[i++] = flipChar(0x4c);
app_vars.pdu[i++] = flipChar(0x00);

field_len += 4;

app_vars.pdu[i++] = flipChar(0x02);
app_vars.pdu[i++] = flipChar(0x15);
for (j=16; j>0; j--) {
app_vars.pdu[i++] = flipChar(ble_uuid[j-1]);
}

// major
app_vars.pdu[i++] = flipChar(0x00);
app_vars.pdu[i++] = flipChar(0xff);
// minor
app_vars.pdu[i++] = flipChar(0x00);
app_vars.pdu[i++] = flipChar(0x0f);
// power level
app_vars.pdu[i++] = flipChar(TXPOWER);

field_len += 23;

app_vars.pdu[1] = flipChar(field_len);

// the pdu length = field_len plus 2 bytes header
return (field_len+2);
}

uint8_t prepare_pdu_nordic_aoa_beacon(void){

uint8_t i;
uint8_t field_len;

memset(app_vars.pdu, 0, sizeof(app_vars.pdu));

i = 0;

app_vars.pdu[i++] = flipChar(0x46);
app_vars.pdu[i++] = flipChar(0x06);
field_len = 6;
app_vars.pdu[i++] = flipChar(0x01);
app_vars.pdu[i++] = flipChar(0x02);
app_vars.pdu[i++] = flipChar(0x03);
app_vars.pdu[i++] = flipChar(0x04);
app_vars.pdu[i++] = flipChar(0x05);
app_vars.pdu[i++] = flipChar(0xc6);

// the pdu length = field_len plus 2 bytes header
return (field_len+2);
}
Loading