diff options
Diffstat (limited to 'Libraries/NixieDriver')
-rw-r--r-- | Libraries/NixieDriver/nixie_driver_config.c | 140 | ||||
-rw-r--r-- | Libraries/NixieDriver/nixie_driver_config.h | 67 | ||||
-rw-r--r-- | Libraries/NixieDriver/nixie_driver_process.c | 441 | ||||
-rw-r--r-- | Libraries/NixieDriver/nixie_driver_process.h | 79 | ||||
-rw-r--r-- | Libraries/NixieDriver/nixie_driver_task.c | 56 | ||||
-rw-r--r-- | Libraries/NixieDriver/nixie_driver_task.h | 2 |
6 files changed, 191 insertions, 594 deletions
diff --git a/Libraries/NixieDriver/nixie_driver_config.c b/Libraries/NixieDriver/nixie_driver_config.c index 6b5ce8a..defc674 100644 --- a/Libraries/NixieDriver/nixie_driver_config.c +++ b/Libraries/NixieDriver/nixie_driver_config.c @@ -1,32 +1,26 @@ #include "nixie_driver_config.h" - static void NixieDriver_TIMConfig ( void ); static void NixieDriver_SPIConfig ( void ); - -// ---------------------------------------------------------------------------- -// -// ---------------------------------------------------------------------------- void NixieDriverConfig ( void ) { NixieDriver_TIMConfig (); NixieDriver_SPIConfig (); } - // ---------------------------------------------------------------------------- -// 100 . 100 -// Nixie +// Конфигурируем таймер на 100 мкс. В прерывании каждые 100 мкс будет +// проворачиваться механизм динамической индикации ламп Nixie // ---------------------------------------------------------------------------- static void NixieDriver_TIMConfig ( void ) { NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; - + /* NIX_DRIVER_TIMx clock enable */ NIX_DRIVER_RCC_APBxPeriphClockCmd ( NIX_DRIVER_TIM_RCC, ENABLE ); - + /* Enable the NIX_DRIVER_TIMx gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = NIX_DRIVER_TIM_IRQx; NVIC_InitStructure.NVIC_IRQChannelPriority = 1; @@ -36,35 +30,35 @@ static void NixieDriver_TIMConfig ( void ) /* ----------------------------------------------------------------------- In this example TIM7 counter clock (TIM7CLK) is set to APB1 clock (PCLK1), since APB1 prescaler is set to 1 and TIM7 prescaler is set to 0. - - In this example TIM7 input clock (TIM7CLK) is set to APB1 clock (PCLK1), - since APB1 prescaler is set to 1. + + In this example TIM7 input clock (TIM7CLK) is set to APB1 clock (PCLK1), + since APB1 prescaler is set to 1. TIM7CLK = PCLK1 = HCLK = SystemCoreClock - + With Prescaler set to 479 and Period to 24999, the TIM7 counter is updated each 250 ms (i.e. and interrupt is generated each 250 ms) TIM7 counter clock = TIM7CLK /((Prescaler + 1)*(Period + 1)) = 48 MHz / ((25000)*(480)) - = 4 Hz + = 4 Hz ==> TIM7 counter period = 250 ms Note: SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f0xx.c file. Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() function to update SystemCoreClock variable value. Otherwise, any configuration - based on this variable will be incorrect. - ----------------------------------------------------------------------- */ - + based on this variable will be incorrect. + ----------------------------------------------------------------------- */ + /* Time base configuration */ - TIM_TimeBaseStructure.TIM_Period = 100; // //24999 + TIM_TimeBaseStructure.TIM_Period = 100; // Это миксросекунды //24999 TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock/1000000)-1; //479; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit ( NIX_DRIVER_TIMx, &TIM_TimeBaseStructure ); - + /* NIX_DRIVER_TIMx Interrupts enable */ TIM_ITConfig ( NIX_DRIVER_TIMx, TIM_IT_Update, ENABLE ); - + /* NIX_DRIVER_TIMx enable counter */ TIM_Cmd ( NIX_DRIVER_TIMx, ENABLE ); } @@ -78,22 +72,22 @@ static void NixieDriver_SPIConfig ( void ) GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - + /* Enable the SPI periph */ NIX_SPIx_RCC_APBxPeriphClockCmd ( NIX_SPIx_CLK, ENABLE ); - + /* Enable SCK, MOSI, MISO and NSS GPIO clocks */ - RCC_AHBPeriphClockCmd ( NIX_SPIx_SCK_GPIO_CLK | - NIX_SPIx_MOSI_GPIO_CLK | + RCC_AHBPeriphClockCmd ( NIX_SPIx_SCK_GPIO_CLK | + NIX_SPIx_MOSI_GPIO_CLK | NIX_SPIx_ST_GPIO_CLK | NIX_GPIOx_TUB_P1_GPIO_CLK | NIX_GPIOx_TUB_P2_GPIO_CLK, ENABLE ); - + GPIO_PinAFConfig ( NIX_SPIx_SCK_GPIO_PORT, NIX_SPIx_SCK_SOURCE, NIX_SPIx_SCK_AF ); GPIO_PinAFConfig ( NIX_SPIx_MOSI_GPIO_PORT, NIX_SPIx_MOSI_SOURCE, NIX_SPIx_MOSI_AF ); //GPIO_PinAFConfig ( NIX_SPIx_ST_GPIO_PORT, NIX_SPIx_ST_SOURCE, NIX_SPIx_ST_AF ); - + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; @@ -106,7 +100,7 @@ static void NixieDriver_SPIConfig ( void ) /* SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = NIX_SPIx_MOSI_PIN; GPIO_Init ( NIX_SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure ); - + /* GPIO ST pin configuration */ GPIO_InitStructure.GPIO_Pin = NIX_SPIx_ST_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; @@ -116,29 +110,28 @@ static void NixieDriver_SPIConfig ( void ) GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_Init ( NIX_SPIx_ST_GPIO_PORT, &GPIO_InitStructure ); - // ( ) - - /* GPIO tub_dp1 pin configuration */ - GPIO_InitStructure.GPIO_Pin = NIX_GPIOx_TUB_DP1_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; - GPIO_Init ( NIX_GPIOx_TUB_DP1_PORT, &GPIO_InitStructure ); - - /* GPIO tub_dp2 pin configuration */ - GPIO_InitStructure.GPIO_Pin = NIX_GPIOx_TUB_DP2_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; - GPIO_Init ( NIX_GPIOx_TUB_DP2_PORT, &GPIO_InitStructure ); - - + // Пины управления точками на лампах (не хватило ног сдвиговых редисок) + + /* GPIO tub_dp1 pin configuration */ + GPIO_InitStructure.GPIO_Pin = NIX_GPIOx_TUB_DP1_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + GPIO_Init ( NIX_GPIOx_TUB_DP1_PORT, &GPIO_InitStructure ); + + /* GPIO tub_dp2 pin configuration */ + GPIO_InitStructure.GPIO_Pin = NIX_GPIOx_TUB_DP2_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + GPIO_Init ( NIX_GPIOx_TUB_DP2_PORT, &GPIO_InitStructure ); + /* SPI configuration -------------------------------------------------------*/ SPI_I2S_DeInit ( NIX_SPIx ); - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - //SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + //SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; @@ -149,61 +142,20 @@ static void NixieDriver_SPIConfig ( void ) SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_Init ( NIX_SPIx, &SPI_InitStructure ); - + /* Enable the SPI peripheral */ SPI_Cmd ( NIX_SPIx, ENABLE ); - + /* Configure the SPI interrupt priority */ NVIC_InitStructure.NVIC_IRQChannel = NIX_SPIx_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init ( &NVIC_InitStructure ); - + // /* Enable the Tx buffer empty interrupt */ SPI_I2S_ITConfig ( NIX_SPIx, SPI_I2S_IT_TXE, ENABLE ); - + NIX_DRIVER_RESET_ST_PIN; NIX_DRIVER_RESET_TUB_DP1_PIN; NIX_DRIVER_RESET_TUB_DP2_PIN; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Libraries/NixieDriver/nixie_driver_config.h b/Libraries/NixieDriver/nixie_driver_config.h index 50c0e5e..29f7a17 100644 --- a/Libraries/NixieDriver/nixie_driver_config.h +++ b/Libraries/NixieDriver/nixie_driver_config.h @@ -3,38 +3,33 @@ #include "stm32f0xx_conf.h" - /* Communication boards SPIx Interface */ #define NIX_SPIx SPI1 #define NIX_SPIx_CLK RCC_APB2Periph_SPI1 #define NIX_SPIx_IRQn SPI1_IRQn #define NIX_SPIx_IRQHandler SPI1_IRQHandler -#define NIX_SPIx_SCK_PIN GPIO_Pin_5 -#define NIX_SPIx_SCK_GPIO_PORT GPIOA +#define NIX_SPIx_SCK_PIN GPIO_Pin_5 +#define NIX_SPIx_SCK_GPIO_PORT GPIOA #define NIX_SPIx_SCK_GPIO_CLK RCC_AHBPeriph_GPIOA #define NIX_SPIx_SCK_SOURCE GPIO_PinSource5 -#define NIX_SPIx_SCK_AF GPIO_AF_0 +#define NIX_SPIx_SCK_AF GPIO_AF_0 -#define NIX_SPIx_MOSI_PIN GPIO_Pin_7 -#define NIX_SPIx_MOSI_GPIO_PORT GPIOA +#define NIX_SPIx_MOSI_PIN GPIO_Pin_7 +#define NIX_SPIx_MOSI_GPIO_PORT GPIOA #define NIX_SPIx_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOA #define NIX_SPIx_MOSI_SOURCE GPIO_PinSource7 #define NIX_SPIx_MOSI_AF GPIO_AF_0 -#define NIX_SPIx_ST_PIN GPIO_Pin_4 -#define NIX_SPIx_ST_GPIO_PORT GPIOA +#define NIX_SPIx_ST_PIN GPIO_Pin_4 +#define NIX_SPIx_ST_GPIO_PORT GPIOA #define NIX_SPIx_ST_GPIO_CLK RCC_AHBPeriph_GPIOA #define NIX_SPIx_ST_SOURCE GPIO_PinSource4 #define NIX_SPIx_ST_AF GPIO_AF_0 -//#define NIX_SPIx_ST_EXTI_PIN GPIO_Pin_14 -//#define NIX_SPIx_ST_EXTI_GPIO_PORT GPIOB -//#define NIX_SPIx_ST_EXTI_GPIO_CLK RCC_AHBPeriph_GPIOB - #define NIX_SPIx_RCC_APBxPeriphClockCmd RCC_APB2PeriphClockCmd -// NixieDriver -------------------------------------- // +// Определения для таймера NixieDriver -------------------------------------- // #define NIX_DRIVER_TIM_IRQHandler TIM16_IRQHandler #define NIX_DRIVER_TIMx TIM16 #define NIX_DRIVER_TIM_RCC RCC_APB2Periph_TIM16 @@ -44,7 +39,7 @@ #define NIX_DRIVER_SET_ST_PIN GPIO_SetBits ( NIX_SPIx_ST_GPIO_PORT, NIX_SPIx_ST_PIN ) #define NIX_DRIVER_RESET_ST_PIN GPIO_ResetBits ( NIX_SPIx_ST_GPIO_PORT, NIX_SPIx_ST_PIN ) -// (.. ) +// Определения для управления точками на лампах (т.к. не хватило ног сдвиговых редисок) #define NIX_GPIOx_TUB_P1_GPIO_CLK RCC_AHBPeriph_GPIOB #define NIX_GPIOx_TUB_P2_GPIO_CLK RCC_AHBPeriph_GPIOB #define NIX_GPIOx_TUB_DP1_PIN GPIO_Pin_14 @@ -56,51 +51,7 @@ #define NIX_DRIVER_SET_TUB_DP1_PIN NIX_GPIOx_TUB_DP1_PORT->BSRR = NIX_GPIOx_TUB_DP1_PIN #define NIX_DRIVER_SET_TUB_DP2_PIN NIX_GPIOx_TUB_DP2_PORT->BSRR = NIX_GPIOx_TUB_DP2_PIN - -//#define NIX_TEST_SET_PB12_PIN GPIO_SetBits ( GPIOB, GPIO_Pin_12 ) -//#define NIX_TEST_RESET_PB12_PIN GPIO_ResetBits ( GPIOB, GPIO_Pin_12 ) -//#define NIX_TEST_PIN_PB11_TOGGLE GPIOB->ODR ^= GPIO_Pin_11 -//#define NIX_TEST_PIN_PB12_TOGGLE GPIOB->ODR ^= GPIO_Pin_12 - void NixieDriverInitProcess ( void ); void NixieDriverConfig ( void ); - #endif //NIXIE_DRIVER_CONFIG_INCLUDED - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Libraries/NixieDriver/nixie_driver_process.c b/Libraries/NixieDriver/nixie_driver_process.c index ddc728b..219494e 100644 --- a/Libraries/NixieDriver/nixie_driver_process.c +++ b/Libraries/NixieDriver/nixie_driver_process.c @@ -5,68 +5,68 @@ #include <stdint.h> -// FreeRTOS includes +// FreeRTOS includes #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "semphr.h" -// - -// - -// - -// - 1 -// - 2 - -#define TUBE_HEATING_UP 0 - - -static const uint16_t tube_off_digit = 0; // , - -// . . -// , 1 -const uint16_t tube_digits [MAX_DIGITS] = { // - TUBE_DIGIT_0, // 0 - TUBE_DIGIT_1, // 1 - TUBE_DIGIT_2, // 2 - TUBE_DIGIT_3, // 3 - TUBE_DIGIT_4, // 4 - TUBE_DIGIT_5, // 5 - TUBE_DIGIT_6, // 6 - TUBE_DIGIT_7, // 7 - TUBE_DIGIT_8, // 8 - TUBE_DIGIT_9, // 9 - TUBE_DIGIT_DP1, // dp1 - TUBE_DIGIT_DP2, // dp2 - TUBE_DIGIT_EMPTY // +// - массив для цифр дешифратора +// - массив для номера лампы +// - счетчик номера текущей лампы +// - таймер1 для времени горения +// - таймер2 для времени затухания + +#define TUBE_HEATING_UP 0 + +static const uint16_t tube_off_digit = 0; // Символ для дешифратора, чтобы лампа не горела + +// Массив значений цифр для дешифратора. Если старший байт вперед. +// И учтено, что все значения сдвинуты на 1 влево +const uint16_t tube_digits [MAX_DIGITS] = { + // Цифра на лампе + TUBE_DIGIT_0, // 0 + TUBE_DIGIT_1, // 1 + TUBE_DIGIT_2, // 2 + TUBE_DIGIT_3, // 3 + TUBE_DIGIT_4, // 4 + TUBE_DIGIT_5, // 5 + TUBE_DIGIT_6, // 6 + TUBE_DIGIT_7, // 7 + TUBE_DIGIT_8, // 8 + TUBE_DIGIT_9, // 9 + TUBE_DIGIT_DP1, // dp1 + TUBE_DIGIT_DP2, // dp2 + TUBE_DIGIT_EMPTY, // лампа не горит }; -// . , -// SPI -// , 1 +// Лампы на плате идут слева направо. Значение ячейки массива с учетом, если +// старший байт идет вперед в SPI +// И учтено, что все значения сдвинуты на 1 влево static const uint16_t tube_num [ MAX_TUBES ] = { - TUBE_NUM_1, // 1- - TUBE_NUM_2, // 2- - TUBE_NUM_3, // 3- - TUBE_NUM_4, // 4- - TUBE_NUM_5, // 5- - TUBE_NUM_6 // 6- + TUBE_NUM_1, // 1-я лампа + TUBE_NUM_2, // 2-я лампа + TUBE_NUM_3, // 3-я лампа + TUBE_NUM_4, // 4-я лампа + TUBE_NUM_5, // 5-я лампа + TUBE_NUM_6, // 6-я лампа }; -// - +// Текущий буфер с данными-цифрами на лампы static uint16_t curr_tube_bufer [ MAX_TUBES ] = { - TUBE_DIGIT_1, // 0 - TUBE_DIGIT_1, // 1 - TUBE_DIGIT_1, // 2 - TUBE_DIGIT_1, // 3 - TUBE_DIGIT_1, // 4 - TUBE_DIGIT_1 // 5 + TUBE_DIGIT_1, // 0 + TUBE_DIGIT_1, // 1 + TUBE_DIGIT_1, // 2 + TUBE_DIGIT_1, // 3 + TUBE_DIGIT_1, // 4 + TUBE_DIGIT_1, // 5 }; -// ------------------------------------------------------------------ // +// Яркость ------------------------------------------------------------------ // -// / +// горит / не горит // time1 / time2 // 1 9 // 2 8 @@ -79,63 +79,40 @@ static uint16_t curr_tube_bufer [ MAX_TUBES ] = { // 9 1 // 10 0 -#define TIME_PERIOD_TCONST (uint32_t)80 // . - // . 100 , = 80 => T = 80*100 = 8000 = 8 -#define TIME_MIN (uint32_t)1 // = 100 . +#define TIME_PERIOD_TCONST (uint32_t)80 // Время полного периода частоты работы ламп. Единица измерения зависит от настройки + // таймера. В данном случае таймер тикает раз в 100 мкс, значит Т = 80 => T = 80*100 = 8000мкс = 8мс +#define TIME_MIN (uint32_t)1 // Минимальный шаг времени таймера = 100 мкс. Минимальное время горения лампы -// - DARK LIGHT -// ( TIME_ON TIME_OFF) +// - добавить состояния DARK и LIGHT +// (по сути это только комбинации TIME_ON и TIME_OFF) #define TIME_ON 2//5//20 #define TIME_OFF 23//22 -// / -#define TIME_OFF_BRIGHT 0 -#define TIME_OFF_DARK 100 +// Время паузы после вкл/выкл всез ламп поочереди +#define TIME_OFF_BRIGHT 0 +#define TIME_OFF_DARK 100 #define TIME_TEST 10000 -static uint32_t time_on = TIME_ON; // -static uint32_t time_off = TIME_OFF; // ( ) +static uint32_t time_on = TIME_ON; // Время горения лампы +static uint32_t time_off = TIME_OFF; // Время на угасание лампы ( чтобы она успела погаснуть полностью ) static uint32_t time_off2 = TIME_OFF_DARK; -// static uint32_t time_on = TIME_OFF; -// static uint32_t time_off = TIME_ON; -// static uint32_t time_off2 = TIME_OFF_BRIGHT; -//static uint32_t coef_brightness = 1; // . ! - -// -// .. 2 . -//static uint8_t first_byte; - -// -//static uint16_t tube_nbr_second_value; - -// +// Сообщения очереди ОСРВ QueueHandle_t queue_new_value; QueueHandle_t queue_new_data; static LightSensorState_t light_sensor_state; extern QueueHandle_t queue_light_sensor; -// -------------------------------------------------- // -// +// Прототипы функций файла -------------------------------------------------- // +// Открытые void NixieDriver_SendValue ( uint8_t *value_arr ); -// +// Закрытые static void SwitchOnTube ( uint8_t tube_nbr ); static void SwitchOffTube ( uint8_t tube_nbr ); -// - ( EE ) -// void NixieDriver_LoadBrightnessFromMemory ( void ); // - coef_brightness -//static void NewTimeCalculate ( uint32_t *time_on, uint32_t *time_off ); -// - - NixieDriver_SetBrightness ( uint32_t ??? ); // ? -// - - NixieDriver_IncreaseBrighntness ( void ); // ( . +1 ) -// - - NixieDriver_DecreaseBrighntness ( void ); // ( . -1 ) -#if TUBE_HEATING_UP == 0 static uint8_t LoadNextValueToTubes ( void ); -#else -static uint8_t LoadNextValueToTubes ( void ); -#endif -//static void TestLoadNewValueToClock ( void ); static void UpdateValueForClock ( void ); static void CheckLightSensor (void); @@ -145,8 +122,6 @@ static void CheckLightSensor (void); // ---------------------------------------------------------------------------- void NixieDriverInitProcess ( void ) { - //first_byte = 0; - queue_new_value = xQueueCreate ( 1, sizeof (uint8_t*) ); configASSERT( queue_new_value ); queue_new_data = xQueueCreate ( 1, sizeof (DataToIndicate_t) ); @@ -155,49 +130,28 @@ void NixieDriverInitProcess ( void ) // ---------------------------------------------------------------------------- -// -, Nixie -// - , 100 +// Ф-я, реализующая беспрерывный процесс динамической индикации ламп Nixie +// Ф-я вызывается из прерывания таймера, настроенного на 100 мкс // ---------------------------------------------------------------------------- void ProcessNixieDriverFromISR ( void ) { static uint8_t process_indic_state = 0; static uint32_t timer = TIME_ON; - static uint8_t curr_tube_num = 0; - + static uint8_t curr_tube_num = 0; timer++; - //timer_test++; - -#if TUBE_HEATING_UP == 0 - +#if TUBE_HEATING_UP == 0 switch ( process_indic_state ) { - case 0: - - if ( timer >= time_off ) // + if ( timer >= time_off ) // Ждем время горения лампы { curr_tube_num = LoadNextValueToTubes (); SwitchOnTube ( curr_tube_num ); timer = 0; process_indic_state = 1; - /* - if ( curr_tube_num == (MAX_TUBES - 1) ) - { - UpdateValueForClock (); - CheckLightSensor(); - - // SwitchOffTube ( curr_tube_num ); - //process_indic_state = 2; - //timer = 0; - - } - */ } - break; - case 1: - if ( timer >= time_on ) { SwitchOffTube ( curr_tube_num ); @@ -215,77 +169,38 @@ void ProcessNixieDriverFromISR ( void ) } } - break; - case 2: - - if ( timer >= time_off2 ) - { - //SwitchOnTube ( curr_tube_num ); - timer = time_off; - process_indic_state = 0; - } - - break; - - } // end switch - -#else -/* - switch ( process_indic_state ) - { - - case 0: - - SwitchOnTube ( curr_tube_num ); - timer = 0; - process_indic_state = 1; - - break; - - case 1: - - if ( timer >= time1 ) // + if ( timer >= time_off2 ) { - curr_tube_num = LoadNextValueToTubes (); - timer = 0; + timer = time_off; process_indic_state = 0; } - break; - } // end switch - */ - #endif - } // ---------------------------------------------------------------------------- -// - SPI -// . -// - , -// - +// Ф-я подготовки и запуска передачи байт по SPI в сдвиговые регистры +// управеления динамической индикацией. По сути включает нужную лампу +// Ф-я принимает текущий номер лампы, для которой будет формироваться +// пакет-кадр // ---------------------------------------------------------------------------- static void SwitchOnTube ( uint8_t tube_nbr ) { - // - - // - - + // - сначала отправляем пару байт с номером лампы + // - затем отправляем пару байт с номером цифры static uint16_t temp; - temp = 0; - temp = tube_num [ tube_nbr ]; //(uint16_t)curr_tube_bufer [ tube_nbr ]; + temp = tube_num [ tube_nbr ]; temp |= curr_tube_bufer [ tube_nbr ]; - NIX_DRIVER_RESET_ST_PIN; - - // .. GPIO, - // - // : - // , SPI, - // , ST + // Т.к. точки на лампах управляются напрямую с МК через GPIO, + // то нужно проверять вручную идет ли в пакете точка + // Маленький нюанс: + // Если мы выставим сигнал на точки раньше, чем передадим пакет на включение ламп по SPI, + // то по идее точки включатся раньше, чем подастся сигнал ST if (curr_tube_bufer [ tube_nbr ] & TUBE_DIGIT_DP1) { NIX_DRIVER_SET_TUB_DP1_PIN; @@ -294,7 +209,6 @@ static void SwitchOnTube ( uint8_t tube_nbr ) { NIX_DRIVER_RESET_TUB_DP1_PIN; } - if (curr_tube_bufer [ tube_nbr ] & TUBE_DIGIT_DP2) { NIX_DRIVER_SET_TUB_DP2_PIN; @@ -303,82 +217,32 @@ static void SwitchOnTube ( uint8_t tube_nbr ) { NIX_DRIVER_RESET_TUB_DP2_PIN; } - SPI_I2S_SendData16 ( NIX_SPIx, temp ); SPI_I2S_ITConfig ( NIX_SPIx, SPI_I2S_IT_TXE, ENABLE ); } - // ---------------------------------------------------------------------------- -// - +// Ф-я отключает лампу // ---------------------------------------------------------------------------- static void SwitchOffTube ( uint8_t tube_nbr ) { - //static uint16_t value_to_spi1; - //static uint16_t temp1; - - //value_to_spi1 = (uint16_t)tube_off_digit; - //value_to_spi1 <<= 8; - - //temp1 = 0; - //temp1 = (uint16_t)tube_num [ tube_nbr ]; - - //value_to_spi1 |= temp1; - - //first_byte = 1; - //tube_nbr_second_value = tube_off_digit; NIX_DRIVER_RESET_ST_PIN; - NIX_DRIVER_RESET_TUB_DP1_PIN; NIX_DRIVER_RESET_TUB_DP2_PIN; SPI_I2S_SendData16 ( NIX_SPIx, tube_off_digit ); SPI_I2S_ITConfig ( NIX_SPIx, SPI_I2S_IT_TXE, ENABLE ); } -// ---------------------------------------------------------------------------- -// - -// SPI -// - SPI -// , GPIO -// ---------------------------------------------------------------------------- -// void NixieDriverCheckDPPins (void) -// { -// ; -// } - - -// ---------------------------------------------------------------------------- -// - 2 SPI -// - NIX_SPIx_IRQHandler -// ---------------------------------------------------------------------------- -// uint8_t NixieDriverProcessCheckIsFirstByte (void) -// { -// //return first_byte; -// return 0; -// } - - -// ---------------------------------------------------------------------------- -// - -// ---------------------------------------------------------------------------- -// void NixieDriverProcessSendSecondByte ( void ) -// { -// first_byte = 0; -// SPI_I2S_SendData16 ( NIX_SPIx, tube_nbr_second_value ); -// } - - #if TUBE_HEATING_UP == 1 // ---------------------------------------------------------------------------- -// - +// Временная ф-я для прогрева каждой лампы по каждому катоду // ---------------------------------------------------------------------------- static uint8_t LoadNextValueToTubes ( void ) { static uint8_t curr_tube_num = 0; static uint8_t curr_digit = 0; - if ( curr_digit == 10 ) - { + { if ( curr_tube_num == 5 ) { curr_tube_num = 0; @@ -402,91 +266,39 @@ static uint8_t LoadNextValueToTubes ( void ) static uint8_t LoadNextValueToTubes ( void ) { static uint8_t curr_tube_num = 5; - if ( curr_tube_num == 5 ) { curr_tube_num = 0; - //NIX_TEST_PIN_PB11_TOGGLE; } else { curr_tube_num++; } - return curr_tube_num; } #endif - -// ---------------------------------------------------------------------------- -// - -// -// ---------------------------------------------------------------------------- -//static void NewTimeCalculate ( uint32_t *time_on, uint32_t *time_off ) -//{ -//// uint32_t time_check; -//// -//// time_on = TIME_MIN*coef_brightness; -//// -//// if ( time_on > TIME_PERIOD_TCONST ) { return; } -// -//} - - -// ---------------------------------------------------------------------------- -// - -// -// ---------------------------------------------------------------------------- -//static void TestLoadNewValueToClock ( void ) -//{ -// static uint8_t digit_num = 0; -// -// //curr_tube_bufer [] = tube_digits []; -// // -// for ( uint8_t tube_num = 0; tube_num < MAX_TUBES; tube_num++ ) -// { -// curr_tube_bufer [tube_num] = tube_digits [digit_num]; -// } -// digit_num++; -// -// if ( digit_num == MAX_DIGITS ) -// { -// digit_num = 0; -// } -//} - - // ---------------------------------------------------------------------------- -// -// - - ProcessNixieDriverFromISR () -// ( 6- ) +// Обновления значения выводимого на индикаторы +// Ф-я вызывается из ф-ии ProcessNixieDriverFromISR () после вывода одного +// цикла ( то есть 6-ти индикаторов ) // ---------------------------------------------------------------------------- -// - ! , -// SPI. , -// . . -// , . -// , . +// - внимание! нужно сделать два буфера, из которых в прерывании берутся +// данные на передачу в лампы в SPI. Это нужно, чтобы не тратить время на +// заполнение данных буфера. Сделать флаг или семафор. Пока из одного +// буфера данные уходят, то в другой заполняют новые данные. А когда они +// заполнятся, то просто поменять указатель на массив. -// - tube_digits [10] -// ( 10) +// - сделать защиту от выхода за границы массива tube_digits [10] +// (не больше 10) static void UpdateValueForClock ( void ) { - // - - // , curr_tube_bufer [] - //uint8_t *value_arr; + // - проверяем сообщение очереди с новыми данными для отображения + // если есть, то заполняем буфер curr_tube_bufer [] новыми значениями DataToIndicate_t data_struct; - -// if ( pdPASS == xQueueReceive ( queue_new_value, &value_arr, 0 ) ) -// { -// for ( uint8_t tube_num = 0; tube_num < MAX_TUBES; tube_num++ ) -// { -// curr_tube_bufer [tube_num] = tube_digits [ value_arr [tube_num] ]; -// } -// } - if ( pdPASS == xQueueReceive ( queue_new_data, &data_struct, 0 ) ) { @@ -496,9 +308,7 @@ static void UpdateValueForClock ( void ) curr_tube_bufer [3] = tube_digits [ data_struct.indic_4 ]; curr_tube_bufer [4] = tube_digits [ data_struct.indic_5 ]; curr_tube_bufer [5] = tube_digits [ data_struct.indic_6 ]; - } - } @@ -527,69 +337,10 @@ static void CheckLightSensor (void) // ---------------------------------------------------------------------------- -// - -// 6 ( ) +// Ф-я кладет сообщение в очередь ОС и передает указатель на массив с данными +// Размер массива всегда 6 (количество ламп) // ---------------------------------------------------------------------------- void NixieDriver_SendValue ( uint8_t *value_arr ) { xQueueSend ( queue_new_value, &value_arr, 0 ); } - -//void NixieDriver_SendValue2 ( uint8_t *value_arr ) -//{ -// xQueueSend ( queue_new_value, &value_arr, 0 ); -//} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Libraries/NixieDriver/nixie_driver_process.h b/Libraries/NixieDriver/nixie_driver_process.h index 00f08f5..bc4b4ca 100644 --- a/Libraries/NixieDriver/nixie_driver_process.h +++ b/Libraries/NixieDriver/nixie_driver_process.h @@ -5,50 +5,48 @@ #include "FreeRTOS.h" #include "queue.h" -// 8- . -// , - -#define MAX_TUBES 6 -#define MAX_DIGITS 13//11 - -// tube_digit [] 16- -#define TUBE_DIGIT_0 8192 //0010 0000 0000 0000 -#define TUBE_DIGIT_1 128 //0000 0000 1000 0000 -#define TUBE_DIGIT_2 64 //0000 0000 0100 0000 -#define TUBE_DIGIT_3 32 //0000 0000 0010 0000 -#define TUBE_DIGIT_4 16 //0000 0000 0001 0000 -#define TUBE_DIGIT_5 8 //0000 0000 0000 1000 -#define TUBE_DIGIT_6 4 //0000 0000 0000 0100 -#define TUBE_DIGIT_7 2 //0000 0000 0000 0010 -#define TUBE_DIGIT_8 32768 //1000 0000 0000 0000 -#define TUBE_DIGIT_9 16384 //0100 0000 0000 0000 -#define TUBE_DIGIT_DP1 1 //0000 0000 0000 0001 , .. GPIO -#define TUBE_DIGIT_DP2 256 //0000 0001 0000 0000 , .. GPIO -#define TUBE_DIGIT_EMPTY 0 - -#define TUBE_EMPTY_VALUE 0 // "10". , - // , - // - -// tube_num [ MAX_TUBES ] -#define TUBE_NUM_6 1 -#define TUBE_NUM_5 256 -#define TUBE_NUM_4 512 -#define TUBE_NUM_3 1024 -#define TUBE_NUM_2 2048 -#define TUBE_NUM_1 4096 - -// -// +// Схема драйвера Никси на трех сдвиговых 8-разрядных регистрах. +// Первые два регистра для цифр, третий регистр для выбора лампы + +#define MAX_TUBES 6 +#define MAX_DIGITS 13//11 + +// Коды цифр ламп для буфера tube_digit [] Значения 16-разрядные +#define TUBE_DIGIT_0 8192 //0010 0000 0000 0000 +#define TUBE_DIGIT_1 128 //0000 0000 1000 0000 +#define TUBE_DIGIT_2 64 //0000 0000 0100 0000 +#define TUBE_DIGIT_3 32 //0000 0000 0010 0000 +#define TUBE_DIGIT_4 16 //0000 0000 0001 0000 +#define TUBE_DIGIT_5 8 //0000 0000 0000 1000 +#define TUBE_DIGIT_6 4 //0000 0000 0000 0100 +#define TUBE_DIGIT_7 2 //0000 0000 0000 0010 +#define TUBE_DIGIT_8 32768 //1000 0000 0000 0000 +#define TUBE_DIGIT_9 16384 //0100 0000 0000 0000 +#define TUBE_DIGIT_DP1 1 //0000 0000 0000 0001 любое отличное от остальных число, т.к. точки на лампах управляются от отдельных GPIO +#define TUBE_DIGIT_DP2 256 //0000 0001 0000 0000 любое отличное от остальных число, т.к. точки на лампах управляются от отдельных GPIO +#define TUBE_DIGIT_EMPTY 0 + +#define TUBE_EMPTY_VALUE 0 // Было "10". Число, которое нужно записать в массив + // данных на вывод, чтобы получить негорящий + // индикатор + +// Коды номера лампы для буфера tube_num [ MAX_TUBES ] +#define TUBE_NUM_6 1 +#define TUBE_NUM_5 256 +#define TUBE_NUM_4 512 +#define TUBE_NUM_3 1024 +#define TUBE_NUM_2 2048 +#define TUBE_NUM_1 4096 + +// Структура данных на индикацию для передачи целиком всей структуры через +// очередь ОС typedef struct { - uint8_t indic_1; uint8_t indic_2; uint8_t indic_3; uint8_t indic_4; uint8_t indic_5; - uint8_t indic_6; - + uint8_t indic_6; } DataToIndicate_t; @@ -60,8 +58,5 @@ extern QueueHandle_t queue_new_data; #define NixieDriver_SendValue2(X) send(X) void ProcessNixieDriverFromISR ( void ); -//uint8_t NixieDriverProcessCheckIsFirstByte (void); -//void NixieDriverCheckDPPins (void); -//void NixieDriverProcessSendSecondByte (void); -#endif //NIXIE_DRIVER_PROCESS_INCLUDED
\ No newline at end of file +#endif //NIXIE_DRIVER_PROCESS_INCLUDED diff --git a/Libraries/NixieDriver/nixie_driver_task.c b/Libraries/NixieDriver/nixie_driver_task.c index 18e554c..b968128 100644 --- a/Libraries/NixieDriver/nixie_driver_task.c +++ b/Libraries/NixieDriver/nixie_driver_task.c @@ -2,7 +2,6 @@ #include "nixie_driver_config.h" #include "nixie_driver_process.h" -// FreeRTOS includes #include "FreeRTOS.h" #include "task.h" #include "queue.h" @@ -20,7 +19,7 @@ void NixieDriverInit ( void ) // ---------------------------------------------------------------------------- -// - , ? +// - нужна ли эта задача, если все работает в прерывании? // ---------------------------------------------------------------------------- void ProcessFSM_NixieDriver ( void ) { @@ -29,60 +28,9 @@ void ProcessFSM_NixieDriver ( void ) // ---------------------------------------------------------------------------- -// , NixieClockSimply +// Задача ОС, реализующая головную задачу программы NixieClockSimply // ---------------------------------------------------------------------------- void NixieDriver_Task ( void *pvParameters ) { while(1)ProcessFSM_NixieDriver (); - //vTaskDelete(NULL); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Libraries/NixieDriver/nixie_driver_task.h b/Libraries/NixieDriver/nixie_driver_task.h index 1c9fb39..71546cd 100644 --- a/Libraries/NixieDriver/nixie_driver_task.h +++ b/Libraries/NixieDriver/nixie_driver_task.h @@ -5,4 +5,4 @@ void NixieDriverInit ( void ); void NixieDriver_Task ( void *pvParameters ); -#endif //NIXIE_DRIVER_TASK_INCLUDED
\ No newline at end of file +#endif //NIXIE_DRIVER_TASK_INCLUDED |