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

NonArduino: Tock: A collection of fixes for LoRaWAN support #1145

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
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
37 changes: 30 additions & 7 deletions examples/NonArduino/Tock/libtockHal.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@

typedef void (*gpioIrqFn)(void);

gpioIrqFn gpio_funcs[4] = { NULL, NULL, NULL, NULL};
uint32_t frequency = 0;

/*
* Get the the timer frequency in Hz.
*/
Expand All @@ -73,7 +76,7 @@ static void lora_phy_gpio_Callback (int gpioPin,
__attribute__ ((unused)) int arg3,
void* userdata)
{
gpioIrqFn fn = *(gpioIrqFn*)(&userdata);
gpioIrqFn fn = gpio_funcs[gpioPin - 1];

if (fn != NULL ) {
fn();
Expand Down Expand Up @@ -136,7 +139,8 @@ class TockHal : public RadioLibHal {
return;
}

libtock_lora_phy_gpio_command_interrupt_callback(lora_phy_gpio_Callback, &interruptCb);
gpio_funcs[interruptNum - 1] = interruptCb;
libtock_lora_phy_gpio_command_interrupt_callback(lora_phy_gpio_Callback, NULL);

// set GPIO as input and enable interrupts on it
libtock_lora_phy_gpio_enable_input(interruptNum, libtock_pull_down);
Expand All @@ -148,24 +152,43 @@ class TockHal : public RadioLibHal {
return;
}

gpio_funcs[interruptNum - 1] = NULL;
libtock_lora_phy_gpio_disable_interrupt(interruptNum);
}

void delay(unsigned long ms) override {
libtocksync_alarm_delay_ms( ms );
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
libtocksync_alarm_delay_ms(ms);
#else
libtocksync_alarm_delay_ms(ms * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
#endif
}

void delayMicroseconds(unsigned long us) override {
libtocksync_alarm_delay_ms( us / 1000 );
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
libtocksync_alarm_delay_ms(us / 1000);
#else
libtocksync_alarm_delay_ms((us * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS)) / 1000);
#endif
}

unsigned long millis() override {
uint32_t frequency, now;
uint32_t now;
unsigned long ms;

if (frequency == 0) {
alarm_internal_frequency(&frequency);
}

alarm_internal_frequency(&frequency);
alarm_internal_read(&now);

return (now / frequency) / 1000;
ms = now / (frequency / 1000);

#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
return ms;
#else
return ms * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS);
#endif
}

unsigned long micros() override {
Expand Down
Loading