// kernel.h


#ifndef _KERNEL_H_
#define _KERNEL_H_




// MACROS
#ifndef COP_OPS
// set COP to time out at 525ms
#define COP_ON()  	   COPCTL = 0xC5
#define COP_OFF()	   COPCTL = 0x00
#define COP_PET(x)     COPRST = (x)
#endif



// ERROR MESSAGES
#define KERNEL_ERROR_MSG	  1
#define KERNEL_DEBUG		  1



// CONSTANTS
/* these must be set correctly for the code 
   to operate properly, ...or at all.  */

// best guess for heap initialization: total heap = ram - globals - stack
#define INITIAL_HEAP_SIZE (1536-550-250)

// total number of tasks allowed to run on the system
#define NUMTASKS 8

// total number of defined resources allowed to run on the system
#define NUMRESOURCES 11			   




// ENUMERATIONS
enum task_state { 	 	idle	 = 0, 
	 			  		pending	 = 1, 
				  		running	 = 2, 
				  		waiting	 = 3, 
				  		finished = 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.



// MESSAGES
#ifndef msg
#define msg(x)	(1 << (x))
#endif



// FUNCTION PROTOTYPES
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 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* version();
*/



#endif
