📄 schedule.s
字号:
.module schedule.c
.area text(rom, con, rel)
.dbfile E:\document\无线传感器\main_frame\api\schedule.c
.dbfunc e atomic_start _atomic_start fc
; result -> R16
.even
_atomic_start::
.dbline -1
.dbline 19
; #include <iom128v.h>
; #include <macros.h>
; #include "schedule.h"
; typedef struct {
; void (*tp) ();
; } TOSH_sched_entry_T;
; typedef unsigned char uint8_t;
; enum {
;
; TOSH_MAX_TASKS = 8,
; TOSH_TASK_BITMASK = (TOSH_MAX_TASKS - 1)
; };
;
; volatile TOSH_sched_entry_T TOSH_queue[TOSH_MAX_TASKS];
; uint8_t TOSH_sched_full;
; volatile uint8_t TOSH_sched_free;
;
; uint8_t atomic_start(void)
; {
.dbline 20
; uint8_t result = SREG;
in R16,0x3f
.dbline 21
; CLI();
cli
.dbline 22
; return result;
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r result 16 c
.dbend
.dbfunc e atomic_end _atomic_end fV
; oldSreg -> R16
.even
_atomic_end::
.dbline -1
.dbline 26
; }
;
; void atomic_end(uint8_t oldSreg)
; {
.dbline 27
; SREG=oldSreg;
out 0x3f,R16
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbsym r oldSreg 16 c
.dbend
.dbfunc e TOSH_wait _TOSH_wait fV
.even
_TOSH_wait::
.dbline -1
.dbline 33
; }
;
;
; /* These are provided in HPL.td */
; void TOSH_wait()
; {
.dbline 34
; ;//asm volatile("nop");
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e TOSH_sleep _TOSH_sleep fV
.even
_TOSH_sleep::
.dbline -1
.dbline 39
; //asm volatile("nop");
; }
;
; void TOSH_sleep()
; {
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e sched_init _sched_init fV
; i -> R20,R21
.even
_sched_init::
xcall push_gset1
.dbline -1
.dbline 46
; //sbi(MCUCR, 5);
; //sbi(MCUCR, SE);
; //asm volatile ("sleep");
; }
;
; void sched_init(void)
; {
.dbline 48
; int i;
; TOSH_sched_free = 0;
clr R2
sts _TOSH_sched_free,R2
.dbline 49
; TOSH_sched_full = 0;
sts _TOSH_sched_full,R2
.dbline 50
; for (i = 0; i < TOSH_MAX_TASKS; i++)
clr R20
clr R21
L8:
.dbline 51
ldi R16,2
ldi R17,0
movw R18,R20
xcall empy16s
movw R30,R16
ldi R24,<_TOSH_queue
ldi R25,>_TOSH_queue
add R30,R24
adc R31,R25
clr R2
clr R3
std z+1,R3
std z+0,R2
L9:
.dbline 50
subi R20,255 ; offset = 1
sbci R21,255
.dbline 50
cpi R20,8
ldi R30,0
cpc R21,R30
brlt L8
.dbline -2
L7:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 I
.dbend
.dbfunc e post _post fc
; fInterruptFlags -> R20
; tmp -> R10
; tp -> R22,R23
.even
_post::
xcall push_gset3
movw R22,R16
.dbline -1
.dbline 64
; TOSH_queue[i].tp = 0x0;
; }
;
; /*
; * TOS_post (thread_pointer)
; *
; * Put the task pointer into the next free slot.
; * Return 1 if successful, 0 if there is no free slot.
; *
; * This function uses a critical section to protect TOSH_sched_free.
; * As tasks can be posted in both interrupt and non-interrupt context,
; * this is necessary.
; */
; char post(void (*tp) ()) {
.dbline 68
; uint8_t fInterruptFlags;
; uint8_t tmp;
;
; fInterruptFlags = atomic_start();
xcall _atomic_start
mov R20,R16
.dbline 70
;
; tmp = TOSH_sched_free;
lds R10,_TOSH_sched_free
.dbline 72
;
; if (TOSH_queue[tmp].tp == 0x0) {
ldi R24,2
mul R24,R10
movw R30,R0
ldi R24,<_TOSH_queue
ldi R25,>_TOSH_queue
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
tst R2
brne L13
tst R3
brne L13
X0:
.dbline 72
.dbline 73
; TOSH_sched_free = (tmp + 1) & TOSH_TASK_BITMASK;
mov R24,R10
subi R24,255 ; addi 1
andi R24,7
sts _TOSH_sched_free,R24
.dbline 74
; TOSH_queue[tmp].tp = tp;
ldi R24,2
mul R24,R10
movw R30,R0
ldi R24,<_TOSH_queue
ldi R25,>_TOSH_queue
add R30,R24
adc R31,R25
std z+1,R23
std z+0,R22
.dbline 75
; atomic_end(fInterruptFlags);
mov R16,R20
xcall _atomic_end
.dbline 76
; return 1;
ldi R16,1
xjmp L12
L13:
.dbline 78
; }
; else {
.dbline 79
; atomic_end(fInterruptFlags);
mov R16,R20
xcall _atomic_end
.dbline 80
; return 0;
clr R16
.dbline -2
L12:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r fInterruptFlags 20 c
.dbsym r tmp 10 c
.dbsym r tp 22 pfV
.dbend
.dbfunc e TOSH_run_next_task _TOSH_run_next_task fi
; fInterruptFlags -> R22
; func -> R20,R21
; old_full -> R10
.even
_TOSH_run_next_task::
xcall push_gset3
.dbline -1
.dbline 93
; }
; }
;
; /*
; * TOSH_schedule_task()
; *
; * Remove the task at the head of the queue and execute it, freeing
; * the queue entry. Return 1 if a task was executed, 0 if the queue
; * is empty.
; */
;
; unsigned int TOSH_run_next_task ()
; {
.dbline 98
; uint8_t fInterruptFlags;
; uint8_t old_full;
; void (*func)(void);
;
; fInterruptFlags = atomic_start();
xcall _atomic_start
mov R22,R16
.dbline 99
; old_full = TOSH_sched_full;
lds R10,_TOSH_sched_full
.dbline 100
; func = TOSH_queue[old_full].tp;
ldi R24,2
mul R24,R10
movw R30,R0
ldi R24,<_TOSH_queue
ldi R25,>_TOSH_queue
add R30,R24
adc R31,R25
ldd R20,z+0
ldd R21,z+1
.dbline 101
; if (func == 0x0)
cpi R20,0
cpc R20,R21
brne L16
X1:
.dbline 102
; {
.dbline 103
; atomic_end(fInterruptFlags);
mov R16,R22
xcall _atomic_end
.dbline 105
; // printf("return 0\n");
; return 0;
clr R16
clr R17
xjmp L15
L16:
.dbline 108
; }
;
; TOSH_queue[old_full].tp = 0x0;
ldi R24,2
mul R24,R10
movw R30,R0
ldi R24,<_TOSH_queue
ldi R25,>_TOSH_queue
add R30,R24
adc R31,R25
clr R2
clr R3
std z+1,R3
std z+0,R2
.dbline 109
; TOSH_sched_full = (old_full + 1) & TOSH_TASK_BITMASK;
mov R24,R10
subi R24,255 ; addi 1
andi R24,7
sts _TOSH_sched_full,R24
.dbline 110
; atomic_end(fInterruptFlags);
mov R16,R22
xcall _atomic_end
.dbline 111
; func();
movw R30,R20
xcall xicall
.dbline 113
; //printf("running task %d",old_full);
; return 1;
ldi R16,1
ldi R17,0
.dbline -2
L15:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r fInterruptFlags 22 c
.dbsym r func 20 pfV
.dbsym r old_full 10 c
.dbend
.dbfunc e run_task _run_task fV
.even
_run_task::
.dbline -1
.dbline 116
; }
;
; void run_task() {
L19:
.dbline 118
L20:
.dbline 117
; while (TOSH_run_next_task())
xcall _TOSH_run_next_task
cpi R16,0
cpc R16,R17
brne L19
X2:
.dbline 119
; ;
; TOSH_sleep();
xcall _TOSH_sleep
.dbline 120
; TOSH_wait();
xcall _TOSH_wait
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbend
.dbfunc e __nesc_enable_interrupt ___nesc_enable_interrupt fV
.even
___nesc_enable_interrupt::
.dbline -1
.dbline 125
; }
;
;
;
; void __nesc_enable_interrupt() {
.dbline 126
; SEI();
sei
.dbline -2
L22:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile E:\document\无线传感器\main_frame\api\schedule.c
_TOSH_sched_free::
.blkb 1
.dbsym e TOSH_sched_free _TOSH_sched_free c
_TOSH_sched_full::
.blkb 1
.dbsym e TOSH_sched_full _TOSH_sched_full c
_TOSH_queue::
.blkb 16
.dbsym e TOSH_queue _TOSH_queue A[16:8]X
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -