From b7d49850909d6d7e82828623bea0c2603db5581c Mon Sep 17 00:00:00 2001 From: mmi Date: Mon, 2 Oct 2017 08:17:27 +0000 Subject: [PATCH] - Tested/debugged the display module. Now functional - Tested the RTC - currently indicated with green LED toggle - functional Started with internal ADC driver git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@226 05563f52-14a8-4384-a975-3d1654cca0fa --- .../0 - Code/Platform/Makefile | 2 + .../0 - Code/Platform/inc/adc.h | 82 ++++ .../0 - Code/Platform/inc/platform.h | 2 + .../0 - Code/Platform/inc/rtc.h | 71 ++++ .../0 - Code/Platform/inc/spiDevice.h | 2 +- .../0 - Code/Platform/src/adc.c | 73 ++++ .../0 - Code/Platform/src/oli_stm32_h107.c | 95 ++++- .../0 - Code/Platform/src/rtc.c | 95 +++++ .../0 - Code/Platform/src/spiDevice.c | 2 +- .../.settings/language.settings.xml | 4 +- .../hsb-mrts/.settings/language.settings.xml | 4 +- .../0 - Code/hsb-mrts/Makefile | 1 + .../0 - Code/hsb-mrts/src/Display_nhd0420.c | 376 ++++++++++++++++++ .../0 - Code/hsb-mrts/src/Logger.c | 2 +- .../0 - Code/hsb-mrts/src/main.c | 23 +- .../0 - Code/hsb-mrts/src/stm32f10x_it.c | 31 ++ 16 files changed, 830 insertions(+), 35 deletions(-) create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/adc.h create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/rtc.h create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/adc.c create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/rtc.c create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display_nhd0420.c diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/Makefile b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/Makefile index 6653a07..3b79d8c 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/Makefile +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/Makefile @@ -24,7 +24,9 @@ ARFLAGS = rs OBJECTS = \ stm32f10x_it.o \ +adc.o \ led.o \ +rtc.o \ spi.o \ spiDevice.o \ uart.o \ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/adc.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/adc.h new file mode 100644 index 0000000..564d8b2 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/adc.h @@ -0,0 +1,82 @@ +// ----------------------------------------------------------------------------- +/// @file adc.h +/// @brief File description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file adc.h +/// @ingroup {group_name} + +#ifndef INC_ADC_H_ +#define INC_ADC_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "platform.h" +#include "IODevice.h" + +#include "stm32f10x.h" +#include "stm32f10x_adc.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + +struct AdcParameters +{ + +}; + +struct Adc +{ + struct IODevice device; + ADC_InitTypeDef adc_InitStruct; + T_PL_GPIO input; +}; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + +/** ---------------------------------------------------------------------------- + * ADC_construct + * Constructor for ADC instance + * + * @param self The ADC instance to initialize + * @param parameters Additional ADC parameters + * + * @return ErrorStatus SUCCESS if initialisation was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters); + +#endif /* INC_ADC_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h index 8d029b5..fc41f85 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h @@ -64,6 +64,8 @@ typedef struct // Export of LEDs extern struct Led* const ledGreen; extern struct Led* const ledOrange; +// Export of the rtc +extern struct Rtc* const rtc; // Export of UARTs extern struct Uart* const uart1; extern struct Uart* const uart3; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/rtc.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/rtc.h new file mode 100644 index 0000000..c476730 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/rtc.h @@ -0,0 +1,71 @@ +// ----------------------------------------------------------------------------- +/// @file rtc.h +/// @brief File description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file rtc.h +/// @ingroup {group_name} + +#ifndef INC_RTC_H_ +#define INC_RTC_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "FreeRTOS.h" +#include "semphr.h" + +#include "stm32f10x.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + +struct Rtc +{ + SemaphoreHandle_t secondSync; +}; + + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + +/** ---------------------------------------------------------------------------- + * RTC_construct + * Constructor of the RealTime Clock + * + * @return ErrorStatus + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus RTC_construct(struct Rtc* self); + + +#endif /* INC_RTC_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/spiDevice.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/spiDevice.h index 2d14bd6..37af12d 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/spiDevice.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/spiDevice.h @@ -57,7 +57,7 @@ struct SpiDevice // ----------------------------------------------------------------------------- -extern ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE); +extern ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters); /** ---------------------------------------------------------------------------- * Spi_Write diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/adc.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/adc.c new file mode 100644 index 0000000..507856b --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/adc.c @@ -0,0 +1,73 @@ +// ----------------------------------------------------------------------------- +/// @file adc.c +/// @brief Description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2017 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @file adc.c +/// @ingroup {group_name} + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "stm32f10x.h" +#include "adc.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// File-scope variables +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + +// NO WRITE - ADCs cannot write +static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength); + +// ----------------------------------------------------------------------------- +// Function definitions +// ----------------------------------------------------------------------------- + +ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters) +{ + ErrorStatus returnValue = SUCCESS; + + IODevice_construct(&self->device, read, NULL); + + return returnValue; +} + +static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength) +{ + ErrorStatus returnValue = SUCCESS; + + return returnValue; +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c index 74e8d0f..ef5ecb1 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c @@ -27,12 +27,15 @@ #include +#include "stm32f10x_bkp.h" #include "stm32f10x_gpio.h" +#include "stm32f10x_pwr.h" #include "stm32f10x_it.h" #include "platform.h" #include "spiDevice.h" #include "led.h" +#include "rtc.h" #include "spi.h" #include "uart.h" #include "keypadMatrix.h" @@ -45,20 +48,16 @@ // ----------------------------------------------------------------------------- // UART1 Settings (Logger/Console) -#define UART_LOG_TYPEDEF (USART1) #define UART_LOG_BAUDRATE (57600) #define UART_LOG_TX_QUEUE (256) // UART3 Settings (Developer terminal) -#define UART_TER_TYPEDEF (USART3) #define UART_TER_BAUDRATE (115200) #define UART_TER_TX_QUEUE (512) // SPI1 settings -#define SPI_DAC_TYPEDEF (SPI1) // SPI3 settings (LCD / EEPROM) -#define SPI_LCD_EEPROM_TYPEDEF (SPI3) #define SPI_LCD_EEPROM_Direction (SPI_Direction_2Lines_FullDuplex) #define SPI_LCD_EEPROM_RX_QUEUE (32) #define SPI_LCD_EEPROM_TX_QUEUE (32) @@ -81,6 +80,9 @@ static struct Led _ledGreen; static struct Led _ledOrange; +// RTC +static struct Rtc _rtc; + // USART static struct Uart _uart1; static struct UartParameters _uart1Parameters; @@ -106,6 +108,8 @@ static struct KeypadParameters _keypadParameters; struct Led* const ledGreen = &_ledGreen; struct Led* const ledOrange = &_ledOrange; +struct Rtc* const rtc = &_rtc; + struct Uart* const uart1 = &_uart1; struct UartParameters* uartLoggerParam = &_uart1Parameters; struct Uart* const uart3 = &_uart3; @@ -127,6 +131,7 @@ struct KeypadParameters* const keypadParam = &_keypadParameters; // Function declarations // ----------------------------------------------------------------------------- +static ErrorStatus initClocks(void); static ErrorStatus initIO (void); // ----------------------------------------------------------------------------- @@ -139,16 +144,39 @@ ErrorStatus initPlatform(void) { ErrorStatus returnValue = SUCCESS; + + // POWER THE PERIPHERY AND CLOCK BUSSES + if (returnValue == SUCCESS) + { + returnValue = initClocks(); + } + + // INITIALIZE ALL REQUIRED GPIO FOR IO OR PERIPHERAL USE if (returnValue == SUCCESS) { returnValue = initIO(); + } + // INITIALIZE AND CONFIGURE ALL REQUIRED IO AND PERIPHERY + if (returnValue == SUCCESS) + { + /* --------------------------------------------------------------------*/ + /* LEDs */ + /* --------------------------------------------------------------------*/ LED_construct(ledGreen); LED_construct(ledOrange); - // Initialize the Console UART + /* --------------------------------------------------------------------*/ + /* RTC */ + /* --------------------------------------------------------------------*/ + IRQ_setInterruptProperties(RTC_IRQn, 12, 12, ENABLE); + RTC_construct(rtc); + + /* --------------------------------------------------------------------*/ + /* USART1 */ + /* --------------------------------------------------------------------*/ IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE); - uart1->USART_TypeDef = UART_LOG_TYPEDEF; + uart1->USART_TypeDef = USART1; Uart_getDefaultParameters(uartLoggerParam); // Adjust to higher baudrate for intensive logging uartLoggerParam->baudrate = UART_LOG_BAUDRATE; @@ -156,9 +184,12 @@ ErrorStatus initPlatform(void) uartLoggerParam->txQueueSize = UART_LOG_TX_QUEUE; returnValue = Uart_construct(uart1, uartLoggerParam); -// // Initialize the Terminal UART + /* --------------------------------------------------------------------*/ + /* USART3 */ + /* --------------------------------------------------------------------*/ + // Initialize the Terminal UART IRQ_setInterruptProperties(USART3_IRQn, 15, 15, ENABLE); - uart3->USART_TypeDef = UART_TER_TYPEDEF; + uart3->USART_TypeDef = USART3; Uart_getDefaultParameters(uartTerminalParam); // Adjust to higher baudrate for intensive logging uartLoggerParam->baudrate = UART_TER_BAUDRATE; @@ -166,16 +197,22 @@ ErrorStatus initPlatform(void) uartLoggerParam->txQueueSize = UART_TER_TX_QUEUE; returnValue = Uart_construct(uart3, uartTerminalParam); + /* --------------------------------------------------------------------*/ + /* SPI1 */ + /* --------------------------------------------------------------------*/ IRQ_setInterruptProperties(SPI1_IRQn, 12, 12, ENABLE); spi1->initialized = false; - spi1->SPI_TypeDef = SPI_DAC_TYPEDEF; + spi1->SPI_TypeDef = SPI1; MAX5715_getSpiParameters(spiDACParam); GPIO_SetBits(spiDAC->SPI_CE.GPIO_Typedef, spiDAC->SPI_CE.GPIO_InitStruct.GPIO_Pin); - SpiDevice_construct(spiDAC, spi1, spiDACParam, spiDAC->SPI_CE); + SpiDevice_construct(spiDAC, spi1, spiDACParam); + /* --------------------------------------------------------------------*/ + /* SPI3 */ + /* --------------------------------------------------------------------*/ IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE); spi3->initialized = false; - spi3->SPI_TypeDef = SPI_LCD_EEPROM_TYPEDEF; + spi3->SPI_TypeDef = SPI3; // Get the SPI parameters from the NHD0420 driver. They are more critical than the parameters from the EEPROM NHD0420_getSpiParameters(spiDisplayParam); // In order to use multiple slaves on this bus (and to increase performance), some parameters are altered @@ -187,9 +224,12 @@ ErrorStatus initPlatform(void) ///TODO SPI_CE should be initialized individually GPIO_SetBits(spiDisplay->SPI_CE.GPIO_Typedef, spiDisplay->SPI_CE.GPIO_InitStruct.GPIO_Pin); GPIO_SetBits(spiEEPROM->SPI_CE.GPIO_Typedef, spiEEPROM->SPI_CE.GPIO_InitStruct.GPIO_Pin); - SpiDevice_construct(spiDisplay, spi3, spiDisplayParam, spiDisplay->SPI_CE); - SpiDevice_construct(spiEEPROM, spi3, spiEEPROMParam, spiEEPROM->SPI_CE); + SpiDevice_construct(spiDisplay, spi3, spiDisplayParam); + SpiDevice_construct(spiEEPROM, spi3, spiEEPROMParam); + /* --------------------------------------------------------------------*/ + /* KEYPAD COLUMNS */ + /* --------------------------------------------------------------------*/ // Set-up the interrupts for the Keypad columns keypad->column[0].EXTI_InitStruct.EXTI_Line = EXTI_Line4; keypad->column[0].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; @@ -228,8 +268,7 @@ ErrorStatus initPlatform(void) } //#endif - -static ErrorStatus initIO (void) +static ErrorStatus initClocks (void) { ErrorStatus returnValue = SUCCESS; @@ -239,6 +278,25 @@ static ErrorStatus initIO (void) RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); + + RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_BKP, ENABLE); + + // Allow access to BKP Domain + PWR_BackupAccessCmd(ENABLE); + // Reset Backup Domain + BKP_DeInit(); + // Enable LSE + RCC_LSEConfig(RCC_LSE_ON); + // Wait till LSE is ready + while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); + // Select LSE as RTC Clock Source + RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); + // Enable RTC Clock + RCC_RTCCLKCmd(ENABLE); + RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); @@ -261,6 +319,13 @@ static ErrorStatus initIO (void) RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); + return returnValue; +} + +static ErrorStatus initIO (void) +{ + ErrorStatus returnValue = SUCCESS; + /*LED IO initialisation --------------------------------------------------*/ // Init LED Green ledGreen->ledGpio.GPIO_Typedef = GPIOC; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/rtc.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/rtc.c new file mode 100644 index 0000000..57bf15a --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/rtc.c @@ -0,0 +1,95 @@ +// ----------------------------------------------------------------------------- +/// @file rtc.c +/// @brief Description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2017 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @file rtc.c +/// @ingroup {group_name} + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "FreeRTOS.h" +#include "semphr.h" + +#include "rtc.h" +#include "stm32f10x_rtc.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// File-scope variables +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function definitions +// ----------------------------------------------------------------------------- + +ErrorStatus RTC_construct(struct Rtc* self) +{ + ErrorStatus returnValue = SUCCESS; + + //! Create semaphore to synchronize with RTC interrupt handler + vSemaphoreCreateBinary(self->secondSync); + // Take semaphore + if (xSemaphoreTake(self->secondSync, 0) == pdFALSE) + { + //! An error has occurred + returnValue = ERROR; + } + + /* Wait for RTC registers synchronization */ + RTC_WaitForSynchro(); + + /* Wait until last write operation on RTC registers has finished */ + RTC_WaitForLastTask(); + + /* Enable the RTC Second */ + RTC_ITConfig(RTC_IT_SEC, ENABLE); + + /* Wait until last write operation on RTC registers has finished */ + RTC_WaitForLastTask(); + + /* Set RTC prescaler: set RTC period to 1sec */ + RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ + + /* Wait until last write operation on RTC registers has finished */ + RTC_WaitForLastTask(); + + return returnValue; +} + + diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/spiDevice.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/spiDevice.c index 91f5c88..e274677 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/spiDevice.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/spiDevice.c @@ -59,7 +59,7 @@ static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t // ----------------------------------------------------------------------------- -ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE) +ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters) { ErrorStatus returnValue = SUCCESS; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml index 700f76c..db8a25d 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml index b045136..981712a 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile index 98d39fc..5e21602 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile @@ -19,6 +19,7 @@ system_stm32f10x.o \ sysmem.o \ startup_stm32f10x_cl.o \ \ +Display_nhd0420.o \ FreeRTOSFixes.o \ Logger.o \ \ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display_nhd0420.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display_nhd0420.c new file mode 100644 index 0000000..1ae48e7 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display_nhd0420.c @@ -0,0 +1,376 @@ +// ----------------------------------------------------------------------------- +/// @file Display_nhd0420.c +/// @brief Description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2017 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @file Display_nhd0420.c +/// @ingroup {group_name} + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "Display.h" +#include "Logger.h" + +#include "nhd0420.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + +#define DISPLAY_TASK_STACK_SIZE (2048) +#define DISPLAY_TRANSMIT_MAX_CHUNK (10) + +// ----------------------------------------------------------------------------- +// Type definitions +// ----------------------------------------------------------------------------- + +struct displayCharacter +{ + char character; + bool isUpdated; +}; + + +// ----------------------------------------------------------------------------- +// File-scope variables +// ----------------------------------------------------------------------------- + +static SemaphoreHandle_t displayShadowAccessSemaphore; + +static struct displayCharacter displayShadow[NHD0420_NUMBER_OF_ROWS][NHD0420_NUMBER_OF_COLUMNS]; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + +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 printfShadow(void); + +// ----------------------------------------------------------------------------- +// Function definitions +// ----------------------------------------------------------------------------- + +ErrorStatus Display_construct(struct Display* self, void* displayDriver) +{ + int rowCounter = 0; + int colCounter = 0; + ErrorStatus returnValue = SUCCESS; + + // This is of type NHD0420 - Cast is valid only within this C file + self->displayDriver = displayDriver; + + // Clear the display shadow + for (rowCounter = 0; rowCounter < NHD0420_NUMBER_OF_ROWS; rowCounter++) + { + for (colCounter = 0; colCounter < NHD0420_NUMBER_OF_COLUMNS; colCounter++) + { + Display_characterUpdate(&displayShadow[rowCounter][colCounter], 0x20); + } + } + + if(returnValue == SUCCESS) + { + // Create a semaphore to sync access to the display shadow + vSemaphoreCreateBinary(displayShadowAccessSemaphore); + xSemaphoreGive(displayShadowAccessSemaphore); + } + + self->runTask = true; + + if(returnValue == SUCCESS) + { + if (xTaskCreate(DisplayTask, (const char*)"DisplayTask", DISPLAY_TASK_STACK_SIZE, self, self->TaskPriority, self->taskHandle) != pdTRUE) + { + returnValue = ERROR; + LOGGER_ERROR("Starting display task failed"); + } + else + { + LOGGER_INFO("Display task started"); + } + } + + if(returnValue == SUCCESS) + { + // If initialisation of module was successful, RESET and adjust the display + NHD0420_clearScreen(self->displayDriver); + vTaskDelay(5); + NHD0420_setContrast(self->displayDriver, 30); + vTaskDelay(5); + NHD0420_setBacklightBrightness(self->displayDriver, 3); + vTaskDelay(5); + NHD0420_turnOnDisplay(self->displayDriver); + vTaskDelay(5); + } + + return returnValue; +} + + +void Display_destruct(struct Display* self) +{ + self->runTask = false; + vSemaphoreDelete(displayShadowAccessSemaphore); +} + + +ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int length, unsigned int row, unsigned int column) +{ + ErrorStatus returnValue = SUCCESS; + // Prior to any action on the display memory, perform necessary checkings + if (returnValue == SUCCESS) + { + // Check that the row coordinate does not exceed the display boundary + if (row - 1 >= NHD0420_NUMBER_OF_ROWS) + { + returnValue = ERROR; + } + } + if (returnValue == SUCCESS) + { + // Check that the column coordinate does not exceed the display boundary + if (column - 1 >= NHD0420_NUMBER_OF_COLUMNS) + { + returnValue = ERROR; + } + } + if (returnValue == SUCCESS) + { + // Check that the length request does not exceed the display boundary + // This is checked in combination with the column coordinate + // NHD0420_NUMBER_OF_COLUMNS - column >= length + // must be valid in order to put the requested message on display + if (NHD0420_NUMBER_OF_COLUMNS - (column - 1) < length) + { + returnValue = ERROR; + } + } + + if (returnValue == SUCCESS) + { + // Get the access semaphore to the display memory - wait for access + xSemaphoreTake(displayShadowAccessSemaphore, portMAX_DELAY); + + int loopCounter; + for (loopCounter = 0; loopCounter < length; loopCounter++) + { + Display_characterUpdate(&displayShadow[row - 1][(column - 1) + loopCounter], buffer[loopCounter]); + } + + xSemaphoreGive(displayShadowAccessSemaphore); + + } + return returnValue; +} + +inline static void Display_characterUpdate (struct displayCharacter* displayCharacter, char character) +{ + displayCharacter->character = character; + displayCharacter->isUpdated = true; +} + + +inline static bool Display_isCharacterUpdated (struct displayCharacter* displayCharacter) +{ + return displayCharacter->isUpdated; +} + + +inline static char Display_getUpdatedCharacter (struct displayCharacter* displayCharacter) +{ + displayCharacter->isUpdated = false; + return displayCharacter->character; +} + + +static void DisplayTask(void* parameters) +{ + const struct Display* self = (const struct Display*)parameters; + const struct NHD0420* displayDriver = (const struct NHD0420*)self->displayDriver; + + bool leaveLoops = false; + char buffer[NHD0420_NUMBER_OF_COLUMNS]; + int bufferIndex = 0; + int rowCounter = 0; + int colCounter = 0; + while (self->runTask) + { + // Get the access semaphore to the shadow - wait until the write function is finished with updating the shadow + xSemaphoreTake(displayShadowAccessSemaphore, portMAX_DELAY); + leaveLoops = false; + bufferIndex = 0; +// printfShadow(); + + // Fragment display writing - writing will be done per line + for (; colCounter < NHD0420_NUMBER_OF_COLUMNS; colCounter++) + { + if (Display_isCharacterUpdated(&displayShadow[rowCounter][colCounter])) + { + // Found a character that has been updated + // Put the display cursor at the appropriate coordinates + NHD0420_setCursorToPosition(displayDriver, rowCounter + 1, colCounter + 1); + for (bufferIndex = 0; (colCounter < NHD0420_NUMBER_OF_COLUMNS); colCounter++, bufferIndex++) + { + // Respect the max number of bytes to transmit + if (bufferIndex < DISPLAY_TRANSMIT_MAX_CHUNK) + { + // Still within the boundaries + if (Display_isCharacterUpdated(&displayShadow[rowCounter][colCounter])) + { + // Current character has been updated and must be sent to display + // But data from display shadow to transmit buffer + buffer[bufferIndex] = Display_getUpdatedCharacter(&displayShadow[rowCounter][colCounter]); + } + else + { + // Current character is already on the display + // Stop scanning for more updated characters here and leave the loops in order + // to start transmission to the display + leaveLoops = true; + break; + } + } + else + { + // Max number of characters reached + // Stop scanning for more updated characters here and leave the loops in order + // to start transmission to the display + leaveLoops = true; + break; + } + } + } + + // Check if loop should be left + if (leaveLoops) + { + // An inner loop decided to leave, so leave + break; + } + } + + // Give back display memory access semaphore to allow new updates + xSemaphoreGive(displayShadowAccessSemaphore); + if (bufferIndex > 0) + { + // If there was an update found, send it to the display + IODevice_write(displayDriver->device, buffer, bufferIndex); + } + + // Handle the counters for row and column + if (colCounter > (NHD0420_NUMBER_OF_COLUMNS - 1)) + { + // End of row reached - reset column and increment row + colCounter = 0; + + if (rowCounter < (NHD0420_NUMBER_OF_ROWS - 1)) + { + // Increment row + rowCounter++; + } + else + { + // Last row reached - restart at row 0 + rowCounter = 0; + } + } + } + + // Task has been marked to end - after leaving the endless loop, end/delete this task + vTaskDelete(self->taskHandle); + +} + + +// DEBUG FUNCTION - MIGHT NOT BE NECESSARY LATER ON +static void printfShadow(void) +{ + char tempBuffer[21]; + char flagBuffer[21]; + int tempLoop; + for (tempLoop = 0; tempLoop < 20; tempLoop++) + { + tempBuffer[tempLoop] = displayShadow[0][tempLoop].character; + if (displayShadow[0][tempLoop].isUpdated) + { + flagBuffer[tempLoop] = '1'; + } + else + { + flagBuffer[tempLoop] = '0'; + } + } + tempBuffer[20] = '\0'; + flagBuffer[20] = '\0'; + + LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer); + for (tempLoop = 0; tempLoop < 20; tempLoop++) + { + tempBuffer[tempLoop] = displayShadow[1][tempLoop].character; + if (displayShadow[1][tempLoop].isUpdated) + { + flagBuffer[tempLoop] = '1'; + } + else + { + flagBuffer[tempLoop] = '0'; + } + } + tempBuffer[20] = '\0'; + flagBuffer[20] = '\0'; + + LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer); + for (tempLoop = 0; tempLoop < 20; tempLoop++) + { + tempBuffer[tempLoop] = displayShadow[2][tempLoop].character; + if (displayShadow[2][tempLoop].isUpdated) + { + flagBuffer[tempLoop] = '1'; + } + else + { + flagBuffer[tempLoop] = '0'; + } + } + tempBuffer[20] = '\0'; + flagBuffer[20] = '\0'; + + LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer); + for (tempLoop = 0; tempLoop < 20; tempLoop++) + { + tempBuffer[tempLoop] = displayShadow[3][tempLoop].character; + if (displayShadow[3][tempLoop].isUpdated) + { + flagBuffer[tempLoop] = '1'; + } + else + { + flagBuffer[tempLoop] = '0'; + } + } + tempBuffer[20] = '\0'; + flagBuffer[20] = '\0'; + LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer); +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c index 62203ad..5997361 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c @@ -43,7 +43,7 @@ // Constant and macro definitions // ----------------------------------------------------------------------------- -#define LOGQUEUE_SIZE (16) +#define LOGQUEUE_SIZE (24) #define LOGGER_STACK_SIZE (512) #define LOGGER_TASK_PRIORITY (2) 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 6e9f263..d78b0fe 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 @@ -31,6 +31,8 @@ // FreeRTOS includes #include "FreeRTOS.h" #include "task.h" + +#include "Display.h" #include "Logger.h" #include "misc.h" @@ -78,6 +80,8 @@ static xTaskHandle initTaskHandle; static xTaskHandle ledTaskHandle; static xTaskHandle sysTaskHandle; +static struct Display display; + static struct NHD0420 nhd0420; static struct MAX5715 max5715; @@ -157,21 +161,14 @@ static void initTask(void* parameters) Logger_construct(&uart1->device); +// NHD0420_construct(&nhd0420, &uart1->device); NHD0420_construct(&nhd0420, &spiDisplay->device); - NHD0420_turnOffDisplay(&nhd0420); - vTaskDelay(1000); - NHD0420_clearScreen(&nhd0420); - vTaskDelay(1000); - NHD0420_turnOnDisplay(&nhd0420); - vTaskDelay(1000); - NHD0420_setContrast(&nhd0420, 30); - vTaskDelay(1000); - NHD0420_setBacklightBrightness(&nhd0420, 3); - vTaskDelay(1000); - NHD0420_setCursorToHome(&nhd0420); - vTaskDelay(1000); - NHD0420_sendData(&nhd0420, "Anode repair A", 20); + Display_construct(&display, &nhd0420); + + Display_write(&display, "anode repair", 12, 1, 1); + Display_write(&display, "A", 1, 1, 20); + Display_write(&display, "SW V. 1.0.0.0", 13, 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 6773be7..942999e 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 @@ -33,11 +33,15 @@ #include "stm32f10x_it.h" #include "stm32f10x_exti.h" +#include "stm32f10x_rtc.h" +#include "stm32f10x_spi.h" +#include "stm32f10x_usart.h" #include "Logger.h" #include "keypadMatrix.h" #include "led.h" #include "platform.h" +#include "rtc.h" #include "spi.h" #include "uart.h" @@ -369,3 +373,30 @@ void EXTI9_5_IRQHandler (void) portEND_SWITCHING_ISR(higherPriorityTaskWoken); } + + +void RTC_IRQHandler(void) +{ + static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; + + if (RTC_GetITStatus(RTC_IT_SEC) != RESET) + { + /* Clear the RTC Second interrupt */ + RTC_ClearITPendingBit(RTC_IT_SEC); + + xSemaphoreGiveFromISR(rtc->secondSync, &higherPriorityTaskWoken); + if (ledGreen->status) + { + LED_turnOff(ledGreen); + } + else + { + LED_turnOn(ledGreen); + } + + /* Wait until last write operation on RTC registers has finished */ + RTC_WaitForLastTask(); + + portEND_SWITCHING_ISR(higherPriorityTaskWoken); + } +}