Вроде все

This commit is contained in:
2022-01-30 18:19:29 +03:00
parent 9e29d3fb02
commit 58522af90f

View File

@@ -19,6 +19,8 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
#include "gyro_mes.h"
#include "stdio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@@ -73,7 +75,6 @@ void StartCalcsUartTask(void const * argument);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint8_t data_in[6] = {0};
uint8_t data_out[6] = {0};
uint8_t flag_receive = 0;
uint8_t flag_cs = 0;
@@ -88,7 +89,7 @@ xSemaphoreHandle semaphoreBin;
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t data_in[6] = {0};
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
@@ -149,12 +150,15 @@ int main(void)
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
int8_t res = comand_mes(data_in, sizeof(data_in) / sizeof(data_in[0]));
if(res != 0) return res;
while (1)
{
flag_cs = 1;
CS1_ON();
HAL_SPI_Transmit_DMA(&hspi1, data_in, sizeof(data_in));
while(!flag_receive) {
HAL_Delay(1);
}
CS1_OFF();
flag_receive = 0;
@@ -162,6 +166,7 @@ int main(void)
CS2_ON();
HAL_SPI_Transmit_DMA(&hspi1, data_in, sizeof(data_in));
while(!flag_receive) {
HAL_Delay(1);
}
CS2_OFF();
flag_receive = 0;
@@ -169,6 +174,7 @@ int main(void)
CS3_ON();
HAL_SPI_Transmit_DMA(&hspi1, data_in, sizeof(data_in));
while(!flag_receive) {
HAL_Delay(1);
}
flag_receive = 0;
/* USER CODE END WHILE */
@@ -377,30 +383,23 @@ void StartCalcsUartTask(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
struct sData data;
for(;;)
{
xSemaphoreTake(semaphoreBin, portMAX_DELAY);
if(flag_cs == 1) {
if(xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) {
//ЗАПИСЬ ДЛЯ ПЕРВОГО ГИРОСКОПА
HAL_UART_Transmit_DMA(&huart1, data_in, sizeof(data_in));
if(xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) {
int8_t res = status_mes(data_out, sizeof(data_out) / sizeof(data_out), &data);
if(res == 0)
{
char str[30];
sprintf (str, "Gyro%u! Temp = %i; Rate = %i.", flag_cs, data.temp, data.rate);
HAL_UART_Transmit_DMA(&huart1, (uint8_t*)str, sizeof(str));
}
xSemaphoreGive(mutex);
}
else if(flag_cs == 2) {
if(xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE ) {
//ЗАПИСЬ ДЛЯ ВТОРОГО ГИРОСКОПА
HAL_UART_Transmit_DMA(&huart1, data_in, sizeof(data_in));
}
xSemaphoreGive(mutex);
}
else if(flag_cs == 3) {
if(xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE ) {
//ЗАПИСЬ ДЛЯ ВТОРОГО ГИРОСКОПА
HAL_UART_Transmit_DMA(&huart1, data_in, sizeof(data_in));
}
xSemaphoreGive(mutex);
}
xSemaphoreGive(mutex);
osDelay(1);
}
/* USER CODE END 5 */