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-06-18 17:21:38 +02:00
|
|
|
This file subject to the terms and conditions of the GNU Lesser General Public
|
|
|
|
License. See the file LICENSE in the top level directory for more details.
|
2010-09-22 15:10:42 +02:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _CPU_H
|
|
|
|
#define _CPU_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup msp430 TI MSP430
|
|
|
|
* @ingroup cpu
|
|
|
|
|
|
|
|
<h2>First steps</h2>
|
|
|
|
\li See the <a href="../manual/index.html">manual</a> for toolchain and ide setup
|
|
|
|
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-10-28 11:22:57 +02:00
|
|
|
#include <sched.h>
|
2010-09-22 15:10:42 +02:00
|
|
|
#include <stdio.h>
|
2013-03-30 21:44:16 +01:00
|
|
|
#include <legacymsp430.h>
|
2010-09-22 15:10:42 +02:00
|
|
|
#include <cpu-conf.h>
|
|
|
|
|
|
|
|
#define WORDSIZE 16
|
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
/* not used(?) */
|
2010-09-22 15:10:42 +02:00
|
|
|
#define F_CPU 10000000
|
|
|
|
|
|
|
|
extern volatile int __inISR;
|
|
|
|
extern char __isr_stack[MSP430_ISR_STACK_SIZE];
|
|
|
|
|
|
|
|
//#define eINT() eint()
|
|
|
|
//#define dINT() dint()
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void __save_context_isr(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
__asm__("push r15");
|
|
|
|
__asm__("push r14");
|
|
|
|
__asm__("push r13");
|
|
|
|
__asm__("push r12");
|
|
|
|
__asm__("push r11");
|
|
|
|
__asm__("push r10");
|
|
|
|
__asm__("push r9");
|
|
|
|
__asm__("push r8");
|
|
|
|
__asm__("push r7");
|
|
|
|
__asm__("push r6");
|
|
|
|
__asm__("push r5");
|
|
|
|
__asm__("push r4");
|
|
|
|
|
2010-10-28 11:22:57 +02:00
|
|
|
__asm__("mov.w r1,%0" : "=r" (active_thread->sp));
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void __restore_context_isr(void) {
|
2010-10-28 11:22:57 +02:00
|
|
|
__asm__("mov.w %0,r1" : : "m" (active_thread->sp));
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
__asm__("pop r4");
|
|
|
|
__asm__("pop r5");
|
|
|
|
__asm__("pop r6");
|
|
|
|
__asm__("pop r7");
|
|
|
|
__asm__("pop r8");
|
|
|
|
__asm__("pop r9");
|
|
|
|
__asm__("pop r10");
|
|
|
|
__asm__("pop r11");
|
|
|
|
__asm__("pop r12");
|
|
|
|
__asm__("pop r13");
|
|
|
|
__asm__("pop r14");
|
|
|
|
__asm__("pop r15");
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void __enter_isr(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
__save_context_isr();
|
|
|
|
__asm__("mov.w %0,r1" : : "i" (__isr_stack+MSP430_ISR_STACK_SIZE));
|
|
|
|
__inISR = 1;
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void __exit_isr(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
__inISR = 0;
|
2010-10-28 11:22:57 +02:00
|
|
|
if (sched_context_switch_request) sched_run();
|
2010-09-22 15:10:42 +02:00
|
|
|
__restore_context_isr();
|
|
|
|
__asm__("reti");
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void __save_context(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
__asm__("push r2"); /* save SR */
|
|
|
|
__save_context_isr();
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void __restore_context(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
__restore_context_isr();
|
|
|
|
__asm__("reti");
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void eINT(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
// puts("+");
|
|
|
|
eint();
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
inline void dINT(void) {
|
2010-09-22 15:10:42 +02:00
|
|
|
// puts("-");
|
|
|
|
dint();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lpm_set(...)
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
void thread_yield(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
int inISR(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/** @} */
|
|
|
|
#endif // _CPU_H
|
|
|
|
|