Ejemplo n.º 1
0
  int main()
{	
 PINSEL0 = 0x00000000;		// Reset all pins as GPIO
 PINSEL1 = 0x00000000;
 PINSEL2 = 0x00000000;
 Init_Peripherals();
	
	
	 
	UART0_SendStr("\t\tMailBox using Task Notification\n");

		xTaskCreate(vn1,"Notifier", 300 ,NULL, tskIDLE_PRIORITY + 1, NULL);//Task Creation
		xTaskCreate(vn2,"Notifier", 300 ,NULL, tskIDLE_PRIORITY + 1, NULL);//Task Creation
		xTaskCreate(vn3,"Notifier", 300 ,NULL, tskIDLE_PRIORITY + 1, NULL);//Task Creation
		xTaskCreate(vn4,"Notifier", 300 ,NULL, tskIDLE_PRIORITY + 1, NULL);//Task Creation
    	xTaskCreate(vnoticer,"Noticer", 300 ,NULL, tskIDLE_PRIORITY + 1, NULL);//Task Creation
	
		
		
		
		vTaskStartScheduler();  //Task Scheduling   					    
		
	while(1)//Never reaches this Part of the main
	{
	UART0_SendStr("\t\tMailBox Bypassed\n");
	}

}
Ejemplo n.º 2
0
  int main()
{	
 PINSEL0 = 0x00000000;		// Reset all pins as GPIO
 PINSEL1 = 0x00000000;
 PINSEL2 = 0x00000000;
 Init_Peripherals();
	
	 
	UART0_SendStr("\t\tCounting Semaphore\n");

	xSemaphore = xSemaphoreCreateCounting( 5, 5 );
		  
	 if( xSemaphore != NULL )
    {	UART0_SendStr("\tSemaphore Created\n");
        
											
xTaskCreate(vfork,"Philospher 1", 300 ,"P1", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 2", 300 ,"P2", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 3", 300 ,"P3", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 4", 300 ,"P4", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 5", 300 ,"P5", tskIDLE_PRIORITY + 1, NULL);//Task Creation
		
		vTaskStartScheduler();  //Task Scheduling   					    
     }
		
	while(1)//Never reaches this Part of the main
	{UART0_SendStr("\t\tSemaphore not Created\n");	}

}
Ejemplo n.º 3
0
void vnoticer( void * pvParameters )
 {		 
  uint32_t ulNotifiedValue=0x01;

    while(1)
    {	
	
      if( xTaskNotifyWait( 0x00,0xffff,&ulNotifiedValue,1000 )==pdTRUE)  
 {
        
	
		if( ( ulNotifiedValue | 0x01 ) == 0x01 )	   //checking if the received message is same as the sent
  {  UART0_SendStr("Received   MSG from N1 \n");	}

       else if( ( ulNotifiedValue | 0x02 ) == 0x02 )
  {  UART0_SendStr("Received   MSG from N2\n");		}
	   	 
		else if( ( ulNotifiedValue | 0x03 ) == 0x03 )
  {  UART0_SendStr("Received   MSG from N3\n"); 	}
       
       else if( ( ulNotifiedValue | 0x04 ) == 0x04 )
  {   UART0_SendStr("Received   MSG from N4\n");  }

         else
  {   UART0_SendStr("Learn Programming !\n");}
  		
}
		 
else
{ UART0_SendStr("No Notice\n"); }
   
 }	 
}
Ejemplo n.º 4
0
void vn4( void * pvParameters )
{  

   xHandle = xTaskGetHandle( "Noticer" );
   
   while(1)
   {
   	vTaskDelay(7000);
	UART0_SendStr("N4 sent a MSG\n");
	xTaskNotify(xHandle, 0x04, eSetBits);
	
	
	}
}
Ejemplo n.º 5
0
void vn2( void * pvParameters )
{  

   xHandle = xTaskGetHandle( "Noticer" );
   
   while(1)
   {
   	vTaskDelay(5000);
	UART0_SendStr("N2 sent a Message\n");
	xTaskNotify(xHandle, 0x02, eSetBits);
	
	
	}
}
Ejemplo n.º 6
0
void vfork( void * pvParameters )
{	 
	int i; 											//For ith Fork
	const unsigned char* str;						//Pointer for the passed Parameter
	str = ( const unsigned char * ) pvParameters; 
				 
				
	//Assignment of forks available on the basis of name of Philospher
	if(str[1]=='1')
	{i=0;}
	if(str[1]=='2')
	{i=1;}
	if(str[1]=='3')
	{i=2;}			
	if(str[1]=='4')
	{i=3;}
	if(str[1]=='5')
	{i=4;}
		 
	while(1)
	{  
	//Waits for 1000 ticks for forks to be avaliable
	//If available checks if the fork is adjacent(Right) or not
	if(( xSemaphoreTake( xSemaphore, 1000 ) == pdTRUE )&&(forks_avail[i]==0))		  	{
		forks_avail[i]=1;
					
		 
		UART0_SendStr(&str[0]);	
		UART0_SendStr(":Right fork obtained\n");
					 	
	if(( xSemaphoreTake( xSemaphore, 2000 ) == pdTRUE )&&(forks_avail[(i+1)%5]==0))
	{ //Waits for 2000 ticcks for Left fork to be available
								   
			forks_avail[(i+1)%5]=1;
										
			UART0_SendStr(&str[0]);
			UART0_SendStr(":Left fork obtained Eating :)\n");
										
			vTaskDelay(2000);
			UART0_SendStr(&str[0]);
			UART0_SendStr(":Ate \n");
		   		 
			xSemaphoreGive(xSemaphore);
			xSemaphoreGive(xSemaphore);
			forks_avail[i]=0;	 
		 	forks_avail[(i+1)%5]=0;
		    UART0_SendStr(&str[0]);
			UART0_SendStr(":Thinking \n");
			vTaskDelay(3000);
}

		else
		{ 		  
	    UART0_SendStr(&str[0]);
		UART0_SendStr(":Returned Right fork:( \n");  
		xSemaphoreGive(xSemaphore);
		forks_avail[i]=0;
		}
				  
	}

   else
	   {				    
	   UART0_SendStr(&str[0]);
	   UART0_SendStr(":Hungry\n"); 
	   vTaskDelay(3000);
		}
		}
 }
Ejemplo n.º 7
0
/* description:	Initialize the motor,the motor can work in three diffrient mode
								posiotion,velocity,torque.this one is initialed to torque,modify
								the code if needed
//		function: void motor_init(void)
//			@param: 
//return value:	
*/
void motor_init(void)
{  
	static char message[32];
	uint8 err;
	sprintf(message, "velocity started:\r\n");
  UART0_SendStr (message);
	
	
	//get initial position step:0
	uint32 pos;
	err=GetPosition(&pos);
	if(err){showerr(err,0);}
  else{
	sprintf(message, "initial pos: %4d\r\n",pos);
  UART0_SendStr (message);
		}

	//	set homing mode step:1
	err=SetHomeMode(1);
  if(err){showerr(err,1);}
	
	//	set homing method step:2
	//	here the mean of homing is that
	//  to use the current position as homing position
	err=Dnld8(OBJID_HOME_METHOD, 0, (uint8)35,2);
  if(err){showerr(err,2);} 
	 
	//	shutdown step:3
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x06,3);
  if(err){showerr(err,3);}
	
	//wait at least 3ms to avoid the Priority inversion
   sysDelayNS(3);
	 
	//	switch on step:4
  err=Dnld16(OBJID_CONTROL, 0, (uint16)0x07,4);
  if(err){showerr(err,4);}
	
	//	enable operation step:5
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x0f,5);
  if(err){showerr(err,5);}
	
	//	 start home mode step:6
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x1f,6);
  if(err){showerr(err,6);}
	 
	//	 home mode active step:7
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x1f,7);
  if(err){showerr(err,7);}
   
   sysDelayNS(10);
	 
	//get current position step:8
	err=GetPosition(&pos);
	if(err){showerr(err,8);}
	else{
	sprintf(message, "current pos: %4d\r\n",pos);
  UART0_SendStr (message);
		}
	//===================================
    
  //	set position mode step:9
	err=SetPositionMode(1);
  if(err){showerr(err,9);}	
	
  //	shutdown step:10
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x06,2);
  if(err){showerr(err,10);}
  
	//	switch on step:11
  err=Dnld16(OBJID_CONTROL, 0, (uint16)0x07,3);
  if(err){showerr(err,11);}
	
	//wait at least 3ms to avoid the Priority inversion
   sysDelayNS(3);

	//	enable operation step:12
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x0f,4);
  if(err){showerr(err,12);}

// 	while(1){;} //just for debug
}
Ejemplo n.º 8
0
static void showerr(uint8 err,uint8 step)
{ static char Err_message[32];
	sprintf(Err_message, "step:%2d err:%2d\r\n",step,err);
  UART0_SendStr (Err_message);
}