Hi friends, I am starting using RIOT (uC Nordic nRF51822, Board pca10000) but I have some issues I would like you could help me:
I couldn’t figure out when the OS takes control of the uC, because in some examples the “main(void)” procedure never calls Riot.
I couldn’t figure out how to make more than one independent task. Again in “main(void)” looks like a bare metal program.
Solving the issue 2, when I put the priority on each task?
Do you have some kind of manual or example telling the configuration of semaphores, mutex, events? There are some example with 2 or more simple tasks like a “blinking led” and “display writing” in same program?
Hi Marcio,
I’m not sure about Nodric uC but I think I can answer some of your questions.
Actually, riot will call main instead. When uC start from a reset (power-on-reset or software/hardware reset), it will do some initialization (which can be found in cpu/nRF51822/startup.c, i think). Then, in a bare-metal program, it will call main but in RIOT, kernel_init will be called instead. kernel_init will then create 2 threads, idle_thread and main_thread with our main program.
In main, we can create other threads using thread_create function. APIs can be found here [1]
Thread priority will be assigned when we create thread. [1]
Not sure there any better manuals yet but we can found the APIs in [2]. Infomation about mutex, scheduling, threads, etc. are in kernel module.
I think a small example like this should work in the way you want. We’ll have 2 tasks which print their names continuously.
#include <stdio.h>
#include "vtimer.h"
#include "thread.h"
const int16_t led_toggling_stack_size = 1024;
char led_toggling_stack[led_toggling_stack_size];
int16_t led_toggling_pid;
void *led_toggling(void *arg)
{
while (1) {
printf("We're in %s\n", thread_getname(thread_getpid()));
vtimer_usleep(1000000); // you can adjust this value for your uC
}
return NULL;
}
int main(void)
{
int count;
led_toggling_pid = thread_create(led_toggling_stack,
led_toggling_stack_size,
PRIORITY_MAIN - 1,
0,
led_toggling,
NULL,
"Led toggling thread");
if (led_toggling_pid < 0) {
printf("Can't create thread\n");
}
while (1) {
printf("We're in %s\n", thread_getname(thread_getpid()));
for (count = 0; count < 10000000; count++) { // you can adjust this value for your uC
;
}
}
return 0;
}
the support for the NRF chip is quite young indeed. Although the base support should be quite stable, there are two known issues I am currently working on: i) the interrupt driven UART is still buggy and ii) the vtimer seems to crash randomly.
For the UART there is an open PR [1], but it still needs to be fixed. For other peripherals there are branches in my github: I2C [2], SPI [3], ADC [4]. These are not well tested yet, but I expect them to be in a merge-able state by mid November.
Regarding Nordics soft-device: There is currently no plan on making it work with RIOT, as I plan to implement the lower BLE layers myself to customize them for the use with 6LoWPAN. But it shouldn’t be hard to use the Nordic stuff - feel free to do so and let us know of your progress!