Difference: TerminalIO (26 vs. 27)

Revision 272022-01-02 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
%DASHBOARD{ section="banner"
Line: 26 to 26
  emit and key can block the calling thread, if the buffer is full (emit) or empty (key). The other threads are not affected (no busy-wait). The incoming characters (Rx) are buffered in a RTOS message queue, outgoing characters are also buffered.
Changed:
<
<
Default console is USB-CDC, but if you press button SW2 on reset, the console is redirected to the UART RS-232 serial device (for details see mecrisp.s). If you press button SW1 on reset, the console is redirected to the Bluetooth LE Cable Replacement Service.
>
>
Default console is USB-CDC, but if you press button SW2 on reset, the console is redirected to the UART RS-232 serial device (for details see mecrisp.s). If you press button SW1 on reset, the console is redirected to the Bluetooth LE Cable Replacement Service.
 
emit         ( char -- )        Emits a character
key          ( -- char )        Waits for and fetches the pressed key
Line: 170 to 170
 

Added:
>
>

Some Sort of SIGINT

  https://en.wikipedia.org/wiki/Signal_(IPC)#SIGINT
Changed:
<
<
>
>
 The SIGINT signal is sent to a process by its controlling terminal when a user wishes to interrupt the process. This is typically initiated by pressing Ctrl+C, but on some systems, the "delete" character or "break" key can be used.
Added:
>
>

You do not have always a reset button to restart a hanging console, power cycle is not convenient in most cases. There is now an assert for ^C, UART errors (FIFO, interruption) throw an assert too.

If you want something similar to an SIGINT, replace the assert ASSERT_nonfatal() with osThreadFlagsSet() or osEventFlagsSet() to inform your application thread. uart.c

/**
  * @brief
  * 	Function implementing the UART Rx thread.
  * @param
  * 	argument: Not used
  * @retval
  * 	None
  */
static void UART_RxThread(void *argument) {
	osStatus_t status;

	osMutexAcquire(UART_MutexID, osWaitForever);
	// wait for the first Rx character
	if (HAL_UART_Receive_IT(&huart1, &UART_RxBuffer, 1) != HAL_OK) {
		// something went wrong
		Error_Handler();
	}
	osMutexRelease(UART_MutexID);

	// Infinite loop
	for(;;) {
		// blocked till a character is received
		status = osThreadFlagsWait(UART_CHAR_RECEIVED, osFlagsWaitAny, osWaitForever);
		ASSERT_nonfatal(UART_RxBuffer != 0x03, ASSERT_UART_SIGINT, 0) // ^C character abort
		// put the received character into the queue
		status = osMessageQueuePut(UART_RxQueueId, &UART_RxBuffer, 0, 100);
		if (status != osOK) {
			// can't put char into queue
			Error_Handler();
		}
		// receive the next character
		osMutexAcquire(UART_MutexID, osWaitForever);
		status = HAL_UART_Receive_IT(&huart1, &UART_RxBuffer, 1);
		osMutexRelease(UART_MutexID);
		if (status != osOK) {
			// can't receive char
			Error_Handler();
		}
	}
}
 

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback