📄 os_cpu_a.asm
字号:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; AVR Specific code
; (AVR-GCC 3.x)
;
;
; File : OS_CPU_A.ASM
; By : Ole Saether
; Port Version : V1.01
;
; AVR-GCC port version : 1.0 2001-04-02 modified/ported to avr-gcc by Jesper Hansen (jesperh@telia.com)
;
; Modifications by Julius Luukko 2003-02-19 (Julius.Luukko@lut.fi):
;
; - Minor modification to OSTickISR's declaration to global and addition of #include <avr/io.h>
; in order to work with gcc 3.3.
; - Moved 'sei' from the beginning of OSTickISR after the increasing of OSIntNesting (as the book suggests)
; - Changed the order of reloading the timer counter and calling of OSIntExit
; - Changed OSIntCtxSw to the way it is supposed to be with OS_VERSION >= 251
; - Changed OSTickISR so that is saves the stack pointer into the current task's OS_TCB if OSTickISR is the
; first level ISR
; - os_cfg.h must be included (definitions of CPU_CLOCK_HZ and OS_TICKS_PER_SEC)
; - avr/io.h is included to get SIG_OVERFLOW0 to produce the code to the interrupt vector table
;
; Modifications by Julius Luukko 2003-03-06 (Julius.Luukko@lut.fi):
;
; - RAMPZ is also saved to the stack
;
; Modifications by Julius Luukko 2003-03-18 (Julius.Luukko@lut.fi):
;
; - RAMPZ and SREG were popped out of the stack in the wrong order! Corrected this.
; - Divided macros PUSHRS and POPRS into to macros PUSHRS, PUSHSREG, POPRS and POPSREG. Additionally,
; in ISRs macro called PUSHSREGISR must be used. It sets the I bit i SREG, since its always unset, when
; ISR is entered. It must be, however, set to enable interrupts when the task is run again.
; - RCALLs changed to CALLs. This allows the code of called functions to be further away from the calls.
; (fixes the "relocating truncated to fit" error from the linker)
;
;
; Modifications by Julius Luukko 2003-03-19 (Julius.Luukko@lut.fi):
;
; - timer interrupt is changed so that the timer counter register is updated right after _not_first_int
; (was AFTER the call to OSIntExit!!)
;
; Modifications by Julius Luukko 2003-06-24 (Julius.Luukko@lut.fi):
;
; - I/O port addressing is now done using the macro _SFR_IO_ADDR from avr-libc and the address
; definitions are removed from here
; - RAMPZ is pushed and popped only if it is defined, i.e. with chips that have it
;
; Modifications by Julius Luukko 2003-07-21 (Julius.Luukko@lut.fi) for V2.70
;
; - OSTaskSwHook is not called if OS_TASK_SW_HOOK_EN == 0
; - defines typedef to ; so that os_cfg_r.h can be used more easily as a starting point for
; the application specific os_cfg.h
;
;********************************************************************************************************
;********************************************************************************************************
; C PREPROCESSOR DIRECTIVES
;********************************************************************************************************
#include <avr/io.h>
#define OS_CPU_A
#include "os_cpu.h"
#define typedef ;
#include "os_cfg.h"
#ifndef OS_TASK_SW_HOOK_EN
#define OS_TASK_SW_HOOK_EN 1
#endif
;********************************************************************************************************
; PUBLIC DECLARATIONS
;********************************************************************************************************
.global OSStartHighRdy
.global OSCtxSw
.global OSIntCtxSw
.global OSTickISR
;********************************************************************************************************
; EXTERNAL DECLARATIONS
;********************************************************************************************************
.extern OSIntExit
.extern OSIntNesting
.extern OSPrioCur
.extern OSPrioHighRdy
.extern OSRunning
#if OS_TASK_SW_HOOK_EN > 0
.extern OSTaskSwHook
#endif
.extern OSTCBCur
.extern OSTCBHighRdy
.extern OSTimeTick
;********************************************************************************************************
; MACROS
;********************************************************************************************************
; Push all registers and the status register
.macro PUSHRS
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
push r16
push r17
push r18
push r19
push r20
push r21
push r22
push r23
push r24
push r25
push r26
push r27
push r28
push r29
push r30
push r31
#ifdef RAMPZ
in r16,_SFR_IO_ADDR(RAMPZ)
push r16
#endif
.endm
; Pop all registers and the status registers
.macro POPRS
#ifdef RAMPZ
pop r16
out _SFR_IO_ADDR(RAMPZ),r16
#endif
pop r31
pop r30
pop r29
pop r28
pop r27
pop r26
pop r25
pop r24
pop r23
pop r22
pop r21
pop r20
pop r19
pop r18
pop r17
pop r16
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
.endm
.macro POPSREG
pop r16
out _SFR_IO_ADDR(SREG),r16
.endm
.macro PUSHSREG
in r16,_SFR_IO_ADDR(SREG)
push r16
.endm
.macro PUSHSREGISR
in r16,_SFR_IO_ADDR(SREG)
sbr r16,0x80
push r16
.endm
.text
.section .text
;********************************************************************************************************
; START HIGHEST PRIORITY TASK READY-TO-RUN
;
; Description : This function is called by OSStart() to start the highest priority task that was created
; by your application before calling OSStart().
;
; Note(s) : 1) The (data)stack frame is assumed to look as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> LSB of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -