int UART_Initialize() { usart1_mutex_id = osMutexCreate(osMutex(usart1_mutex)); usart2_mutex_id = osMutexCreate(osMutex(usart2_mutex)); usart6_mutex_id = osMutexCreate(osMutex(usart6_mutex)); if ((usart1_mutex_id == NULL) || (usart2_mutex_id == NULL) || (usart6_mutex_id == NULL)) { ERROR_MiscRTOS("Failed to create a uart mutex"); } /* UART2 configured as follow: - Word Length = 8 Bits - Stop Bit = One Stop bit - Parity = Disabled - BaudRate = 38400 baud - Hardware flow control disabled (RTS and CTS signals) */ handles[INDEX_USART2].Instance = USART2; handles[INDEX_USART2].Init.BaudRate = 38400; handles[INDEX_USART2].Init.WordLength = UART_WORDLENGTH_8B; handles[INDEX_USART2].Init.StopBits = UART_STOPBITS_1; handles[INDEX_USART2].Init.Parity = UART_PARITY_NONE; handles[INDEX_USART2].Init.HwFlowCtl = UART_HWCONTROL_NONE; handles[INDEX_USART2].Init.Mode = UART_MODE_TX_RX; handles[INDEX_USART2].Init.OverSampling = UART_OVERSAMPLING_16; if(HAL_UART_Init(&handles[INDEX_USART2]) != HAL_OK) { return -1; } initialized[INDEX_USART2] = 1; return 0; }
int ANTENNAS_Deploy() { dbg_printf("Starting antenna thread"); antenna_thread_id = osThreadCreate(osThread(antenna_thread), NULL); if (antenna_thread_id == NULL) { ERROR_MiscRTOS("No thread was created"); return -1; } else { return 0; } }
ssize_t UART_Write(enum UART_Uart uart, uint8_t * data, uint16_t size) { UART_HandleTypeDef *uartHandle; uartHandle = UART_GetHandle(uartToUsart(uart)); if (uartHandle == &handles[INDEX_USART1]) { if (osMutexWait(usart1_mutex_id, osWaitForever) != osOK) { ERROR_MiscRTOS("Mutex wait failed"); } } else if (uartHandle == &handles[INDEX_USART2]) { if (osMutexWait(usart2_mutex_id, osWaitForever) != osOK) { ERROR_MiscRTOS("Mutex wait failed"); } } else if (uartHandle == &handles[INDEX_USART6]) { if (osMutexWait(usart6_mutex_id, osWaitForever) != osOK) { ERROR_MiscRTOS("Mutex wait failed"); } } else { ERROR_NotImplemented("Invalid UART for mutex"); } HAL_UART_Transmit(uartHandle, data, size, 0xFFFF); if (uartHandle == &handles[INDEX_USART1]) { if (osMutexRelease(usart1_mutex_id) != osOK) { ERROR_MiscRTOS("Mutex release failed"); } } else if (uartHandle == &handles[INDEX_USART2]) { if (osMutexRelease(usart2_mutex_id) != osOK) { ERROR_MiscRTOS("Mutex release failed"); } } else if (uartHandle == &handles[INDEX_USART6]) { if (osMutexRelease(usart6_mutex_id) != osOK) { ERROR_MiscRTOS("Mutex release failed"); } } else { ERROR_NotImplemented("Invalid UART for mutex"); } return size; }