// kernel.h


#ifndef _KERNEL_H_
#define _KERNEL_H_




// SYSTEM CONFIGURATION CONSTANTS
/* these must be set correctly for the code 
   to operate properly, ...or at all.  */
#define KERNEL_ERROR_MSGS    1
#define KDB_TRACE_LEVEL_1	 1		// major blocks
//#define KDB_TRACE_LEVEL_2    1		// inside loops, if's, etc.
#define RAM_SIZE    		 1536
#define STACK_SIZE    		 50
#define USED_RAM    		 (64+100)
#define INITIAL_HEAP_SIZE    (RAM_SIZE - USED_RAM)
#define MAXTASKS     		 8
#define NUMRESOURCES     	 4
#define LOAD_SHELL    		 1
#define BUS_FREQ    		 4
	   




// MACROS
#ifndef COP_OPS
// set COP to time out at 1 second
#define COP_ON()  	   COPCTL = 0xC6
#define COP_OFF()	   COPCTL = 0x00
#define COP_PET(x)     COPRST = (x)
#endif




// ENUMERATIONS
enum task_state { 	 	IDLE	 = 0, // capitalize all these
	 			  		PENDING	 = 1, 
				  		RUNNING	 = 2, 
				  		WAITING	 = 3, 
				  		STOPPED	 = 4
				};
enum resource_state { 	NOTBUSY	 = 0, 
	 				  	BUSY	 = 1
					};
enum message_box { 	  	STATE_FLAG 	  = 0x01, // 0000 0001
	 			   		PRIO_FLAG 	  = 0x02  // 0000 0010
				 };  	// =4, =8, =16, etc.
				 
enum message_box_data { STATE_BOX  	  = 0, 
	 				  	PRIO_BOX 	  = 1 
					  }; // =2, =3, =4, etc.




// FUNCTION PROTOTYPES
int get_task_address(char id);
char get_task_id(void);
char *get_task_name(unsigned char id);
int get_task_state(unsigned char id);
int get_task_priority(unsigned char id);
int get_task_messages(unsigned char id);
int set_task_state(unsigned char id, unsigned char state);
int set_task_priority(unsigned char id, unsigned char priority);
int create_task(char *name, void (*addr)(), unsigned char priority, int state);

int get_resource_state(unsigned char id);
int get_resource_owner(unsigned char id);
int get_resource_queuelen(unsigned char id);

int get_free_memory(void);
/*
unsigned long get_time(void);
void set_time(unsigned char hour, unsigned char min, unsigned char sec);
char* get_os_version();
*/



#endif

