⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_5.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 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.*//* Automated test for sleep */#include <inttypes.h>#include "command_daemon.h"#include "msched.h"  // MANTIS scheduler (gives us start)#include "led.h"     // LED control#include "dev.h"#include "com.h"#include "plat_clock.h"#include "clock.h"#include "printf.h"#include "realtime.h"#include "tlist.h"#include "sem.h"uint16_t get_last_sleep_time (void);static void thread_a (void);static void thread_b (void);static void thread_c (void);static void test (void);static void alarmfunc (void *data);uint32_t count = 0;mos_alarm_t timer;sem clock_sem;/* The start function is automatically called by the operating system,   for single-threaded applications, treat start() like main(). for multi-   threaded applications, start each thread in the start() function.*/void start(void){//   mos_thread_new (thread_a, 128, PRIORITY_NORMAL);   mos_thread_new (thread_b, 128, PRIORITY_NORMAL);   mos_thread_new (thread_c, 128, PRIORITY_NORMAL);//   mos_thread_new (test, 128, PRIORITY_NORMAL);}static void thread_a (void){   uint32_t sleep_time_a = 15000;   uint8_t state_flag;   printf ("thread_a: %x\n", mos_thread_current ());   mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP);   while (count < 30) {      state_flag = mos_thread_get_suspend_state ();      printf ("Thread A %l %C sleeping 5000\n",	      sleep_time_a, state_flag);      mos_mdelay(100);//      mos_thread_sleep (sleep_time_a);   }}static void thread_b (void){   uint32_t sleep_time_b = 5000;   uint8_t state_flag;   printf ("thread_b: %x\n", mos_thread_current ());   mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP);      mos_alarm(&timer, 5, 0);   while (count < 30) {//      state_flag = mos_thread_get_suspend_state ();//      printf ("Thread B %l %C sleeping 15000\n",//	      sleep_time_b, state_flag);      printf("sleepin\n");      mos_thread_sleep (sleep_time_b);   }  }static void thread_c (void){   uint32_t sleep_time_c = 1000;   uint8_t state_flag;   printf ("thread_c: %x\n", mos_thread_current ());   mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP);   while (count < 30) {      //     state_flag = mos_thread_get_suspend_state ();      printf ("Thread C %d %C sleeping 1000\n",	      sleep_time_c, state_flag);      mos_thread_sleep (sleep_time_c);      count++;   }  }static void alarmfunc (void *data){   printf("alarm expired\n");   //mos_sem_post(&clock_sem);   mos_alarm(&timer, 5, 0);}static void test (void){   mos_sem_init(&clock_sem, 0);   timer.func = alarmfunc;   timer.data = "Dunno";//   printf("here\n");      while(count < 30)   {      mos_sem_wait(&clock_sem);      printf("Alarm Expired\n");   }   mos_thread_new(mos_command_daemon, 196, PRIORITY_NORMAL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -