From 32be39611ed4dd3aeb16c6d483a574f81a5a3653 Mon Sep 17 00:00:00 2001 From: mmi Date: Wed, 4 Oct 2017 10:00:15 +0000 Subject: [PATCH] Fixed a display error display has now a refresh timer to totally refresh the display contents (to prevent EMC issues) Fixed PCBA names git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@229 05563f52-14a8-4384-a975-3d1654cca0fa --- .../0 - Code/HAL/inc/MAX5715.h | 34 +++++----- .../0 - Code/Platform/src/PCBA.c | 8 +-- .../0 - Code/hsb-mrts/inc/Display.h | 20 +++++- .../0 - Code/hsb-mrts/src/Display.c | 65 +++++++++++++++---- .../0 - Code/hsb-mrts/src/main.c | 16 ++--- .../0 - Code/hsb-mrts/src/stm32f10x_it.c | 3 + 6 files changed, 103 insertions(+), 43 deletions(-) diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/MAX5715.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/MAX5715.h index 0fc522e..2b04426 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/MAX5715.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/MAX5715.h @@ -37,26 +37,26 @@ // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- -#define MAX5715_NUMBER_OF_DACS (4) +#define MAX5715_NUMBER_OF_DACS (4) -#define MAX5715_SPI_MAX_CLK_HZ (50000000) +#define MAX5715_SPI_MAX_CLK_HZ (50000000) // SPI settings -#define MAX5715_SPI_Direction (SPI_Direction_1Line_Tx) -#define MAX5715_SPI_Mode (SPI_Mode_Master) -#define MAX5715_SPI_DataSize (SPI_DataSize_8b) -#define MAX5715_SPI_CPOL (SPI_CPOL_Low) -#define MAX5715_SPI_CPHA (SPI_CPHA_1Edge) -#define MAX5715_SPI_NSS (SPI_NSS_Soft) -#define MAX5715_SPI_NSS_INTERNAL (SPI_NSSInternalSoft_Reset) -#define MAX5715_SPI_FirstBit (SPI_FirstBit_MSB) -#define MAX5715_SPI_CRCPolynomial (7) -#define MAX5715_SPI_RX_QUEUE (1) -#define MAX5715_SPI_TX_QUEUE (32) +#define MAX5715_SPI_Direction (SPI_Direction_1Line_Tx) +#define MAX5715_SPI_Mode (SPI_Mode_Master) +#define MAX5715_SPI_DataSize (SPI_DataSize_8b) +#define MAX5715_SPI_CPOL (SPI_CPOL_Low) +#define MAX5715_SPI_CPHA (SPI_CPHA_1Edge) +#define MAX5715_SPI_NSS (SPI_NSS_Soft) +#define MAX5715_SPI_NSS_INTERNAL (SPI_NSSInternalSoft_Reset) +#define MAX5715_SPI_FirstBit (SPI_FirstBit_MSB) +#define MAX5715_SPI_CRCPolynomial (7) +#define MAX5715_SPI_RX_QUEUE (1) +#define MAX5715_SPI_TX_QUEUE (32) -#define MAX5715_SEL_DACA (0x1) -#define MAX5715_SEL_DACB (0x2) -#define MAX5715_SEL_DACC (0x4) -#define MAX5715_SEL_DACD (0x8) +#define MAX5715_SEL_DACA (0x1) +#define MAX5715_SEL_DACB (0x2) +#define MAX5715_SEL_DACC (0x4) +#define MAX5715_SEL_DACD (0x8) #define MAX5715_CMD_CODEn (0x00) #define MAX5715_CMD_LOADn (0x10) diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c index 672b9ea..3293655 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c @@ -48,10 +48,10 @@ static struct Pcba thisPCBA; static const char nameArray[4][20] = { - "Cathode/MCP repair ", - "Tesla repair ", - "Anode repair ", - "UNDEFINED PCBA ", + "Cathode/MCP repair", + "Tesla repair", + "Anode repair", + "UNDEFINED PCBA", }; // ----------------------------------------------------------------------------- diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Display.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Display.h index e9d6aec..0800e20 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Display.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Display.h @@ -68,6 +68,9 @@ struct Display SemaphoreHandle_t displayShadowAccessSemaphore; struct DisplayCharacter displayShadow[DISPLAY_MAX_ROWS][DISPLAY_MAX_COLUMNS]; int maxCharactersPerTransmit; + int refreshFeedCounter; + int refreshFeedFrequency_ms; + int refreshPeriod_ms; }; // ----------------------------------------------------------------------------- @@ -94,7 +97,7 @@ struct Display * @todo * ----------------------------------------------------------------------------- */ -extern ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displayDevice, int TaskPriority, uint16_t stackSize, int maxCharactersPerTransmit); +extern ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displayDevice, int TaskPriority, uint16_t stackSize, int maxCharactersPerTransmit, int refreshFeedFrequency_ms, int refreshPeriod); /** ---------------------------------------------------------------------------- @@ -197,4 +200,19 @@ extern ErrorStatus Display_setContrast(struct Display* self, size_t contrast); */ extern ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int length, size_t row, size_t column); + +/** ---------------------------------------------------------------------------- + * Display_feedRefreshCounter + * Feeds the refresh counter for display content + * Must be called regulary. Count rhythm and limits are defined in self + * + * @param self The display instance + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void Display_feedRefreshCounter(struct Display* self); + #endif /* DISPLAY_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c index 0b076d9..ae34367 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c @@ -54,15 +54,14 @@ static void DisplayTask(void* parameters); inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character); inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter); inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter); +static void Display_characterUpdateAll(struct Display* self); // ----------------------------------------------------------------------------- // Function definitions // ----------------------------------------------------------------------------- -ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displayDevice, int TaskPriority, uint16_t stackSize, int maxCharactersPerTransmit) +ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displayDevice, int TaskPriority, uint16_t stackSize, int maxCharactersPerTransmit, int refreshFeedFrequency_ms, int refreshPeriod) { - int rowCounter = 0; - int colCounter = 0; ErrorStatus returnValue = SUCCESS; @@ -70,21 +69,27 @@ ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displa self->TaskPriority = TaskPriority; self->stackSize = stackSize; self->maxCharactersPerTransmit = maxCharactersPerTransmit; + self->refreshFeedCounter = 0; + self->refreshFeedFrequency_ms = refreshFeedFrequency_ms; + self->refreshPeriod_ms = refreshPeriod; - // Clear the display shadow - for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++) - { - for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++) - { - Display_characterUpdate(&self->displayShadow[rowCounter][colCounter], 0x20); - } - } - + if(returnValue == SUCCESS) { // Create a semaphore to sync access to the display shadow vSemaphoreCreateBinary(self->displayShadowAccessSemaphore); xSemaphoreGive(self->displayShadowAccessSemaphore); + + // Clear the display shadow + size_t rowCounter; + size_t colCounter; + for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++) + { + for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++) + { + Display_characterUpdate(&self->displayShadow[rowCounter][colCounter], 0x20); + } + } } self->runTask = true; @@ -186,6 +191,13 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int return returnValue; } + +void Display_feedRefreshCounter(struct Display* self) +{ + self->refreshFeedCounter++; +} + + inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character) { displayCharacter->character = character; @@ -206,6 +218,25 @@ inline static char Display_getUpdatedCharacter (struct DisplayCharacter* display } +static void Display_characterUpdateAll(struct Display* self) +{ + size_t rowCounter; + size_t colCounter; + + // Get the access semaphore to the shadow - wait until the other functions are finished with updating the shadow + xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY); + // Clear the display shadow + for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++) + { + for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++) + { + self->displayShadow[rowCounter][colCounter].isUpdated = true; + } + } + // Give back display memory access semaphore to allow new updates + xSemaphoreGive(self->displayShadowAccessSemaphore); +} + static void DisplayTask(void* parameters) { struct Display* self = (struct Display*)parameters; @@ -220,7 +251,7 @@ static void DisplayTask(void* parameters) size_t columnStart; while (self->runTask) { - // Get the access semaphore to the shadow - wait until the write function is finished with updating the shadow + // Get the access semaphore to the shadow - wait until the other functions are finished with updating the shadow xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY); leaveLoops = false; bufferIndex = 0; @@ -299,6 +330,14 @@ static void DisplayTask(void* parameters) rowCounter = 0; } } + + // Check for display refresh timings + if (self->refreshFeedCounter * self->refreshFeedFrequency_ms > self->refreshPeriod_ms) + { + self->refreshFeedCounter = 0; + Display_characterUpdateAll(self); + } + vTaskDelay(10); } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c index 7fdf58b..021d3fd 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c @@ -85,7 +85,8 @@ static xTaskHandle initTaskHandle; static xTaskHandle ledTaskHandle; static xTaskHandle sysTaskHandle; -static struct Display display; +static struct Display _display; +struct Display* display = &_display; static struct NHD0420 nhd0420; static struct MAX5715 max5715; @@ -136,10 +137,9 @@ static void printSystemInfoTask(void* parameters) { while (1) { - uint16_t adcValue = 0; LOGGER_INFO("---------------------------------------"); systeminfoCommandHandler(); - vTaskDelay(2000); + vTaskDelay(60000); } } @@ -159,7 +159,7 @@ static ErrorStatus systeminfoCommandHandler(void) vTaskDelay(100); OS_logTaskInfo(sysTaskHandle); vTaskDelay(100); - OS_logTaskInfo(display.taskHandle); + OS_logTaskInfo(display->taskHandle); return errorStatus; } @@ -174,18 +174,18 @@ static void initTask(void* parameters) NHD0420_construct(&nhd0420, &spiDisplay->device); - Display_construct(&display, &nhd0420.displayDevice, 0, 1024, 10); + Display_construct(display, &nhd0420.displayDevice, 0, 1024, 10, 1000, 5000); - Display_clearScreen(&display); + Display_clearScreen(display); - Display_write(&display, pcba->name, sizeof(pcba->name) / sizeof(pcba->name[0]), 1, 1); + Display_write(display, pcba->name, strlen(pcba->name), 1, 1); char buffer[20]; snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "SW V. %d.%d.%d.%d", Version_getInstance()->major, Version_getInstance()->minor, Version_getInstance()->branch, Version_getInstance()->patch); - Display_write(&display, buffer, strlen(buffer), 3, 4); + Display_write(display, buffer, strlen(buffer), 3, 4); MAX5715_construct(&max5715, &spiDAC->device); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c index cbef31d..b111881 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c @@ -37,6 +37,7 @@ #include "stm32f10x_spi.h" #include "stm32f10x_usart.h" +#include "Display.h" #include "Logger.h" #include "led.h" #include "platform.h" @@ -374,6 +375,7 @@ void EXTI9_5_IRQHandler (void) } +extern struct Display* display; void RTC_IRQHandler(void) { static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; @@ -384,6 +386,7 @@ void RTC_IRQHandler(void) RTC_ClearITPendingBit(RTC_IT_SEC); xSemaphoreGiveFromISR(rtc->secondSync, &higherPriorityTaskWoken); + Display_feedRefreshCounter(display); if (ledGreen->status) { LED_turnOff(ledGreen);