aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/common/ports/MSP430X/chcore.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/common/ports/MSP430X/chcore.c')
-rw-r--r--lib/chibios-contrib/os/common/ports/MSP430X/chcore.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/common/ports/MSP430X/chcore.c b/lib/chibios-contrib/os/common/ports/MSP430X/chcore.c
new file mode 100644
index 000000000..c60c0a5f8
--- /dev/null
+++ b/lib/chibios-contrib/os/common/ports/MSP430X/chcore.c
@@ -0,0 +1,110 @@
1/*
2 ChibiOS/HAL - Copyright (C) 2016 Andrew Wygle aka awygle
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file MSP430X/nilcore.c
19 * @brief MSP430X port code.
20 *
21 * @addtogroup MSP430X_CORE
22 * @{
23 */
24
25#include "ch.h"
26
27/*===========================================================================*/
28/* Module local definitions. */
29/*===========================================================================*/
30
31/*===========================================================================*/
32/* Module exported variables. */
33/*===========================================================================*/
34
35bool __msp430x_in_isr;
36
37/*===========================================================================*/
38/* Module local types. */
39/*===========================================================================*/
40
41/*===========================================================================*/
42/* Module local variables. */
43/*===========================================================================*/
44
45/*===========================================================================*/
46/* Module local functions. */
47/*===========================================================================*/
48
49/*===========================================================================*/
50/* Module exported functions. */
51/*===========================================================================*/
52
53/**
54 * @brief Performs a context switch between two threads.
55 * @details This is the most critical code in any port, this function
56 * is responsible for the context switch between 2 threads.
57 * @note The implementation of this code affects <b>directly</b> the context
58 * switch performance so optimize here as much as you can.
59 *
60 * @param[in] ntp the thread to be switched in
61 * @param[in] otp the thread to be switched out
62 */
63#if !(__GNUC__ < 6 && __GNUC_MINOR__ < 4) || defined(__OPTIMIZE__)
64__attribute__((naked))
65#endif
66void _port_switch(thread_t *ntp, thread_t *otp) {
67#if (__GNUC__ < 6 && __GNUC_MINOR__ < 4) && !defined(__OPTIMIZE__)
68 asm volatile ("add #4, r1");
69#endif
70 (void)(ntp);
71 (void)(otp);
72#if defined(__MSP430X_LARGE__)
73 asm volatile ("pushm.a #7, R10");
74 asm volatile ("mova r1, @R13");
75 asm volatile ("mova @R12, r1");
76 asm volatile ("popm.a #7, R10");
77 asm volatile ("reta");
78#else
79 asm volatile ("pushm.w #7, R10");
80 asm volatile ("mov r1, @R13");
81 asm volatile ("mov @R12, r1");
82 asm volatile ("popm.w #7, R10");
83 asm volatile ("ret");
84#endif
85}
86
87/**
88 * @brief Start a thread by invoking its work function.
89 * @details If the work function returns @p chThdExit() is automatically
90 * invoked.
91 */
92void _port_thread_start(void) {
93
94 /* See PORT_SETUP_CONTEXT in nilcore.h */
95 chSysUnlock();
96#if defined(__MSP430X_LARGE__)
97 asm volatile ("mova R5, R12");
98 asm volatile ("calla R4");
99#else
100 asm volatile ("mov R5, R12");
101 asm volatile ("call R4");
102#endif
103#if defined(_CHIBIOS_RT_CONF_)
104 chThdExit(MSG_OK);
105#endif
106#if defined(_CHIBIOS_NIL_CONF_)
107 chSysHalt(0);
108#endif
109}
110/** @} */