/************************************************************************* 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 ================================== Dec 2004 Modified by Bruce Land to include: -- testing task monitors **************************************************************************/ #include #include #include "aos.h" #include "user_tasks.h" #include "aos_core.c" #include "aos_task.c" #include "semaphore.c" #include "mbox.c" #include "aos_uart.c" //global variables for all tasks aos_mailbox *task23_pipe ; /*string from task2 to task3*/ //task control block pointers aos_tcb *t1, *t2, *t3, *t4 ; //******************************************************** void task1( void ) { int i; //get the current task control block t1 = aos_ctbl.tcb_current; //start a task aos_task_create( task2, hw_stack2, data_stack2, 100 ); //allocate UART structures, turn on UART aos_init_uart(); //Halt at reset to check for suprious resets printf("RESET"); while(PINC.0==1){}; //init portB to output DDRB = 0xff ; while(1) { //toggle the led PORTB ^= 0x01; //spin some cycles for (i=0;i<10000;i++) {}; //give another process a chance to compute aos_sleep( 100 ); } } //******************************************************** void task2( void ) { char t2str[32]; //start another task aos_task_create( task3, hw_stack3, data_stack3, 150 ); //get current task block t2 = aos_ctbl.tcb_current; //make a commuinctions channel from task 2 to task 3 task23_pipe = aos_mbox_create(); while(1) { //toggle the led PORTB ^= 0x02; //read user input aos_gets(t2str); //and send it aos_mbox_send(task23_pipe,t2str); } } //******************************************************** void task3( void ) { char *msg; char crlf[4]; //make another task aos_task_create( Stats, hw_stack4, data_stack4, 200 ); //get current task t3 = aos_ctbl.tcb_current; while(1) { //toggle the led PORTB ^= 0x04; //wait for a message msg = aos_mbox_recv(task23_pipe); //and print it aos_puts(msg); //crlf sprintf(crlf,"\n\r"); aos_puts(crlf); } } //******************************************************** void Stats( void ) { char str4[40]; //get current task block t4 = aos_ctbl.tcb_current; while(1) { //toggle the led PORTB ^= 0x08; //format the uptime and print it sprintf(str4,"Uptime:%ld ticks\n\r",aos_uptime()) ; aos_puts(str4); //print the accumulated task times sprintf(str4,"Task times:\n\r%ld %ld %ld %ld %ld \n\r", t1->ttime,t2->ttime, t3->ttime,t4->ttime,(NULL_TASK->ttime)) ; aos_puts(str4); //Print the dispatches/sec sprintf(str4,"%ld Dispatch/sec\n\r\n\r", aos_ctbl.aos_dispcntr) ; aos_ctbl.aos_dispcntr = 0; //reset for next second aos_puts(str4); //get stack paramters sprintf(str4,"Task3: Dstk,Hstk free\n\r %d %d\n\r", aos_task_dstk_chck(t3), aos_task_hstk_chck(t3) ) ; aos_puts(str4); //wait one second aos_sleep(100); } } //********************************************************