Browse Source

Убрал RTOS из проекта. Исправил подсчёт ёмкости.

Vladimir N. Shilov 8 years ago
parent
commit
e1f2c914f2
5 changed files with 105 additions and 39 deletions
  1. 1 8
      ChACM.cbp
  2. 6 6
      Makefile
  3. 6 1
      ReadMe.txt
  4. 84 16
      src/main.c
  5. 8 8
      src/stm8s_it.c

+ 1 - 8
ChACM.cbp

@@ -6,7 +6,7 @@
 		<Option makefile_is_custom="1" />
 		<Option pch_mode="2" />
 		<Option compiler="null" />
-		<Option virtualFolders="RTOS\;SPL\;SPL\src\;SPL\inc\;" />
+		<Option virtualFolders="SPL\;SPL\src\;SPL\inc\;" />
 		<Build>
 			<Target title="Release">
 				<Option output="bin/Release/ChACM" prefix_auto="1" extension_auto="1" />
@@ -197,13 +197,6 @@
 		</Unit>
 		<Unit filename="inc/stm8s_conf.h" />
 		<Unit filename="inc/stm8s_it.h" />
-		<Unit filename="lib/rtos.c">
-			<Option compilerVar="CC" />
-			<Option virtualFolder="RTOS/" />
-		</Unit>
-		<Unit filename="lib/rtos.h">
-			<Option virtualFolder="RTOS/" />
-		</Unit>
 		<Unit filename="src/main.c">
 			<Option compilerVar="CC" />
 		</Unit>

+ 6 - 6
Makefile

@@ -16,20 +16,20 @@ FLASHTOOL=C:/STMicroelectronics/st_toolset/stvp/STVP_CmdLine.exe
 FLASHOPT=-Device=STM8S003x6
 
 DEFINES = -D USE_STDPERIPH_DRIVER
-DEFINES += -D USE_RTOS
 DEFINES += -D STM8S003
+#DEFINES += -D USE_RTOS
 
 # Sources paths
 APP_SRC = src
-LIB_SRC = lib
+#LIB_SRC = lib
 
 vpath %.c $(APP_SRC)
-vpath %.c $(LIB_SRC)
+#vpath %.c $(LIB_SRC)
 vpath %.c StdPerphDrv/src
 
 # Include paths
 INCLUDES = -I inc
-INCLUDES += -I lib
+#INCLUDES += -I lib
 INCLUDES += -I StdPerphDrv/inc
 
 
@@ -50,7 +50,7 @@ DATA_MODEL = small
 # Application object files
 APP_OBJECTS = main.o
 APP_OBJECTS += stm8s_it.o
-APP_OBJECTS += rtos.o
+#APP_OBJECTS += rtos.o
 #APP_ASM_OBJECTS = atomport-asm-iar.o
 
 # STM8S Peripheral driver object files
@@ -87,7 +87,7 @@ vpath %.elf .\$(OUT_DIR)
 vpath %.hex .\$(OUT_DIR)
 
 # Compiler/Assembler flags
-CFLAGS = -e -Oh $(DEFINES)
+CFLAGS = -e -Ohs $(DEFINES)
 CFLAGS += --code_model $(CODE_MODEL) --data_model $(DATA_MODEL)
 CFLAGS += --dlib_config "$(EWSTM8_DIR)\lib\$(LIB_MODEL)"
 CFLAGS += -D NDEBUG -D $(PART)

+ 6 - 1
ReadMe.txt

@@ -106,7 +106,12 @@ Vin	    Vout	    R1	    R2	    Error
 2016.11.12
 
 Смотрю на программу и хочу выкинуть "ртос".
-1-ый таймер остаётся пинать АЦП, 4-ый будет каждые 5 мсек переключать 
+1-ый таймер остаётся пинать АЦП, 4-ый будет каждые 5 мсек переключать
 индикаторы, а 2-ой каждый 200 мсек будет обновлять инфу для выхода.
 Обработчик кнопки или паузы прилепить тоже на 4-ый.
 Хотя 2-ой тут и не нужен...
+
+---
+2016.11.14
+
+RTOS выкинул. на очереди SPL? :-)

+ 84 - 16
src/main.c

@@ -21,15 +21,30 @@
 
 /* Includes ------------------------------------------------------------------*/
 #include "stm8s.h"
-#include "rtos.h"
+//#include "rtos.h"
 
 /* Private defines -----------------------------------------------------------*/
+// for 1 msek ticks
+#define TIM4_PERIOD  (uint8_t)124
+
 #define ADC_PORT  GPIOD
 #define ADC_PINS  GPIO_PIN_3
 #define ADC_CHNL  ADC1_CHANNEL_4
 #define ADC_SCHT  ADC1_SCHMITTTRIG_CHANNEL4
 #define ADC_SMPLS 64
 
+#define BTN_PORT  (GPIOA)
+#define BTN_PINS  (GPIO_PIN_2)
+
+/*
+ AAA
+F   B
+F   B
+ GGG
+E   C
+E   C
+ DDD P
+*/
 #define LED_ANOD1_PORT  GPIOA
 #define LED_ANOD1_PIN   GPIO_PIN_3
 #define LED_ANOD2_PORT  GPIOD
@@ -37,19 +52,26 @@
 #define LED_ANOD3_PORT  GPIOD
 #define LED_ANOD3_PIN   GPIO_PIN_4
 
-#define LED_SEG1_PORT  GPIOA
-#define LED_SEG1_PINS  GPIO_PIN_1
-#define LED_SEG2_PORT  GPIOB
-#define LED_SEG2_PINS  (GPIO_PIN_5 | GPIO_PIN_4)
-#define LED_SEG3_PORT  GPIOC
-#define LED_SEG3_PINS  (GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_3 | GPIO_PIN_5)
+#define LED_SEG1_PORT   GPIOA
+#define LED_SEG1_PINS   GPIO_PIN_1
+#define LED_SEG_F       GPIO_PIN_1
 
-#define BTN_PORT  (GPIOA)
-#define BTN_PINS  (GPIO_PIN_2)
+#define LED_SEG2_PORT   GPIOB
+#define LED_SEG2_PINS   (GPIO_PIN_5 | GPIO_PIN_4)
+#define LED_SEG_A       GPIO_PIN_5
+#define LED_SEG_B       GPIO_PIN_4
+
+#define LED_SEG3_PORT   GPIOC
+#define LED_SEG3_PINS   (GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_3 | GPIO_PIN_5)
+#define LED_SEG_G       GPIO_PIN_3
+#define LED_SEG_C       GPIO_PIN_4
+#define LED_SEG_P       GPIO_PIN_5
+#define LED_SEG_D       GPIO_PIN_6
+#define LED_SEG_E       GPIO_PIN_7
 
 #define LED_OUT_OFF   {LED_SEG1_PORT->ODR |= LED_SEG1_PINS; LED_SEG2_PORT->ODR |= LED_SEG2_PINS; LED_SEG3_PORT->ODR |= LED_SEG3_PINS;}
-#define LED_OUT_DP    GPIOC->ODR &= (~GPIO_PIN_5);
-#define LED_OUT_MM    GPIOC->ODR &= 0xF7;
+#define LED_OUT_DP    GPIOC->ODR &= (~LED_SEG_P);
+#define LED_OUT_MM    GPIOC->ODR &= LED_SEG_G;
 #define LED_OUT_0     GPIOA->ODR &= 0xFD; GPIOB->ODR &= 0xCF; GPIOC->ODR &= 0x29;
 #define LED_OUT_1     GPIOB->ODR &= 0xEF; GPIOC->ODR &= 0xE9;
 #define LED_OUT_2     GPIOB->ODR &= 0xCF; GPIOC->ODR &= 0x31;
@@ -67,11 +89,13 @@
 #define LED_ANODE_ON3 LED_ANOD3_PORT->ODR |= LED_ANOD3_PIN;
 
 #define SUB_SECOND_CNT  5
+#define LED_ONE_PERIOD  5
 
 /* Private function prototypes -----------------------------------------------*/
 static void ADC_Config(void);
 static void GPIO_Config(void);
 static void TIM1_Config(void);
+static void TIM4_Config(void);
 static void OutputToLed(void);
 static void PrepareForLed(void);
 //static void CountCapacity(void);
@@ -81,6 +105,7 @@ static void PrepareForLed(void);
 /* Private variables ---------------------------------------------------------*/
 __IO uint16_t ConversionBuffer[ADC_SMPLS];
 __IO uint8_t BufferIndex = 0;
+__IO uint8_t LedCnt = 0;
 static uint16_t Current = 0;
 static uint32_t Capacity = 0;
 static uint8_t LedDigits[3] = {0, 0, 0};
@@ -112,14 +137,25 @@ void main(void)
   TIM1_Config();
 
   /* Initialize dispatcher */
-  RTOS_Init();
-  RTOS_SetTask(OutputToLed, 0, 5);
-  RTOS_SetTask(PrepareForLed, 210, 200);
+  //RTOS_Init();
+  //RTOS_SetTask(OutputToLed, 0, 5);
+  //RTOS_SetTask(PrepareForLed, 210, 200);
   //RTOS_SetTask(CountCapacity, 1005, 1000);
 
+  /* TIM4 configuration -----------------------------------------*/
+  TIM4_Config();
+
+  /* enable interrupts */
+  enableInterrupts();
+
   /* Infinite loop */
   while (1)
   {
+    if (LedCnt >= LED_ONE_PERIOD) {
+      LedCnt = 0;
+      OutputToLed();
+    }
+
     if (BufferIndex >= ADC_SMPLS) {
         BufferIndex = 0;
 
@@ -153,14 +189,16 @@ void main(void)
         SubSecondCnt --;
 
         if(SubSecondCnt == 0){
-          Capacity += SubSecondBfr;
+          Capacity += ( (SubSecondBfr + (SUB_SECOND_CNT/2)) / SUB_SECOND_CNT );
           SubSecondBfr = 0;
           SubSecondCnt = SUB_SECOND_CNT;
         }
 
+        PrepareForLed();
+
     } // End of if (BufferIndex >= ADC_SMPLS)
 
-    RTOS_DispatchTask();
+    //RTOS_DispatchTask();
     wfi();
   } // End of infinity
 
@@ -348,6 +386,36 @@ static void TIM1_Config(void)
   TIM1_Cmd(ENABLE);
 }
 
+/**
+  * @brief  Configure TIM4.
+  * @param  None
+  * @retval None
+  */
+static void TIM4_Config(void)
+{
+  TIM4_DeInit();
+
+  /*
+  TIM4 configuration:
+   - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
+     clock used is 16 MHz / 128 = 125 000 Hz
+   - With 125 000 Hz we can generate time base:
+     max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms
+     min time base is 0.016 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 = 0.016 ms
+   - In this example we need to generate a time base equal to 1 ms
+     so TIM4_PERIOD = (0.001 * 125000 - 1) = 124
+   */
+
+  /* Time base configuration */
+  TIM4_TimeBaseInit(TIM4_PRESCALER_128, TIM4_PERIOD);
+  /* Clear TIM4 update flag */
+  TIM4_ClearFlag(TIM4_FLAG_UPDATE);
+  /* Enable update interrupt */
+  TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
+
+  /* Enable TIM4 */
+  TIM4_Cmd(ENABLE);
+}
 
 #ifdef USE_FULL_ASSERT
 

+ 8 - 8
src/stm8s_it.c

@@ -40,6 +40,7 @@
 /* Private variables ---------------------------------------------------------*/
 extern __IO uint16_t ConversionBuffer[64];
 extern __IO uint8_t BufferIndex;
+extern __IO uint8_t LedCnt;
 
 /* Private function prototypes -----------------------------------------------*/
 /* Private functions ---------------------------------------------------------*/
@@ -496,19 +497,18 @@ INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23)
   */
  }
 #else /* STM8S208 or STM8S207 or STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x */
-#ifndef USE_RTOS
 /**
   * @brief Timer4 Update/Overflow Interrupt routine.
   * @param  None
   * @retval None
   */
- INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
- {
-  /* In order to detect unexpected events during development,
-     it is recommended to set a breakpoint on the following instruction.
-  */
- }
-#endif
+INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
+{
+   /* Cleat Interrupt Pending bit */
+   TIM4->SR1 = (uint8_t)(~(uint8_t)TIM4_IT_UPDATE);
+
+   LedCnt ++;
+}
 #endif /* (STM8S903) || (STM8AF622x)*/
 
 /**