Beispiel #1
0
/*! \fn void threadIdle (void const *argument)
    \brief Thread definition for the idle thread.
    \param argument A pointer to the list of arguments.
*/
void threadIdle (void const *argument) 
{
	if (addTraceProtected("threadIdle start run") != TRACE_OK)
	{
		stop_cpu;
	}
	
  while (1) 
	{
		work();
		
		if (addTraceProtected("threadIdle yields") != TRACE_OK)
		{
			stop_cpu;
		}		
    osThreadYield();                                            // suspend thread

		// throttle mechanism in place to stop this thread from running if no other traces added but its own
		// if other work scheduled, this mechanism can be removed or adapted as necessary
		while (getTraceCounter() <= 3)
		{
			osThreadYield();             // suspend thread
		}
		
		if (addTraceProtected("threadIdle back from yield") != TRACE_OK)
		{
			stop_cpu;
		}
		
  }
}
Beispiel #2
0
/*! \fn void task0(void)
    \brief Toggle LED #0
*/
void task0(void)
{ 
  LED_blink(LED0);
	if (addTraceProtected("thread0 flips LED") != TRACE_OK)
	{
		stop_cpu;
	}		
}
/*! 
    \brief Perform any work scheduled for the background
*/
void work(void)
{ 
	/// Print trace information
	dumpTraceProtected();
	if (addTraceProtected("threadIdle dumped trace") != TRACE_OK)
	{
		stop_cpu;
	}
}
Beispiel #4
0
/*! \fn int Terminate_thread0 (void) 
    \brief Terminating thread0
		\return 0=successful; -1=failure
*/
int Terminate_thread0 (void) 
{	
	if (addTraceProtected("thread0 terminate attempt") != TRACE_OK)
	{
		stop_cpu;
	}		
	
	if (osThreadTerminate(tid_thread0) != osOK)
	{
		if (addTraceProtected("could not terminate thread0") != TRACE_OK)
		{
			stop_cpu;
		}			
		return(-1);
	}

  return(0);
}
Beispiel #5
0
/*! \fn void thread0 (void const *argument)
    \brief Thread definition for thread 0.
    \param argument A pointer to the list of arguments.
*/
void thread0 (void const *argument) 
{
	
	if (addTraceProtected("thread0 start run") != TRACE_OK)
	{
		stop_cpu;
	}
	
  while (1) 
	{	
		
		if (addTraceProtected("thread0 take sem0 attempt") != TRACE_OK)
		{
			stop_cpu;
		}			
    if ( osSemaphoreWait (sid_Semaphore0, 0) != -1 ) // no wait
		{      
			if (addTraceProtected("thread0 take sem0 success") != TRACE_OK)
			{
				stop_cpu;
			}	
			
			task0(); // thread code 
			count1Sec();
			task0();
			
			if (addTraceProtected("thread0 set priority to osPriorityLow") != TRACE_OK)
			{
				stop_cpu;
			}			
			osThreadSetPriority(osThreadGetId(), osPriorityLow);
							
			
			if (addTraceProtected("thread0 yields") != TRACE_OK)
			{
				stop_cpu;
			}	
			osThreadYield();  // suspend thread			
				
			if (addTraceProtected("thread0 release sem0 attempt") != TRACE_OK)
			{
				stop_cpu;
			}				
			if (osSemaphoreRelease (sid_Semaphore0) != osOK)
			{
				if (addTraceProtected("thread0 release sem0 fail") != TRACE_OK)
				{
					stop_cpu;
				}						
			}
			else
			{
				if (addTraceProtected("thread0 release sem0 success") != TRACE_OK)
				{
					stop_cpu;
				}					
			}
			
		}
		else
		{
			if (addTraceProtected("thread0 take sem0 fail") != TRACE_OK)
			{
				stop_cpu;
			}				
		}
		
		if (addTraceProtected("thread0 set priority to osPriorityLow") != TRACE_OK)
		{
			stop_cpu;
		}			
		osThreadSetPriority(osThreadGetId(), osPriorityLow);
		    
		
		if (addTraceProtected("thread0 yields") != TRACE_OK)
		{
			stop_cpu;
		}	
    osThreadYield();  // suspend thread
		
		if (addTraceProtected("thread0 back from yield") != TRACE_OK)
		{
			stop_cpu;
		}		
		
		if (addTraceProtected("thread0 delete sem0") != TRACE_OK)
		{
			stop_cpu;
		}				
		if (Delete_Semaphore0() != 0)
		{
			stop_cpu;
		}			
				
    // This should terminate the current thread0 thread		
		if (Terminate_thread0() != 0)
		{
			stop_cpu;		
		}
		
  }
}
Beispiel #6
0
/*! 
    \brief Thread definition for thread 2.
    \param argument A pointer to the list of arguments.
*/
void thread2 (void const *argument) 
{
  if (addTraceProtected("thread2 start run") != TRACE_OK)
	{
		stop_cpu;
	}
	
  while (1) 
	{		
		if (addTraceProtected("thread2 take sem0 attempt") != TRACE_OK)
		{
			stop_cpu;
		}		
    if ( osSemaphoreWait (sid_Semaphore0, osWaitForever) != -1 ) // wait forever
		{					 
			if (addTraceProtected("thread2 take sem0 success") != TRACE_OK)
			{
				stop_cpu;
			}	
			
			task2(); // thread code
			count1Sec();
			task2();
			
			if (addTraceProtected("thread2 release sem0 attempt") != TRACE_OK)
			{
				stop_cpu;
			}				
			if (osSemaphoreRelease (sid_Semaphore0) != osOK)
			{
				if (addTraceProtected("thread2 release sem0 fail") != TRACE_OK)
				{
					stop_cpu;
				}						
			}
		}
		else
		{
			if (addTraceProtected("thread2 take sem0 fail") != TRACE_OK)
			{
				stop_cpu;
			}				
		}

		if (addTraceProtected("thread2 set priority to osPriorityBelowNormal") != TRACE_OK)
		{
			stop_cpu;
		}		
		osThreadSetPriority(osThreadGetId(), osPriorityBelowNormal);
		
		if (addTraceProtected("thread2 yields") != TRACE_OK)
		{
			stop_cpu;
		}		
    osThreadYield();                                            // suspend thread
		
		if (addTraceProtected("thread2 back from yield") != TRACE_OK)
		{
			stop_cpu;
		}
		
		// This should terminate the current thread2 thread		
		if (Terminate_thread2() != 0)
		{
			stop_cpu;		
		}
		
  }
}