📄 app.s
字号:
.module app.c
.area text(rom, con, rel)
.dbfile D:\MICRIUM\app.c
.dbfunc e main _main fV
.even
_main::
sbiw R28,3
.dbline -1
.dbline 79
; /*
; *************************************************************************************************************
; * uC/OS-II
; * The Real-Time Kernel
; *
; * ATmega128 Sample code
; *
; * File : APP.C
; * By : Jean J. Labrosse
; *************************************************************************************************************
; */
;
; #include <includes.h>
;
; /*
; **************************************************************************************************************
; * CONSTANTS
; *
; * Note(s) : 1) See OS_CFG.H for the default stack size: 'OS_TASK_STK_SIZE'
; **************************************************************************************************************
; */
;
; #define OS_TASK_START_STK_SIZE OS_TASK_STK_SIZE
; #define OS_TASK_START_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
;
; #define OS_TASK_1_STK_SIZE OS_TASK_STK_SIZE
; #define OS_TASK_1_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
;
; #define OS_TASK_2_STK_SIZE OS_TASK_STK_SIZE
; #define OS_TASK_2_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
;
;
; /*
; **************************************************************************************************************
; * VARIABLES
; **************************************************************************************************************
; */
;
; OS_STK AppTaskStartStk[OS_TASK_START_STK_SIZE];
; OS_STK AppTask1Stk[OS_TASK_1_STK_SIZE];
; OS_STK AppTask2Stk[OS_TASK_2_STK_SIZE];
;
; /*
; **************************************************************************************************************
; * FUNCTION PROTOTYPES
; **************************************************************************************************************
; */
;
; void main(void);
;
; static void AppTaskStart(void *p_arg);
; static void AppTaskCreate(void);
; static void AppTask1(void *p_arg);
; static void AppTask2(void *p_arg);
;
; static void AppIOInit(void);
;
; static void LED_Toggle(INT8U led);
;
; /*
; **************************************************************************************************************
; * MAIN
; *
; * Note(s): 1) You SHOULD use OS_TASK_STK_SIZE (see OS_CFG.H) when setting OSTaskStkSize prior to calling
; * OSInit() because OS_TASK_IDLE_STK_SIZE and OS_TASK_STAT_STK_SIZE are set to this value in
; * OS_CFG.H.
; **************************************************************************************************************
; */
;
; /*
; #pragma interrupt_handler timer0_ovf_isr:17
; void timer0_ovf_isr(void)
; {
; OSTickISR();
; }
; */
;
; void main (void)
; {
.dbline 83
; /*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
;
; /* IMPORTANT: MUST be setup before calling 'OSInit()' */
; OSTaskStkSize = OS_TASK_STK_SIZE; /* Setup the default stack size */
ldi R24,256
ldi R25,1
sts _OSTaskStkSize+1,R25
sts _OSTaskStkSize,R24
.dbline 84
; OSTaskHardStkSize = OS_TASK_HARD_STK_SIZE; /* Setup the default hardware stack size */
ldi R24,64
ldi R25,0
sts _OSTaskHardStkSize+1,R25
sts _OSTaskHardStkSize,R24
.dbline 86
;
; OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
xcall _OSInit
.dbline 90
;
; /*---- Any initialization code before starting multitasking ---------------------------------------*/
;
; OSTaskStkSize = OS_TASK_START_STK_SIZE; /* Setup the total stack size */
ldi R24,256
ldi R25,1
sts _OSTaskStkSize+1,R25
sts _OSTaskStkSize,R24
.dbline 91
; OSTaskHardStkSize = OS_TASK_START_HARD_STK_SIZE; /* Setup the hardware stack size */
ldi R24,64
ldi R25,0
sts _OSTaskHardStkSize+1,R25
sts _OSTaskHardStkSize,R24
.dbline 92
; OSTaskCreate(AppTaskStart, (void *)0, (OS_STK *)&AppTaskStartStk[OSTaskStkSize - 1], 0);
clr R2
std y+2,R2
ldi R24,<_AppTaskStartStk
ldi R25,>_AppTaskStartStk
lds R30,_OSTaskStkSize
lds R31,_OSTaskStkSize+1
sbiw R30,1
add R30,R24
adc R31,R25
std y+1,R31
std y+0,R30
clr R18
clr R19
ldi R16,<PL_AppTaskStart
ldi R17,>PL_AppTaskStart
xcall _OSTaskCreate
.dbline 96
;
; /*---- Create any other task you want before we start multitasking --------------------------------*/
;
; OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
xcall _OSStart
.dbline -2
L1:
.dbline 0 ; func end
adiw R28,3
ret
.dbend
.dbfunc s AppTaskStart _AppTaskStart fV
; p_arg -> <dead>
.even
_AppTaskStart:
st -y,r17
st -y,r16
.dbline -1
.dbline 114
; }
;
; /*
; *********************************************************************************************************
; * STARTUP TASK
; *
; * Description : This is an example of a startup task. As mentioned in the book's text, you MUST
; * initialize the ticker only once multitasking has started.
; *
; * Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
; *
; * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
; * used. The compiler should not generate any code for this statement.
; *********************************************************************************************************
; */
;
; static void AppTaskStart (void *p_arg)
; {
.dbline 115
; p_arg = p_arg; /* Prevent compiler warnings */
.dbline 117
;
; OSTickISR_Init(); /* Initialize the ticker */
xcall _OSTickISR_Init
.dbline 119
;
; AppIOInit(); /* Initialize the I/Os */
xcall _AppIOInit
.dbline 121
;
; AppTaskCreate();
xcall _AppTaskCreate
xjmp L4
L3:
.dbline 123
;
; while (TRUE) { /* Task body, always written as an infinite loop. */
.dbline 124
; LED_Toggle(1);
ldi R16,1
xcall _LED_Toggle
.dbline 125
; OSTimeDly(OS_TICKS_PER_SEC / 10);
ldi R16,5
ldi R17,0
xcall _OSTimeDly
.dbline 126
; }
L4:
.dbline 123
xjmp L3
X0:
.dbline -2
L2:
.dbline 0 ; func end
adiw R28,2
ret
.dbsym l p_arg 0 pV
.dbend
.dbfunc s AppTaskCreate _AppTaskCreate fV
.even
_AppTaskCreate:
sbiw R28,3
.dbline -1
.dbline 144
; }
;
;
; /*
; *********************************************************************************************************
; * CREATE APPLICATION TASKS
; *
; * Description : This function creates the application tasks.
; *
; * Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
; *
; * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
; * used. The compiler should not generate any code for this statement.
; *********************************************************************************************************
; */
;
; static void AppTaskCreate (void)
; {
.dbline 146
; /*---- Task initialization code goes HERE! --------------------------------------------------------*/
; OSTaskStkSize = OS_TASK_1_STK_SIZE; /* Setup the default stack size */
ldi R24,256
ldi R25,1
sts _OSTaskStkSize+1,R25
sts _OSTaskStkSize,R24
.dbline 147
; OSTaskHardStkSize = OS_TASK_1_HARD_STK_SIZE; /* Setup the default hardware stack size */
ldi R24,64
ldi R25,0
sts _OSTaskHardStkSize+1,R25
sts _OSTaskHardStkSize,R24
.dbline 148
; OSTaskCreate(AppTask1, (void *)0, (OS_STK *)&AppTask1Stk[OSTaskStkSize - 1], 1);
ldi R24,1
std y+2,R24
ldi R24,<_AppTask1Stk
ldi R25,>_AppTask1Stk
lds R30,_OSTaskStkSize
lds R31,_OSTaskStkSize+1
sbiw R30,1
add R30,R24
adc R31,R25
std y+1,R31
std y+0,R30
clr R18
clr R19
ldi R16,<PL_AppTask1
ldi R17,>PL_AppTask1
xcall _OSTaskCreate
.dbline 150
;
; OSTaskStkSize = OS_TASK_2_STK_SIZE; /* Setup the default stack size */
ldi R24,256
ldi R25,1
sts _OSTaskStkSize+1,R25
sts _OSTaskStkSize,R24
.dbline 151
; OSTaskHardStkSize = OS_TASK_2_HARD_STK_SIZE; /* Setup the default hardware stack size */
ldi R24,64
ldi R25,0
sts _OSTaskHardStkSize+1,R25
sts _OSTaskHardStkSize,R24
.dbline 152
; OSTaskCreate(AppTask2, (void *)0, (OS_STK *)&AppTask2Stk[OSTaskStkSize - 1], 2);
ldi R24,2
std y+2,R24
ldi R24,<_AppTask2Stk
ldi R25,>_AppTask2Stk
lds R30,_OSTaskStkSize
lds R31,_OSTaskStkSize+1
sbiw R30,1
add R30,R24
adc R31,R25
std y+1,R31
std y+0,R30
clr R18
clr R19
ldi R16,<PL_AppTask2
ldi R17,>PL_AppTask2
xcall _OSTaskCreate
.dbline -2
L6:
.dbline 0 ; func end
adiw R28,3
ret
.dbend
.dbfunc s AppTask1 _AppTask1 fV
; p_arg -> <dead>
.even
_AppTask1:
st -y,r17
st -y,r16
.dbline -1
.dbline 162
; }
;
; /*
; *********************************************************************************************************
; * TASK #1
; *********************************************************************************************************
; */
;
; static void AppTask1(void *p_arg)
; {
.dbline 163
; p_arg = p_arg;
xjmp L9
L8:
.dbline 164
; while (TRUE) {
.dbline 165
; LED_Toggle(2);
ldi R16,2
xcall _LED_Toggle
.dbline 166
; OSTimeDly(OS_TICKS_PER_SEC / 5);
ldi R16,10
ldi R17,0
xcall _OSTimeDly
.dbline 167
; }
L9:
.dbline 164
xjmp L8
X1:
.dbline -2
L7:
.dbline 0 ; func end
adiw R28,2
ret
.dbsym l p_arg 0 pV
.dbend
.dbfunc s AppTask2 _AppTask2 fV
; p_arg -> <dead>
.even
_AppTask2:
st -y,r17
st -y,r16
.dbline -1
.dbline 177
; }
;
; /*
; *********************************************************************************************************
; * TASK #2
; *********************************************************************************************************
; */
;
; static void AppTask2(void *p_arg)
; {
.dbline 178
; p_arg = p_arg;
xjmp L13
L12:
.dbline 179
; while (TRUE) {
.dbline 180
; LED_Toggle(3);
ldi R16,3
xcall _LED_Toggle
.dbline 181
; OSTimeDly(OS_TICKS_PER_SEC / 2);
ldi R16,25
ldi R17,0
xcall _OSTimeDly
.dbline 182
; }
L13:
.dbline 179
xjmp L12
X2:
.dbline -2
L11:
.dbline 0 ; func end
adiw R28,2
ret
.dbsym l p_arg 0 pV
.dbend
.dbfunc s AppIOInit _AppIOInit fV
.even
_AppIOInit:
.dbline -1
.dbline 192
; }
;
; /*
; *********************************************************************************************************
; * SETUP THE I/Os
; *********************************************************************************************************
; */
;
; static void AppIOInit (void)
; {
.dbline 193
; DDRD = 0xFF; /* All PORTD pins are outputs */
ldi R24,255
out 0x11,R24
.dbline 194
; PORTD = 0xFF;
out 0x12,R24
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc s LED_Toggle _LED_Toggle fV
; cpu_sr -> R10
; led -> R12
.even
_LED_Toggle:
xcall push_xgset303C
mov R12,R16
.dbline -1
.dbline 205
; }
;
;
; /*
; *********************************************************************************************************
; * TOGGLE LED
; *********************************************************************************************************
; */
;
; static void LED_Toggle (INT8U led)
; {
.dbline 211
; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; OS_CPU_SR cpu_sr;
; #endif
;
;
; OS_ENTER_CRITICAL();
xcall _OS_CPU_SR_Save
mov R10,R16
.dbline 212
; switch (led) {
mov R20,R12
clr R21
cpi R20,1
ldi R30,0
cpc R21,R30
breq L20
X3:
cpi R20,2
ldi R30,0
cpc R21,R30
breq L21
X4:
cpi R20,3
ldi R30,0
cpc R21,R30
breq L22
X5:
cpi R20,4
ldi R30,0
cpc R21,R30
breq L23
X6:
xjmp L17
L20:
.dbline 214
; case 1:
; PORTD ^= 0x01;
ldi R24,1
in R2,0x12
eor R2,R24
out 0x12,R2
.dbline 215
; break;
xjmp L18
L21:
.dbline 218
;
; case 2:
; PORTD ^= 0x02;
ldi R24,2
in R2,0x12
eor R2,R24
out 0x12,R2
.dbline 219
; break;
xjmp L18
L22:
.dbline 222
;
; case 3:
; PORTD ^= 0x04;
ldi R24,4
in R2,0x12
eor R2,R24
out 0x12,R2
.dbline 223
; break;
xjmp L18
L23:
.dbline 226
;
; case 4:
; PORTD ^= 0x08;
ldi R24,8
in R2,0x12
eor R2,R24
out 0x12,R2
.dbline 227
; break;
L17:
L18:
.dbline 229
; }
; OS_EXIT_CRITICAL();
mov R16,R10
xcall _OS_CPU_SR_Restore
.dbline -2
L16:
.dbline 0 ; func end
xjmp pop_xgset303C
.dbsym r cpu_sr 10 c
.dbsym r led 12 c
.dbend
.area bss(ram, con, rel)
.dbfile D:\MICRIUM\app.c
_AppTask2Stk::
.blkb 256
.dbsym e AppTask2Stk _AppTask2Stk A[256:256]c
_AppTask1Stk::
.blkb 256
.dbsym e AppTask1Stk _AppTask1Stk A[256:256]c
_AppTaskStartStk::
.blkb 256
.dbsym e AppTaskStartStk _AppTaskStartStk A[256:256]c
; }
.area func_lit
PL_AppTask2: .word `_AppTask2
PL_AppTask1: .word `_AppTask1
PL_AppTaskStart: .word `_AppTaskStart
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -