1 /*********************************************************************************
\r
3 * --------------------------------------------------------------------------------
\r
5 * This file is part of MiMic
\r
6 * Copyright (C)2011 Ryo Iizuka
\r
8 * MiMic is free software: you can redistribute it and/or modify
\r
9 * it under the terms of the GNU Lesser General Public License as published
\r
10 * by the Free Software Foundation, either version 3 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU Lesser General Public License
\r
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
21 * For further information please contact.
\r
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 *********************************************************************************/
\r
26 #include "NyLPC_cThread.h"
\r
27 #include "FreeRTOS.h"
\r
35 static void _task(void *pvParameters);
\r
37 void NyLPC_cThread_initialize(NyLPC_TcThread_t* i_inst,NyLPC_TInt32 i_stack)
\r
39 i_inst->_sbit=NyLPC_TcThread_BIT_IS_TERMINATED;
\r
40 NyLPC_AbortIfNot(pdPASS==xTaskCreate(
\r
42 (const portCHAR*)"th",
\r
43 i_stack<1?NyLPC_TcThread_DEFAULT_STACKSIZE:i_stack,
\r
46 &(i_inst->_taskid)));
\r
49 void NyLPC_cThread_start(NyLPC_TcThread_t* i_inst,NyLPC_TcThread_ThreadFunc i_func,void* i_param)
\r
51 NyLPC_ArgAssert(i_inst!=NULL);
\r
52 NyLPC_ArgAssert(i_func!=NULL);
\r
53 i_inst->_func=i_func;
\r
54 i_inst->_param=i_param;
\r
56 vTaskResume(i_inst->_taskid);
\r
59 void NyLPC_cThread_join(NyLPC_TcThread_t* i_inst)
\r
61 NyLPC_TUInt32_setBit(i_inst->_sbit,NyLPC_TcThread_BIT_IS_JOIN_REQ);
\r
62 while(!NyLPC_TUInt32_isBitOn(i_inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED))
\r
64 vTaskDelay(2);//少し待つ。
\r
69 void NyLPC_cThread_sleep(NyLPC_TUInt32 i_time_in_msec)
\r
72 vTaskDelay(i_time_in_msec/portTICK_RATE_MS);
\r
75 static void _task(void *pvParameters)
\r
77 NyLPC_TcThread_t* inst=(NyLPC_TcThread_t*)pvParameters;
\r
78 vTaskSuspend(inst->_taskid);
\r
80 inst->_func(inst->_param);
\r
81 NyLPC_TUInt32_setBit(inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED);
\r
82 vTaskSuspend(inst->_taskid);
\r