Esempio n. 1
0
//等待邮箱中的消息
//*mbox:消息邮箱
//*msg:消息
//timeout:超时时间,如果timeout为0的话,就一直等待
//返回值:当timeout不为0时如果成功的话就返回等待的时间,
//		失败的话就返回超时SYS_ARCH_TIMEOUT
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
{ 
	u8_t ucErr;
	u32_t ucos_timeout,timeout_new;
	void *temp;
	sys_mbox_t m_box=*mbox;
	if(timeout!=0)
	{
		ucos_timeout=(timeout*OS_TICKS_PER_SEC)/1000; //转换为节拍数,因为UCOS延时使用的是节拍数,而LWIP是用ms
		if(ucos_timeout<1)ucos_timeout=1;//至少1个节拍
	}else ucos_timeout = 0; 
	timeout = OSTimeGet(); //获取系统时间 
	temp=OSQPend(m_box->pQ,(u16_t)ucos_timeout,&ucErr); //请求消息队列,等待时限为ucos_timeout
	if(msg!=NULL)
	{	
		if(temp==(void*)&pvNullPointer)*msg = NULL;   	//因为lwip发送空消息的时候我们使用了pvNullPointer指针,所以判断pvNullPointer指向的值
 		else *msg=temp;									//就可知道请求到的消息是否有效
	}    
	if(ucErr==OS_ERR_TIMEOUT)timeout=SYS_ARCH_TIMEOUT;  //请求超时
	else
	{
		LWIP_ASSERT("OSQPend ",ucErr==OS_ERR_NONE); 
		timeout_new=OSTimeGet();
		if (timeout_new>timeout) timeout_new = timeout_new - timeout;//算出请求消息或使用的时间
		else timeout_new = 0xffffffff - timeout + timeout_new; 
		timeout=timeout_new*1000/OS_TICKS_PER_SEC + 1; 
	}
	return timeout; 
}
Esempio n. 2
0
void task2(task* pdata)
{
  int start = 0;
  int end;
  int delay;
  INT8U err;
  int arrival = 3;
  OSTCBCur->Period = pdata->period;
  OSTCBCur->Exec = pdata->exec;
  OSTCBCur->ExecTime = pdata->exec;
  OSTCBCur->Start = 0;
  OSTCBCur->Deadline = pdata->period + arrival;
  OSTCBCur->Org_Deadline = pdata->period + arrival;
  OSTimeDly(arrival);

  while (1)
  { 
    printf("\t%d\tTask_2\n",OSTimeGet());
    mywait(OSTCBCur->Exec); // CPU time
    printf("\t%d\tTask_2 get R2\t",OSTimeGet());
    OSMutexPend(R2, 0, &err);
    mywait(3); // R2
    printf("\t%d\tTask_2 release R2",OSTimeGet());
    OSMutexPost(R2);
    
    end = OSTimeGet();
    delay = OSTCBCur->Deadline-end;            // let it delay 1 timetick to avoid running the while loop
    OSTCBCur->Resp = end-start;
    start += pdata->period; 
    OSTCBCur->Deadline += OSTCBCur->Period;
    OSTCBCur->Org_Deadline = OSTCBCur->Deadline;
    OSTimeDly(delay);
  }
}
Esempio n. 3
0
/***********************************************************
pEndObj:  发送接口
pMsgInfo: 发送消息内容通过链路层发送消息
************************************************************/
unsigned short End_send( P_MSG_INFO pMsgInfo)
{
    P_END_OBJ pEndObj;

    if( (( pEndObj = End_get_end_obj(pMsgInfo->msg_header.end_id)) == NULL) ||
            ( pMsgInfo->msg_header.msg_len == 0) )
    {
        // alan dynamic sending buffer.
        // 这些发送失败时,这里不直接释放sending buffer,由end send 调用释放。
        if( pMsgInfo->msg_header.need_buffer_free == TRUE)
        {
            free_send_buffer(pMsgInfo);
        }

        return FALSE;
    }


    if( END_IDLE != End_IsIdle(pEndObj) )
    {
        /* 不在IDLE State, 将数据挂在queue 里*/
        enqueue(g_EndTxQueue[pEndObj->end_id], pMsgInfo);

        pMsgInfo->msg_header.time_stamp = OSTimeGet();

        return TRUE;
    }


    if( TRUE == End_uart_send( pEndObj->end_id, pMsgInfo->msg_buffer, pMsgInfo->msg_header.msg_len) )
    {

        // 发送buffer 直接挂在end object , 后续可以直接释放!
        pEndObj->pMsgInfo = pMsgInfo;

        // 底层状态迁移到SENDING
        pEndObj->end_send_status = END_STATUS_SENDING;

        pMsgInfo->msg_header.block_state = SENDING;

        pEndObj->endStatistics.txPacketCount++;

        pMsgInfo->msg_header.time_stamp = OSTimeGet();

        
        return TRUE;
    }
    else
    {
        if( pMsgInfo->msg_header.need_buffer_free == TRUE)
        {
            free_send_buffer(pMsgInfo);
        }

        return FALSE;
    }

}
Esempio n. 4
0
u8 TestSPITransferData(void)
{
	u32 i = 0;
	u8 cmd[40];
	u8 buf[40];
	u8 *TXBuf;
	int time;
//	int ret;

	TXBuf = tls_mem_alloc(TEST_SPI_SPEED_SIZE);
	if(NULL == TXBuf)
		return 0;
	memset(TXBuf,0xaa,TEST_SPI_SPEED_SIZE);
	
	memset(cmd,0,32);
	memset(buf,0,32);
	cmd[0] = 0x03;
	while(1)
	{		
#if 	CS_CTRL_SOFT
		tls_gpio_write(18, 0);
#endif
		tls_spi_write_then_read(cmd, 1, buf, 2);
#if 	CS_CTRL_SOFT
		tls_gpio_write(18, 1);
#endif
		if(buf[0] & 0x01)
			break;
		OSTimeDly(1);
		printf("\ncan not tx data\n");
	}

	cmd[0] =0x00;
	*TXBuf = 0x90;	//命令字
	time = OSTimeGet();
	printf("\ntime1 = %d\n",time);
	for(i = 0;i < 1000;i ++)
	{
#if 	CS_CTRL_SOFT
		tls_gpio_write(18, 0);
#endif	
		tls_spi_write(TXBuf,TEST_SPI_SPEED_SIZE);
#if 	CS_CTRL_SOFT
		tls_gpio_write(18, 1);
#endif
	}
	time = OSTimeGet();
	printf("\ntime2 = %d\n",time);
	printf("\ntx cnt =%d\n",i);	
	tls_mem_free(TXBuf);
	
	return	0;
}
Esempio n. 5
0
void mywait(int tick)
{
    int now, exit;
    OS_ENTER_CRITICAL();
    now = OSTimeGet();
    exit = now + tick;
    OS_EXIT_CRITICAL();
    while(1) {
        if(exit <= OSTimeGet())
            break;
    }
}
Esempio n. 6
0
/*
 * timerCheck - If there are any expired timers, wake up the timer task.
 * This is designed to be called from within the Jiffy timer interrupt so
 * it has to have minimal overhead.
 */
void timerCheck(void)
{
#ifdef OS_DEPENDENT
	if ((long)(timerHead.timerNext->expiryTime - OSTimeGet()) <= 0)
		(void) OSTaskResume(PRI_TIMER);
#endif
#if ONETASK_SUPPORT > 0
  // Support for non multitasking environment
  // Call timerTask if a timer has expired
	if ((long)(timerHead.timerNext->expiryTime - OSTimeGet()) <= 0)	timerTask(NULL);
#endif
}
Esempio n. 7
0
/*
  Blocks the thread while waiting for the semaphore to be
  signaled. If the "timeout" argument is non-zero, the thread should
  only be blocked for the specified time (measured in
  milliseconds).

  If the timeout argument is non-zero, the return value is the number of
  milliseconds spent waiting for the semaphore to be signaled. If the
  semaphore wasn't signaled within the specified time, the return value is
  SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore
  (i.e., it was already signaled), the function may return zero.

  Notice that lwIP implements a function with a similar name,
  sys_sem_wait(), that uses the sys_arch_sem_wait() function.
*/
u32_t
sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
{
	u8_t ucErr;
	u32_t ucos_timeout, timeout_new;
	
	/* timeout 单位以ms计 转换为ucos_timeout 单位以TICK计 */
	if(	timeout != 0)
	{
		ucos_timeout = (timeout * OS_TICKS_PER_SEC) / 1000;  /* convert to timetick */
		if(ucos_timeout < 1)
		{
			ucos_timeout = 1;
		}
		else if(ucos_timeout > 65536) /* uC/OS only support u16_t pend */
		{
			ucos_timeout = 65535;     /* 最多等待TICK数 这是uC/OS所能 处理的最大延时 */
		}
	}
	else 
	{
		ucos_timeout = 0;
	}
	timeout = OSTimeGet();            /* 记录起始时间 */
	
	OSSemPend ((OS_EVENT *)sem,(u16_t)ucos_timeout, (u8_t *)&ucErr);
	
	if(ucErr == OS_ERR_TIMEOUT)
	{
		timeout = SYS_ARCH_TIMEOUT;	  /* only when timeout! */
	}
	else
	{    
		/* LWIP_ASSERT( "OSSemPend ", ucErr == OS_ERR_NONE ); */
		/* for pbuf_free, may be called from an ISR */
		
		timeout_new = OSTimeGet();  /* 记录终止时间 */
		if (timeout_new>=timeout)
		{
			timeout_new = timeout_new - timeout;
		}
		else 
		{
			timeout_new = 0xffffffff - timeout + timeout_new;
		}
		timeout = (timeout_new * 1000 / OS_TICKS_PER_SEC + 1);  /* convert to milisecond 为什么加1 */
	}
	
	return timeout;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_TimeGetMsec
 * Description   : This function gets current time in milliseconds.
 *
 *END**************************************************************************/
uint32_t OSA_TimeGetMsec(void)
{
    OS_ERR err;

    OS_TICK timeTick = OSTimeGet(&err);
    return TICKS_TO_MSEC(timeTick);
}
Esempio n. 9
0
/*
 * timerInit - Initialize the timer timer subsystem.
 */
void timerInit(void)
{
	int i;
	
	/* Initialize the timer queue sentinal. */
	memset(&timerHead, 0, sizeof(Timer));
	timerHead.timerNext = &timerHead;
	timerHead.timerPrev = &timerHead;
	timerHead.expiryTime = OSTimeGet() + MAXJIFFYDELAY;
	timerHead.timerHandler = nullTimer;
	
	/* Initialize the timer free list. */
	timerFree = &timerHeap[0];
	memset(timerFree, 0, sizeof(timerHeap));
	for (i = 0; i < MAXFREETIMERS; i++) {
		timerHeap[i].timerFlags = TIMERFLAG_TEMP;
		timerHeap[i].timerNext = &timerHeap[i + 1];
	}
	timerHeap[MAXFREETIMERS - 1].timerNext = NULL;
	
	/* Start the timer task. */
#ifdef OS_DEPENDENT
	mutex = OSSemCreate(1);
	OSTaskCreate(timerTask, NULL, timerStack+TIMER_STACK_SIZE, PRI_TIMER);
#endif
}
Esempio n. 10
0
extern int32_t clock_gettime
    (
    int32_t clock_id,       /* clock ID (always CLOCK_REALTIME) */
    struct timespec * tp    /* where to store current time */
    )
{
    uint32_t diffTicks;       /* system clock tick count */

    clockLibInit ();

    if (clock_id != CLOCK_REALTIME) {
        return (ERROR);
    }

    if (tp == NULL) {
        return (ERROR);
    }

    diffTicks = OSTimeGet() - _clockRealtime.tickBase;

    TV_CONVERT_TO_SEC(*tp, diffTicks);
    TV_ADD (*tp, _clockRealtime.timeBase);

    return (OK);
}
Esempio n. 11
0
File: os_view.c Progetto: flyoo/gprs
static  void  OSView_CmdGetTaskInfo (void)
{
    OS_TCB  *ptcb;
    INT32U   cycles;
    INT8U    stat;


    ptcb   = (OS_TCB *)OSView_RxGetINT32U();                         /* Get the desired task's TCB address     */
    cycles = OSView_TimeGetCycles();                                 /* Get timestamp                          */
    OSView_TxStoINT32U(cycles);
    if (ptcb != (OS_TCB *)0 && ptcb != (OS_TCB *)1) {                /* Make sure we have a valid TCB pointer  */
        if (ptcb == OSTCBCur) {
            ptcb->OSTCBCyclesTot  += cycles - ptcb->OSTCBCyclesStart;
            ptcb->OSTCBCyclesStart = cycles;
        }
        OSView_TxStoStr(ptcb->OSTCBTaskName); 						 /* Task name                              */
        OSView_TxStoINT8U(ptcb->OSTCBPrio);                          /* Prio                                   */
        stat = OSView_CmdGetTaskInfo_TCBStat(ptcb);                  /* Task status                            */
        OSView_TxStoINT8U(stat);
        OSView_TxStoINT32U((INT32U)ptcb->OSTCBEventPtr);             /* Pointer to event task is waiting for.  */
        OSView_TxStoINT32U((INT32U)ptcb->OSTCBDly);                  /* Timeout (i.e. ticks of delayed task)   */
        OSView_TxStoINT32U(ptcb->OSTCBCyclesTot);                    /* ExecTime                               */
        OSView_TxStoINT32U(ptcb->OSTCBCtxSwCtr);                     /* NumActivations                         */

        OSView_TxStoINT32U((INT32U)ptcb->OSTCBStkBase);              /* Stack base address                     */
        OSView_TxStoINT32U(ptcb->OSTCBStkSize * sizeof(OS_STK));     /* Stack size (in #bytes)                 */
        OSView_TxStoINT32U(ptcb->OSTCBStkUsed);                      /* Number of bytes used                   */
        OSView_TxStoINT32U((INT32U)ptcb->OSTCBStkPtr);               /* Current stack pointer address          */
    } else {
        OSView_CmdGetTaskInfo_InvalidTask();
    }
				OSView_TxStoINT16U((INT16U)OSTimeGet());
}
Esempio n. 12
0
PUBLIC int websOpenAuth(int minimal)
{
    char    sbuf[64];
    
    assert(minimal == 0 || minimal == 1);

    if ((users = hashCreate(-1)) < 0) {
        return -1;
    }
    if ((roles = hashCreate(-1)) < 0) {
        return -1;
    }
    if (!minimal) {
        fmt(sbuf, sizeof(sbuf), "%x:%x", rand(), OSTimeGet());
        secret = websMD5(sbuf);
#if ME_GOAHEAD_JAVASCRIPT && FUTURE
        websJsDefine("can", jsCan);
#endif
        websDefineAction("login", loginServiceProc);
        websDefineAction("logout", logoutServiceProc);
    }
    if (smatch(ME_GOAHEAD_AUTH_STORE, "file")) {
        verifyPassword = websVerifyPasswordFromFile;
#if ME_COMPILER_HAS_PAM
    } else if (smatch(ME_GOAHEAD_AUTH_STORE, "pam")) {
        verifyPassword = websVerifyPasswordFromPam;
#endif
    }
    return 0;
}
Esempio n. 13
0
void TTCP_LogStatistics(PTEST_BLOCK pTBLK)
{
	float realt;                 // user, real time (seconds)

	pTBLK->m_tFinish = OSTimeGet();//GetTickCount();

	realt = ((float )pTBLK->m_tFinish - (float )pTBLK->m_tStart)/100;//1000

#if USE_UDP
	printf( "\r\n  Statistics  : UDP <- %s:%d\r\n",
	inet_ntoa( pTBLK->remote_ip ),
	htons( pTBLK->remote_port ) );
#else
	printf( "\r\n  Statistics  : TCP <- %s:%d\r\n",
	inet_ntoa( pTBLK->remote_ip ),
	htons( pTBLK->remote_port ) );
#endif

   printf( 
      "%ld bytes in %ld real seconds = %ld KB/sec +++\r\n",
      (u32_t)pTBLK->m_nbytes,
      (u32_t)realt,
      (u32_t)(pTBLK->m_nbytes/(realt*1024.0))
      );

   printf( "numCalls: %ld; msec/call: %ld; calls/sec: %ld\r\n",
      (u32_t)pTBLK->m_numCalls,
      (u32_t)(1024.0 * realt/((u32_t)pTBLK->m_numCalls)),
      (u32_t)(((u32_t)pTBLK->m_numCalls)/realt)
      );
}
Esempio n. 14
0
void TTCP_InitStatistics(PTEST_BLOCK pTBLK)
{
   pTBLK->m_numCalls = 0;       // # of I/O system calls
   pTBLK->m_nbytes = 0;      // bytes on net

   pTBLK->m_tStart = OSTimeGet();//GetTickCount();
}
Esempio n. 15
0
void task2(task* pdata)
{
  int start = 0;
  int end;
  int delay;
  OSTCBCur->NoJob = 0;
  OSTCBCur->Period = pdata->period;
  OSTCBCur->Exec = pdata->exec;
  OSTCBCur->ExecTime = pdata->exec;
  OSTCBCur->Start = 0;
  OSTCBCur->Deadline = pdata->period;
  while (1)
  { 
    
    while(OSTCBCur->ExecTime){}
    
    end = OSTimeGet();
    if(end != OSTCBCur->Deadline-OSTCBCur->Period) {    // if finish time = deadline
        delay = pdata->period - (end-start);            // let it delay 1 timetick to avoid running the while loop
    }
    else
        delay =1;
    OSTCBCur->Resp = end-start;
    start += pdata->period; 
    OSTimeDly(delay);
    
  }
}
Esempio n. 16
0
File: os_view.c Progetto: flyoo/gprs
static  void  OSView_CmdGetSysInfo (void)
{
    INT8U   s[OS_VIEW_CPU_NAME_SIZE+1];
    INT8U   i;
    INT32U  stk_base;
    INT32U  stk_size;
    INT32U  time;


    time = OSTimeGet();                                     /* Send current value of tick counter              */
    OSView_TxStoINT32U(time);
    OSView_TxStoPtr(OSTCBCur);                              /* Current task's OS_TCB                           */
    OSView_TxStoINT16U(OS_VERSION);                         /* Send uC/OS-II's version number                  */
    OSView_TxStoINT8U(1);                                   /* Indicate profiling information will be sent     */

    for (i = 0; i < OS_VIEW_CPU_NAME_SIZE; i++) {           /* Clear buffer to help with debug.                */
        s[i] = 0x00;
    }
    OSView_GetCPUName(s);                                   /* Get Processor Name in string 's'                */
    OSView_TxStoStr(s);

    stk_base = OSView_GetIntStkBase();                      /* Interrupt stack base from port specific file    */
    OSView_TxStoINT32U(stk_base);

    stk_size = OSView_GetIntStkSize();                      /* Interrupt stack size from port specific file    */
    OSView_TxStoINT32U(stk_size);
}
void SendQueryTimePacked(int sockfd, struct sockaddr_in *addr_src)
{
    NTPPACKED SynNtpPacked;
    int ticks;
    int timer;

    memset(&SynNtpPacked, 0, sizeof(SynNtpPacked));
    SynNtpPacked.header.ntptd.ntptime.local_precision = -6;
    SynNtpPacked.header.ntptd.ntptime.Poll = 4;
    SynNtpPacked.header.ntptd.ntptime.stratum = 0;
    SynNtpPacked.header.ntptd.ntptime.Mode = 3;
    SynNtpPacked.header.ntptd.ntptime.VN = 3;
    SynNtpPacked.header.ntptd.ntptime.LI = 0;
    SynNtpPacked.root_delay = 1<<16;      	/* Root Delay (seconds) */
    SynNtpPacked.root_dispersion = 1<<16; 	/* Root Dispersion (seconds) */
    SynNtpPacked.header.ntptd.headData = htonl(SynNtpPacked.header.ntptd.headData);
    SynNtpPacked.root_delay = htonl(SynNtpPacked.root_dispersion);
    SynNtpPacked.root_dispersion = htonl(SynNtpPacked.root_dispersion);
    ticks = OSTimeGet();
    timer = ticks / OS_TICKS_PER_SEC ;
    SynNtpPacked.trantime.coarse = htonl((long)timer + JAN_1970); 	/* Transmit Timestamp coarse */
    SynNtpPacked.trantime.fine = htonl(NTPFRAC(timer));  			/* Transmit Timestamp fine   */
    
	sendto(sockfd, &SynNtpPacked, sizeof(SynNtpPacked), 0, addr_src, sizeof(struct sockaddr));
}
void GetLocalTime( struct timeval* tv)
{
    unsigned int ticks;
    ticks = OSTimeGet();
    tv->tv_sec = ticks / OS_TICKS_PER_SEC ;
    tv->tv_sec = (tv->tv_sec + 1417305600 + 28800);
    tv->tv_usec = ticks % OS_TICKS_PER_SEC / OS_TICKS_PER_SEC * 1000 ;	
}
Esempio n. 19
0
/*----------------------------------------------------------------------*
                         rtp_get_system_sec
 *----------------------------------------------------------------------*/
unsigned long rtp_get_system_sec (void)
{
unsigned long elapsed_sec;

	elapsed_sec = OSTimeGet() / OS_TICKS_PER_SEC;
	
    return (elapsed_sec);
}
Esempio n. 20
0
ULONG QCHDIGetTimestamp(void)
{
    ULONG return_value;

    return_value = OSTimeGet();

    return(return_value);
}
Esempio n. 21
0
/*
  Blocks the thread until a message arrives in the mailbox, but does
  not block the thread longer than "timeout" milliseconds (similar to
  the sys_arch_sem_wait() function). The "msg" argument is a result
  parameter that is set by the function (i.e., by doing "*msg =
  ptr"). The "msg" parameter maybe NULL to indicate that the message
  should be dropped.

  The return values are the same as for the sys_arch_sem_wait() function:
  Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a
  timeout.

  Note that a function with a similar name, sys_mbox_fetch(), is
  implemented by lwIP. 
*/
u32_t _sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
{
    u8_t	ucErr;
    u32_t	ucos_timeout, timeout_new;
    void	*temp;

    if(timeout != 0)
    {
        ucos_timeout = (timeout * OS_TICKS_PER_SEC)/1000; //convert to timetick

        if(ucos_timeout < 1)
            ucos_timeout = 1;
        else if(ucos_timeout > 65535)    //ucOS only support u16_t timeout
            ucos_timeout = 65535;
    }
    else 
        ucos_timeout = 0;

    timeout = OSTimeGet();

    temp = OSQPend( (*mbox)->pQ, (u16_t)ucos_timeout, &ucErr );

    if(msg != NULL)
    {
        if( temp == (void*)&pvNullPointer )
            *msg = NULL;
        else
            *msg = temp;
    }   

    if(ucErr == OS_ERR_TIMEOUT ) 
        timeout = SYS_ARCH_TIMEOUT;
    else
    {
        LWIP_ASSERT( "OSQPend ", ucErr == OS_ERR_NONE );

        timeout_new = OSTimeGet();
        if (timeout_new>timeout) timeout_new = timeout_new - timeout;
        else timeout_new = 0xffffffff - timeout + timeout_new;

        timeout = timeout_new * 1000 / OS_TICKS_PER_SEC + 1; //convert to milisecond
    }

    return timeout; 
}
Esempio n. 22
0
/*
*********************************************************************************************************
* GetTimeStamp
*********************************************************************************************************
*   Arguments:
*       none.
*   Returns:
*       The timestamp 
*********************************************************************************************************
*/
CPU_INT32U GetTimeStamp()
{
  OS_ERR      err = 0;
  CPU_INT32U uTimeStamp = 0;
  
  uTimeStamp = OSTimeGet(&err);
  
  return uTimeStamp;
}
Esempio n. 23
0
//--------------------------------------------------------------------------
// Get the current millisecond tick count.  Does not have to represent
// an actual time, it just needs to be an incrementing timer.
//
long msGettick(void)
{
#ifdef UCOS_II
   // uCOS-II tick counter
	OSTimeGet();
#else
   // TODO add platform specific code here
   return 0;
#endif
}
Esempio n. 24
0
/*
    Create a nonce value for digest authentication (RFC 2617)
 */
static char *createDigestNonce(Webs *wp)
{
    static int64 next = 0;
    char         nonce[256];

    assert(wp);
    assert(wp->route);
    fmt(nonce, sizeof(nonce), "%s:%s:%x:%x", secret, ME_GOAHEAD_REALM, OSTimeGet(), next++);
    return websEncode64(nonce);
}
Esempio n. 25
0
//产生随机数函数
int make_rand(int start, int end)
{
	int value = 0;
	if (end <= start) 
		return -1;
	srand(OSTimeGet());
	value = ((rand() % (end - start + 1)) + start);

	return value;
}
Esempio n. 26
0
void App_TaskSwHook(void)
{
#if OS_TASK_PROFILE_EN > 0
	INT32U cycles;

	cycles = OSTimeGet();	/* This task is done                           */
	OSTCBCur->OSTCBCyclesTot += cycles - OSTCBCur->OSTCBCyclesStart;
	OSTCBHighRdy->OSTCBCyclesStart = cycles;
#endif
}
Esempio n. 27
0
systime_t osGetSystemTime(void)
{
   OS_ERR err;
   systime_t time;

   //Get current tick count
   time = OSTimeGet(&err);

   //Convert system ticks to milliseconds
   return OS_SYSTICKS_TO_MS(time);
}
Esempio n. 28
0
uint32_t SIM90x_GetIdleTime(void)
{
    OS_ERR error;
    OS_TICK tick;
    uint32_t idle_ms;

    tick = OSTimeGet(&error) - IdleTick;
    idle_ms = SYS_TickToMs(tick);

    return idle_ms;
}
Esempio n. 29
0
/*
 * This is the wrapper for the task that executes rendundantly on both cores
 * There is one VERY important thing to note. When the critical task begins executing
 * the value of the stack pointer MUST be the same on both cores. This means that
 * the wrapper must have the same number of variables declared within its scope (i.e.
 * onto its stack) before calling the critical task (pt() in this example)
 */
void preemption_task(void* pdata){
	int done = 0;
	int first = 0;
	int t_os;

	CriticalFunctionPointers* cp =
				(CriticalFunctionPointers*) SHARED_MEMORY_BASE;
	pt = cp->task[1];

	while(1){
		// Get initial time, then wait for 2 ticks
		t_os = OSTimeGet();
		OSTimeDly(2 - t_os);

		//This is a crude way of synchronizing the beginning of the task
		//on both cores
		while (done == 0) {
			altera_avalon_mutex_lock(mutex, 1); //Acquire the hardware mutex
			{
				if(first == 0){
					cp->checkout[1] = 1;
					first = 1;
				}
				if( cp->checkout[0] == 1){
					cp->checkout[0] = 0;
					done = 1;
				}

			}
			altera_avalon_mutex_unlock(mutex);
		}

		// Set default block size for fingerprinting
		fprint_set_block_size(cp->blocksize[1]);

		//Context switch is necessary to clear the callee saved registers
		long registers[8];
		context_switch(registers);

		//Set the global pointer in case of compilation issues related
		//to global variables
		set_gp();
		//call the critical task
		pt(cp->args[1]);
		//restore the original global pointer
		restore_gp();
		//Restore the callee saved registers
		context_restore(registers);
		//Get the end time
		alt_u64 t = alt_timestamp();
		//store the end time
		cp->core_time[1] = t;
	}
}
Esempio n. 30
0
static bool CheckTimer()
{
	if((OSTimeGet() - SONICDEVICE.oldmstime) > SONICDEVICE.mstime)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}