Skip to content

Instantly share code, notes, and snippets.

@dubkov
Last active October 23, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubkov/dde05976209c4a817d387911d54d4e1f to your computer and use it in GitHub Desktop.
Save dubkov/dde05976209c4a817d387911d54d4e1f to your computer and use it in GitHub Desktop.
RIOT-THREADS
#include <stdio.h>
#include <string.h>
#include "thread.h"
#include "xtimer.h"
#include "timex.h"
#include "periph/gpio.h"
char stack_one[THREAD_STACKSIZE_DEFAULT];
char stack_two[THREAD_STACKSIZE_DEFAULT];
void *thread_one(void *arg)
{
(void) arg;
xtimer_ticks32_t last_wakeup_one = xtimer_now();
while(1){
gpio_toggle(GPIO_PIN(PORT_C,8));
xtimer_periodic_wakeup(&last_wakeup_one, 100000);
}
return NULL;
}
void *thread_two(void *arg)
{
(void) arg;
xtimer_ticks32_t last_wakeup_two = xtimer_now();
while(1){
gpio_toggle(GPIO_PIN(PORT_C,9));
xtimer_periodic_wakeup(&last_wakeup_two, 99333);
}
return NULL;
}
int main(void)
{
gpio_init(GPIO_PIN(PORT_C,8), GPIO_OUT);
gpio_init(GPIO_PIN(PORT_C,9), GPIO_OUT);
thread_create(stack_one, sizeof(stack_one),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
thread_one,
NULL, "thread_one");
thread_create(stack_two, sizeof(stack_two),
THREAD_PRIORITY_MAIN - 2,
THREAD_CREATE_STACKTEST,
thread_two,
NULL, "thread_two");
return 0;
}
APPLICATION = threads
RIOTBASE ?= $(CURDIR)/../../RIOT
BOARD ?= stm32f0discovery
USEMODULE += xtimer
CFLAGS += -DDEVELHELP
QUIET ?= 1
FEATURES_REQUIRED += periph_timer
FEATURES_REQUIRED += periph_gpio
include $(RIOTBASE)/Makefile.include
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment