示例#1
0
/**
 * @brief	Write the next message in flash to the main text box
 * @param	None
 * @retval	None
 */
void guiCan1WriteNextCanMessageFromFlashToMainTextBox(const uint32_t constStartFlashAddress, uint32_t currentWriteAddress,
											 CANSettings* pSettings, SemaphoreHandle_t* pSemaphore)
{
	CANMessage message = {0};

	/* Try to take the settings semaphore */
	if (*pSemaphore != 0 && xSemaphoreTake(*pSemaphore, 100) == pdTRUE)
	{
		/* Get the ID */
		uint8_t* pData = (uint8_t*)&message.id;
		SPI_FLASH_ReadBufferDMA(pData, pSettings->readAddress, sizeof(message.id), 100);
		pSettings->readAddress += sizeof(message.id);

		/* Get the DLC */
		pData = (uint8_t*)&message.dlc;
		SPI_FLASH_ReadBufferDMA(pData, pSettings->readAddress, sizeof(message.dlc), 100);
		pSettings->readAddress += sizeof(message.dlc);

		/* Get the amount of data that is specified in the DLC */
		pData = (uint8_t*)&message.data;
		SPI_FLASH_ReadBufferDMA(pData, pSettings->readAddress, message.dlc, 100);
		pSettings->readAddress += message.dlc;

		/* Give back the semaphore now that we are done */
		xSemaphoreGive(*pSemaphore);

		/* Insert the message in the message list */
		prvInsertMessageInList(message);

		/* Update the display */
		prvWriteMessageListToDisplay();
	}
}
示例#2
0
/**
 * @brief	Read settings from SPI FLASH
 * @param	None
 * @retval	None
 */
static ErrorStatus prvReadSettingsFromSpiFlash()
{
	/* Read to a temporary settings variable */
	CANSettings settings = {0};
	if (SPI_FLASH_ReadBufferDMA((uint8_t*)&settings, FLASH_ADR_CAN1_SETTINGS, sizeof(CANSettings), 2000) == SUCCESS)
	{
		/* Check to make sure the data is reasonable */
		if (IS_CAN_CONNECTION(settings.connection) &&
			IS_CAN_TERMINATION(settings.termination) &&
			IS_CAN_BIT_RATE(settings.bitRate))
		{
			/* Try to take the settings semaphore */
			if (xSettingsSemaphore != 0 && xSemaphoreTake(xSettingsSemaphore, 100) == pdTRUE)
			{
				/* Copy to the real settings variable */
				memcpy(&prvCurrentSettings, &settings, sizeof(CANSettings));
				prvCurrentSettings.connection = CANConnection_Disconnected;
				prvCurrentSettings.termination = CANTermination_Disconnected;
				can1UpdateWithNewSettings();
				/* Give back the semaphore now that we are done */
				xSemaphoreGive(xSettingsSemaphore);
				return SUCCESS;
			}
			else
			{
				/* Something went wrong as we couldn't take the semaphore */
				return ERROR;
			}
		}
		else
			return ERROR;
	}
	else
		return ERROR;
}
示例#3
0
/**
 * @brief	Read settings from SPI FLASH
 * @param	None
 * @retval	None
 */
static ErrorStatus prvReadSettingsFromSpiFlash()
{
	/* Read to a temporary settings variable */
	UARTSettings settings = {0};
	if (SPI_FLASH_ReadBufferDMA((uint8_t*)&settings, FLASH_ADR_UART1_SETTINGS, sizeof(UARTSettings), 2000) == SUCCESS)
	{
		/* Check to make sure the data is reasonable */
		if (IS_UART_CONNECTION(settings.connection) &&
			IS_UART_BAUDRATE(settings.baudRate) &&
			IS_UART_POWER(settings.power) &&
			IS_UART_MODE_APP(settings.mode) &&
			IS_GUI_TEXT_FORMAT(settings.textFormat))
		{
			/* Try to take the settings semaphore */
			if (xSettingsSemaphore != 0 && xSemaphoreTake(xSettingsSemaphore, 100) == pdTRUE)
			{
				/* Copy to the real settings variable */
				memcpy(&prvCurrentSettings, &settings, sizeof(UARTSettings));
				prvCurrentSettings.power = UARTPower_5V;
				prvCurrentSettings.mode = UARTMode_TX_RX;
				uart1UpdateWithNewSettings();
				/* Give back the semaphore now that we are done */
				xSemaphoreGive(xSettingsSemaphore);
				return SUCCESS;
			}
			else
			{
				/* Something went wrong as we couldn't take the semaphore */
				return ERROR;
			}
		}
		else
			return ERROR;
	}
	else
		return ERROR;
}