Эх сурвалжийг харах

VAPC: добавил диспетчер.

Vladimir N. Shilov 10 жил өмнө
parent
commit
cdc4354c28
9 өөрчлөгдсөн 378 нэмэгдсэн , 231 устгасан
  1. 8 0
      ReadMe.txt
  2. 5 5
      VAPC-meter.cbp
  3. 41 16
      VAPC-meter.layout
  4. 225 0
      lib/rtos.c
  5. 62 0
      lib/rtos.h
  6. 0 155
      lib/timing_delay.c
  7. 0 43
      lib/timing_delay.h
  8. 26 3
      src/main.c
  9. 11 9
      src/stm8l15x_it.c

+ 8 - 0
ReadMe.txt

@@ -49,3 +49,11 @@ SVN-
 
 настройка SPI.
 должно вывести 0-7 на индикаторы.
+
+---
+2015.05.18
+
+добавил RTOS, перенёс туда timing_delay, задержка на 4-ом таймере 1 мс,
+обработчик таймера перенёс в RTOS.
+
+должно вывести 0-7, через 5 сек 8-f, и так по кругу.

+ 5 - 5
VAPC-meter.cbp

@@ -6,7 +6,7 @@
 		<Option makefile_is_custom="1" />
 		<Option pch_mode="2" />
 		<Option compiler="null" />
-		<Option virtualFolders="MAX7219\;StdPerphDrv\;StdPerphDrv\sources\;StdPerphDrv\headers\;Timing delay\;" />
+		<Option virtualFolders="MAX7219\;StdPerphDrv\;StdPerphDrv\sources\;StdPerphDrv\headers\;RTOS\;" />
 		<Build>
 			<Target title="Release">
 				<Option output="bin/Release/VAPC-meter" prefix_auto="1" extension_auto="1" />
@@ -225,12 +225,12 @@
 		<Unit filename="lib/max7219.h">
 			<Option virtualFolder="MAX7219/" />
 		</Unit>
-		<Unit filename="lib/timing_delay.c">
+		<Unit filename="lib/rtos.c">
 			<Option compilerVar="CC" />
-			<Option virtualFolder="Timing delay/" />
+			<Option virtualFolder="RTOS/" />
 		</Unit>
-		<Unit filename="lib/timing_delay.h">
-			<Option virtualFolder="Timing delay/" />
+		<Unit filename="lib/rtos.h">
+			<Option virtualFolder="RTOS/" />
 		</Unit>
 		<Unit filename="src/main.c">
 			<Option compilerVar="CC" />

+ 41 - 16
VAPC-meter.layout

@@ -1,44 +1,69 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 <CodeBlocks_layout_file>
 	<ActiveTarget name="Release" />
-	<File name="StdPerphDrv\inc\stm8l15x_clk.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="11542" topLine="255" />
+			<Cursor1 position="2638" topLine="90" />
 		</Cursor>
 	</File>
-	<File name="StdPerphDrv\src\stm8l15x_clk.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\stm8l15x_it.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="21509" topLine="515" />
+			<Cursor1 position="1360" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="lib\timing_delay.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="3396" topLine="54" />
+			<Cursor1 position="6475" topLine="148" />
 		</Cursor>
 	</File>
-	<File name="lib\max7219.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="813" topLine="0" />
+			<Cursor1 position="2457" topLine="26" />
 		</Cursor>
 	</File>
-	<File name="lib\max7219.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="Makefile" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2218" topLine="50" />
+			<Cursor1 position="4622" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="src\main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="StdPerphDrv\src\stm8l15x_tim4.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1495" topLine="58" />
+			<Cursor1 position="19494" topLine="537" />
 		</Cursor>
 	</File>
-	<File name="Makefile" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="StdPerphDrv\inc\stm8l15x.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="4622" topLine="0" />
+			<Cursor1 position="129580" topLine="2906" />
+		</Cursor>
+	</File>
+	<File name="inc\stm8l15x_conf.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="759" topLine="27" />
+		</Cursor>
+	</File>
+	<File name="StdPerphDrv\inc\stm8l15x_clk.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="11542" topLine="255" />
+		</Cursor>
+	</File>
+	<File name="lib\max7219.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="813" topLine="0" />
+		</Cursor>
+	</File>
+	<File name="StdPerphDrv\src\stm8l15x_clk.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="21509" topLine="515" />
+		</Cursor>
+	</File>
+	<File name="lib\max7219.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="2218" topLine="50" />
 		</Cursor>
 	</File>
-	<File name="lib\timing_delay.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="StdPerphDrv\inc\stm8l15x_tim4.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="933" topLine="0" />
+			<Cursor1 position="11103" topLine="332" />
 		</Cursor>
 	</File>
 </CodeBlocks_layout_file>

+ 225 - 0
lib/rtos.c

@@ -0,0 +1,225 @@
+#include "rtos.h"
+#include "stm8l15x_it.h"
+
+/* Private define ------------------------------------------------------------*/
+#define TIM4_PERIOD  (uint8_t)124
+
+/******************************************************************************************
+ * Ïåðåìåííûå ìîäóëÿ
+ */
+static __IO task TaskArray[MAX_TASKS];	// î÷åðåäü çàäà÷
+static __IO uint8_t arrayTail;         // "õâîñò" î÷åðåäè
+static __IO uint16_t TimingDelay;
+
+
+/******************************************************************************************
+ * Èíèöèàëèçàöèÿ ÐÒÎÑ, âðåìÿ òèêà - 1 ìñ
+ */
+inline void RTOS_Init()
+{
+  /* 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 interrupts */
+  enableInterrupts();
+
+  /* Enable TIM4 */
+  TIM4_Cmd(ENABLE);
+
+  /* "õâîñò" â 0 */
+  arrayTail = 0;
+}
+
+/******************************************************************************************
+ * Äîáàâëåíèå çàäà÷è â ñïèñîê
+ */
+void RTOS_SetTask (void (*taskFunc)(void), uint16_t taskDelay, uint16_t taskPeriod)
+{
+   uint8_t i;
+
+   if(!taskFunc) return;
+
+   for(i = 0; i < arrayTail; i++)                     // ïîèñê çàäà÷è â òåêóùåì ñïèñêå
+   {
+      if(TaskArray[i].pFunc == taskFunc)              // åñëè íàøëè, òî îáíîâëÿåì ïåðåìåííûå
+      {
+         DISABLE_INTERRUPT;
+
+         TaskArray[i].delay  = taskDelay;
+         TaskArray[i].period = taskPeriod;
+         TaskArray[i].run    = 0;
+
+//         RESTORE_INTERRUPT;
+         ENABLE_INTERRUPT;
+         return;                                      // îáíîâèâ, âûõîäèì
+      }
+   }
+
+   if (arrayTail < MAX_TASKS)                         // åñëè òàêîé çàäà÷è â ñïèñêå íåò
+   {                                                  // è åñòü ìåñòî,òî äîáàâëÿåì
+      DISABLE_INTERRUPT;
+
+      TaskArray[arrayTail].pFunc  = taskFunc;
+      TaskArray[arrayTail].delay  = taskDelay;
+      TaskArray[arrayTail].period = taskPeriod;
+      TaskArray[arrayTail].run    = 0;
+
+      arrayTail++;                                    // óâåëè÷èâàåì "õâîñò"
+//      RESTORE_INTERRUPT;
+      ENABLE_INTERRUPT;
+   }
+}
+
+/******************************************************************************************
+ * Óäàëåíèå çàäà÷è èç ñïèñêà
+ */
+void RTOS_DeleteTask (void (*taskFunc)(void))
+{
+   uint8_t i;
+
+   for (i=0; i<arrayTail; i++)                        // ïðîõîäèì ïî ñïèñêó çàäà÷
+   {
+      if(TaskArray[i].pFunc == taskFunc)              // åñëè çàäà÷à â ñïèñêå íàéäåíà
+      {
+
+         DISABLE_INTERRUPT;
+         if(i != (arrayTail - 1))                     // ïåðåíîñèì ïîñëåäíþþ çàäà÷ó
+         {                                            // íà ìåñòî óäàëÿåìîé
+            TaskArray[i] = TaskArray[arrayTail - 1];
+         }
+         arrayTail--;                                 // óìåíüøàåì óêàçàòåëü "õâîñòà"
+//         RESTORE_INTERRUPT;
+         ENABLE_INTERRUPT;
+         return;
+      }
+   }
+}
+
+/******************************************************************************************
+ * Äèñïåò÷åð ÐÒÎÑ, âûçûâàåòñÿ â main
+ */
+
+void RTOS_DispatchTask(void)
+{
+   uint8_t i;
+   void (*function) (void);
+
+   for (i=0; i<arrayTail; i++)                        // ïðîõîäèì ïî ñïèñêó çàäà÷
+   {
+      if (TaskArray[i].run == 1)                      // åñëè ôëàã íà âûïîëíåíèå âçâåäåí,
+      {                                               // çàïîìèíàåì çàäà÷ó, ò.ê. âî
+         function = TaskArray[i].pFunc;               // âðåìÿ âûïîëíåíèÿ ìîæåò
+                                                      // èçìåíèòüñÿ èíäåêñ
+         if(TaskArray[i].period == 0)
+         {                                            // åñëè ïåðèîä ðàâåí 0
+            RTOS_DeleteTask(TaskArray[i].pFunc);      // óäàëÿåì çàäà÷ó èç ñïèñêà,
+         } else {
+            TaskArray[i].run = 0;                     // èíà÷å ñíèìàåì ôëàã çàïóñêà
+            if(!TaskArray[i].delay)                   // åñëè çàäà÷à íå èçìåíèëà çàäåðæêó
+            {                                         // çàäàåì åå
+               TaskArray[i].delay = TaskArray[i].period-1;
+            }                                         // çàäà÷à äëÿ ñåáÿ ìîæåò ñäåëàòü ïàóçó
+         }
+         (*function)();                               // âûïîëíÿåì çàäà÷ó
+      }
+   }
+}
+
+/******************************************************************************************
+ * Òàéìåðíàÿ ñëóæáà ÐÒÎÑ (ïðåðûâàíèå àïïàðàòíîãî òàéìåðà)
+ */
+/*
+static void RTOS_Timer(void)
+{
+   uint8_t i;
+
+   for (i=0; i<arrayTail; i++)         // ïðîõîäèì ïî ñïèñêó çàäà÷
+   {
+      if  (TaskArray[i].delay == 0) {  // åñëè âðåìÿ äî âûïîëíåíèÿ èñòåêëî
+         TaskArray[i].run = 1;         // âçâîäèì ôëàã çàïóñêà,
+      } else {
+         TaskArray[i].delay--;         // èíà÷å óìåíüøàåì âðåìÿ
+      }
+   }
+}
+*/
+/**
+  * @brief  Inserts a delay time.
+  * @param  nTime: specifies the delay time length, in milliseconds.
+  * @retval None
+  */
+void Delay(__IO uint16_t nTime)
+{
+  TimingDelay = nTime;
+  while (TimingDelay != 0) {
+      // çäåñü ìîæíî ñïàòü è æäàòü ïðåðûâàíèå
+  }
+}
+
+/**
+  * @brief  Decrements the TimingDelay variable.
+  * @note   This function should be called in the
+  *         TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler in the stm8l15x_it.c file.
+  *
+  *       // INTERRUPT_HANDLER(TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler, 19)
+  *       // {
+  *           // TimingDelay_Decrement();
+  *           // TIM2_ClearITPendingBit(TIM2_IT_Update);
+  *
+  *       // }
+  * @param  None
+  * @retval None
+  */
+/*
+static void TimingDelay_Decrement(void)
+{
+  if (TimingDelay != 0x00)
+  {
+    TimingDelay--;
+  }
+}
+*/
+/**
+  * @brief TIM4 Update/Overflow/Trigger Interrupt routine.
+  * @param  None
+  * @retval None
+  */
+INTERRUPT_HANDLER(TIM4_UPD_OVF_TRG_IRQHandler,25)
+{
+    /* In order to detect unexpected events during development,
+       it is recommended to set a breakpoint on the following instruction.
+    */
+
+    /* Cleat Interrupt Pending bit */
+//    TIM4_ClearITPendingBit(TIM4_IT_Update);
+    TIM4->SR1 = (uint8_t)(~(uint8_t)TIM4_IT_Update);
+
+//    TimingDelay_Decrement();
+   if (TimingDelay > 0) {
+      TimingDelay --;
+   }
+
+//    RTOS_Timer();
+   uint8_t i;
+
+   for (i=0; i<arrayTail; i++) {       // ïðîõîäèì ïî ñïèñêó çàäà÷
+      if  (TaskArray[i].delay == 0) {  // åñëè âðåìÿ äî âûïîëíåíèÿ èñòåêëî
+         TaskArray[i].run = 1;         // âçâîäèì ôëàã çàïóñêà,
+      } else {
+         TaskArray[i].delay--;         // èíà÷å óìåíüøàåì âðåìÿ
+      }
+   }
+
+}

+ 62 - 0
lib/rtos.h

@@ -0,0 +1,62 @@
+#pragma once
+#ifndef __RTOS_H
+#define __RTOS_H
+
+/******************************************************************************************
+ * За основу взят планировщик задач с сайта ChipEnable.ru                                 *
+ * http://chipenable.ru/index.php/programming-avr/item/110-planirovschik.html             *
+ *                                                                                        *
+ * Доработал Шибанов Владимир aka KontAr                                                  *
+ * Дата: 26.03.2014                                                                       *
+ *                                                                                        *
+ * Изменения:                                                                             *
+ * - добавлен однократный вызов задачи                                                    *
+ * - добавлено удаление задачи по имени                                                   *
+ * - при повторном добавлении задачи обновляются ее переменные                            *
+ * - добавлен указатель на "хвост" списка                                                 *
+ * - функции РТОС скорректированы с учетом "хвоста"                                       *
+ *                                                                                        *
+ * 18.05.2015, Shilov V.N. <shilow@ukr.net>                                               *
+ * - скрестил с timing_delay от ST                                                        *
+ * - перенёс сюда обработчик прерываний для уменьшения оверхеда                           *
+ *                                                                                        *
+ ******************************************************************************************/
+
+#include "stm8l15x.h"
+
+// Количество задач
+#define MAX_TASKS	9
+
+#define  ENABLE_INTERRUPT enableInterrupts()
+#define DISABLE_INTERRUPT disableInterrupts()
+
+/******************************************************************************************
+ * Структура задачи
+ */
+typedef struct task
+{
+   void (*pFunc) (void); // указатель на функцию
+   uint16_t delay;       // задержка перед первым запуском задачи
+   uint16_t period;      // период запуска задачи
+   uint8_t run;          // флаг готовности задачи к запуску
+} task;
+
+
+/******************************************************************************************
+ * Переменные
+ */
+
+
+/******************************************************************************************
+ * Прототипы фукнций
+ */
+void RTOS_Init (void);
+void RTOS_SetTask (void (*taskFunc)(void), uint16_t taskDelay, uint16_t taskPeriod);
+void RTOS_DeleteTask (void (*taskFunc)(void));
+void RTOS_DispatchTask (void);
+//void RTOS_Timer(void);
+
+void Delay(__IO uint16_t nTime);
+//void TimingDelay_Decrement(void);
+
+#endif /* __RTOS_H */

+ 0 - 155
lib/timing_delay.c

@@ -1,155 +0,0 @@
-/**
-  ******************************************************************************
-  * @file    timing_delay.c
-  * @author  MCD Application Team
-  * @version V2.1.3
-  * @date    28-June-2013
-  * @brief   This file contains a set of functions needed to generate 1ms time 
-  *          base delay using TIM2 update interrupt.
-  *          TimingDelay_Init() function, should be called in the main.c file to
-  *          ensure TIM2 initialization and configuration.
-  *          The timing accuracy is based on the use of the external low speed
-  *          clock source(LSE).
-  *          Delay() function should be called in main.c file to specify the 
-  *          duration of the desired delay in ms.   
-  *          Counter decrementation is performed in TIM2 Update interrupt Handler
-  *          by the mean of TimingDelay_Decrement() function. 
-  *          This function should be called in the stm8l15x_it.c file in the 
-  *          TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler handler.
-  *            
-  *          @note TimingDelay_Init() function should be tailored in case user 
-  *                wants to use a different clock source.
-  *           
-  *          For more details on timing_delay driver use, you can refer to 
-  *          CLK_SYSCLKSwitch example in the STM8L15x_StdPeriph_Lib package.         
-  ******************************************************************************
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Includes ------------------------------------------------------------------*/
-#include "timing_delay.h"
-
-/** @addtogroup Utilities
-  * @{
-  */
-
-/** @addtogroup Misc
-  * @{
-  */
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-#define TIM2_PERIOD  (uint8_t) 7
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-static __IO uint32_t TimingDelay;
-
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/**
-  * @addtogroup TIMING_DELAY_Functions
-  * @{
-  */
-
-/**
-  * @brief  timing delay init:to generate 1 ms time base using TIM2 update interrupt
-  * @note   The external low speed clock (LSE) is used to ensure timing accuracy.
-  *         This function should be updated in case of use of other clock source.      
-  * @param  None
-  * @retval None
-  */
-void TimingDelay_Init(void)
-{
-  /* Enable TIM2 clock */
-  CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
-
-  /* Remap TIM2 ETR to LSE: TIM2 external trigger becomes controlled by LSE clock */
-  SYSCFG_REMAPPinConfig(REMAP_Pin_TIM2TRIGLSE, ENABLE);
-
-  /* Enable LSE clock */
-  CLK_LSEConfig(CLK_LSE_ON);
-  /* Wait for LSERDY flag to be reset */
-  while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);
-
-  /* TIM2 configuration:
-     - TIM2 ETR is mapped to LSE
-     - TIM2 counter is clocked by LSE div 4
-      so the TIM2 counter clock used is LSE / 4 = 32.768 / 4 = 8.192 KHz
-     TIM2 Channel1 output frequency = TIM2CLK / (TIM2 Prescaler * (TIM2_PERIOD + 1))
-                                    = 8192 / (1 * 8) = 1024 Hz                */
-                                    
-  /* Time Base configuration */
-  TIM2_TimeBaseInit(TIM2_Prescaler_1, TIM2_CounterMode_Up, TIM2_PERIOD);
-  TIM2_ETRClockMode2Config(TIM2_ExtTRGPSC_DIV4, TIM2_ExtTRGPolarity_NonInverted, 0);
-
-  TIM2_UpdateRequestConfig(TIM2_UpdateSource_Global);
-
-  /* Clear TIM2 update flag */
-  TIM2_ClearFlag(TIM2_FLAG_Update);
-
-  /* Enable update interrupt */
-  TIM2_ITConfig(TIM2_IT_Update, ENABLE);
-
-  TIM2_Cmd(ENABLE);
-}
-
-/**
-  * @brief  Inserts a delay time.
-  * @param  nTime: specifies the delay time length, in milliseconds.
-  * @retval None
-  */
-void Delay(__IO uint32_t nTime)
-{
-  TimingDelay = nTime;
-  while (TimingDelay != 0);
-}
-
-/**
-  * @brief  Decrements the TimingDelay variable.
-  * @note   This function should be called in the
-  *         TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler in the stm8l15x_it.c file.
-  *
-  *       // INTERRUPT_HANDLER(TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler, 19)
-  *       // {
-  *           // TimingDelay_Decrement(); 
-  *           // TIM2_ClearITPendingBit(TIM2_IT_Update);
-  *             
-  *       // }  
-  * @param  None
-  * @retval None
-  */
-void TimingDelay_Decrement(void)
-{
-  if (TimingDelay != 0x00)
-  {
-    TimingDelay--;
-  }
-}
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-  
-/**
-  * @}
-  */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 43
lib/timing_delay.h

@@ -1,43 +0,0 @@
-/**
-  ******************************************************************************
-  * @file    timing_delay.h
-  * @author  MCD Application Team
-  * @version V2.1.3
-  * @date    28-June-2013
-  * @brief   Header for timing_delay.c
-  ******************************************************************************
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */ 
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __TIMING_DELAY_H
-#define __TIMING_DELAY_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm8l15x.h"
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported variables --------------------------------------------------------*/
-/* Exported functions --------------------------------------------------------*/
-void Delay(__IO uint32_t nTime);
-void TimingDelay_Decrement(void);
-void TimingDelay_Init(void);
-
-#endif /* __TIMING_DELAY_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 26 - 3
src/main.c

@@ -20,6 +20,7 @@
 
 /* Includes ------------------------------------------------------------------*/
 #include "stm8l15x.h"
+#include "rtos.h"
 #include "max7219.h"
 
 /** @addtogroup STM8L15x_StdPeriph_Template
@@ -67,6 +68,9 @@ static const max7219_sym_t num[16] = {
 static void GPIO_Config(void);
 static void CLK_Config(void);
 
+static void OutLed07(void);
+static void OutLed8f(void);
+
 /* Private functions ---------------------------------------------------------*/
 
 /**
@@ -82,20 +86,39 @@ void main(void)
   /* GPIO Configuration  -----------------------------------------*/
   GPIO_Config();
 
+  /* RTOS Configuration */
+  RTOS_Init();
+
   /* MAX7219 Configuration */
   MAX7219_Init();
 
+    RTOS_SetTask(OutLed07,0,10000);
+    RTOS_SetTask(OutLed8f,5000,10000);
+
+  /* Infinite loop */
+  while (1)
+  {
+      RTOS_DispatchTask();
+      Delay(1);
+  }
+}
+
+/* для теста */
+static void OutLed07(void){
   uint8_t i;
   for (i=0;i<8;i++) {
     MAX7219_WriteData(dig[i], num[i]);
   }
+}
 
-  /* Infinite loop */
-  while (1)
-  {
+static void OutLed8f(void){
+  uint8_t i;
+  for (i=0;i<8;i++) {
+    MAX7219_WriteData(dig[i], num[i+8]);
   }
 }
 
+
 /**
   * @brief  Configure GPIO for button available on the VAPC board
   * @param  None

+ 11 - 9
src/stm8l15x_it.c

@@ -17,8 +17,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -32,7 +32,7 @@
 /** @addtogroup STM8L15x_StdPeriph_Template
   * @{
   */
-	
+
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
 /* Private macro -------------------------------------------------------------*/
@@ -46,7 +46,7 @@
   * @brief Dummy interrupt routine
   * @par Parameters:
   * None
-  * @retval 
+  * @retval
   * None
 */
 INTERRUPT_HANDLER(NonHandledInterrupt,0)
@@ -61,7 +61,7 @@ INTERRUPT_HANDLER(NonHandledInterrupt,0)
   * @brief TRAP interrupt routine
   * @par Parameters:
   * None
-  * @retval 
+  * @retval
   * None
 */
 INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler)
@@ -349,7 +349,7 @@ INTERRUPT_HANDLER(TIM1_CC_IRQHandler,24)
        it is recommended to set a breakpoint on the following instruction.
     */
 }
-
+#ifdef NO_RTOS
 /**
   * @brief TIM4 Update/Overflow/Trigger Interrupt routine.
   * @param  None
@@ -361,6 +361,8 @@ INTERRUPT_HANDLER(TIM4_UPD_OVF_TRG_IRQHandler,25)
        it is recommended to set a breakpoint on the following instruction.
     */
 }
+#endif // NO_RTOS
+
 /**
   * @brief SPI1 Interrupt routine.
   * @param  None
@@ -370,7 +372,7 @@ INTERRUPT_HANDLER(SPI1_IRQHandler,26)
 {
     /* In order to detect unexpected events during development,
        it is recommended to set a breakpoint on the following instruction.
-    */		
+    */
 }
 
 /**
@@ -410,6 +412,6 @@ INTERRUPT_HANDLER(I2C1_SPI2_IRQHandler,29)
 }
 /**
   * @}
-  */ 
+  */
 
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/