Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cThread.cpp
00001 /********************************************************************************* 00002 * PROJECT: MiMic 00003 * -------------------------------------------------------------------------------- 00004 * 00005 * This file is part of MiMic 00006 * Copyright (C)2011 Ryo Iizuka 00007 * 00008 * MiMic is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published 00010 * by the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * For further information please contact. 00022 * http://nyatla.jp/ 00023 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> 00024 * 00025 *********************************************************************************/ 00026 #include "../NyLPC_cThread.h" 00027 00028 #if NyLPC_ARCH==NyLPC_ARCH_MBEDRTOS 00029 #include "mbed.h" 00030 #include "rtos.h" 00031 00032 static osPriority prio_table[]={ 00033 osPriorityNormal,osPriorityHigh}; 00034 00035 00036 00037 static void proc(void const *argument) 00038 { 00039 NyLPC_TcThread_t* t=(NyLPC_TcThread_t*)argument; 00040 for(;;){ 00041 do{ 00042 Thread::wait(30);// danger wait! 00043 }while(NyLPC_TUInt32_isBitOn(t->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED)); 00044 t->_func(t->_arg); 00045 NyLPC_TUInt32_setBit(t->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED); 00046 } 00047 } 00048 00049 00050 void NyLPC_cThread_initialize(NyLPC_TcThread_t* i_inst,NyLPC_TInt32 i_stack,NyLPC_TInt32 i_prio) 00051 { 00052 NyLPC_TUInt32_setBit(i_inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED); 00053 i_inst->_thread=new Thread(proc,i_inst,prio_table[i_prio],i_stack); 00054 } 00055 void NyLPC_cThread_finalize(NyLPC_TcThread_t* i_inst) 00056 { 00057 NyLPC_cThread_join(i_inst); 00058 delete (Thread*)(i_inst->_thread); 00059 } 00060 00061 00062 void NyLPC_cThread_start(NyLPC_TcThread_t* i_inst,NyLPC_TcThread_ThreadFunc i_func,void* i_param) 00063 { 00064 NyLPC_ArgAssert(i_inst!=NULL); 00065 NyLPC_ArgAssert(i_func!=NULL); 00066 i_inst->_sbit=0; 00067 i_inst->_func=i_func; 00068 i_inst->_arg=i_param; 00069 return; 00070 } 00071 void NyLPC_cThread_join(NyLPC_TcThread_t* i_inst) 00072 { 00073 NyLPC_TUInt32_setBit(i_inst->_sbit,NyLPC_TcThread_BIT_IS_JOIN_REQ); 00074 while(!NyLPC_TUInt32_isBitOn(i_inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED)) 00075 { 00076 Thread::wait(10); 00077 } 00078 return; 00079 } 00080 void NyLPC_cThread_sleep(NyLPC_TUInt32 i_time_in_msec) 00081 { 00082 //ミリ秒単位で待つ 00083 Thread::wait(i_time_in_msec); 00084 } 00085 void NyLPC_cThread_yield(void) 00086 { 00087 Thread::yield(); 00088 } 00089 00090 #endif
Generated on Tue Jul 12 2022 16:22:59 by
