2010-09-22 15:10:42 +02:00
|
|
|
/******************************************************************************
|
2013-06-18 17:21:38 +02:00
|
|
|
Copyright (C) 2013, Freie Universitaet Berlin (FUB). All rights reserved.
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
These sources were developed at the Freie Universitaet Berlin, Computer Systems
|
|
|
|
and Telematics group (http://cst.mi.fu-berlin.de).
|
|
|
|
-------------------------------------------------------------------------------
|
2013-03-07 20:51:26 +01:00
|
|
|
This file is part of RIOT.
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-11-23 13:43:47 +01:00
|
|
|
This file is subject to the terms and conditions of the LGPLv2.
|
|
|
|
See the file LICENSE in the top level directory for more details.
|
2010-09-22 15:10:42 +02:00
|
|
|
*******************************************************************************/
|
2013-12-09 11:12:39 +01:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "kernel.h"
|
2013-07-16 16:36:37 +02:00
|
|
|
#include "kernel_internal.h"
|
2010-10-28 11:22:57 +02:00
|
|
|
#include "sched.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
volatile int __inISR = 0;
|
|
|
|
|
|
|
|
char __isr_stack[MSP430_ISR_STACK_SIZE];
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
void thread_yield()
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
__save_context();
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
dINT();
|
2010-10-28 11:22:57 +02:00
|
|
|
/* have active_thread point to the next thread */
|
|
|
|
sched_run();
|
2010-09-22 15:10:42 +02:00
|
|
|
eINT();
|
|
|
|
|
|
|
|
__restore_context();
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
void cpu_switch_context_exit(void)
|
|
|
|
{
|
2010-10-28 11:22:57 +02:00
|
|
|
active_thread = sched_threads[0];
|
|
|
|
sched_run();
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
__restore_context();
|
|
|
|
}
|
|
|
|
|
2013-12-18 02:25:48 +01:00
|
|
|
/**
|
|
|
|
* mspgcc handles main specially - it does not return but falls
|
|
|
|
* through to section .fini9.
|
|
|
|
* To "fix" this, we put a return in section .fini9 to make main
|
|
|
|
* behave like a regular function. This enables a common
|
|
|
|
* thread_stack_init behavior. */
|
|
|
|
__attribute__((section (".fini9"))) void __main_epilogue(void) { __asm__("ret"); }
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Processor specific routine - here for MSP
|
|
|
|
//----------------------------------------------------------------------------
|
2013-06-01 18:35:25 +02:00
|
|
|
char *thread_stack_init(void (*task_func)(void), void *stack_start, int stack_size)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned short *stk;
|
|
|
|
stk = (unsigned short *)(stack_start + stack_size);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2010-10-28 11:22:57 +02:00
|
|
|
*stk = (unsigned short) sched_task_exit;
|
2010-09-22 15:10:42 +02:00
|
|
|
--stk;
|
|
|
|
|
|
|
|
*stk = (unsigned short) task_func;
|
|
|
|
--stk;
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
/* initial value for SR */
|
|
|
|
|
|
|
|
*stk = GIE;
|
|
|
|
--stk;
|
|
|
|
|
|
|
|
/* Space for registers. */
|
2013-06-24 22:37:35 +02:00
|
|
|
for (unsigned int i = 15; i > 4; i--) {
|
2010-09-22 15:10:42 +02:00
|
|
|
*stk = i;
|
|
|
|
--stk;
|
|
|
|
}
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
//stk -= 11;
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
return (char *) stk;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
int inISR()
|
|
|
|
{
|
|
|
|
return __inISR;
|
|
|
|
}
|