Пример #1
0
void CDC_Init(void)
{
	uint_8   error;
    g_send_size = 0;
    
  	// Create USB semaphore
  	if (OSSemCreate(0,&USB_Sem) != ALLOC_EVENT_OK)
    {
        while(1){};
    };
  	
  	// Cria uma fila de recepcao para a porta serial
  	if (OSQueueCreate(CONSOLE_BUFFER_SIZE, &USB) != ALLOC_EVENT_OK)
  	{
  		while(1){};
  	};	    
    
    UserEnterCritical();	
    #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H) || (defined _MCF51JE128_H)
     usb_int_dis();
    #endif
    
    /* Initialize the USB interface */
    SCGC2 |= SCGC2_USB_MASK;     /* Enables usb clock */
    
    error = USB_Class_CDC_Init(CONTROLLER_ID,USB_App_Callback,
                                NULL,USB_Notify_Callback);
    //if(error != USB_OK)
    /* Error initializing USB-CDC Class */
    
    UserExitCritical();
	#if (defined _MCF51MM256_H) || (defined _MCF51JE256_H) || (defined _MCF51JE128_H)
     usb_int_en();
    #endif
}
Пример #2
0
void Keyboard_Handler(void)
{
	// task setup
	INT16U ADSample = 0;
	INT8U Key = NO_KEY;

	// Initialize ACM keyboard for channel 1  
	ACM_Keyb_Setup(Enable, Enable, Rising, ACM_CHANNEL1);

	if (OSSemCreate(0, &sKeyboard) != ALLOC_EVENT_OK)
	{
		while (1){};
	};

	if (OSQueueCreate(&KeyboardBuffer, 64, &qKeyboard) != ALLOC_EVENT_OK)
	{
		while (1){};
	};

	// task main loop
	for (;;)
	{
		// Wait for a keyboard interrupt
		OSSemPend(sKeyboard, 0);
		DelayTask(50);

		// Converts the value of AD to discover the pressed key
		UserEnterCritical();
		ADSample = ADConvert(KEYB_CHANNEL);
		UserExitCritical();

		UserEnterCritical();
		ADSample += ADConvert(KEYB_CHANNEL);
		UserExitCritical();

		ADSample = ADSample >> 1;

		// Find out which key was pressed
		Key = FindKey(ADSample);

		// Copy the key to the keyboard buffer
		if (Key != NO_KEY)
		{
			if (OSQueuePost(qKeyboard, Key) == BUFFER_UNDERRUN)
			{
				// Buffer overflow
				OSCleanQueue(qKeyboard);
			}
		}

		// Enable interrupt to the next key detection
		DelayTask(200);
		ACMEnable();
	}
}
Пример #3
0
void GPSNET_RxApp(void)
{

   INT8U  ret = 0; 
       
   // task setup   
   if ((INT8U)OSQueueCreate(&PacketsBuffer,RFBufferSize,&Pkt) != ALLOC_EVENT_OK)
   {
      while(1){};
   }; 
      
   // task main loop
   for (;;)
   {
     
      // Wait event from APP layer, with or without timeout             
      ret = OSSemPend(SIGNAL_APP1, SIGNAL_TIMEOUT);      
      
      #if (defined BOOTLOADER_ENABLE) && (BOOTLOADER_ENABLE==1)       
      if(ret != TIMEOUT){      
      #endif
       
       acquireRadio();
       
       switch(app_packet.APP_Profile) 
       {
        case GENERAL_PROFILE:
          Decode_General_Profile();
          break;
          
        case LIGHTING_PROFILE:
          Decode_Lighting_Profile();
          break;
        
        #if (defined BOOTLOADER_ENABLE) && (BOOTLOADER_ENABLE==1)  
        case BULK_DATA_PROFILE:
          WBootloader_Handler();
          break;
        #endif
        
        default:
          break;
       }        
       releaseRadio();
      
      #if (defined BOOTLOADER_ENABLE) && (BOOTLOADER_ENABLE==1)       
      }else{          
        WBootloader_Handler_Timeout();         
      }
      #endif 

   }
}
Пример #4
0
void Keyboard_Handler(void)
{
   // task setup
   INT8U  key      = NO_KEY;
   INT32U read = 0;

   ButtonsInit();

   if (OSSemCreate(0,&sKeyboard) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     while(1){};
   };

   if (OSQueueCreate(64, &qKeyboard) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     while(1){};
   };

   // task main loop
   for (;;)
   {
      // Wait for a keyboard interrupt
      OSSemPend (sKeyboard,0);
      DelayTask(50);

      read = GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS);

      // Find out which key was pressed
      key = (INT8U)read;

      // Copy the key to the keyboard buffer
      if(key != NO_KEY)
      {
    	if (OSQueuePost(qKeyboard, key) == BUFFER_UNDERRUN)
        {
          // Buffer overflow
          OSQueueClean(qKeyboard);
        }
      }

      key = NO_KEY;
      DelayTask(200);
      // Enable interrupt to the next key detection
      GPIOIntEnable(BUTTONS_GPIO_BASE, ALL_BUTTONS);
   }
}
Пример #5
0
void Init_UART0(int baud, int buffer_size)
{
	xtEventCallback UART0_INT_HANDLE = USART0IntHandler;

	// Enable GPIO and UART Clock
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	// Remap UART pin to GPIO Port UART0_RX --> PA2 UART0_TX --> PA1
	xSPinTypeUART(UART0RX, PA1);
	xSPinTypeUART(UART0TX, PA2);

	// Set UART clock
	SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2);

	// Disable UART Receive/Transmit
	UARTDisable(UART0_BASE, UART_TX | UART_RX);

	// Configure UART Baud 115200
	UARTConfigSet(UART0_BASE, baud, UART_CONFIG_SAMPLE_RATE_DEFAULT | UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1);

	if (OSSemCreate(0, &SerialTX0) != ALLOC_EVENT_OK)
	{
	  // Oh Oh
	  // Não deveria entrar aqui !!!
	  while(1){};
	};

	// Só cria fila se for passado um tamanho maior que 0
	if (buffer_size){
		if (OSQueueCreate(buffer_size, &Serial0) != ALLOC_EVENT_OK)
		{
		  // Oh Oh
		  // Não deveria entrar aqui !!!
		  while(1){};
		};
	}

	UARTIntEnable(UART0_BASE, UART_INT_R);
	UARTIntCallbackInit(UART0_BASE, UART0_INT_HANDLE);

	// Enable UART Receive and Transmit
	UARTEnable(UART0_BASE, UART_TX | UART_RX);

	xIntEnable(28);
}
Пример #6
0
void UART_init(INT8U priority)
{  
  UART_CTRL1 = 0x12;               /* Configure the SCI */ 
  /* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */  
  UART_CTRL3 = 0x00;               /* Disable error interrupts */ 
  /* SCI1S2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,??=0,RAF=0 */
  UART_STAT2 = 0x00;                
  /* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
  UART_CTRL2 = 0x00;               /* Disable all interrupts */ 
  
  // 0x4E = 19200 bauds at 24Mhz /////  0x52 = 19200 bauds at 25.33Mhz
  // 0x20 = 38400 bauds at 24Mhz /////  0x29 = 38400 bauds at 25.33Mhz
  // 0x16 = 57600 bauds at 24Mhz /////  0x1B = 57600 bauds at 25.33Mhz
  UART_BDH = 0x00;   /* Set high divisor register (enable device) */
  UART_BDL = 0x1B;   /* Set low divisor register (enable device) */        /* Configure the SCI */ 
  
  /* SCI1C3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */
  UART_CTRL3 |= 0x0F;                      /* Enable error interrupts */
  //SCI1C2 |= ( SCI1C2_TE_MASK | SCI1C2_RE_MASK | SCI1C2_RIE_MASK); /*  Enable transmitter, Enable receiver, Enable receiver interrupt */
  UART_CTRL2 = 0x2C;
  
  (void)UART_STAT1;    /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
  (void)UART_STAT2;    /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
  (void)UART_CTRL3;    /* Leitura do registrador SCI1C3 para limpar o bit de paridade */  

  // Cria um mutex com contador = 1, informando que o recurso está disponível
  // após a inicialização
  // Prioridade máxima a acessar o recurso = priority
  if (OSMutexCreate(&SerialResource,priority) != ALLOC_EVENT_OK)
  {
    while(1){};
  }  
  
  if (OSSemCreate(0, &SerialTX) != ALLOC_EVENT_OK)
  {
    while(1){};
  }  
  
  if (OSQueueCreate(&SerialPortBuffer,SERIALPORT_BUFFERSIZE, &Serial) != ALLOC_EVENT_OK)
  {
    while(1){};
  } 
  
}
Пример #7
0
void Init_UART2(void)
{
	xtEventCallback UART2_INT_HANDLE = USART2IntHandler;

	// Enable GPIO and UART Clock
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

	// Remap UART pin to GPIO Port UART0_RX --> PA2 UART0_TX --> PA1
	xSPinTypeUART(UART2RX, PE23);
	xSPinTypeUART(UART2TX, PE22);

	// Set UART clock
	SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2);

	// Disable UART Receive/Transmit
	UARTDisable(UART2_BASE, UART_TX | UART_RX);

	// Configure UART Baud 115200
	UARTConfigSet(UART2_BASE, 9600, UART_CONFIG_SAMPLE_RATE_DEFAULT | UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1);

	if (OSSemCreate(0, &SerialTX2) != ALLOC_EVENT_OK)
	{
	  // Oh Oh
	  // Não deveria entrar aqui !!!
	  while(1){};
	};

	if (OSQueueCreate(128, &Serial2) != ALLOC_EVENT_OK)
	{
	  // Oh Oh
	  // Não deveria entrar aqui !!!
	  while(1){};
	};

	UARTIntEnable(UART2_BASE, UART_INT_R);
	UARTIntCallbackInit(UART2_BASE, UART2_INT_HANDLE);

	// Enable UART Receive and Transmit
	UARTEnable(UART2_BASE, UART_TX | UART_RX);

	xIntEnable(30);
}
Пример #8
0
void Terminal(void)
{
	char data;

   if (OSSemCreate(0,&sUART) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     BlockTask(th6);
   };

   if (OSMutexCreate(&mutexTx,6) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     BlockTask(th6);
   };

   if (OSQueueCreate(64, &qUART) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
	 BlockTask(th6);
   };

	//
	// Enable the peripherals used by this example.
	// The UART itself needs to be enabled, as well as the GPIO port
	// containing the pins that will be used.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Configure the GPIO pin muxing for the UART function.
	// This is only necessary if your part supports GPIO pin function muxing.
	// Study the data sheet to see which functions are allocated per pin.
	// TODO: change this to select the port/pin you are using
	//
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);

	//
	// Since GPIO A0 and A1 are used for the UART function, they must be
	// configured for use as a peripheral function (instead of GPIO).
	// TODO: change this to match the port/pin you are using
	//
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	//
	// Configure the UART for 115,200, 8-N-1 operation.
	// This function uses SysCtlClockGet() to get the system clock
	// frequency.  This could be also be a variable or hard coded value
	// instead of a function call.
	//
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
						(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
						 UART_CONFIG_PAR_NONE));

	UARTFIFODisable(UART0_BASE);

	//
	// Enable the UART interrupt.
	//
	ROM_IntEnable(INT_UART0);
	ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Put a character to show start of example.  This will display on the
    // terminal.
    //
    UARTPutString(UART0_BASE, "Iniciou!\n\r\n\r");

    while(1)
    {
    	if(!OSQueuePend(qUART, (INT8U*)&data, 0))
    	{
    		if (data != 13)
    		{
    			UARTPutChar(UART0_BASE, data);
    		}else
    		{
    			UARTPutString(UART0_BASE, "\n\r");
    		}
    	}
    }
}
Пример #9
0
void uart_init(INT8U uart, INT16U baudrate, INT16U buffersize, INT8U mutex, INT8U priority)
{
	
	/* check if UART 1 is already init */
	if(uart == 1 && Serial1 != NULL)
	{
		if(Serial1->OSEventAllocated == TRUE)
		{
			return;
		}
	}
	
	/* check if UART 2 is already init */
	if(uart == 2 && Serial2 != NULL)
	{
		if(Serial2->OSEventAllocated == TRUE)
		{
			return;
		}
	}
			
		// Configure UART 1
#if (ENABLE_UART1 == TRUE)
		if (uart == 1)
		{
			
			switch (CONF_UART1_PINS)
			{
				case UART1_PTA1_PTA2:
					SOPT3 = SOPT3 & 0xBF;
					break;
				case UART1_PTD6_PTD7:
					SOPT3 = SOPT3 | 0x40;
					break;
				default:
					break;
			}
			
			SCGC1 |= SCGC1_SCI1_MASK; /* Enables sci1 clock */
			
			/* set baudrate and parity type */
			uart1_set(baudrate,NONE);

			/* Cria um mutex com contador = 1, e prioridade máxima a acessar o recurso = priority */
		
			if (mutex == TRUE)
			{
				if (OSMutexCreate(&SerialResource1, priority) != ALLOC_EVENT_OK)
				{
					while (1){};
				}
			}

			if (OSSemCreate(0, &SerialTX1) != ALLOC_EVENT_OK)
			{
				while (1){};
			}

			if (OSQueueCreate(buffersize,&Serial1) != ALLOC_EVENT_OK)
			{
				while (1){};
			}
		}		
#endif

		// Configure UART 2
#if (ENABLE_UART2 == TRUE)
		if (uart == 2)
		{
			switch (CONF_UART2_PINS)
			{			
				case UART2_PTE5_PTE6:
					SOPT3 = SOPT3 & 0x7F;
					break;
				case UART2_PTF1_PTF2:
					SOPT3 = SOPT3 | 0x80;
					break;
				default:
					break;
			}
			
			SCGC1 |= SCGC1_SCI2_MASK; /* Enables sci2 clock */
			
			/* set baudrate and parity type */
			uart2_set(baudrate,NONE);

			/* Cria um mutex com contador = 1, e prioridade máxima a acessar o recurso = priority */
			if (mutex == TRUE)
			{
				if (OSMutexCreate(&SerialResource2, priority) != ALLOC_EVENT_OK)
				{
					while (1){};
				}
			}

			if (OSSemCreate(0, &SerialTX2) != ALLOC_EVENT_OK)
			{
				while (1){};
			}

			if (OSQueueCreate(buffersize,&Serial2) != ALLOC_EVENT_OK)
			{
				while (1){};
			}
		}
#endif

}
Пример #10
0
/* Function to start all GPSNET Tasks */   
void GPSNET_Init(void)
{  
  ////////////////////////////////////////////////////
  //     Initialize IEEE 802.15.4 radio mutex     ////
  ////////////////////////////////////////////////////  
  init_radio_resource(GPSNET_Mutex_Priority);
  
  
  ////////////////////////////////////////////////
  //     Initialize OS Network Services     //////
  ////////////////////////////////////////////////  
  if ((INT8U)OSQueueCreate(&RFBuffer,RFBufferSize,&RF) != ALLOC_EVENT_OK)
  {
    while(1){};              
  }

  /* GPSNET signals */
  if ((INT8U)OSSemCreate(0,&RF_RX_Event) != ALLOC_EVENT_OK)
  {
    while(1){};
  }
  
  if ((INT8U)OSSemCreate(0,&RF_TX_Event) != ALLOC_EVENT_OK)
  {
    while(1){};
  }  
  
  if ((INT8U)OSSemCreate(0,&MAC_Event) != ALLOC_EVENT_OK)
  {
    while(1){};
  } 
   
  
  #ifdef SIGNAL_APP1
    if ((INT8U)OSSemCreate(0,&(SIGNAL_APP1)) != ALLOC_EVENT_OK)
    {
      while(1){};
    } 
  #endif
  #ifdef SIGNAL_APP2
    if ((INT8U)OSSemCreate(0,&(SIGNAL_APP2)) != ALLOC_EVENT_OK)
    {
      while(1){};
    } 
  #endif 
  #ifdef SIGNAL_APP3
    if ((INT8U)OSSemCreate(0,&(SIGNAL_APP3)) != ALLOC_EVENT_OK)
    {
      while(1){};
    } 
  #endif 
  #ifdef SIGNAL_APP4
    if ((INT8U)OSSemCreate(0,&(SIGNAL_APP4)) != ALLOC_EVENT_OK)
    {
      while(1){};
    } 
  #endif 
  #ifdef SIGNAL_APP255
    if ((INT8U)OSSemCreate(0,&(SIGNAL_APP255)) != ALLOC_EVENT_OK)
    {
      while(1){};
    } 
  #endif    

     
  
    
  ////////////////////////////////////////////////
  //     Initialize Network Tasks           //////
  ////////////////////////////////////////////////
  if(InstallTask(&GPSNET_RF_Event,"RF Event Handler",GPSNET_RF_Event_StackSize,RF_EventHandlerPriority) != OK)
  {
     while(1){};
  }
  if(InstallTask(&GPSNET_MAC,"GPS MAC Handler",GPSNET_MAC_StackSize,MAC_HandlerPriority) != OK)
  {
     while(1){};
  }
  
  if(InstallTask(&GPSNET_NWK,"GPS NWK Handler",GPSNET_NWK_StackSize,NWK_HandlerPriority) != OK)
  {
     while(1){};
  }

}
Пример #11
0
void uart_init(INT8U uart, INT16U baudrate, INT16U buffersize, INT8U mutex, INT8U priority)
{
	
	/* check if UART 1 is already init */
	if(uart == 1 && Serial1 != NULL)
	{
		if(Serial1->OSEventAllocated == TRUE)
		{
			return;
		}
	}
	
	/* check if UART 2 is already init */
	if(uart == 2 && Serial2 != NULL)
	{
		if(Serial2->OSEventAllocated == TRUE)
		{
			return;
		}
	}
	
	if ((uart == 1) || (uart == 2))
	{						
		// Configure UART 1
#if (ENABLE_UART1 == TRUE)
		if (uart == 1)
		{
			
			switch (CONF_UART1_PINS)
			{
				case UART1_PTA1_PTA2:
					SOPT3 = SOPT3 & 0xBF;
					break;
				case UART1_PTD6_PTD7:
					SOPT3 = SOPT3 | 0x40;
					break;
				default:
					break;
			}
			
			SCGC1 |= SCGC1_SCI1_MASK; /* Enables sci1 clock */
			//SCI1C1 = 0x12; /* Configure the SCI */
			SCI1C1 = 0x00; /* Configure the SCI */
			/* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
			SCI1C3 = 0x00; /* Disable error interrupts */
			/* SCI1S2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,??=0,RAF=0 */
			SCI1S2 = 0x00;
			/* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
			SCI1C2 = 0x00; /* Disable all interrupts */

			// 0x270 = 2400  bauds at 24Mhz     // 0x138 = 4800  bauds at 24Mhz
			// 0x9C  = 9600  bauds at 24Mhz     // 0x4E  = 19200 bauds at 24Mhz
			// 0x20  = 38400 bauds at 24Mhz     // 0x16  = 57600 bauds at 24Mhz
			switch (baudrate)
			{
			case 2400:
				SCI1BD = 0x270;
				break;
			case 4800:
				SCI1BD = 0x138;
				break;
			case 9600:
				SCI1BD = 0x9C;
				break;
			case 19200:
				SCI1BD = 0x4E;
				break;
			case 38400:
				SCI1BD = 0x20;
				break;
			case 57600:
				SCI1BD = 0x16;
				break;
			default:
				break;
			}

			/* SCI1C3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */
			//SCI1C3 |= 0x0F; /* Enable error interrupts */
			SCI1C3 = 0x00; /* Enable error interrupts */
			//SCI1C2 |= ( SCI1C2_TE_MASK | SCI1C2_RE_MASK | SCI1C2_RIE_MASK); /*  Enable transmitter, Enable receiver, Enable receiver interrupt */
			SCI1C2 = 0x2C;

			(void) SCI1S1; /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
			(void) SCI1S2; /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
			(void) SCI1C3; /* Leitura do registrador SCI1C3 para limpar o bit de paridade */

			// Cria um mutex com contador = 1, informando que o recurso está disponível
			// após a inicialização
			// Prioridade máxima a acessar o recurso = priority
		
			if (mutex == TRUE)
			{
				if (OSMutexCreate(&SerialResource1, priority) != ALLOC_EVENT_OK)
				{
					while (1){};
				}
			}

			if (OSSemCreate(0, &SerialTX1) != ALLOC_EVENT_OK)
			{
				while (1){};
			}

			if (OSQueueCreate(&SerialPortBuffer1, buffersize,
					&Serial1) != ALLOC_EVENT_OK)
			{
				while (1){};
			}
		}		
#endif

		// Configure UART 2
#if (ENABLE_UART2 == TRUE)
		if (uart == 2)
		{
			switch (CONF_UART2_PINS)
			{			
				case UART2_PTE5_PTE6:
					SOPT3 = SOPT3 & 0x7F;
					break;
				case UART2_PTF1_PTF2:
					SOPT3 = SOPT3 | 0x80;
					break;
				default:
					break;
			}
			
			SCGC1 |= SCGC1_SCI2_MASK; /* Enables sci2 clock */
			SCI2C1 = 0x00; /* Configure the SCI */
			/* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
			SCI2C3 = 0x00; /* Disable error interrupts */
			/* SCI1S2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,??=0,RAF=0 */
			SCI2S2 = 0x00;
			/* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
			SCI2C2 = 0x00; /* Disable all interrupts */

			// 0x270 = 2400  bauds at 24Mhz     // 0x138 = 4800  bauds at 24Mhz
			// 0x9C  = 9600  bauds at 24Mhz     // 0x4E  = 19200 bauds at 24Mhz
			// 0x20  = 38400 bauds at 24Mhz     // 0x16  = 57600 bauds at 24Mhz
			switch (baudrate)
			{
			case 2400:
				SCI2BD = 0x270;
				break;
			case 4800:
				SCI2BD = 0x138;
				break;
			case 9600:
				SCI2BD = 0x9C;
				break;
			case 19200:
				SCI2BD = 0x4E;
				break;
			case 38400:
				SCI2BD = 0x20;
				break;
			case 57600:
				SCI2BD = 0x16;
				break;
			default:
				break;
			}

			/* SCI1C3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */
			SCI2C3 |= 0x0F; /* Enable error interrupts */
			//SCI1C2 |= ( SCI1C2_TE_MASK | SCI1C2_RE_MASK | SCI1C2_RIE_MASK); /*  Enable transmitter, Enable receiver, Enable receiver interrupt */
			SCI2C2 = 0x2C;

			(void) SCI2S1; /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
			(void) SCI2S2; /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
			(void) SCI2C3; /* Leitura do registrador SCI1C3 para limpar o bit de paridade */

			// Cria um mutex com contador = 1, informando que o recurso está disponível
			// após a inicialização
			// Prioridade máxima a acessar o recurso = priority
			if (mutex == TRUE)
			{
				if (OSMutexCreate(&SerialResource2, priority) != ALLOC_EVENT_OK)
				{
					while (1){};
				}
			}

			if (OSSemCreate(0, &SerialTX2) != ALLOC_EVENT_OK)
			{
				while (1){};
			}

			if (OSQueueCreate(&SerialPortBuffer2, buffersize,
					&Serial2) != ALLOC_EVENT_OK)
			{
				while (1){};
			}
		}
#endif
	}
}