22#include "lwip/stats.h"
23#include "lwip/debug.h"
24#include "lwip/timeouts.h"
26#include "arch/sys_arch.h"
28#include "ps2ip_internal.h"
37static int MsgCountSema;
44 if(PollSema(MsgCountSema)==0)
49 free_head = free_head->next;
62 WaitSema(MsgCountSema);
67 free_head = free_head->next;
80 msg->next = free_head;
84 SignalSema(MsgCountSema);
88TimeoutHandler(
void* pvArg)
90 iReleaseWaitThread((
int)pvArg);
98 u32 iSec, iUSec, iDiff;
100 Diff.lo=pEnd->lo-pStart->lo;
101 Diff.hi=pEnd->hi-pStart->hi - (pStart->lo>pEnd->lo);
103 SysClock2USec(&Diff, &iSec, &iUSec);
104 iDiff=(iSec*1000)+(iUSec/1000);
106 return((iDiff!=0)?iDiff:1);
110sys_thread_t sys_thread_new(
const char *name, lwip_thread_fn
thread,
void *arg,
int stacksize,
int prio)
118 thp.option = (u32)
"PS2IP";
120 thp.stacksize = stacksize;
123 if((tid = CreateThread(&thp)) < 0)
125 dbgprintf(
"sys_thread_new: CreateThread failed, EC: %d\n", tid);
129 if((rv = StartThread(tid, arg)) < 0)
131 dbgprintf(
"sys_thread_new: StartThread failed, EC: %d\n", rv);
136 dbgprintf(
"sys_thread_new: thread %d\n", tid);
138 return((sys_thread_t) tid);
147 mbp.attr = MBA_THFIFO;
148 mbp.option = (u32)
"PS2IP";
150 if((*
mbox = CreateMbx(&mbp)) < 0)
152 printf(
"sys_mbox_new: CreateMbx failed, EC: %d\n", *
mbox);
156 dbgprintf(
"sys_mbox_new: mbox %d\n", *
mbox);
175 if((MsgPkt = try_alloc_msg()) != NULL){
176 MsgPkt->sys_msg = msg;
189 MsgPkt->sys_msg = msg;
198static u32_t sys_arch_mbox_fetch_internal(
sys_mbox_t pMBox,
void** ppvMSG, u32_t TimeElaspedout,
char block)
201 u32_t TimeElasped = 0;
214 if(TimeElaspedout > 0)
216 GetSystemTime(&Start);
217 USec2SysClock(TimeElaspedout * 1000, &ClockTicks);
218 SetAlarm(&ClockTicks, &TimeoutHandler, (
void*)iPID);
221 if((result=ReceiveMbx(&pmsg, pMBox))!= 0) {
return(SYS_ARCH_TIMEOUT); }
223 if(TimeElaspedout > 0)
225 CancelAlarm(TimeoutHandler,(
void*)iPID);
228 TimeElasped = ComputeTimeDiff(&Start, &End);
232 TimeElasped=((result=PollMbx(&pmsg, pMBox))!=0)?SYS_MBOX_EMPTY:0;
247u32_t sys_arch_mbox_fetch(
sys_mbox_t *
mbox,
void **msg, u32_t timeout)
249 return(sys_arch_mbox_fetch_internal(*
mbox, msg, timeout, 1));
253 return(sys_arch_mbox_fetch_internal(*
mbox, msg, 0, 0));
256err_t sys_sem_new(sys_sem_t *sem, u8_t
count)
262 if((*sem=CreateSema(&Sema))<0)
264 printf(
"sys_sem_new: CreateSema failed, EC: %d\n", *sem);
269 dbgprintf(
"sys_sem_new: CreateSema cnt %d sema %d\n",
count, *sem);
274int sys_sem_valid(sys_sem_t *sem){
278void sys_sem_set_invalid(sys_sem_t *sem){
282u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
290 result=(WaitSema(*sem)==0)?0:SYS_ARCH_TIMEOUT;
295 result=(PollSema(*sem)==0)?0:SYS_ARCH_TIMEOUT;
303 int iPID=GetThreadId();
306 GetSystemTime(&Start);
307 USec2SysClock(timeout*1000,&ClockTicks);
308 SetAlarm(&ClockTicks, &TimeoutHandler, (
void*)iPID);
310 if(WaitSema(*sem)==0){
311 CancelAlarm(TimeoutHandler,(
void*)iPID);
314 u32WaitTime=ComputeTimeDiff(&Start, &End);
315 result=(u32WaitTime<=timeout)?u32WaitTime:timeout;
316 }
else result=SYS_ARCH_TIMEOUT;
322void sys_sem_signal(sys_sem_t *sem)
327void sys_sem_free(sys_sem_t *sem)
338 sema.initial=sema.max=SYS_MAX_MESSAGES;
339 sema.attr=sema.option=0;
340 MsgCountSema=CreateSema(&sema);
342 free_head = &msg_pool[0];
345 for(i = 1; i < SYS_MAX_MESSAGES; i++)
347 prev->next = &msg_pool[i];
355sys_prot_t sys_arch_protect(
void)
363void sys_arch_unprotect(sys_prot_t Flags)
368void *malloc(
size_t size)
374 ptr=AllocSysMemory(ALLOC_LAST, size, NULL);
389void *calloc(
size_t n,
size_t size)
395 ptr=AllocSysMemory(ALLOC_LAST, n * size, NULL);
399 memset(ptr, 0, n * size);
409 GetSystemTime(&timenow);
410 SysClock2USec(&timenow, &seconds, &usecs);
412 return(seconds*1000 + usecs / 1000);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
u32 count
start sector of fragmented bd/file