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

📄 schedule.s

📁 mega128平台下
💻 S
字号:
	.module schedule.c
	.area text(rom, con, rel)
;         result -> R16
	.even
_atomic_start::
; #include <iom128v.h>
; #include <macros.h>
; #include "schedule.h"
; #include "timer.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)
; {
;   uint8_t result = SREG;
	in R16,0x3f
;   CLI();
	cli
;   return result;
L3:
	.dbline 0 ; func end
	ret
;        oldSreg -> R16
	.even
_atomic_end::
; }
; 
; void atomic_end(uint8_t oldSreg)
; {
;   SREG=oldSreg;
	out 0x3f,R16
L4:
	.dbline 0 ; func end
	ret
	.even
_TOSH_wait::
; }
; 
; 
; /* These are provided in HPL.td */
; void TOSH_wait()
; {
;   asm("nop");
	nop
;   asm("nop");
	nop
L5:
	.dbline 0 ; func end
	ret
	.even
_TOSH_sleep::
; 
; }
; 
; void TOSH_sleep()
; {
;     MCUCR |= 1<<5;
	in R24,0x35
	ori R24,32
	out 0x35,R24
L6:
	.dbline 0 ; func end
	ret
;              i -> R20,R21
	.even
_sched_init::
	xcall push_gset1
;    // asm("sleep");
; 	//MCUCR =0x0;
;    
;     //sbi(MCUCR, 5);
;   //sbi(MCUCR, SE);
;   //asm volatile ("sleep");
; }
; 
; void sched_init(void)
; {
;   int i;
;   TOSH_sched_free = 0;
	clr R2
	sts _TOSH_sched_free,R2
;   TOSH_sched_full = 0;
	sts _TOSH_sched_full,R2
;   for (i = 0; i < TOSH_MAX_TASKS; i++)
	clr R20
	clr R21
L8:
	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:
	subi R20,255  ; offset = 1
	sbci R21,255
	cpi R20,8
	ldi R30,0
	cpc R21,R30
	brlt L8
L7:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
; fInterruptFlags -> R20
;            tmp -> R10
;             tp -> R22,R23
	.even
_post::
	xcall push_gset3
	movw R22,R16
;     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) ()) {
;   uint8_t fInterruptFlags;
;   uint8_t tmp;
;   
;   fInterruptFlags = atomic_start();
	xcall _atomic_start
	mov R20,R16
; 
;   tmp = TOSH_sched_free;
	lds R10,_TOSH_sched_free
;   
;   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:
;     TOSH_sched_free = (tmp + 1) & TOSH_TASK_BITMASK;
	mov R24,R10
	subi R24,255    ; addi 1
	andi R24,7
	sts _TOSH_sched_free,R24
;     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
;     atomic_end(fInterruptFlags);
	mov R16,R20
	xcall _atomic_end
;     return 1;
	ldi R16,1
	xjmp L12
L13:
;   }
;   else {	
;     atomic_end(fInterruptFlags);
	mov R16,R20
	xcall _atomic_end
;     return 0;
	clr R16
L12:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
; fInterruptFlags -> R22
;           func -> R20,R21
;       old_full -> R10
	.even
_TOSH_run_next_task::
	xcall push_gset3
;   }
; }
; 
; /*
;  * 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.
;  */
; 
; int TOSH_run_next_task ()
; {
;   uint8_t fInterruptFlags;
;   uint8_t old_full;
;   void (*func)(void);
;   
;   fInterruptFlags = atomic_start();
	xcall _atomic_start
	mov R22,R16
;   old_full = TOSH_sched_full;
	lds R10,_TOSH_sched_full
;   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
;   if (func == 0x0)
	cpi R20,0
	cpc R20,R21
	brne L16
X1:
;   {
;       atomic_end(fInterruptFlags);
	mov R16,R22
	xcall _atomic_end
; 	 // printf("return 0\n");
;       return 0;
	clr R16
	clr R17
	xjmp L15
L16:
;   }
; 
;   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
;   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
;   atomic_end(fInterruptFlags);
	mov R16,R22
	xcall _atomic_end
;   func();
	movw R30,R20
	xcall xicall
; //  printf("tsk\n");
;   //printf("running task %d",old_full);
;   return 1;
	ldi R16,1
	ldi R17,0
L15:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
;              x -> <dead>
; fInterruptFlags -> <dead>
	.even
_run_task::
; }
; extern sleep_flag;
; void run_task() {
L19:
L20:
;   uint8_t fInterruptFlags,x;
;   while (TOSH_run_next_task()) 
	xcall _TOSH_run_next_task
	cpi R16,0
	cpc R16,R17
	brne L19
X2:
;     ;
;  /* fInterruptFlags = atomic_start();
;   x = (T1.on==1) ||(T2.on==1)||(T3.on==1);
;   atomic_end(fInterruptFlags);
;   if (x)//||(sleep_flag==0))
;   */  
;   if((T1.on==1) ||(T2.on==1)||(T3.on==1))
	lds R24,_T1+1
	cpi R24,1
	breq L28
	lds R24,_T2+1
	cpi R24,1
	breq L28
	lds R24,_T3+1
	cpi R24,1
	brne L30
L28:
;   ;
	xjmp L23
X3:
;   else
;   {
L29:
L30:
;     while (TOSH_run_next_task()) 
	xcall _TOSH_run_next_task
	cpi R16,0
	cpc R16,R17
	brne L29
X4:
;     ;
;   	TOSH_sleep();
	xcall _TOSH_sleep
;     TOSH_wait();
	xcall _TOSH_wait
;   } 
L23:
L18:
	.dbline 0 ; func end
	ret
	.even
___nesc_enable_interrupt::
;   
; 	
;   //printf("wkup\n");
;   //delay_x(1000);
;  
; }
; 
; 
; 
; void __nesc_enable_interrupt() {
;   SEI();
	sei
L32:
	.dbline 0 ; func end
	ret
	.area bss(ram, con, rel)
_TOSH_sched_free::
	.blkb 1
_TOSH_sched_full::
	.blkb 1
_TOSH_queue::
	.blkb 16

⌨️ 快捷键说明

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