Пример #1
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_arch_sem_wait
 *---------------------------------------------------------------------------*
 * Description:
 *      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.
 * Inputs:
 *      sys_sem_t sem           -- Semaphore to wait on
 *      u32_t timeout           -- Number of milliseconds until timeout
 * Outputs:
 *      u32_t                   -- Time elapsed or SYS_ARCH_TIMEOUT.
 *---------------------------------------------------------------------------*/
u32_t sys_arch_sem_wait( sys_sem_t *pxSemaphore, u32_t ulTimeout ) {
	BT_u32 ulStartTime, ulEndTime, ulElapsed;
	BT_u32 ulReturn;

	ulStartTime = BT_GetKernelTick();

	if( ulTimeout != 0UL ) {
		if(BT_PendMutex( *pxSemaphore, ulTimeout) == BT_TRUE ) {
			ulEndTime = BT_GetKernelTick();
			ulElapsed = (ulEndTime - ulStartTime);
			ulReturn = ulElapsed;
		}
		else {
			ulReturn = SYS_ARCH_TIMEOUT;
		}
	}
	else {
		BT_PendMutex( *pxSemaphore, 0 );
		ulEndTime = BT_GetKernelTick();
		ulElapsed = ( ulEndTime - ulStartTime );

		if( ulElapsed == 0UL ) {
			ulElapsed = 1UL;
		}

		ulReturn = ulElapsed;
	}

	return ulReturn;
}
Пример #2
0
BT_ERROR BT_kPrint(const char *format, ... ) {
	va_list ap;

#ifndef BT_CONFIG_KERNEL_NONE

#ifdef BT_CONFIG_SYSLOG_SYSTICK
	BT_TICK oTicks = BT_GetKernelTick();
	bt_printf("[%5d.%03d] : ", oTicks / 1000, oTicks % 1000);
#else
	BT_u64 gt 	= BT_GetGlobalTimer();
	BT_u32 rate = BT_GetGlobalTimerRate();

	bt_printf("[%5d.%06d] : ", (BT_u32) (gt / (BT_u64)rate), (BT_u32) ((1000000 * (gt % (BT_u64)rate)) / rate ));
#endif

#endif

	va_start(ap, format);
	bt_kvprintf(format, bt_fputc, BT_GetStdout(), 10, ap);
	va_end(ap);

#ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_CR
	bt_printf("\n");
#endif
#ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_LF
	bt_printf("\r");
#endif
#ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_CRLF
	bt_printf("\n\r");
#endif
#ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_LFCR
	bt_printf("\r\n");
#endif
	return BT_ERR_NONE;
}
Пример #3
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_arch_mbox_fetch
 *---------------------------------------------------------------------------*
 * Description:
 *      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.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void **msg              -- Pointer to pointer to msg received
 *      u32_t timeout           -- Number of milliseconds until timeout
 * Outputs:
 *      u32_t                   -- SYS_ARCH_TIMEOUT if timeout, else number
 *                                  of milliseconds until received.
 *---------------------------------------------------------------------------*/
u32_t sys_arch_mbox_fetch( sys_mbox_t *pxMailBox, void **ppvBuffer, u32_t ulTimeOut ) {
	void *pvDummy;
	BT_TICK ulStartTime, ulEndTime, ulElapsed;
	BT_u32 ulReturn;

	ulStartTime = BT_GetKernelTick();

	if( NULL == ppvBuffer ) {
		ppvBuffer = &pvDummy;
	}


	if( ulTimeOut != 0UL ) {
		if( BT_TRUE == BT_QueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut ) ) {
			ulEndTime = BT_GetKernelTick();
			ulElapsed = ( ulEndTime - ulStartTime );

			ulReturn = ulElapsed;
		}
		else {
			/* Timed out. */
			*ppvBuffer = NULL;
			ulReturn = SYS_ARCH_TIMEOUT;
		}
	}
	else {
		while( BT_TRUE != BT_QueueReceive( *pxMailBox, &( *ppvBuffer ), 0 ) );
		ulEndTime = BT_GetKernelTick();
		ulElapsed = ( ulEndTime - ulStartTime );

		if( ulElapsed == 0UL ) {
			ulElapsed = 1UL;
		}

		ulReturn = ulElapsed;
	}

	return ulReturn;
}
Пример #4
0
u32_t sys_now(void) {
	return BT_GetKernelTick();
}