Comments (3)
Could you elaborate a bit more on what this would look like?
It's true that on MCUs typically the only recovery method is a reset and/or power cycle. We also don't expect things like SPI initialization or GPIO writes to fail, because in a multithreaded environment (e.g. some RTOS), if the SPI/GPIO is to be considered a shared resource, it is up to the user of the library to guard that resource properly - RadioLib is agnostic about this, that's why HAL exists. However, I don't think it's up to the library itself to be deciding what is and is not recoverrable, that should be delegated to the HAL implementation for the specific platform.
For example, some Linux HAL might implement additional error checking when accessing system resources (GPIO and SPI), but if a radio transciever refuses to execute a command (e.g. attempting to set an out-of-range carrier frequency), I don't think the error handling on Linux will be different than on any MCU.
from radiolib.
An example would be init()
. Instead of returning void
, it can return an int (which can be ignored on Arduino or other places we generally assume it's going to succeed). If something goes south during, say, GPIO init, we can report it to the user. Same with spiBegin()
etc.
Things you might expect to be infallible can fail on Linux too. Even delay functions can fail, for instance, if a signal is received and we woke up too soon (though in that case it may be better to just handle EINTR). Or say an SPI transfer fails. Claiming/reading/writing pins also on Linux can fail.
It doesn't make sense of course to put error returns everywhere. For instance, in theory something like clock_gettime
can fail; in practise, the only way it would do so is if there was a bug in the HAL itself and there was a colossal screwup somewhere (like requesting an invalid clock).
Generally speaking, the right thing to do if an operation fails and it's not recoverable is tell the application about it somehow. If that's not possible for whatever reason, maybe call an abort()
function in the HAL and punt to the user. Maybe log it and call the C library abort()
, maybe set a global event and flag, maybe call up a friend and let them know (kidding 😛). That'd be up to the application.
from radiolib.
You are correct that the current HAL interface is mostly based on the assumption that the library has exclusive access to the system resources. This assumption obviously does not hold in Linux, but the real problem is that this assumption falls apart in any multi-threaded environment. Even ones common on MCUs, like RTOS - for example, delay can fail very easily there, just by getting blocked by a higher-priority thread. While no exception will be generated, the behavior will not be what you intended. In other example, acquiring SPI access will likely involve obtaining some mutex, which may already be held by some other thread.
So this should probably be resolved in the HAL. Having at least init
, spiBegin
and spiTransfer
return error code instead of nothing seems reasonable. There's actually not that many calls to these methods in the library source.
from radiolib.
Related Issues (20)
- RP2040-LoRa Development kit HOT 6
- SPIcheckStream in Module.cpp is ineffective (does nothing) HOT 1
- LoRaWAN ESP32 (Heltec WSL V3) reboot with stack error HOT 14
- TTGO LoRa32 (T3S3 v1.2) Error -16 HOT 10
- Sending more than one message in POCSAG HOT 1
- 'virtual float PhysicalLayer::getRSSI()' was hidden ESP-IDF HOT 10
- Feature request: AX.25 parser HOT 4
- Think I introduced a bug with Promiscuous (requireCarrierSense) when used with directMode HOT 2
- Move Raspberry Pi example to another GPIO library HOT 10
- CC1101 Direct Mode getRSSI() only ever returns -74.0 HOT 2
- importing Radiolib into VSCODE + Platformio with NRF52840 board does not compile HOT 13
- SX1280 startTransmit after CAD not working HOT 4
- Move examples to a separate repository HOT 14
- Invalid calibrateImage parameters prevent initializing with 915MHz frequency on SX126x-based STM32WLx HOT 2
- #include <Radiolib/SX1262.h> is available to use less space than the hole library? HOT 1
- Minor issue in startReceiveDutyCycleAuto HOT 3
- GFSK support for SX1231/RFM69 and SX127x/RFM9x HOT 2
- Support for MSPM0 Microcontroller HOT 1
- STM8 Arduino HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from radiolib.