-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add support for NuttX RTOS. #21372
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
Add support for NuttX RTOS. #21372
Conversation
Signed-off-by: Takeyoshi Kikuchi <[email protected]>
Signed-off-by: Takeyoshi Kikuchi <[email protected]>
How should I handle this error? |
Unrelated CI failures. I'm restarting the CI for you. Btw, nice work! |
CI passed, thank you! |
@centurysys Nice work! Please note that After this gets merged, there may be a pool of preallocated connections, but the system may also be able to dynamically allocate more, if needed (depending on the configuration). Either way, keep in mind that even before this change, if |
@fjpanag Thank you for pointing this out ! I was not aware of that change. I see that I need to calculate the maximum value of fd according to the user's configuration. |
@fjpanag var fdLim: RLimit
if getrlimit(RLIMIT_NOFILE, fdLim) < 0:
raiseOSError(osLastError())
result = int(fdLim.rlim_cur) - 1 |
…tack Size. Like FreeRTOS/Zephyr, add support for following configurations. -d:nimThreadStackSize=xxxxx -d:nimThreadStackGuard=yyyy Signed-off-by: Takeyoshi Kikuchi <[email protected]>
Shouldn't you also update compiler/platform.nim? |
@Araq There are some items not supported, such as dlls, but I have added in accordance with FreeRTOS. Please check them. |
@centurysys As fas as I can tell, (It may be a good idea to open issues for missing functionality, to express interest. It may not be implemented promptly, but at least it indicates which features are actually desired.) So, regarding determining the maximum number of connections. It seems a bit difficult to get the information that you are looking for. That is because (assuming that #7525 is merged as it is today):
When this PR gets merged, the system will have 3 possible configurations for every protocol. Statically Allocated Dynamically Allocated Dynamically Allocated + Limit All in all, I see that FreeRTOS and Zephyr use Maybe this is the way to go for NuttX too? |
@fjpanag Thank you for your detailed analysis. What do you think? |
Hmm... I am not sure about this. Indeed a "large enough" number would work. Maybe someone in the mailing list has a better idea on this.... |
Or just use (Assuming that a failed |
In the case of FreeRTOS(+lwIP), it seems that FD_MAX reflects the user's setting. var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header: "<lwipopts.h>".}: cint In the Github issue on arduino-ESP32, there was one that said '10 is too small', so it does not seem that a very large value is set. CONFIG_LWIP_MAX_SOCKETS=10 is too small #5699 |
So, how about deriving approximate values from CONFIG_RAM_SIZE in .config? |
I reviewed it this way, follow up PRs are welcome. |
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
Nah, the available memory for the connections can be practically unrelated, as Furthermore this config has different meaning on each arch. For example the STM32F4's have two RAM regions, and this config represents only the one of them. The second one may or may not be available, depending on other configurations. I sincerely have no idea how the maximum number of connections can reliably be obtained (without checking a dozen configs). I think that you should either select a "good enough" limit arbitrarily, or maybe ask in the NuttX mailing list for help, where other knowledgeable people may have any good propositions. |
@fjpanag I sent a question on the NuttX mailing list. proc newSelector*[T](): Selector[T] =
# Retrieve the maximum fd count (for current OS) via getrlimit()
var maxFD = maxDescriptors()
doAssert(maxFD > 0)
# Start with a reasonable size, checkFd() will grow this on demand
const numFD = 1024 <---
...
result.fds = newSeq[SelectorKey[T]](numFD) (this will be hard on devices with small memory) |
@fjpanag |
@fjpanag |
* Add support for NuttX RTOS. Signed-off-by: Takeyoshi Kikuchi <[email protected]> * lib: pure: asyncdispatch: assign to result. Signed-off-by: Takeyoshi Kikuchi <[email protected]> * lib: std: typedthreads: add support for parameters to adjust Thread Stack Size. Like FreeRTOS/Zephyr, add support for following configurations. -d:nimThreadStackSize=xxxxx -d:nimThreadStackGuard=yyyy Signed-off-by: Takeyoshi Kikuchi <[email protected]> --------- Signed-off-by: Takeyoshi Kikuchi <[email protected]>
* Add support for NuttX RTOS. Signed-off-by: Takeyoshi Kikuchi <[email protected]> * lib: pure: asyncdispatch: assign to result. Signed-off-by: Takeyoshi Kikuchi <[email protected]> * lib: std: typedthreads: add support for parameters to adjust Thread Stack Size. Like FreeRTOS/Zephyr, add support for following configurations. -d:nimThreadStackSize=xxxxx -d:nimThreadStackGuard=yyyy Signed-off-by: Takeyoshi Kikuchi <[email protected]> --------- Signed-off-by: Takeyoshi Kikuchi <[email protected]>
* Add support for NuttX RTOS. Signed-off-by: Takeyoshi Kikuchi <[email protected]> * lib: pure: asyncdispatch: assign to result. Signed-off-by: Takeyoshi Kikuchi <[email protected]> * lib: std: typedthreads: add support for parameters to adjust Thread Stack Size. Like FreeRTOS/Zephyr, add support for following configurations. -d:nimThreadStackSize=xxxxx -d:nimThreadStackGuard=yyyy Signed-off-by: Takeyoshi Kikuchi <[email protected]> --------- Signed-off-by: Takeyoshi Kikuchi <[email protected]>
Porting Nim to run on Apache NuttX RTOS.
Merge NuttX specific consts to posix_other_consts
SO_REUSEPORT is not supported, so use SO_REUSEADDR to avoid compilation errors.