tdse-tp2_02-model_integration

Index Commits Files Refs README
app/src/task_system_interface.c (3703B)
   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  *
  33  * @file   : task_system_interface.c
  34  * @date   : Set 26, 2023
  35  * @author : Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>
  36  * @version    v1.0.0
  37  */
  38 
  39 /********************** inclusions *******************************************/
  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_system_attribute.h"
  51 
  52 /********************** macros and definitions *******************************/
  53 #define EVENT_UNDEFINED    (255)
  54 #define MAX_EVENTS        (16)
  55 
  56 /********************** internal data declaration ****************************/
  57 
  58 /********************** internal functions declaration ***********************/
  59 
  60 /********************** internal data definition *****************************/
  61 struct
  62 {
  63     uint32_t    head;
  64     uint32_t    tail;
  65     uint32_t    count;
  66     task_system_ev_t    queue[MAX_EVENTS];
  67 } queue_task_a;
  68 
  69 /********************** external data declaration ****************************/
  70 
  71 /********************** external functions definition ************************/
  72 void init_queue_event_task_system(void)
  73 {
  74     uint32_t i;
  75 
  76     queue_task_a.head = 0;
  77     queue_task_a.tail = 0;
  78     queue_task_a.count = 0;
  79 
  80     for (i = 0; i < MAX_EVENTS; i++)
  81         queue_task_a.queue[i] = EVENT_UNDEFINED;
  82 }
  83 
  84 void put_event_task_system(task_system_ev_t event)
  85 {
  86     queue_task_a.count++;
  87     queue_task_a.queue[queue_task_a.head++] = event;
  88 
  89     if (MAX_EVENTS == queue_task_a.head)
  90         queue_task_a.head = 0;
  91 }
  92 
  93 task_system_ev_t get_event_task_system(void)
  94 {
  95     task_system_ev_t event;
  96 
  97     queue_task_a.count--;
  98     event = queue_task_a.queue[queue_task_a.tail];
  99     queue_task_a.queue[queue_task_a.tail++] = EVENT_UNDEFINED;
 100 
 101     if (MAX_EVENTS == queue_task_a.tail)
 102         queue_task_a.tail = 0;
 103 
 104     return event;
 105 }
 106 
 107 bool any_event_task_system(void)
 108 {
 109   return (queue_task_a.head != queue_task_a.tail);
 110 }
 111 
 112 /********************** end of file ******************************************/