?? os_cpu_c.c
字號(hào):
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* ATmega128 Specific code
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#define IN_OS_CPU_C
#include "includes.h"
/*
**********************************************************************************************************
* INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
* stack frame of the task being created. This function is highly processor specific.
*
* Arguments : task is a pointer to the task code
*
* p_arg is a pointer to a user supplied data area that will be passed to the task
* when the task first executes.
*
* ptos is a pointer to the top of stack. It is assumed that 'ptos' points to the
* highest valid address on the stack.
*
* opt specifies options that can be used to alter the behavior of OSTaskStkInit().
* (see uCOS_II.H for OS_TASK_OPT_???).
*
* Returns : Always returns the location of the new top-of-stack' once the processor registers have
* been placed on the stack in the proper order.
*
* Note(s) : Interrupts are enabled when your task starts executing. You can change this by setting the
* SREG to 0x00 instead. In this case, interrupts would be disabled upon task startup. The
* application code would be responsible for enabling interrupts at the beginning of the task
* code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable interrupts.
* Failure to do this will make your system crash!
*
* The AVR return stack is placed OS_TASK_STK_SIZE_HARD bytes before the bottom of the task's
* stack.
**********************************************************************************************************
*/
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, uint16 opt)
{
uint8 *psoft_stk;
uint8 *phard_stk; /* Temp. variable used for setting up AVR hardware stack */
uint16 tmp;
(void)opt; /* 'opt' is not used, prevent warning */
psoft_stk = (uint8 *)ptos;
phard_stk = (uint8 *)ptos
- OSTaskStkSize /* Task stack size */
+ OSTaskStkSizeHard; /* AVR return stack ("hardware stack") */
tmp = (uint16)task;
/* Put task start address on top of "hardware stack" */
*phard_stk-- = (uint8)(tmp & 0xFF); /* Save PC return address */
tmp >>= 8;
*phard_stk-- = (uint8)(tmp & 0xFF);
*psoft_stk-- = (uint8)0x00; /* R0 = 0x00 */
*psoft_stk-- = (uint8)0x01; /* R1 = 0x01 */
*psoft_stk-- = (uint8)0x02; /* R2 = 0x02 */
*psoft_stk-- = (uint8)0x03; /* R3 = 0x03 */
*psoft_stk-- = (uint8)0x04; /* R4 = 0x04 */
*psoft_stk-- = (uint8)0x05; /* R5 = 0x05 */
*psoft_stk-- = (uint8)0x06; /* R6 = 0x06 */
*psoft_stk-- = (uint8)0x07; /* R7 = 0x07 */
tmp = (uint16)p_arg;
*psoft_stk-- = (uint8)tmp; /* 'p_arg' passed in R17:R16 */
*psoft_stk-- = (uint8)(tmp >> 8);
*psoft_stk-- = (uint8)0x18; /* R18 = 0x18 */
*psoft_stk-- = (uint8)0x19; /* R19 = 0x19 */
*psoft_stk-- = (uint8)0x20; /* R20 = 0x20 */
*psoft_stk-- = (uint8)0x21; /* R21 = 0x21 */
*psoft_stk-- = (uint8)0x22; /* R22 = 0x22 */
*psoft_stk-- = (uint8)0x23; /* R23 = 0x23 */
*psoft_stk-- = (uint8)0x24; /* R24 = 0x24 */
*psoft_stk-- = (uint8)0x25; /* R25 = 0x25 */
*psoft_stk-- = (uint8)0x26; /* R26 = 0x26 */
*psoft_stk-- = (uint8)0x27; /* R27 = 0x27 */
/* R28 R29:R28 is the software stack which gets ... */
/* R29 ... in the TCB. */
*psoft_stk-- = (uint8)0x30; /* R30 = 0x30 */
*psoft_stk-- = (uint8)0x31; /* R31 = 0x31 */
*psoft_stk-- = (uint8)0xAA; /* RAMPZ = 0xAA */
*psoft_stk-- = (uint8)0x80; /* SREG = Interrupts enabled */
tmp = (uint16)phard_stk;
*psoft_stk-- = (uint8)(tmp >> 8); /* SPH */
*psoft_stk = (uint8)(tmp & 0xFF); /* SPL */
return ((OS_STK *)psoft_stk);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -