예제 #1
0
파일: demo.c 프로젝트: igou/tx
void    thread_3_and_4_entry(ULONG thread_input)
{

UINT    status;


    /* This function is executed from thread 3 and thread 4.  As the loop
       below shows, these function compete for ownership of semaphore_0.  */
    while(1)
    {

        /* Increment the thread counter.  */
        if (thread_input == 3)
            thread_3_counter++;
        else
            thread_4_counter++;

        /* Get the semaphore with suspension.  */
        status =  tx_semaphore_get(&semaphore_0, TX_WAIT_FOREVER);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;

        /* Sleep for 2 ticks to hold the semaphore.  */
        tx_thread_sleep(2);

        /* Release the semaphore.  */
        status =  tx_semaphore_put(&semaphore_0);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;
    }
}
void __mg_os_time_delay (int ms)
{
#ifndef __NOUNIX__
    /* use select instead of usleep */
    struct timeval timeout;
    timeout.tv_sec=0;
    timeout.tv_usec=ms*1000;
    while (select (0, NULL, NULL, NULL, &timeout) < 0);
#elif defined (__UCOSII__)
    OSTimeDly (OS_TICKS_PER_SEC * ms / 1000);
#elif defined (__VXWORKS__) 
    taskDelay (sysClkRateGet() * ms / 1000);
#elif defined (__PSOS__) || defined (__ECOS__)
    struct timespec ts;
    ts.tv_sec = 0;
    ts.tv_nsec = ms * 1000000;
    nanosleep (&ts, NULL);
#elif defined (WIN32)
    void __stdcall Sleep (DWORD dwMilliSeconds);
    Sleep (ms);
#elif defined (__THREADX__)
    tx_thread_sleep (ms/10);
#elif defined (__NUCLEUS__)
    NU_Sleep (ms/10);
#elif defined (__OSE__)
    delay(ms);
#endif
}
예제 #3
0
void Slow_Thread_entry(ULONG thread_input)
{


	ULONG current_time;

	while(1)
	{
		/* Activity 5 - 12 timer-ticks *** critical section *** */

		/* Get the mutex with suspension */
		tx_mutex_get(&my_mutex, TX_WAIT_FOREVER);

		tx_thread_sleep(12);

		/* Release the mutex */
		tx_mutex_put(&my_mutex);

		/* Activity 6 - 8 timer-ticks */
		tx_thread_sleep(8);

		/* Activity 7 - 11 timer-ticks *** critical section *** */

		/* Get the mutex with suspension */
		tx_mutex_get(&my_mutex, TX_WAIT_FOREVER);

		tx_thread_sleep(11);

		/* Release the mutex */
		tx_mutex_put(&my_mutex);

		/* Activity 8 - 9 timer-ticks */
		tx_thread_sleep(9);

		current_time = tx_time_get();
		printf("Current Time: %5lu Slow_Thread finished a cycle¡­\n",
			current_time);

	}
}
예제 #4
0
파일: demo.c 프로젝트: igou/tx
void    thread_6_and_7_entry(ULONG thread_input)
{

UINT    status;


    /* This function is executed from thread 6 and thread 7.  As the loop
       below shows, these function compete for ownership of mutex_0.  */
    while(1)
    {

        /* Increment the thread counter.  */
        if (thread_input == 6)
            thread_6_counter++;
        else
            thread_7_counter++;

        /* Get the mutex with suspension.  */
        status =  tx_mutex_get(&mutex_0, TX_WAIT_FOREVER);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;

        /* Get the mutex again with suspension.  This shows
           that an owning thread may retrieve the mutex it
           owns multiple times.  */
        status =  tx_mutex_get(&mutex_0, TX_WAIT_FOREVER);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;

        /* Sleep for 2 ticks to hold the mutex.  */
        tx_thread_sleep(2);

        /* Release the mutex.  */
        status =  tx_mutex_put(&mutex_0);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;

        /* Release the mutex again.  This will actually 
           release ownership since it was obtained twice.  */
        status =  tx_mutex_put(&mutex_0);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;
    }
}
예제 #5
0
void Speedy_Thread_entry(ULONG thread_input)
{

	ULONG current_time;

	while (1)
	{
		/* Activity 1: 2 timer-ticks */
		tx_thread_sleep(2);

		/* Get the mutex with suspension */
		tx_mutex_get(&my_mutex, TX_WAIT_FOREVER);

		/* Activity 2: 5 timer-ticks *** critical section *** */
		tx_thread_sleep(5);

		/* Release the mutex */
		tx_mutex_put(&my_mutex);

		/* Activity 3: 4 timer-ticks */
		tx_thread_sleep(4);

		/* Get the mutex with suspension */
		tx_mutex_get(&my_mutex, TX_WAIT_FOREVER);

		/* Activity 4: 3 timer-ticks *** critical section *** */
		tx_thread_sleep(3);

		/* Release the mutex */
		tx_mutex_put(&my_mutex);

		current_time = tx_time_get();
		printf(" Current Time: %5lu Speedy_Thread finished a cycle¡­\n",
			current_time);

	}
}
예제 #6
0
/**
 * Delay for a number of milliseconds
 *
 * Processing of this function depends on the minimum sleep
 * time resolution of the RTOS.
 * The current thread sleeps for the longest period possible which
 * is less than the delay required, then makes up the difference
 * with a tight loop
 *
 * @return wwd_result_t : WWD_SUCCESS if delay was successful
 *                        : WICED_ERROR if an error occurred
 *
 */
wwd_result_t host_rtos_delay_milliseconds( uint32_t num_ms )
{
    if ( ( num_ms * SYSTICK_FREQUENCY / 1000 ) != 0 )
    {
        if ( ( tx_thread_sleep( (ULONG) ( num_ms * SYSTICK_FREQUENCY / 1000 ) ) ) != TX_SUCCESS )
        {
            return WWD_SLEEP_ERROR;
        }
    }
    else
    {
        uint32_t time_reference = host_platform_get_cycle_count( );
        int32_t wait_time       = (int32_t)num_ms * CPU_CLOCK_HZ / 1000;
        while ( wait_time > 0 )
        {
            uint32_t current_time = host_platform_get_cycle_count( );
            wait_time            -= (int32_t)( current_time - time_reference );
            time_reference        = current_time;
        }
    }

    return WWD_SUCCESS;
}
예제 #7
0
파일: demo.c 프로젝트: igou/tx
void    thread_0_entry(ULONG thread_input)
{

UINT    status;


    /* This thread simply sits in while-forever-sleep loop.  */
    while(1)
    {

        /* Increment the thread counter.  */
        thread_0_counter++;

        /* Sleep for 10 ticks.  */
        tx_thread_sleep(10);

        /* Set event flag 0 to wakeup thread 5.  */
        status =  tx_event_flags_set(&event_flags_0, 0x1, TX_OR);

        /* Check status.  */
        if (status != TX_SUCCESS)
            break;
    }
}