2014-08-27 18:47:31 +02:00
|
|
|
/*
|
2014-09-09 12:16:26 +02:00
|
|
|
* Copyright (C) 2014, Freie Universitaet Berlin (FUB) & INRIA.
|
|
|
|
* All rights reserved.
|
2014-08-27 18:47:31 +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.
|
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2015-07-06 01:17:05 +02:00
|
|
|
#ifndef CPU_H_
|
|
|
|
#define CPU_H_
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/**
|
2015-07-06 01:17:05 +02:00
|
|
|
* @defgroup cpu_msp430_common TI MSP430
|
2013-11-27 17:54:30 +01:00
|
|
|
* @ingroup cpu
|
|
|
|
* @brief Texas Instruments MSP430 specific code
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
<h2>First steps</h2>
|
2013-11-27 17:54:30 +01:00
|
|
|
\li See the <a href="../manual/index.html">manual</a> for toolchain and ide setup
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2013-03-30 21:44:16 +01:00
|
|
|
#include <legacymsp430.h>
|
2013-12-09 11:12:39 +01:00
|
|
|
|
|
|
|
#include <msp430.h>
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "board.h"
|
2013-12-09 11:12:39 +01:00
|
|
|
|
|
|
|
#include "sched.h"
|
|
|
|
#include "msp430_types.h"
|
2015-05-22 14:31:23 +02:00
|
|
|
#include "cpu_conf.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-10-13 10:53:20 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Wordsize in bit for MSP430 platforms
|
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
#define WORDSIZE 16
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief The current ISR state (inside or not)
|
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
extern volatile int __inISR;
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Memory used as stack for the interrupt context
|
|
|
|
*/
|
|
|
|
extern char __isr_stack[MSP430_ISR_STACK_SIZE];
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2015-03-10 13:20:04 +01:00
|
|
|
/**
|
|
|
|
* @brief definition of legacy interrupt control functions
|
|
|
|
*/
|
|
|
|
#define eINT enableIRQ
|
|
|
|
#define dINT disableIRQ
|
|
|
|
/** @} */
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Save the current thread context from inside an ISR
|
|
|
|
*/
|
2013-06-21 03:52:57 +02: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");
|
|
|
|
|
2014-04-10 22:28:35 +02:00
|
|
|
__asm__("mov.w r1,%0" : "=r"(sched_active_thread->sp));
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Restore the thread context from inside an ISR
|
|
|
|
*/
|
2013-06-21 03:52:57 +02:00
|
|
|
inline void __restore_context_isr(void)
|
|
|
|
{
|
2014-04-10 22:28:35 +02:00
|
|
|
__asm__("mov.w %0,r1" : : "m"(sched_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");
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Run this code on entering interrupt routines
|
|
|
|
*/
|
2013-06-21 03:52:57 +02:00
|
|
|
inline void __enter_isr(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
__save_context_isr();
|
2013-06-21 03:52:57 +02:00
|
|
|
__asm__("mov.w %0,r1" : : "i"(__isr_stack+MSP430_ISR_STACK_SIZE));
|
2010-09-22 15:10:42 +02:00
|
|
|
__inISR = 1;
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Run this code on exiting interrupt routines
|
|
|
|
*/
|
2013-06-21 03:52:57 +02:00
|
|
|
inline void __exit_isr(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
__inISR = 0;
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (sched_context_switch_request) {
|
2013-06-21 03:52:57 +02:00
|
|
|
sched_run();
|
|
|
|
}
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
__restore_context_isr();
|
|
|
|
__asm__("reti");
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Save the current context on the stack
|
|
|
|
*/
|
2013-06-21 03:52:57 +02:00
|
|
|
inline void __save_context(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
__asm__("push r2"); /* save SR */
|
|
|
|
__save_context_isr();
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Restore the thread context from the stack
|
|
|
|
*
|
|
|
|
* @param[in] irqen former interrupt state
|
|
|
|
*/
|
2014-08-26 14:28:01 +02:00
|
|
|
inline void __restore_context(unsigned int irqen)
|
2013-06-21 03:52:57 +02:00
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
__restore_context_isr();
|
2014-08-26 14:28:01 +02:00
|
|
|
|
2014-09-09 12:16:26 +02:00
|
|
|
/*
|
|
|
|
* we want to enable appropriate IRQs *just after*
|
|
|
|
* quitting the interrupt handler; to that end,
|
|
|
|
* we change the GIE bit in the value to be restored
|
|
|
|
* in R2 (a.k.a. SR) by the next RETI instruction
|
|
|
|
*/
|
2014-08-26 14:28:01 +02:00
|
|
|
if (irqen) {
|
|
|
|
__asm__("bis.w #8, 0(r1)");
|
|
|
|
} else {
|
|
|
|
__asm__("bic.w #8, 0(r1)");
|
|
|
|
}
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
__asm__("reti");
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:45:34 +02:00
|
|
|
/**
|
|
|
|
* @brief Initialize the cpu
|
|
|
|
*/
|
2013-08-14 23:46:51 +02:00
|
|
|
void msp430_cpu_init(void);
|
|
|
|
|
2014-10-13 10:53:20 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
/** @} */
|
2015-07-06 01:17:05 +02:00
|
|
|
#endif /* CPU_H_ */
|