📄 test_4.c
字号:
/* This file is part of MANTIS OS, Operating System for Nymph. See http://mantis.cs.colorado.edu/ Copyright (C) 2003 University of Colorado, Boulder This program 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. This program 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 (See http://www.gnu.org/copyleft/gpl.html) along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA, or send email to mantis-users@cs.colorado.edu.*/#include "mos.h"#include "command_daemon.h"#ifndef ARCH_AVR#include <stdio.h>#else#include "printf.h"#endif#include <string.h>//#include <unistd.h>#include "clock.h"#include "sem.h"/** * File: clock_test.c * Author: Adam, Charles, Cyrus, Jeff * Date: 05-24-2004 * * Description: This app is for testing the clock alarm service * */thread_t *current_thread;mos_sem_t alarm0_sem, alarm1_sem, alarm2_sem, alarm3_sem;bool FLAG;mos_alarm_t timer0;mos_alarm_t timer1;mos_alarm_t timer2;mos_alarm_t timer3;mos_alarm_t timer4;mos_alarm_t timer5;void test_alarm0 (void *data){ mos_sem_post (&alarm0_sem); mos_alarm (&timer0, 3, 0);}void test_alarm1 (void *data){ mos_sem_post (&alarm1_sem); mos_alarm (&timer1, 2, 500000);}void test_alarm2 (void *data){ mos_sem_post (&alarm2_sem); mos_alarm (&timer2, 26, 0);}void test_alarm3 (void *data){ mos_sem_post (&alarm3_sem); mos_alarm (&timer3, 1, 0);}void alarm0_thread (void){ mos_sem_init (&alarm0_sem, 0); timer0.func = test_alarm0; timer0.data = "Timer 0: 3 seconds"; mos_alarm (&timer0, 3, 0); while (1) { mos_sem_wait (&alarm0_sem); if(FLAG) mos_thread_suspend(); printf ("Alarm 0 expired\n"); }}void alarm1_thread (void){ mos_sem_init (&alarm1_sem, 0); timer1.func = test_alarm1; timer1.data = "Timer 1: 2 seconds 500000 u-seconds"; mos_alarm (&timer1, 2, 500000); while (1) { mos_sem_wait (&alarm1_sem); if(FLAG) mos_thread_suspend(); printf ("Alarm 1 expired\n"); }}void alarm2_thread (void){ FLAG = false; mos_sem_init (&alarm2_sem, 0); timer2.func = test_alarm2; timer2.data = "Timer 2: 26 seconds"; mos_alarm (&timer2, 26, 0); while (1) { mos_sem_wait (&alarm2_sem); mos_thread_resume(current_thread); printf ("Alarm 2 expired\n"); FLAG = true; mos_thread_suspend(); }}void alarm3_thread (void){ mos_sem_init (&alarm3_sem, 0); timer3.func = test_alarm3; timer3.data = "Timer 3: 1 second"; mos_alarm (&timer3, 1, 0); while (1) { mos_sem_wait (&alarm3_sem); if(FLAG) mos_thread_suspend(); printf ("Alarm 3 expired\n"); }}void start(void){ printf ("\nStarting clock test -- REBOOT!!\n"); // 3 seconds mos_thread_new (alarm0_thread, 128, PRIORITY_NORMAL); // 2.5 seconds mos_thread_new (alarm1_thread, 128, PRIORITY_NORMAL); // 26 seconds mos_thread_new (alarm2_thread, 128, PRIORITY_NORMAL); // 1 second mos_thread_new (alarm3_thread, 128, PRIORITY_NORMAL); print_clock_list (); printf ("%s", "Now we begin!\n"); current_thread = mos_thread_current(); mos_thread_suspend(); mos_thread_new (mos_command_daemon, 196, PRIORITY_NORMAL); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -