2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2017-01-09 17:07:03 +01:00
|
|
|
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
* 2013 Freie Universität Berlin
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* 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.
|
2013-11-27 16:28:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup core_internal
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2019-10-23 21:21:04 +02:00
|
|
|
* @brief Platform-independent kernel initialization
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2014-01-28 11:50:12 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2010-09-22 15:10:42 +02:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
2016-02-27 01:12:02 +01:00
|
|
|
#include "kernel_init.h"
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "thread.h"
|
2014-12-04 17:17:24 +01:00
|
|
|
#include "irq.h"
|
2015-02-25 16:31:03 +01:00
|
|
|
#include "log.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2017-01-09 17:10:58 +01:00
|
|
|
#include "periph/pm.h"
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#ifdef MODULE_AUTO_INIT
|
|
|
|
#include <auto_init.h>
|
|
|
|
#endif
|
|
|
|
|
2020-10-22 01:02:11 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
|
|
|
#include "debug.h"
|
|
|
|
|
2020-07-02 18:35:29 +02:00
|
|
|
#ifndef CONFIG_BOOT_MSG_STRING
|
2021-01-19 17:47:23 +01:00
|
|
|
#define CONFIG_BOOT_MSG_STRING "main(): This is RIOT! (Version: " \
|
|
|
|
RIOT_VERSION ")"
|
2020-07-02 18:35:29 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-09 18:02:58 +02:00
|
|
|
extern int main(void);
|
2020-01-31 10:12:49 +01:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
static void *main_trampoline(void *arg)
|
|
|
|
{
|
2020-01-31 10:12:49 +01:00
|
|
|
(void)arg;
|
2014-03-04 20:20:01 +01:00
|
|
|
|
|
|
|
#ifdef MODULE_AUTO_INIT
|
|
|
|
auto_init();
|
|
|
|
#endif
|
|
|
|
|
2020-07-02 18:35:29 +02:00
|
|
|
if (!IS_ACTIVE(CONFIG_SKIP_BOOT_MSG)) {
|
|
|
|
LOG_INFO(CONFIG_BOOT_MSG_STRING "\n");
|
|
|
|
}
|
2015-09-09 13:27:38 +02:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
main();
|
2020-01-31 10:12:49 +01:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2020-06-04 21:52:57 +02:00
|
|
|
static char main_stack[THREAD_STACKSIZE_MAIN];
|
|
|
|
static char idle_stack[THREAD_STACKSIZE_IDLE];
|
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
static void *idle_thread(void *arg)
|
2013-06-20 18:18:29 +02:00
|
|
|
{
|
2020-01-31 10:12:49 +01:00
|
|
|
(void)arg;
|
2014-03-04 20:20:01 +01:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (1) {
|
2017-01-09 17:10:58 +01:00
|
|
|
pm_set_lowest();
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
2014-03-04 20:20:01 +01:00
|
|
|
|
|
|
|
return NULL;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void kernel_init(void)
|
|
|
|
{
|
2020-01-31 10:12:49 +01:00
|
|
|
irq_disable();
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2020-06-04 21:52:57 +02:00
|
|
|
if (IS_USED(MODULE_CORE_IDLE_THREAD)) {
|
|
|
|
thread_create(idle_stack, sizeof(idle_stack),
|
|
|
|
THREAD_PRIORITY_IDLE,
|
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
|
|
|
idle_thread, NULL, "idle");
|
|
|
|
}
|
2015-08-14 01:35:48 +02:00
|
|
|
|
|
|
|
thread_create(main_stack, sizeof(main_stack),
|
2020-01-31 10:12:49 +01:00
|
|
|
THREAD_PRIORITY_MAIN,
|
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
|
|
|
main_trampoline, NULL, "main");
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2010-10-28 11:22:57 +02:00
|
|
|
cpu_switch_context_exit();
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|