This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NyLPC_cThread.h Source File

NyLPC_cThread.h

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 #ifndef NYLPC_CTHREAD_H_
00027 #define NYLPC_CTHREAD_H_
00028 
00029 ////////////////////////////////////////////////////////////////////////////////
00030 // Include
00031 ////////////////////////////////////////////////////////////////////////////////
00032 #include "NyLPC_stdlib.h"
00033 #if NyLPC_ARCH==NyLPC_ARCH_FREERTOS
00034 #include "FreeRTOS.h"
00035 #include "task.h"
00036 #elif NyLPC_ARCH==NyLPC_ARCH_MBEDRTOS
00037 #elif NyLPC_ARCH==NyLPC_ARCH_WIN32
00038     //not work!
00039 #else
00040 #error Bad NyLPC_ARCH!
00041 #endif
00042 
00043 /**********************************************************************
00044  *
00045  * NyLPC_TcThread class
00046  *
00047  **********************************************************************/
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif /* __cplusplus */
00051 
00052 /**
00053  * 関数スレッドを実行します。
00054  */
00055 typedef struct NyLPC_TcThread NyLPC_TcThread_t;
00056 
00057 /** スレッドの関数型 */
00058 typedef int (*NyLPC_TcThread_ThreadFunc)(void* i_param);
00059 /** */
00060 #define NyLPC_TcThread_DEFAULT_STACKSIZE configMINIMAL_STACK_SIZE
00061 
00062 /** ターミネイトしたときに1*/
00063 #define NyLPC_TcThread_BIT_IS_TERMINATED 0
00064 /** JOINリクエストがある場合に1*/
00065 #define NyLPC_TcThread_BIT_IS_JOIN_REQ   1
00066 
00067 /**
00068  * Thread priorities
00069  */
00070 #define NyLPC_TcThread_PRIORITY_IDLE    0
00071 #define NyLPC_TcThread_PRIORITY_SERVICE 1
00072 
00073 #if NyLPC_ARCH==NyLPC_ARCH_FREERTOS
00074 
00075 struct NyLPC_TcThread {
00076     NyLPC_TUInt32 _sbit;
00077     xTaskHandle _taskid;
00078     NyLPC_TcThread_ThreadFunc _func;
00079     void* _param;
00080 };
00081 #elif NyLPC_ARCH==NyLPC_ARCH_MBEDRTOS
00082 
00083 struct NyLPC_TcThread
00084 {
00085     NyLPC_TUInt32 _sbit;
00086     void* _thread; //Thread* type.
00087     NyLPC_TcThread_ThreadFunc _func;
00088     void* _arg;
00089 };
00090 #elif NyLPC_ARCH==NyLPC_ARCH_WIN32
00091 //this is dummy definition.
00092 struct NyLPC_TcThread
00093 {
00094     int dummy;
00095     NyLPC_TcThread_ThreadFunc _func;
00096 };
00097 #else
00098 #error Bad NyLPC_ARCH!
00099 #endif
00100 
00101 /**
00102  * 終了要求フラグの値を返します。
00103  * スレッドのループ内で、Join要求の有無を確認するために使います。
00104  * スレッドは定期的にこの関数を実行して、trueの場合は速やかに関数を終了する必要があります。
00105  */
00106 #define NyLPC_cThread_isJoinReqest(i_inst) NyLPC_TUInt32_isBitOn((i_inst)->_sbit,NyLPC_TcThread_BIT_IS_JOIN_REQ)
00107 #define NyLPC_cThread_isTerminated(i_inst) NyLPC_TUInt32_isBitOn((i_inst)->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED)
00108 
00109 void NyLPC_cThread_initialize(NyLPC_TcThread_t* i_inst, NyLPC_TInt32 i_stack,NyLPC_TInt32 i_prio);
00110 void NyLPC_cThread_finalize(NyLPC_TcThread_t* i_inst);
00111 void NyLPC_cThread_start(NyLPC_TcThread_t* i_inst,
00112         NyLPC_TcThread_ThreadFunc i_func, void* i_param);
00113 void NyLPC_cThread_join(NyLPC_TcThread_t* i_inst);
00114 void NyLPC_cThread_yield(void);
00115 /**
00116  * 一定時間、スレッドをスリープする。
00117  * この関数はstatic関数です。
00118  */
00119 void NyLPC_cThread_sleep(NyLPC_TUInt32 i_time_in_msec);
00120 
00121 #ifdef __cplusplus
00122 }
00123 #endif /* __cplusplus */
00124 
00125 #endif /* NYLPC_CTHREAD_H_ */