license
Task level names

The task levels are given names so that magic numbers do not have to be used in following code.

Different interrupts restart the schedular at differnt levels. The level is scheduled when the system switches from supervisor to user. Interrupt routines need to be kept short for this model to work. Try to do as little as possible in interrupts an schedule a task to do most of the work.

 
	\ Interrupt level names
	zero
	DUP CONSTANT #interrupt7       1+
	DUP CONSTANT #interrupt6       1+
	DUP CONSTANT #interrupt5       1+
	DUP CONSTANT #interrupt4       1+
	DUP CONSTANT #interrupt3       1+
	DUP CONSTANT #interrupt2       1+
	DUP CONSTANT #interrupt1       1+
	\ clock routine restarts the scheduler at this level
	\ every xbase ticks.
	DUP CONSTANT #clock_high       1+
	DUP CONSTANT #clock_medium     1+
	\ spare cpu time is sent in this level  
	DUP CONSTANT #tcp/ip           1+  
	DUP CONSTANT #clock_low        1+
	    CONSTANT _#task_level_number

	\ used by .tasks
	CREATE _level_names
		 ' #interrupt7   t_xt>nfa  t,     
		 ' #interrupt6   t_xt>nfa  t,         
		 ' #interrupt5   t_xt>nfa  t,       
		 ' #interrupt4   t_xt>nfa  t,   
		 ' #interrupt3   t_xt>nfa  t,   
		 ' #interrupt2   t_xt>nfa  t,   
		 ' #interrupt1   t_xt>nfa  t,   
		 ' #clock_high   t_xt>nfa  t,      
		 ' #clock_medium  t_xt>nfa  t,
		 ' #tcp/ip        t_xt>nfa  t,      
		 ' #clock_low     t_xt>nfa  t,      


	??HEX
    \ The level head is arranged
	zero
	DUP CONSTANT _#level_head_trap           2+
	\ The address on the stack after trap executed.
	DUP CONSTANT _#level_head_trapPC
	DUP CONSTANT _#level_head_next_level     2+
	\ link used by the multitasker.
	DUP CONSTANT _#level_head_loop_head          4+

	\ Set by code that initiates the levels execution
	\ The following two flags have to be together as they are tested as one.
	\ See trap27
	\ Set by code that initiates the levels execution
	DUP CONSTANT _#level_head_restart_flag   2+
	\ Set to true if level is to be repeated, only set for 
	\ the lowest priority.
	DUP CONSTANT _#level_head_repeat_flag    2+
	DUP CONSTANT _#level_head_facility #facility_length +
	DROP


	0C #facility_length ??=
	| CREATE TSK-CODE assembler
    LABEL tsk0
		7 # TRAP            \ switch task level 
      	#interrupt6 tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,   
		0 t, 
		\ tasks can come and go .tasks and .task need to claim a task to print it's
		\ details out.
		\ facility
		0 t, 0 t, 0 t, 

    LABEL tsk1
		7 # TRAP            \ switch task level 
      	#interrupt5 tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t,
		\ facility
		0 t, 0 t, 0 t, 
 

    LABEL tsk2
		7 # TRAP            \ switch task level 
      	#interrupt4 tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t, 
		\ facility
		0 t, 0 t, 0 t, 

	LABEL tsk3
		7 # TRAP            \ switch task level 
      	#interrupt3 tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t, 
		\ facility
		0 t, 0 t, 0 t, 

    LABEL tsk4
		7 # TRAP            \ switch task level 
      	#interrupt2 tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t, 
		\ facility
		0 t, 0 t, 0 t, 

    LABEL tsk5
		7 # TRAP            \ switch task level 
      	#interrupt1 tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t,
		\ facility
		0 t, 0 t, 0 t, 
		 
    LABEL tsk6
		7 # TRAP            \ switch task level 
      	#clock_high tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t, 
		\ facility
		0 t, 0 t, 0 t, 

	LABEL tsk7
		7 # TRAP            \ switch task level 
      	#clock_medium tw,
		\ the link address has to be in the same location as it is in 
		\ a task.
		FFFFFFFF t,
		0 t,
		\ facility
		0 t, 0 t, 0 t, 

    LABEL tsk8
		7 # TRAP 
    	#tcp/ip tw,
    	FFFFFFFF t,
		0 t,
		\ facility
		0 t, 0 t, 0 t, 

    LABEL tsk9
		7 # TRAP 
    	#clock_low tw,
    	FFFFFFFF t,
		0 t,
		\ facility
		0 t, 0 t, 0 t, 

    LABEL tsk10
	    7 # TRAP 
      	#clock_low tw,
      	FFFFFFF t,
		0 tw,
		-1 tw,	( level can be executed without the execute flag set)
		\ facility
		0 t, 0 t, 0 t, 


    LABEL end.tsk
    
    | ram_create  base-tasks
    						ram_create TSK0 tsk1 tsk0 -      ram_allot
    						ram_create TSK1 tsk2 tsk1 -      ram_allot
    						ram_create TSK2 tsk3 tsk2 -      ram_allot
    						ram_create TSK3 tsk4 tsk3 -      ram_allot
    						ram_create TSK4 tsk5 tsk4 -      ram_allot
    						ram_create TSK5 tsk6 tsk5 -      ram_allot
    						ram_create TSK6 tsk7 tsk6 -      ram_allot

    						ram_create TSK7 tsk8 tsk7 -      ram_allot
    						ram_create TSK8 tsk9 tsk8 -      ram_allot
							ram_create TSK9 tsk10 tsk9 -      ram_allot

    						ram_create TSK10 end.tsk tsk10 -   ram_allot
    
   CREATE _xheads TSK0 t, TSK1 t, TSK2 t, TSK3 t, 
	              TSK4 t, TSK5 t, TSK6 t, TSK7 t, 
				  TSK8 t, TSK9 t, TSK10 t,
    
    \ Go back and set initial task addresses
    TSK0	 tsk0 #activation_task_link  +  t!  
	TSK1	 tsk1 #activation_task_link  +  t!   
    TSK2	 tsk2 #activation_task_link  +  t!   
    TSK3	 tsk3 #activation_task_link  +  t!   
    TSK4	 tsk4 #activation_task_link  +  t!   
    TSK5	 tsk5 #activation_task_link  +  t!   
    TSK6	 tsk6 #activation_task_link  +  t!   
 
    TSK7	 tsk7 #activation_task_link  +  t!
    TSK8	 tsk8 #activation_task_link  +  t!
    TSK9	 tsk9 #activation_task_link  +  t!
	TSK10	 tsk10 #activation_task_link +  t!


	: restart_level ( --)
		TRUE _xlevel @ CELLS _xheads + @ 
		[ _#level_head_restart_flag _#level_head_trap - ]T LITERAL + W!
	;