// Function used to print a string in the terminal by other tasks
void echo (char *string, char Terminalbackup)
{
    INT8U backup_cnt = 0;
    INT8U i = 0;
    char backup[(CONSOLE_BUFFER_SIZE/2)];
	char *command_start = "echo ";
    char *command_end   = "\n\r";

    if (Terminalbackup == TRUE)
    {
    	backup_cnt = TerminalBackup(&backup[0]);
    }

    SetSilentMode(TRUE);
    while (*command_start)
    {
			if (OSQueuePost(USB, *command_start++) == BUFFER_UNDERRUN)
			{
			  // Problema: Estouro de buffer
			  OSCleanQueue(USB);
			}
    }

	while (*string)
    {
			if (OSQueuePost(USB, *string++) == BUFFER_UNDERRUN)
			{
			  // Problema: Estouro de buffer
			  OSCleanQueue(USB);
			}
    }

    while (*command_end)
    {
			if (OSQueuePost(USB, *command_end++) == BUFFER_UNDERRUN)
			{
			  // Problema: Estouro de buffer
			  OSCleanQueue(USB);
			}
    }

    if (Terminalbackup == TRUE)
    {
		for(i=0;i<backup_cnt;i++)
		{
			if (OSQueuePost(USB, backup[i]) == BUFFER_UNDERRUN)
			{
			  // Problema: Estouro de buffer
			  OSCleanQueue(USB);
			}
		}
    }
}
예제 #2
0
interrupt void serial_rx(void)
#endif
{
  // ************************
  // Entrada de interrupção
  // ************************
  OS_INT_ENTER();

  // Tratamento da interrupção
  (void)UART_STAT1;  /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
  (void)UART_CTRL3;  /* Leitura do registrador SCI1C3 para limpar o bit de paridade */    
  receive_byte = UART_DATA; /* Leitura dos dados recebidos */
  
  #if (NESTING_INT == 1)
  OS_ENABLE_NESTING();
  #endif  
  
  if (OSQueuePost(Serial, receive_byte) == BUFFER_UNDERRUN)
  {
    // Problema: Estouro de buffer
    OSCleanQueue(Serial);
  }
  
  // ************************
  // Interrupt Exit
  // ************************
  OS_INT_EXIT();  
  // ************************
}
예제 #3
0
interrupt void uart2_rx(void)
#endif
{
	// ************************
	// Entrada de interrupção
	// ************************
	OS_INT_ENTER();

	// Tratamento da interrupção
	(void) SCI2S1; /* Leitura do registrador SCIxS1 para analisar o estado da transmissão */
	(void) SCI2C3; /* Leitura do registrador SCIxC3 para limpar o bit de paridade */
	receive_byte2 = SCI2D; /* Leitura dos dados recebidos */

#if (NESTING_INT == 1)
	OS_ENABLE_NESTING();
#endif  

	if (OSQueuePost(Serial2, receive_byte2) == BUFFER_UNDERRUN)
	{
		// Problema: Estouro de buffer
		OSCleanQueue(Serial2);
	}

	// ************************
	// Interrupt Exit
	// ************************
	OS_INT_EXIT();
	// ************************
}
예제 #4
0
파일: tasks.c 프로젝트: barriquello/uFSM_OS
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();
	}
}
예제 #5
0
unsigned long USART0IntHandler(void *pvCBData,
        unsigned long ulEvent,
        unsigned long ulMsgParam,
        void *pvMsgData)
{
	char receive_byte;

	if ((ulEvent & UART_EVENT_RX) == UART_EVENT_RX)
	{
		receive_byte = xHWREGB(UART0_BASE + UART_012_D);

		if (slip_input_byte(receive_byte) == 1) OSSemPost(Contiki_Sem);
		//slip_input_byte(receive_byte);
		//OSSemPost(Contiki_Sem);

#if 0
		if (OSQueuePost(Serial0, receive_byte) == BUFFER_UNDERRUN)
		{
			// Problema: Estouro de buffer
			OSCleanQueue(Serial0);
		}
#endif
	}

	if ((ulEvent & UART_EVENT_TC) == UART_EVENT_TC)
	{
		if ((xHWREGB(UART0_BASE + UART_012_C2) & UART_EVENT_TC) == UART_EVENT_TC)
		{
			UARTIntDisable(UART0_BASE, UART_INT_TC);
			(void)OSSemPost(SerialTX0);
		}
	}

	// ************************
	// Interrupt Exit
	// ************************
	OS_INT_EXIT_EXT();
	// ************************

	return 0;
}
예제 #6
0
void rs485_rx_flush(void)
{
	OSCleanQueue(RS485_QUEUE);
}