////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 Xilinx, Inc.  All rights reserved.
//
// Xilinx, Inc.
// XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A 
// COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
// ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR 
// STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
// IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE 
// FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.  
// XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO 
// THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO 
// ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE 
// FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE.
// 
// Date   : 2002, November.
// Author : Raj Nagarajan (rajn@xilinx.com)
// Company: Xilinx
// Group  : Emerging Software Technologies
//
// $Id :$
//
//////////////////////////////////////////////////////////////////////////////

/***************************************************************************/
/**
 * @file process.h
 *
 * This contains the function decleration for process management and thread
 * management modules. Process Control Block structure and other process 
 * related functions are declared here.
 * 
 ***************************************************************************/
#ifndef _PROCESS_H_
#define _PROCESS_H_

#include <sys/queue.h>

/** 
 * @name Process States.
 * The system process is in any of the four states.
 * @{ 
 */
/** State when the process is created */
#define PROC_NEW     0
/** 
 * State when the process is running. On a single processor only one 
 * process runs at any time.
 */
#define PROC_RUNNING 1
/** State when the process is ready to run and is in Ready Queue */
#define PROC_READY   2
/** State of process waiting for a resource. Not considered for scheduling */
#define PROC_WAITING 3
/** State of process that has called exit and is now "dead" */
#define PROC_DEAD 4
/*@}*/

/*
 * Diff. types of interrupt in the system
 */
#define TIMER_INTR 1	/* Timer Interrupt, used for process scheduling */
#define SYSCALL_INTR 2	/* Soft Interrupt - Used for system call interface */
#define SYSCALL_BLK  3	

/*
 * Different Flags used in the kernel
 */
#define THREAD_CREATE 	0x01
#define PROCESS_YIELD 	0x02
#define PROCESS_BLOCK	0x04
#define CS_TIMER	0x08

typedef struct _process_struct process_struct ;
typedef struct _process_context process_context ;

/**
 * Register values are stored here for context switch.
 */
struct _process_context {
	unsigned int regs[33] ; 	/* Lot of details goes in here */
} ;

/**
 * Process Control Block - Information about the Process
 */
struct _process_struct {
	unsigned char 	state ;		/**< Process State */
	signed char 	pid ;		/**< Unique Process Identifier */
	signed char 	priority ;	/**< Process Priority */
	process_context pcontext ;	/**< Context switch store */
	signed char 	mem_id ;	/**< Mem ID of thread context */
	signed char 	is_allocated ;	/**< If the PCB has been allocated  
					   0 - Unallocated, 1 - Allocated */
} ;

/**
 * Process Status structure used for process_status
 */
typedef struct _ps_stat{
	signed char 	pid ;		/**< Process ID */
	unsigned char 	state ;		/**< State of process */
} p_stat ;


/***************************************************************************
 * Function prototypes - defined in sys/process.h
 ***************************************************************************/

/*
 * Internal Kernel functions. These routines are not directly called from any
 * process. They don't have reentrant code.
 */
void enter_kernel( void ) ;
void exit_kernel( void ) ;
void process_block( queuep queue, unsigned int state ) ;
void process_blockp( queuep queue, unsigned int pid, unsigned int state ) ;
void process_unblock( queuep queue ) ;

/*
 * Functions related to process management.
 */
void sys_init() ;
int sys_process_create( unsigned int pstart_addr, unsigned int priority ) ;
int sys_process_exit() ;
int sys_process_kill( unsigned int pid ) ;
int sys_process_status( unsigned int pid, p_stat *ps ) ;
int sys_process_sleep( unsigned int time ) ;
int sys_process_yield() ;
int sys_get_currentPID() ;
int sys_process_getpriority() ;
int sys_process_setpriority( int priority ) ;

#ifdef CONFIG_THREAD_SUPPORT	/* Functions related to thread handling */
int sys_thread_create( void *func, int arg, unsigned int priority ) ;
int sys_thread_exit() ;
/*
 * Other functions are similar to that of process.
 */
#endif

#endif
