Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ OLD_USEPKG := $(sort $(USEPKG))
# processed before RIOT ones to be evaluated before the 'default' rules.
-include $(EXTERNAL_MODULE_DIRS:%=%/Makefile.dep)

# pull dependencies from sys and drivers
# pull dependencies from core, sys and drivers
include $(RIOTBASE)/core/Makefile.dep
include $(RIOTBASE)/sys/Makefile.dep
include $(RIOTBASE)/drivers/Makefile.dep

Expand Down Expand Up @@ -529,6 +530,7 @@ ifneq (,$(filter cpp11-compat,$(USEMODULE)))
endif

ifneq (,$(filter gnrc,$(USEMODULE)))
USEMODULE += multi_tasking
USEMODULE += gnrc_netapi
USEMODULE += gnrc_netreg
USEMODULE += gnrc_netif
Expand Down
16 changes: 15 additions & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# exclude submodule sources from *.c wildcard source selection
SRC := $(filter-out mbox.c msg.c thread_flags.c,$(wildcard *.c))
SUBMODULE_SRC += cond.c
SUBMODULE_SRC += kernel_init.c
SUBMODULE_SRC += mbox.c
SUBMODULE_SRC += msg.c
SUBMODULE_SRC += mutex.c
SUBMODULE_SRC += rmutex.c
SUBMODULE_SRC += sched.c
SUBMODULE_SRC += st_kernel_init.c
SUBMODULE_SRC += st_mutex.c
SUBMODULE_SRC += st_sched.c
SUBMODULE_SRC += st_thread.c
SUBMODULE_SRC += thread.c
SUBMODULE_SRC += thread_flags.c

SRC := $(filter-out $(SUBMODULE_SRC),$(wildcard *.c))

# enable submodules
SUBMODULES := 1
Expand Down
29 changes: 29 additions & 0 deletions core/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
MODS_MULTI_TASKING += core_cond
MODS_MULTI_TASKING += core_kernel_init
MODS_MULTI_TASKING += core_mutex
MODS_MULTI_TASKING += core_rmutex
MODS_MULTI_TASKING += core_sched
MODS_MULTI_TASKING += core_thread

MODS_REQUIRE_MT += core_mbox
MODS_REQUIRE_MT += core_msg
MODS_REQUIRE_MT += core_thread_flags

MODS_SINGLE_TASKING += core_st_kernel_init
MODS_SINGLE_TASKING += core_st_mutex
MODS_SINGLE_TASKING += core_st_sched
MODS_SINGLE_TASKING += core_st_thread

# Any of these modules requires multi-tasking support
ifneq (,$(filter $(MODS_MULTI_TASKING) $(MODS_REQUIRE_MT),$(USEMODULE)))
USEMODULE += multi_tasking
endif

ifeq (,$(filter multi_tasking,$(USEMODULE)))
USEMODULE += $(MODS_SINGLE_TASKING)
else
ifneq (,$(filter $(MODS_SINGLE_TASKING),$(USEMODULE)))
$(error Multi-tasking both enabled and disabled!)
endif
USEMODULE += $(MODS_MULTI_TASKING)
endif
23 changes: 23 additions & 0 deletions core/include/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define MUTEX_H

#include <stddef.h>
#include <stdint.h>

#include "list.h"

Expand All @@ -33,6 +34,7 @@
/**
* @brief Mutex structure. Must never be modified by the user.
*/
#if defined(MODULE_MULTI_TASKING) || defined(DOXYGEN)
typedef struct {
/**
* @brief The process waiting queue of the mutex. **Must never be changed
Expand All @@ -41,24 +43,38 @@ typedef struct {
*/
list_node_t queue;
} mutex_t;
#else
typedef uint8_t mutex_t;
#endif


/**
* @brief Static initializer for mutex_t.
* @details This initializer is preferable to mutex_init().
*/
#if defined(MODULE_MULTI_TASKING) || defined(DOXYGEN)
#define MUTEX_INIT { { NULL } }
#else
#define MUTEX_INIT 0
#endif

/**
* @brief Static initializer for mutex_t with a locked mutex
*/
#if defined(MODULE_MULTI_TASKING) || defined(DOXYGEN)
#define MUTEX_INIT_LOCKED { { MUTEX_LOCKED } }
#else
#define MUTEX_INIT_LOCKED 1
#endif

/**
* @cond INTERNAL
* @brief This is the value of the mutex when locked and no threads are waiting
* for it
*/
#if defined(MODULE_MULTI_TASKING) || defined(DOXYGEN)
#define MUTEX_LOCKED ((list_node_t *)-1)
#endif
/**
* @endcond
*/
Expand All @@ -69,10 +85,17 @@ typedef struct {
* Only use the function call for dynamically allocated mutexes.
* @param[out] mutex pre-allocated mutex structure, must not be NULL.
*/
#if defined(MODULE_MULTI_TASKING) || defined(DOXYGEN)
static inline void mutex_init(mutex_t *mutex)
{
mutex->queue.next = NULL;
}
#else
static inline void mutex_init(mutex_t *mutex)
{
*mutex = MUTEX_INIT;
}
#endif

/**
* @brief Lock a mutex, blocking or non-blocking.
Expand Down
38 changes: 38 additions & 0 deletions core/st_kernel_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup core_internal
* @{
*
* @file
* @brief Platform-independent kernel initilization
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/

#include "kernel_init.h"
#include "log.h"

#include "periph/pm.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

extern int main(void);
void kernel_init(void)
{
LOG_INFO("main(): This is RIOT! (Version: " RIOT_VERSION ")\n");
main();
LOG_INFO("main() exited, interrupts will still be served\n");
while (1) {
pm_set_lowest();
}
}
64 changes: 64 additions & 0 deletions core/st_mutex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2013 Freie Universität Berlin
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2019 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup core_sync
* @{
*
* @file
* @brief Kernel mutex implementation
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/

#include "mutex.h"
#include "irq.h"
#include "thread.h"
#include "sched.h"
#include "periph/pm.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

int _mutex_lock(mutex_t *mutex, int blocking)
{
unsigned irqstate = irq_disable();
if (*mutex && !blocking) {
irq_restore(irqstate);
return 0;
}

while (*mutex) {
irq_restore(irqstate);
pm_set_lowest();
irqstate = irq_disable();
}

*mutex = 1;
irq_restore(irqstate);
return 1;
}

void mutex_unlock(mutex_t *mutex)
{
unsigned irqstate = irq_disable();
*mutex = 0;
irq_restore(irqstate);
}

void mutex_unlock_and_sleep(mutex_t *mutex)
{
mutex_unlock(mutex);
pm_set_lowest();
}
47 changes: 47 additions & 0 deletions core/st_sched.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* 2019 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup core_sched
* @{
*
* @file
* @brief Scheduler implementation
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author René Kijewski <rene.kijewski@fu-berlin.de>
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/

#include <stdint.h>

#include "sched.h"
#include "thread.h"
#include "panic.h"

#include "log.h"

volatile int sched_num_threads = 1;
volatile unsigned int sched_context_switch_request = 0;
volatile thread_t *sched_active_thread = NULL;
volatile kernel_pid_t sched_active_pid = 0;

int sched_run(void)
{
core_panic(PANIC_GENERAL_ERROR, "sched_run() called in single-threaded "
"application. This should never happen.");
}

NORETURN void sched_task_exit(void)
{
core_panic(PANIC_GENERAL_ERROR, "Only task in single-threaded application "
"exited. This should never happen.");
}
80 changes: 80 additions & 0 deletions core/st_thread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup core_thread
* @{
*
* @file
* @brief Mock threading implementation
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/

#include <errno.h>
#include <stdio.h>

#include "irq.h"
#include "periph/pm.h"
#include "thread.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

static uint8_t sleeping = 0;

int thread_getstatus(kernel_pid_t pid)
{
if (pid == 0) {
return (int)STATUS_RUNNING;
}
return (int)STATUS_NOT_FOUND;
}

const char *thread_getname(kernel_pid_t pid)
{
#ifdef DEVELHELP
if (pid == 0) {
return "main";
}
#endif
(void)pid;
return NULL;
}

void thread_sleep(void)
{
unsigned state = irq_disable();
sleeping = 1;
while (sleeping) {
irq_restore(state);
pm_set_lowest();
state = irq_disable();
}
irq_restore(state);
}

int thread_wakeup(kernel_pid_t pid)
{
if (pid != 0) {
return (int)STATUS_NOT_FOUND;
}
unsigned old_state = irq_disable();

sleeping = 0;

irq_restore(old_state);
return 1;
}

void thread_yield(void)
{
/* nothing to do */
}
1 change: 0 additions & 1 deletion cpu/msp430_common/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void *thread_isr_stack_start(void)

NORETURN void cpu_switch_context_exit(void)
{
sched_active_thread = sched_threads[0];
sched_run();

__restore_context();
Expand Down
1 change: 1 addition & 0 deletions cpu/msp430fxyz/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef PERIPH_CPU_H
#define PERIPH_CPU_H

#include <stdbool.h>
#include "cpu.h"
#include "msp430_regs.h"

Expand Down
4 changes: 4 additions & 0 deletions examples/hello-world/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

# Disable support for multi-tasking, which is not needed for this trivial
# application
DISABLE_MODULE += multi_tasking core_msg

include $(RIOTBASE)/Makefile.include
Loading