Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SW-23. Adjust BLE TX frequency based on 802.15.4 RX frequency #20

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
c987435
Track 15.4 RX frequency using weighted mean
tryuan99 Feb 26, 2020
cd9a6d7
Rename project to ble_tx_154_rx_track_mean
tryuan99 Mar 1, 2020
9c978e1
Initial attempt at estimating IF offset
tryuan99 Mar 3, 2020
be20cf9
Read IF estimate and LQI before turning the radio off
tryuan99 Mar 6, 2020
bf6cf2b
Verify frequency tracking using IF estimate
tryuan99 Mar 7, 2020
95eebd0
Change calibration period and averaging calculation
tryuan99 Mar 15, 2020
ae21ecf
Store IF offset and previous IF offset in app_vars
tryuan99 Mar 16, 2020
cd038d5
Change application description for IF tracking
tryuan99 Apr 15, 2020
c970150
Merge branch 'develop' into titan/SW-23
tryuan99 May 2, 2020
483cea4
Fix typos and formatting
tryuan99 May 2, 2020
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
162 changes: 162 additions & 0 deletions scm_v3c/applications/ble_tx/ble_tx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
\brief This program lets SCuM transmit BLE packets.
*/

#include <string.h>

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

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

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

#define TIMER_PERIOD 50000 ///< 500 = 1ms@500kHz

#define BLE_CALIBRATE_LC false
#define BLE_SWEEP_FINE true

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

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

bool txNext;
} app_vars_t;

app_vars_t app_vars;

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

void cb_timer(void);
void transmit_ble_packet(void);

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

int main(void) {

uint32_t calc_crc;

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();

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);
}

// Debug output
// printf("\r\nCode length is %u bytes",code_length);
// printf("\r\nCRC calculated by SCM is: 0x%X",calc_crc);

//printf("done\r\n");

// 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

#if BLE_CALIBRATE_LC
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;

// For TX, LC target freq = 2.402G - 0.25M = 2.40175 GHz.
optical_setLCTarget(250020);
#endif

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

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

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

// Disable static divider to save power
divProgram(480, 0, 0);

// Configure coarse, mid, and fine codes for TX.
#if BLE_CALIBRATE_LC
app_vars.tx_coarse = optical_getLCCoarse();
app_vars.tx_mid = optical_getLCMid();
app_vars.tx_fine = optical_getLCFine();
#else
// CHANGE THESE VALUES AFTER LC CALIBRATION.
app_vars.tx_coarse = 23;
app_vars.tx_mid = 11;
app_vars.tx_fine = 23;
#endif

ble_gen_packet();

while (1) {
transmit_ble_packet();
rftimer_setCompareIn(rftimer_readCounter() + TIMER_PERIOD);
app_vars.txNext = false;
while (!app_vars.txNext);
}
}

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

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

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

void transmit_ble_packet(void) {
int t, tx_fine;

#if BLE_SWEEP_FINE
for (tx_fine = 0; tx_fine < 32; ++tx_fine) {
LC_FREQCHANGE(app_vars.tx_coarse, app_vars.tx_mid, tx_fine);
printf("Transmitting on %u %u %u\n", app_vars.tx_coarse, app_vars.tx_mid, tx_fine);

// Wait for frequency to settle.
for (t = 0; t < 5000; ++t);

ble_transmit();
}
#else
LC_FREQCHANGE(app_vars.tx_coarse, app_vars.tx_mid, app_vars.tx_fine);
printf("Transmitting on %u %u %u\n", app_vars.tx_coarse, app_vars.tx_mid, app_vars.tx_fine);

// Wait for frequency to settle.
for (t = 0; t < 5000; ++t);

ble_transmit();
#endif
}
Loading