|
发表于 2011-2-24 22:33:54
|
显示全部楼层
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
{
u8_t ucErr;
u32_t ucos_timeout;
u32_t start;
void *data;
//in lwip ,timeout is millisecond
//in ucosII ,timeout is timer tick!
//chang timeout from millisecond to ucos tick
ucos_timeout = 0;
if(timeout != 0){
ucos_timeout = (timeout * OS_TICKS_PER_SEC)/1000;
if(ucos_timeout < 1)
ucos_timeout = 1;
else if(ucos_timeout > 65535)
ucos_timeout = 65535;
}
start = OSTimeGet();
data = OSQPend( mbox->pQ, (u16_t)ucos_timeout, &ucErr );
if( ucErr == OS_TIMEOUT ) {
timeout = SYS_ARCH_TIMEOUT;
} else {
//单位转换,从ucos tick->ms
timeout = (OSTimeGet() - start)*(1000/ OS_TICKS_PER_SEC);
//timeout = 1;
if(msg)
{
if(data == (void*)&pvNullPointer )
*msg = NULL;
else
*msg = data;
}
}
return timeout;
}
/** Wait for a new message to arrive in the mbox
* @param mbox mbox to get a message from
* @param msg pointer where the message is stored
* @param timeout maximum time (in milliseconds) to wait for a message
* @return time (in milliseconds) waited for a message, may be 0 if not waited
or SYS_ARCH_TIMEOUT on timeout
* The returned time has to be accurate to prevent timer jitter! */
其实 准确点的是这样的 不要endless 这个超时了需要返回的 不是sem_wait那个wait forever
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
{
u8_t ucErr;
u32_t ucos_timeout;
u32_t start;
void *data;
//in lwip ,timeout is millisecond
//in ucosII ,timeout is timer tick!
//chang timeout from millisecond to ucos tick
ucos_timeout = 3; //
if(timeout != 0){
ucos_timeout = (timeout * OS_TICKS_PER_SEC)/1000;
if(ucos_timeout < 1)
ucos_timeout = 1;
else if(ucos_timeout > 65535)
ucos_timeout = 65535;
}
start = OSTimeGet();
data = OSQPend( mbox->pQ, (u16_t)ucos_timeout, &ucErr );
if( ucErr == OS_TIMEOUT ) {
timeout = SYS_ARCH_TIMEOUT;
} else {
//单位转换,从ucos tick->ms
timeout = (OSTimeGet() - start)*(1000/ OS_TICKS_PER_SEC);
//timeout = 1;
if(msg)
{
if(data == (void*)&pvNullPointer )
*msg = NULL;
else
*msg = data;
}
}
return timeout;
} |
|