資源簡介
下面是一些接口文件代碼:
/*
如果timeout參數不為零,則返回值為
等待信號量所花費的毫秒數。如果
信號量未在指定時間內發出信號,返回值為
SYS_ARCH_TIMEOUT。如果線程不必等待信號量
該函數返回零。 */
u32_t
sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
{
u32_t wait_tick = 0;
u32_t start_tick = 0 ;
//看看信號量是否有效
if(*sem == SYS_SEM_NULL)
return SYS_ARCH_TIMEOUT;
//首先獲取開始等待信號量的時鐘節拍
start_tick = xTaskGetTickCount();
//timeout != 0,需要將ms換成系統的時鐘節拍
if(timeout != 0)
{
//將ms轉換成時鐘節拍
wait_tick = timeout / portTICK_PERIOD_MS;
if (wait_tick == 0)
wait_tick = 1;
}
else
wait_tick = portMAX_DELAY; //一直阻塞
//等待成功,計算等待的時間,否則就表示等待超時
if(xSemaphoreTake(*sem, wait_tick) == pdTRUE)
return ((xTaskGetTickCount()-start_tick)*portTICK_RATE_MS);
else
return SYS_ARCH_TIMEOUT;
}
void
sys_sem_signal(sys_sem_t *sem)
{
if(xSemaphoreGive( *sem ) != pdTRUE)
printf("[sys_arch]:sem signal fail!\n");
}
err_t
sys_mutex_new(sys_mutex_t *mutex)
{
/* 創建 sem */
*mutex = xSemaphoreCreateMutex();
if(*mutex != SYS_MRTEX_NULL)
return ERR_OK;
else
{
printf("[sys_arch]:new mutex fail!\n");
return ERR_MEM;
}
}
代碼片段和文件信息
/*
????FreeRTOS?V9.0.0?-?Copyright?(C)?2016?Real?Time?Engineers?Ltd.
????All?rights?reserved
????VISIT?http://www.FreeRTOS.org?TO?ENSURE?YOU?ARE?USING?THE?LATEST?VERSION.
????This?file?is?part?of?the?FreeRTOS?distribution.
????FreeRTOS?is?free?software;?you?can?redistribute?it?and/or?modify?it?under
????the?terms?of?the?GNU?General?Public?License?(version?2)?as?published?by?the
????Free?Software?Foundation?>>>>?AND?MODIFIED?BY?<<<
????***************************************************************************
????>>!???NOTE:?The?modification?to?the?GPL?is?included?to?allow?you?to?????!<<
????>>!???distribute?a?combined?work?that?includes?FreeRTOS?without?being???!<<
????>>!???obliged?to?provide?the?source?code?for?proprietary?components?????!<<
????>>!???outside?of?the?FreeRTOS?kernel.???????????????????????????????????!<<
????***************************************************************************
????FreeRTOS?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.??Full?license?text?is?available?on?the?following
????link:?http://www.freertos.org/a00114.html
????***************************************************************************
?????*???????????????????????????????????????????????????????????????????????*
?????*????FreeRTOS?provides?completely?free?yet?professionally?developed????*
?????*????robust?strictly?quality?controlled?supported?and?cross??????????*
?????*????platform?software?that?is?more?than?just?the?market?leader?it?????*
?????*????is?the?industry‘s?de?facto?standard.???????????????????????????????*
?????*???????????????????????????????????????????????????????????????????????*
?????*????Help?yourself?get?started?quickly?while?simultaneously?helping?????*
?????*????to?support?the?FreeRTOS?project?by?purchasing?a?FreeRTOS???????????*
?????*????tutorial?book?reference?manual?or?both:??????????????????????????*
?????*????http://www.FreeRTOS.org/Documentation??????????????????????????????*
?????*???????????????????????????????????????????????????????????????????????*
????***************************************************************************
????http://www.FreeRTOS.org/FAQHelp.html?-?Having?a?problem???Start?by?reading
????the?FAQ?page?“My?application?does?not?run?what?could?be?wrong?“.??Have?you
????defined?configASSERT()?
????http://www.FreeRTOS.org/support?-?In?return?for?receiving?this?top?quality
????embedded?software?for?free?we?request?you?assist?our?global?community?by
????participating?in?the?support?forum.
????http://www.FreeRTOS.org/training?-?Investing?in?training?allows?your?team?to
????be?as?productive?as?possible?as?early?as?possible.??Now?you?can?receive
????FreeRTOS?training?directly?from?Richard?Barry?CEO?of?Real?Time?Engineers
????Ltd?and?the?world‘s?leading?authority?on?the?world‘s?leading?RTOS.
評論
共有 條評論