Browse Source

Format module.

Vladimir N. Shilov 2 years ago
parent
commit
8f9fb14cae
1 changed files with 78 additions and 77 deletions
  1. 78 77
      src/rtos.c

+ 78 - 77
src/rtos.c

@@ -4,10 +4,10 @@
  * @brief Task Structure
  */
 typedef struct task {
-   void (*pFunc) (void);  /**< @brief function pointer */
-   uint32_t delay;  /**< @brief delay before the first start of the task */
-   uint32_t period; /**< @brief task start period */ 
-        int run;    /**< @brief task ready flag */
+  void (*pFunc) (void);  /**< @brief function pointer */
+  uint32_t delay;  /**< @brief delay before the first start of the task */
+  uint32_t period; /**< @brief task start period */ 
+       int run;    /**< @brief task ready flag */
 } task_t;
 
 /*
@@ -41,45 +41,46 @@ void RTOS_Init(void) {
  * @param taskPeriod    task start period
  */
 void RTOS_SetTask (void (*taskFunc)(void), uint32_t taskDelay, uint32_t taskPeriod) {
-   int i;
+  int i;
 
-   if (!taskFunc) {
+  if (!taskFunc) {
     return;
-   }
+  }
 
    // search for a task in the current list
-   for(i = 0; i < arrayTail; i++) {
-      // if found, then update the variables
-      if (TaskArray[i].pFunc == taskFunc) {
-         __disable_irq();
-
-         TaskArray[i].delay  = taskDelay;
-         TaskArray[i].period = taskPeriod;
-         TaskArray[i].run    = 0;
-
-         __enable_irq();
-         // update, exit
-         return;
-      }
-   }
-
-   // if there is no such task in the list
-   if (arrayTail < MAX_TASKS) {
-      // and there is a place, then we add
+  for(i = 0; i < arrayTail; i++) {
+    // if found, then update the variables
+    if (TaskArray[i].pFunc == taskFunc) {
       __disable_irq();
 
-      TaskArray[arrayTail].pFunc  = taskFunc;
-      TaskArray[arrayTail].delay  = taskDelay;
-      TaskArray[arrayTail].period = taskPeriod;
-      TaskArray[arrayTail].run    = 0;
+      TaskArray[i].delay  = taskDelay;
+      TaskArray[i].period = taskPeriod;
+      TaskArray[i].run    = 0;
 
-      // enlarge the "tail"
-      arrayTail++;
       __enable_irq();
-   } else {
-     //!!! no left space for new task :-(
-     while (1);
-   }
+      // update, exit
+      return;
+    }
+  }
+
+  // if there is no such task in the list
+  if (arrayTail < MAX_TASKS) {
+    // and there is a place, then we add
+    __disable_irq();
+
+    TaskArray[arrayTail].pFunc  = taskFunc;
+    TaskArray[arrayTail].delay  = taskDelay;
+    TaskArray[arrayTail].period = taskPeriod;
+    TaskArray[arrayTail].run    = 0;
+
+    // enlarge the "tail"
+    arrayTail++;
+    __enable_irq();
+  } else {
+    //!!! no left space for new task :-(
+    display_String("Sheduler Error: No left space for new Tasks!\0", 3);
+    while(1);
+  }
 }
 
 /**
@@ -88,61 +89,61 @@ void RTOS_SetTask (void (*taskFunc)(void), uint32_t taskDelay, uint32_t taskPeri
  * @param taskFunc  function pointer
  */
 void RTOS_DeleteTask (void (*taskFunc)(void)) {
-   int i;
-
-   // go through the list of tasks
-   for (i=0; i<arrayTail; i++) {
-      // if the task is found in the list
-      if (TaskArray[i].pFunc == taskFunc) {
-         __disable_irq();
-         // move the last task
-         if (i != (arrayTail - 1)) {
-            // in place of the removed
-            TaskArray[i] = TaskArray[arrayTail - 1];
-         }
-         // decrement "tail" pointer
-         arrayTail--;
-         __enable_irq();
-         return;
+  int i;
+
+  // go through the list of tasks
+  for (i=0; i<arrayTail; i++) {
+    // if the task is found in the list
+    if (TaskArray[i].pFunc == taskFunc) {
+      __disable_irq();
+      // move the last task
+      if (i != (arrayTail - 1)) {
+        // in place of the removed
+        TaskArray[i] = TaskArray[arrayTail - 1];
       }
-   }
+      // decrement "tail" pointer
+      arrayTail--;
+      __enable_irq();
+      return;
+    }
+  }
 }
 
 /**
  * @brief RTOS dispatcher, called in main
  */
 void RTOS_DispatchTask(void) {
-   int i;
-   void (*function) (void);
-   // go through the list of tasks
-   for (i=0; i<arrayTail; i++) {
-      // if the execution flag is set,
-      if (TaskArray[i].run != 0) {
-        // we remember the task, because index may change during runtime
-        function = TaskArray[i].pFunc;
-        if (TaskArray[i].period == 0) {
-          // if the period is 0, remove the task from the list,
-          RTOS_DeleteTask(TaskArray[i].pFunc);
-        } else {
-          // otherwise remove the start flag
-          TaskArray[i].run = 0;
-          // if the task has not changed the delay
-          if (!TaskArray[i].delay) {
-            // set her
-            TaskArray[i].delay = TaskArray[i].period-1;
-            // task for itself can pause
-          }
+  int i;
+  void (*function) (void);
+  // go through the list of tasks
+  for (i=0; i<arrayTail; i++) {
+    // if the execution flag is set,
+    if (TaskArray[i].run != 0) {
+      // we remember the task, because index may change during runtime
+      function = TaskArray[i].pFunc;
+      if (TaskArray[i].period == 0) {
+        // if the period is 0, remove the task from the list,
+        RTOS_DeleteTask(TaskArray[i].pFunc);
+      } else {
+        // otherwise remove the start flag
+        TaskArray[i].run = 0;
+        // if the task has not changed the delay
+        if (!TaskArray[i].delay) {
+          // set her
+          TaskArray[i].delay = TaskArray[i].period-1;
+          // task for itself can pause
         }
-        // run the task
-        (*function)();
       }
-   }
+      // run the task
+      (*function)();
+    }
+  }
 }
 
 /**
  * @brief Inserts a delay time.
  * 
- * @param msek   specifies the delay time length, in milliseconds.
+ * @param msek  specifies the delay time length, in milliseconds.
  */
 void tdelay_ms(uint32_t msek) {
 
@@ -154,7 +155,7 @@ void tdelay_ms(uint32_t msek) {
       RTOS_DispatchTask();
     }
     /* there is nothing to do - sleep, waiting for an interruption */
-    __WFI();
+     __WFI();
   } while (TDelay != 0);
 
 }