/************************************************************************* This file is part of aOS. aOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. aOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with aOS; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Copyright 2001, 2002 Anssi Ylätalo ======== Modified by Bruce Land Jan 2005 --added time accumulation to task control block --added stack check fields to task control block --added suspended states --added tick time define --added time accumulate flag and dispatch counter --added global variable macro (does not work in 1.24.6) **************************************************************************/ //#pragma regalloc- //#define AOS_ENTER_CRITICAL #asm("cli") //#define AOS_EXIT_CRITICAL #asm("sei") //changed 03/2005 by Gregory Roth to make // AOS_ENTER_CRITICAL keep a stack #define AOS_ENTER_CRITICAL { \ #asm("cli") \ aos_crit_count++; \ } #define AOS_EXIT_CRITICAL { \ --aos_crit_count; \ if(!aos_crit_count){ \ #asm("sei") \ } \ } int aos_crit_count; //*/ #define AOS_TASK_RUNNABLE 0b00000000 #define AOS_TASK_RUNNING 0b00000001 #define AOS_TASK_WAITING 0b00000010 #define AOS_TASK_DELAYD 0b00000100 #define AOS_TASK_SUSPENDED 0b00001000 #define AOS_TASK_SUSPENDED_WAIT 0b00010000 #define AOS_TASK_SUSPENDED_DELA 0b00100000 #define AOS_TICK_TIME 10 //mSec #define AOS_SEM_MAX 7 #define AOS_TASK_MAX 5 #define AOS_MBOX_MAX 2 #define AOS_TASK_HSTK_SIZE 100 #define AOS_TASK_DSTK_SIZE 200 //Scheduler task time acculumulator //NOTE!!! When AOS_CHCK==1 the scheduler uses timer1! #define AOS_CHCK 1 //sched time enable typedef unsigned char UBYTE; typedef unsigned int UWORD; typedef unsigned long int UDWORD; typedef unsigned long int ULONG; typedef struct aos_task_control_block { void *hwstk; /* Pointer to task's hardware stack */ void *datastk; /* Pointer to task's data stack */ UBYTE status; /* Status of task */ UBYTE prio; /* Priority of task */ UWORD delay; /* Nbr of ticks to keep task sleeping */ ULONG ttime; //added by BRL to track task time void *hstktop ; //added by BRL to track stack use void *dstktop ; //added by BRL to track stack use struct aos_task_control_block *next_tcb; /* Pointer to next task's TCB */ void *tcb_sem_q; /* Next task on semaphore waiting list */ } aos_tcb; typedef struct aos_sema { UWORD count; /* Semaphore value */ aos_tcb *scb_sem_q; /* Semaphore queue */ struct aos_sema *next_scb; /* Pointer next semaphore's SCB */ } aos_scb; typedef struct aos_mail_box { aos_scb *msend; /* Semaphore for sending to mailbox */ aos_scb *mrecv; /* Semaphore for receiving from mailbox */ void *mmsg; /* Pointer to message */ struct aos_mail_box *next_mcb; /* Pointer to next mailbox */ } aos_mcb; typedef struct aos_central_table { ULONG aos_systime; /* Timer ticks since last boot */ ULONG aos_dispcntr; //BRL added dispatch counter ULONG aos_idlecntr; /* Counter for processor idle time */ UBYTE aos_version; /* OS version */ UBYTE aos_running; /* AOS running flag */ UBYTE aos_schedrun; //scheduler flag aos_tcb *tcb_used_list; /* Pointer to used TCBs */ aos_tcb *tcb_free_list; /* Pointer to TCB freelist */ aos_tcb *tcb_current; /* Pointer to current running task TCB */ aos_tcb *tcb_runq; /* Pointer to highest priority runnable task TCB (= run-queue) */ aos_scb *scb_used_list; /* Pointer to used semaphores */ aos_scb *scb_free_list; /* Pointer to semaphores freelist */ aos_mcb *mcb_used_list; /* Pointer to used message mailboxes */ aos_mcb *mcb_free_list; /* Pointer to mailbox freelist */ } aos_cent_tbl; /* Kernel services and data-types that are visible to user tasks */ typedef aos_scb aos_semaphore; typedef aos_mcb aos_mailbox; typedef aos_tcb aos_task; aos_tcb *aos_task_create( void (*task)(void), UBYTE *hstack, UBYTE *dstack, UBYTE p ); void aos_sleep( UWORD ticks ); ULONG aos_uptime( void ); aos_scb *aos_sem_create( UWORD ival ); void aos_wait( aos_scb *semaphore ); //extern UBYTE aos_signal( aos_scb *semaphore ); void aos_signal( aos_scb *semaphore ); //change to avoid error aos_mcb *aos_mbox_create( void ); void aos_mbox_send( aos_mcb *mbox, void *msg ); void *aos_mbox_recv( aos_mcb *mbox ); //extern *char *aos_mbox_recv( aos_mcb *mbox ); //change