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
|
2013-11-27 16:28:31 +01:00
|
|
|
* @brief Platform-independent kernel initilization
|
|
|
|
*
|
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 "sched.h"
|
|
|
|
#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"
|
|
|
|
|
2015-07-29 19:59:16 +02:00
|
|
|
#ifdef MODULE_SCHEDSTATISTICS
|
|
|
|
#include "sched.h"
|
|
|
|
#endif
|
|
|
|
|
2014-02-14 00:09:19 +01:00
|
|
|
#define ENABLE_DEBUG (0)
|
|
|
|
#include "debug.h"
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#ifdef MODULE_AUTO_INIT
|
|
|
|
#include <auto_init.h>
|
|
|
|
#endif
|
|
|
|
|
2013-06-09 18:02:58 +02:00
|
|
|
extern int main(void);
|
2014-03-04 20:20:01 +01:00
|
|
|
static void *main_trampoline(void *arg)
|
|
|
|
{
|
|
|
|
(void) arg;
|
|
|
|
|
|
|
|
#ifdef MODULE_AUTO_INIT
|
|
|
|
auto_init();
|
|
|
|
#endif
|
|
|
|
|
2015-07-29 19:59:16 +02:00
|
|
|
#ifdef MODULE_SCHEDSTATISTICS
|
|
|
|
schedstat *stat = &sched_pidlist[thread_getpid()];
|
|
|
|
stat->laststart = 0;
|
|
|
|
#endif
|
|
|
|
|
2015-09-09 13:27:38 +02:00
|
|
|
LOG_INFO("main(): This is RIOT! (Version: " RIOT_VERSION ")\n");
|
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
main();
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
static void *idle_thread(void *arg)
|
2013-06-20 18:18:29 +02:00
|
|
|
{
|
2014-03-04 20:20:01 +01:00
|
|
|
(void) arg;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
const char *main_name = "main";
|
|
|
|
const char *idle_name = "idle";
|
|
|
|
|
2015-04-28 20:02:05 +02:00
|
|
|
static char main_stack[THREAD_STACKSIZE_MAIN];
|
|
|
|
static char idle_stack[THREAD_STACKSIZE_IDLE];
|
2010-10-25 15:40:01 +02:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
void kernel_init(void)
|
|
|
|
{
|
2016-03-19 09:25:47 +01:00
|
|
|
(void) irq_disable();
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2015-08-14 01:35:48 +02:00
|
|
|
thread_create(idle_stack, sizeof(idle_stack),
|
|
|
|
THREAD_PRIORITY_IDLE,
|
2015-12-02 11:59:20 +01:00
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
2015-08-14 01:35:48 +02:00
|
|
|
idle_thread, NULL, idle_name);
|
|
|
|
|
|
|
|
thread_create(main_stack, sizeof(main_stack),
|
|
|
|
THREAD_PRIORITY_MAIN,
|
2015-12-02 11:59:20 +01:00
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
2015-08-14 01:35:48 +02:00
|
|
|
main_trampoline, NULL, main_name);
|
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
|
|
|
}
|