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_b_commented_read.me (5074B)
   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_b.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_B_CNT_INI    0ul
  52 
  53 #define TASK_B_CNT_INI        0ul
  54 #define TASK_B_CNT_MAX        50ul
  55 
  56 #define TASK_B_DEL_INI        0ul
  57 #define TASK_B_DEL_MAX        500ul
  58 
  59 /********************** internal data declaration ****************************/
  60 
  61 /********************** internal functions declaration ***********************/
  62 
  63 /********************** internal data definition *****************************/
  64 const char *p_task_b         = "Task B - Non-Blocking Code";
  65 
  66 /********************** external data declaration ****************************/
  67 uint32_t g_task_b_cnt;
  68 
  69 /********************** external functions definition ************************/
  70 void task_b_init(void *parameters)
  71 {
  72     /* Print out: Task Initialized */
  73     LOGGER_INFO(" ");
  74     LOGGER_INFO("  %s is running - %s", GET_NAME(task_b_init), p_task_b);
  75 
  76     /* Init & Print out: Task execution counter */
  77     g_task_b_cnt = G_TASK_B_CNT_INI;
  78     LOGGER_INFO("   %s = %lu", GET_NAME(g_task_b_cnt), g_task_b_cnt);
  79 }
  80 
  81 void task_b_update(void *parameters)
  82 {
  83     #if (TEST_X == TEST_0)
  84 
  85     /* Memory Layout of C Programs (https://www.geeksforgeeks.org/) */
  86     /* Storage Classes in C (https://www.geeksforgeeks.org/) */
  87     /* C Variables (https://www.geeksforgeeks.org/) */
  88     /* Static Variables in C (https://www.geeksforgeeks.org/) */
  89     /* Initialization of static variables in C
  90      * (https://www.geeksforgeeks.org/) */
  91     /* Internal static variable vs. External static variable with Examples in C
  92      * (https://www.geeksforgeeks.org/) */
  93     /*
  94      * Static variables have the property of preserving their value even after
  95      * they are out of their scope!
  96      * Hence, a static variable preserves its previous value in its previous
  97      * scope and is not initialized again in the new scope.
  98      */
  99     static uint32_t task_b_cnt = TASK_B_CNT_INI;
 100 
 101     /* Update Task Counter */
 102     g_task_b_cnt++;
 103 
 104     /* Blocking and Non-Blocking in Node.js (https://www.geeksforgeeks.org/) */
 105     /*
 106      * Non-Blocking: It refers to the program that does not block the
 107      * execution of further operations.
 108      * Non-Blocking methods are executed asynchronously.
 109      * Asynchronously means that the program may not necessarily execute line
 110      * by line.
 111      * The program calls the function and move to the next operation and does
 112      * not wait for it to return.
 113      */
 114     if (task_b_cnt < TASK_B_CNT_MAX)
 115         task_b_cnt++;
 116     else
 117         task_b_cnt = TASK_B_CNT_INI;
 118 
 119     #endif
 120 
 121     #if (TEST_X == TEST_1)
 122 
 123     static uint32_t then = TASK_B_DEL_INI;
 124     static uint32_t now = TASK_B_DEL_INI;
 125 
 126     /* Check the current tick */
 127     now = HAL_GetTick();
 128     if ((now - then) >= TASK_B_DEL_MAX)
 129     {
 130         /* Only if the current tick is TASK_B_DEL_MAX mS after the last */
 131         /* Reset then = now */
 132         then = now;
 133     }
 134 
 135     #endif
 136 
 137     #if (TEST_X == TEST_2)
 138 
 139     /* Here Chatbot Artificial Intelligence generated code */
 140 
 141     #endif
 142 }
 143 
 144 /********************** end of file ******************************************/