2010-09-22 15:10:42 +02:00
|
|
|
/**
|
|
|
|
* platform-independent kernel initialization
|
|
|
|
*
|
2013-06-18 17:21:38 +02:00
|
|
|
* Copyright (C) 2013 Freie Universität Berlin
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2013-11-22 20:47:05 +01:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
2013-06-18 17:21:38 +02:00
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
|
|
|
* @ingroup kernel
|
|
|
|
* @{
|
|
|
|
* @file
|
2013-12-04 15:07:56 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2010-09-22 15:10:42 +02:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
2010-11-07 23:18:41 +01:00
|
|
|
#include <tcb.h>
|
|
|
|
#include <kernel.h>
|
2013-07-16 16:36:37 +02:00
|
|
|
#include <kernel_internal.h>
|
2010-11-07 23:18:41 +01:00
|
|
|
#include <sched.h>
|
|
|
|
#include <flags.h>
|
|
|
|
#include <cpu.h>
|
|
|
|
#include <lpm.h>
|
|
|
|
#include <thread.h>
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_AUTO_INIT
|
|
|
|
#include <auto_init.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
volatile int lpm_prevent_sleep = 0;
|
|
|
|
|
2013-06-09 18:02:58 +02:00
|
|
|
extern int main(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-20 18:18:29 +02:00
|
|
|
static void idle_thread(void)
|
|
|
|
{
|
2013-06-24 22:37:35 +02:00
|
|
|
while (1) {
|
|
|
|
if (lpm_prevent_sleep) {
|
2010-09-22 15:10:42 +02:00
|
|
|
lpm_set(LPM_IDLE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lpm_set(LPM_IDLE);
|
2013-06-20 18:18:29 +02:00
|
|
|
/* lpm_set(LPM_SLEEP); */
|
|
|
|
/* lpm_set(LPM_POWERDOWN); */
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *main_name = "main";
|
|
|
|
const char *idle_name = "idle";
|
|
|
|
|
2010-10-25 15:40:01 +02:00
|
|
|
static char main_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
|
|
|
static char idle_stack[KERNEL_CONF_STACKSIZE_IDLE];
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#ifdef MODULE_AUTO_INIT
|
|
|
|
#define MAIN_FUNC auto_init
|
|
|
|
#else
|
2013-06-10 16:23:42 +02:00
|
|
|
#define MAIN_FUNC ((void (*) (void)) main)
|
2010-09-22 15:10:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void kernel_init(void)
|
|
|
|
{
|
|
|
|
dINT();
|
2013-11-23 17:22:27 +01:00
|
|
|
printf("kernel_init(): This is RIOT! (Version: %s)\n", VERSION);
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2010-10-28 11:22:57 +02:00
|
|
|
sched_init();
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (thread_create(idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, idle_name) < 0) {
|
2010-09-22 15:10:42 +02:00
|
|
|
printf("kernel_init(): error creating idle task.\n");
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (thread_create(main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, MAIN_FUNC, main_name) < 0) {
|
2010-09-22 15:10:42 +02:00
|
|
|
printf("kernel_init(): error creating main task.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("kernel_init(): jumping into first task...\n");
|
2013-06-20 18:18:29 +02:00
|
|
|
|
2010-10-28 11:22:57 +02:00
|
|
|
cpu_switch_context_exit();
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|