tdse-tp3_02-code_integration

Index Commits Files Refs
app/src/task_test.c (5161B)
   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_test.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 
  40 /* Project includes */
  41 #include "main.h"
  42 
  43 /* Demo includes */
  44 #include "logger.h"
  45 #include "dwt.h"
  46 
  47 /* Application & Tasks includes */
  48 #include "board.h"
  49 #include "app.h"
  50 #include "task_test_attribute.h"
  51 #include "display.h"
  52 
  53 /********************** macros and definitions *******************************/
  54 #define G_TASK_TEST_CNT_INIT        0ul
  55 #define G_TASK_TEST_TICK_CNT_INI    0ul
  56 
  57 #define DEL_TEST_XX_MIN             0ul
  58 #define DEL_TEST_XX_MED           500ul
  59 #define DEL_TEST_XX_MAX          1000ul
  60 
  61 /********************** internal data declaration ****************************/
  62 task_test_dta_t task_test_dta =
  63 {DEL_TEST_XX_MIN};
  64 
  65 /********************** internal functions declaration ***********************/
  66 void task_test_statechart(void);
  67 
  68 /********************** internal data definition *****************************/
  69 const char *p_task_test = "Task Test (Test Code Integration)";
  70 const char *p_task_test_ = "Non-Blocking & Update By Time Code";
  71 
  72 /********************** external data declaration ****************************/
  73 uint32_t g_task_test_cnt;
  74 volatile uint32_t g_task_test_tick_cnt;
  75 
  76 /********************** external functions definition ************************/
  77 void task_test_init(void *parameters)
  78 {
  79     task_test_dta_t *p_task_test_dta;
  80     uint32_t tick;
  81 
  82     /* Print out: Task Initialized */
  83     LOGGER_INFO(" ");
  84     LOGGER_INFO("  %s is running - %s", GET_NAME(task_test_init), p_task_test);
  85     LOGGER_INFO("  %s is a %s", GET_NAME(task_test), p_task_test_);
  86 
  87     /* Init & Print out: Task execution counter */
  88     g_task_test_cnt = G_TASK_TEST_CNT_INIT;
  89     LOGGER_INFO("   %s = %lu", GET_NAME(g_task_test_cnt), g_task_test_cnt);
  90 
  91     /* Update Task Test Configuration & Data Pointer */
  92     p_task_test_dta = &task_test_dta;
  93 
  94     tick = DEL_TEST_XX_MAX;
  95     p_task_test_dta->tick = tick;
  96     LOGGER_INFO("   %s = %lu", GET_NAME(tick), (uint32_t)tick);
  97 
  98     /* Init & Print out: LCD Display */
  99     display_init();
 100 
 101     display_char_position_write(0, 0);
 102     display_string_write("Hello, World!");
 103 }
 104 
 105 void task_test_update(void *parameters)
 106 {
 107     bool b_time_update_required = false;
 108 
 109     /* Protect shared resource */
 110     __asm("CPSID i");    /* disable interrupts */
 111     if (G_TASK_TEST_TICK_CNT_INI < g_task_test_tick_cnt)
 112     {
 113         /* Update Tick Counter */
 114         g_task_test_tick_cnt--;
 115         b_time_update_required = true;
 116     }
 117     __asm("CPSIE i");    /* enable interrupts */
 118 
 119     while (b_time_update_required)
 120     {
 121         /* Update Task Counter */
 122         g_task_test_cnt++;
 123 
 124         /* Run Task Statechart */
 125         task_test_statechart();
 126 
 127         /* Protect shared resource */
 128         __asm("CPSID i");    /* disable interrupts */
 129         if (G_TASK_TEST_TICK_CNT_INI < g_task_test_tick_cnt)
 130         {
 131             /* Update Tick Counter */
 132             g_task_test_tick_cnt--;
 133             b_time_update_required = true;
 134         }
 135         else
 136         {
 137             b_time_update_required = false;
 138         }
 139         __asm("CPSIE i");    /* enable interrupts */
 140     }
 141 }
 142 
 143 void task_test_statechart(void)
 144 {
 145     task_test_dta_t *p_task_test_dta;
 146 
 147     /* Update Task Test Configuration & Data Pointer */
 148     p_task_test_dta = &task_test_dta;
 149 
 150     if (DEL_TEST_XX_MIN < p_task_test_dta->tick)
 151     {
 152         p_task_test_dta->tick--;
 153     }
 154     else
 155     {
 156     }
 157 }