|
From: | hnclcj |
Subject: | Re: [lwip-users] lwIP and uC/OS-II |
Date: | Wed, 30 Jun 2010 21:42:47 +0800 |
/*******************************************************************************************************/
const void * const pvNullPointer = NULL;
static OS_MEM *pQueueMem;
static char pcQueueMemoryPool[MAX_QUEUES * sizeof(TQ_DESCR)];
static u8_t curr_prio_offset;
static struct sys_timeouts lwip_timeouts[LWIP_TASK_MAX];
struct sys_timeouts null_timeouts;
OS_STK LWIP_TASK_STK[LWIP_TASK_MAX][LWIP_STK_SIZE];
/*******************************************************************************************************/
sys_mbox_t sys_mbox_new (int size)
{
u8_t err;
PQ_DESCR pQDesc;
size = size;
pQDesc = (PQ_DESCR)OSMemGet(pQueueMem, &err);
if (err == OS_NO_ERR) {
pQDesc->pQ = OSQCreate(&(pQDesc->pvQEntries[0]), MAX_QUEUE_ENTRIES);
if (pQDesc->pQ != NULL) {
return pQDesc;
}
}
return SYS_MBOX_NULL;
}
/*******************************************************************************************************/
void sys_mbox_free (sys_mbox_t mbox)
{
u8_t err;
u8_t cnt;
for (cnt=0; cnt<0xfe; cnt++) {
OSQFlush(mbox->pQ);
OSQDel(mbox->pQ, OS_DEL_NO_PEND, &err);
if (err == OS_ERR_NONE) {
break;
} else {
OSTimeDly(1);
}
}
OSMemPut(pQueueMem, mbox);
}
/*******************************************************************************************************/
void sys_mbox_post (sys_mbox_t mbox, void *msg)
{
if (msg == NULL) {
msg = (void *)&pvNullPointer;
}
(void)OSQPost(mbox->pQ, msg);
}
/*******************************************************************************************************/
err_t sys_mbox_trypost (sys_mbox_t mbox, void *msg)
{
u8_t err;
if (msg == NULL) {
msg = (void *)&pvNullPointer;
}
err = OSQPost(mbox->pQ, msg);
if (err == OS_NO_ERR) {
return ERR_OK;
} else {
return !ERR_OK;
}
}
/*******************************************************************************************************/
u32_t sys_arch_mbox_fetch (sys_mbox_t mbox, void **msg, u32_t timeout)
{
/* u32_t ucos_timeout;
void *temp;
u8_t err;
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;
}
temp = OSQPend(mbox->pQ, ucos_timeout, &err);
timeout = SYS_ARCH_TIMEOUT;
*msg = NULL;
if (err == OS_NO_ERR) {
timeout = !SYS_ARCH_TIMEOUT;
if (msg != NULL) {
if (temp != (void *)&pvNullPointer) {
*msg = temp;
}
}
}
return timeout;
*/
u8_t err;
u32_t ucos_timeout;
void *temp;
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;
}
temp = OSQPend(mbox->pQ, ucos_timeout, &err);
if (msg != NULL) {
if (temp == (void *)&pvNullPointer) {
*msg = NULL;
} else {
*msg = temp;
}
}
if ( err == OS_TIMEOUT ) {
timeout = SYS_ARCH_TIMEOUT;//0;
} else {
timeout = !SYS_ARCH_TIMEOUT;
}
return timeout;
}
/*******************************************************************************************************/
u32_t sys_arch_mbox_tryfetch (sys_mbox_t mbox, void **msg)
{
void *temp;
u32_t result;
u8_t err;
temp = OSQAccept(mbox->pQ, &err);
*msg = NULL;
result = SYS_MBOX_EMPTY;
if ( err == OS_NO_ERR ) {
// if (temp != (void *)&pvNullPointer) {
*msg = temp;
result = !SYS_MBOX_EMPTY;
// }
}
return result;
}
/*******************************************************************************************************/
sys_sem_t sys_sem_new (u8_t count)
{
sys_sem_t pSem;
pSem = OSSemCreate(count);
return pSem;
}
/*******************************************************************************************************/
void sys_sem_signal(sys_sem_t sem)
{
OSSemPost(sem);
}
/*******************************************************************************************************/
u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
{
u8_t err;
u32_t ucos_timeout;
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;
}
OSSemPend (sem, ucos_timeout, &err);
if (err == OS_TIMEOUT) {
return SYS_ARCH_TIMEOUT;
} else {
return !SYS_ARCH_TIMEOUT;
}
}
/*******************************************************************************************************/
void sys_sem_free(sys_sem_t sem)
{
u8_t err;
u8_t cnt;
for (cnt=0; cnt<0xfe; cnt++) {
OSSemDel(sem, OS_DEL_NO_PEND, &err);
if (err == OS_ERR_NONE) {
break;
} else {
OSTimeDly(1);
}
}
}
/*******************************************************************************************************/
void sys_init(void)
{
u8_t i;
u8_t err;
pQueueMem = OSMemCreate((void*)pcQueueMemoryPool, MAX_QUEUES, sizeof(TQ_DESCR), &err);
curr_prio_offset = 0;
for (i=0; i<LWIP_TASK_MAX; i++){
lwip_timeouts[i].next = NULL;
}
}
/*******************************************************************************************************/
struct sys_timeouts *sys_arch_timeouts (void)
{
u8_t curr_prio;
s16_t offset;//err,
OS_TCB curr_task_pcb;
null_timeouts.next = NULL;
OSTaskQuery(OS_PRIO_SELF, &curr_task_pcb);
curr_prio = curr_task_pcb.OSTCBPrio;
offset = curr_prio - LWIP_START_PRIO;
if (offset < 0 || offset >= LWIP_TASK_MAX) {
return &null_timeouts;
}
return &lwip_timeouts[offset];
}
/*******************************************************************************************************/
sys_thread_t sys_thread_new (char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio)
{
name = name;
stacksize = stacksize;
if (curr_prio_offset < LWIP_TASK_MAX) {
OSTaskCreate(thread, (void *)arg, &LWIP_TASK_STK[curr_prio_offset][LWIP_STK_SIZE-1],LWIP_START_PRIO+curr_prio_offset );
curr_prio_offset++;
} else {
// PRINT(" lwip task prio out of range ! error! ");
}
return (LWIP_START_PRIO+curr_prio_offset);
}
/*******************************************************************************************************/
sys_prot_t sys_arch_protect(void)
{
sys_prot_t cpu_sr;
OS_ENTER_CRITICAL();
return cpu_sr;
}
/*******************************************************************************************************/
void sys_arch_unprotect(sys_prot_t pval)
{
sys_prot_t cpu_sr;
cpu_sr = pval;
OS_EXIT_CRITICAL();
} 2010-06-30
hnclcj
发件人: Marco
发送时间: 2010-06-30 20:18:11
收件人: lwip-users
抄送:
主题: [lwip-users] lwIP and
uC/OS-II
Hi all,
I am new to lwIP. I am deploying uC/OS-II in my project and was
wondering, if there is a recent port for lwIP to uC/OS-II.
On the download page of lwIP there is a link to Guido Konrad's
uC/OS-II port, but the link is dead...
Any hints and directions for recent uC/OS-II ports are highly appreciated!
Thanks a lot in advance!
--
Best regards,
Marco
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users |
[Prev in Thread] | Current Thread | [Next in Thread] |