⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 context_switch.h

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 H
字号:
//  This file is part of MANTIS OS, Operating System//  See http://mantis.cs.colorado.edu/////  Copyright (C) 2003,2004,2005 University of Colorado, Boulder////  This program is free software; you can redistribute it and/or//  modify it under the terms of the mos license (see file LICENSE)/** @file msp430/include/context_switch.h * @brief Assembly routines required to preform a context switch on the MSP430 architecture. */#ifndef __context_switch_h__#define __context_switch_h__/** @brief save the necessary registers for a context switch * Save current stack pointer * Change stack pointer to process stack * Push address of start_thread function onto stack * Push zeroes for initial register vals and sreg * Save adjusted stack ptr to thread struct * Restore kernel stack ptr */#define CONTEXT_SWITCH_PREAMBLE()                  \{                                                  \   asm volatile("mov.w r1, %0\n\t"                 \		:"=r"(_current_thread->sp) : );    \                                                   \   asm volatile("mov.w %0, r1\n\t"                 \		:: "r"(stack_addr) );              \                                                   \   asm volatile("push %0\n\t"                      \                ::"r"(start_wrapper));             \                                                   \   for(i = 0; i < 13; i++)                         \      asm volatile("push r3\n\t");                 \                                                   \   asm volatile("mov.w r1, %0\n\t"                 \		:"=r"(threads[id].sp) : );         \                                                   \   asm volatile("mov.w %0, r1\n\t"                 \		::"r"(_current_thread->sp) );      \                                                   \}/** @brief save the current thread's context to the stack * Push status register * Push general purpose registers * Save the stack pointer to the thread struct */#define PUSH_THREAD_STACK()			\   {						\      asm volatile(				\	 "push r2\n\t"				\	 "dint\n\t"				\	 );					\      asm volatile(				\	 "push r15\n\t"				\	 "push r14\n\t"				\	 "push r13\n\t"				\	 "push r12\n\t"				\	 "push r11\n\t"				\	 "push r10\n\t"				\	 "push r9\n\t"				\	 "push r8\n\t"				\	 "push r7\n\t"				\	 "push r6\n\t"				\	 "push r5\n\t"				\	 "push r4\n\t"				\	 );					\      asm volatile(				\         "mov.w r1, %0\n\t"                     \         :"=r"(_current_thread->sp) : );	\   }/** @brief retrieve a thread and context from the stack * Restore the stack pointer from the thread struct * Pop the status register * Pop the general purpose registers */#define POP_THREAD_STACK()                      \{                                               \   asm volatile("mov.w %0, r1\n\t"              \		::"r"(_current_thread->sp));    \                                                \   asm volatile(                                \      "pop r4\n\t"                              \      "pop r5\n\t"                              \      "pop r6\n\t"                              \      "pop r7\n\t"                              \      "pop r8\n\t"                              \      "pop r9\n\t"                              \      "pop r10\n\t"                             \      "pop r11\n\t"                             \      "pop r12\n\t"                             \      "pop r13\n\t"                             \      "pop r14\n\t"                             \      "pop r15\n\t"                             \      );                                        \                                                \   asm volatile("pop r2\n\t");                  \   asm volatile("eint\n\t");                    \}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -