tdse-tp0_03-hw_sw_test

FIUBA - Electrónica - Taller de Sistemas Embebidos - Trabajo Práctico N°: 0 - Proyecto N°: 03
Index Commits Files Refs README
app/src/task_c.c (4240B)
   1 /*
   2  * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
   3  * All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions are met:
   7  *
   8  * 1. Redistributions of source code must retain the above copyright
   9  *    notice, this list of conditions and the following disclaimer.
  10  *
  11  * 2. Redistributions in binary form must reproduce the above copyright
  12  *    notice, this list of conditions and the following disclaimer in the
  13  *    documentation and/or other materials provided with the distribution.
  14  *
  15  * 3. Neither the name of the copyright holder nor the names of its
  16  *    contributors may be used to endorse or promote products derived from
  17  *    this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30  * POSSIBILITY OF SUCH DAMAGE.
  31  *
  32  * @file   : task_c.c
  33  * @date   : Set 26, 2023
  34  * @author : Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>
  35  * @version    v1.0.0
  36  */
  37 
  38 /********************** inclusions *******************************************/
  39 /* Project includes */
  40 #include "main.h"
  41 
  42 /* Demo includes */
  43 #include "logger.h"
  44 #include "dwt.h"
  45 
  46 /* Application & Tasks includes */
  47 #include "board.h"
  48 #include "app.h"
  49 
  50 /********************** macros and definitions *******************************/
  51 #define G_TASK_C_CNT_INI            0ul
  52 #define G_TASK_C_TICK_CNT_INI        0ul
  53 
  54 /********************** internal data declaration ****************************/
  55 
  56 /********************** internal functions declaration ***********************/
  57 
  58 /********************** internal data definition *****************************/
  59 const char *p_task_c = "Task C - Update by Time Code";
  60 
  61 /********************** external data declaration ****************************/
  62 uint32_t g_task_c_cnt;
  63 volatile uint32_t g_task_c_tick_cnt;
  64 
  65 /********************** external functions definition ************************/
  66 void task_c_init(void *parameters)
  67 {
  68     /* Print out: Task Initialized */
  69     LOGGER_INFO(" ");
  70     LOGGER_INFO("  %s is running - %s", GET_NAME(task_c_init), p_task_c);
  71 
  72     /* Init & Print out: Task execution counter */
  73     g_task_c_cnt = G_TASK_C_CNT_INI;
  74     LOGGER_INFO("   %s = %lu", GET_NAME(g_task_c_cnt), g_task_c_cnt);
  75 }
  76 
  77 void task_c_update(void *parameters)
  78 {
  79     bool b_time_update_required = false;
  80 
  81     /* Protect shared resource */
  82     __asm("CPSID i");
  83     /* disable interrupts */
  84     if (G_TASK_C_TICK_CNT_INI < g_task_c_tick_cnt) {
  85         /* Update Tick Counter */
  86         g_task_c_tick_cnt--;
  87         b_time_update_required = true;
  88     }
  89     __asm("CPSIE i");
  90     /* enable interrupts */
  91 
  92     while (b_time_update_required) {
  93         /* Update Task Counter */
  94         g_task_c_cnt++;
  95 
  96         /* Here run code that needs update by time */
  97         /*
  98          * For example, update Software Timers
  99          *
 100          */
 101 
 102         /* Protect shared resource */
 103         __asm("CPSID i");
 104         /* disable interrupts */
 105         if (G_TASK_C_TICK_CNT_INI < g_task_c_tick_cnt) {
 106             /* Update Tick Counter */
 107             g_task_c_tick_cnt--;
 108             b_time_update_required = true;
 109         } else {
 110             b_time_update_required = false;
 111         }
 112         __asm("CPSIE i");
 113         /* enable interrupts */
 114     }
 115 }
 116 
 117 /********************** end of file ******************************************/