-
Notifications
You must be signed in to change notification settings - Fork 379
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
Module: Mark some functions as virtual #776
Conversation
In an effort to support RadioLib on Tock (github.com/tock/tock) we want to replace some of the Module tranfer functions. This is because we want to replace the entire read/write command with an operating system call, instead of performing individual options. For example we don't want to manually control the CS line, but instead want to just specify a read buffer, write buffer and length and have Tock perform the operation for us. The current Hal abstraction isn't powerful enough for this, so we need to override some Module functions instead. Signed-off-by: Alistair Francis <alistair@alistair23.me>
I have marked this as a draft as I don't yet have a complete list of the functions that I need to override. I wanted to open this though to get feedback if this is acceptable |
I'm not sure about this approach - why can't this be done on the HAL level? If you know that all your SPI transactions are syscalls, what is preventing you from impementing the syscall in the HAL? |
The problem is that we want to complete the operation in a single command. So for example the current While the syscall interface instead requires us to complete the operation in a single command, something more like this: int16_t SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes, bool waitForGpio, uint32_t timeout) override {
char wbuf[cmdLen + numBytes];
char rbuf[cmdLen + numBytes];
uint8_t status = 0;
for(uint8_t n = 0; n < cmdLen; n++) {
wbuf[n] = cmd[n];
}
if (write) {
for(uint8_t n = 0; n < numBytes; n++) {
wbuf[cmdLen + n] = dataOut[n];
}
} else {
for(uint8_t n = 0; n < numBytes; n++) {
wbuf[cmdLen + n] = this->SPInopCommand;
}
}
lora_phy_read_write_sync(wbuf, rbuf, cmdLen + numBytes);
status = rbuf[cmdLen];
if (!write) {
for(size_t n = 0; n < numBytes; n++) {
dataIn[n] = rbuf[cmdLen + 1 + n];
}
}
return RADIOLIB_ERR_NONE;
} Which I don't think can be done with just the HAL |
I wasn't able to find source for The simplest change to HAL I can think of that would resolve this would be to add a "buffered" SPI transfer method to HAL as an alternative to the "byte-wise" transfer, and in Module, check whether it exists or not. If it does exist, Module can use it, it might even be preffered as it could be faster than going one byte at a time (e.g. if it is implemented by DMA). If it does not exist, then Module can fall back to byte-wise transfer. My point is that I would rather adapt the existing HAL than create a new one ;) |
I have basic functionality working and it seems that only Do you want me to prepare a PR to add a buffered transfer? |
It's going to take some changes in the current SPI methods in Module to not lose any functionality, so I will implement it and let you know. For now though, I will close this PR. |
@alistair23 in the end I ended up with implementing the buffered SPI in the HAL by default (the reasoning is that buffered SPI can be implemented by calling the byte-wise transfer in loop). So now you should be able to implement SPI transfer quite easily. I'm planning to release version 6.1.0 wiht this change later this week. |
Thanks for that! |
In an effort to support RadioLib on Tock (github.com/tock/tock) we want to replace some of the Module tranfer functions. This is because we want to replace the entire read/write command with an operating system call, instead of performing individual options. For example we don't want to manually control the CS line, but instead want to just specify a read buffer, write buffer and length and have Tock perform the operation for us.
The current Hal abstraction isn't powerful enough for this, so we need to override some Module functions instead.