tdse-tp2_04-model_integration

Index Commits Files Refs README
app/inc/task_sensor_attribute.h (6666B)
   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_sensor_attribute.h
  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 #ifndef TASK_INC_TASK_SENSOR_ATTRIBUTE_H_
  39 #define TASK_INC_TASK_SENSOR_ATTRIBUTE_H_
  40 
  41 /********************** CPP guard ********************************************/
  42 #ifdef __cplusplus
  43 extern "C" {
  44 #endif
  45 
  46 /********************** inclusions *******************************************/
  47 
  48 /********************** macros ***********************************************/
  49 
  50 /********************** typedef **********************************************/
  51 /* Sensor Statechart - State Transition Table */
  52 /* +-------------------+----------------+-------------+-------------------+-----------------------+
  53  * | Current           | Event          |             | Next              |                       |
  54  * | State             | (Parameters)   | [Guard]     | State             | Actions               |
  55  * |===================+================+=============+===================+=======================|
  56  * | INICIAL           |                |             | ST_BTN_XX_UP      |                       |
  57  * |-------------------+----------------+-------------+-------------------+-----------------------|
  58  * | ST_BTN_XX_UP      | EV_BTN_XX_UP   |             | ST_BTN_XX_UP      |                       |
  59  * |                   +----------------+-------------+-------------------+-----------------------|
  60  * |                   | EV_BTN_XX_DOWN |             | ST_BTN_XX_FALLING | tick = TICK_MAX       |
  61  * |-------------------+----------------+-------------+-------------------+-----------------------|
  62  * | ST_BTN_XX_FALLING | EV_BTN_XX_UP   | [tick == 0] | ST_BTN_XX_UP      |                       |
  63  * |                   |                +-------------+-------------------+-----------------------|
  64  * |                   |                | [tick >  0] | ST_BTN_XX_FALLING | tick--                |
  65  * |                   +----------------+-------------+-------------------+-----------------------|
  66  * |                   | EV_BTN_XX_DOWN | [tick == 0] | ST_BTN_XX_DOWN    | put_event_task_system |
  67  * |                   |                |             |                   |  (event)              |
  68  * |                   |                +-------------+-------------------+-----------------------|
  69  * |                   |                | [tick >  0] | ST_BTN_XX_FALLING | tick--                |
  70  * |-------------------+----------------+-------------+-------------------+-----------------------|
  71  * | ST_BTN_XX_DOWN    | EV_BTN_XX_UP   |             | ST_BTN_XX_RISING  | tick = TICK_MAX       |
  72  * |                   +----------------+-------------+-------------------+-----------------------|
  73  * |                   | EV_BTN_XX_DOWN |             | ST_BTN_XX_DOWN    |                       |
  74  * |-------------------+----------------+-------------+-------------------+-----------------------|
  75  * | ST_BTN_XX_RISING  | EV_BTN_XX_UP   | [tick == 0] | ST_BTN_XX_UP      | put_event_task_system |
  76  * |                   |                |             |                   |  (event)              |
  77  * |                   |                +-------------+-------------------+-----------------------|
  78  * |                   |                | [tick >  0] | ST_BTN_XX_RISING  | tick--                |
  79  * |                   +----------------+-------------+-------------------+-----------------------|
  80  * |                   | EV_BTN_XX_DOWN | [tick == 0] | ST_BTN_XX_DOWN    |                       |
  81  * |                   |                +-------------+-------------------+-----------------------|
  82  * |                   |                | [tick >  0] | ST_BTN_XX_RISING  | tick--                |
  83  * +-------------------+----------------+-------------+-------------------+-----------------------+
  84  */
  85 
  86 /* Events to excite Task Sensor */
  87 typedef enum
  88 {
  89     EV_BTN_XX_UP,
  90     EV_BTN_XX_DOWN
  91 } task_sensor_ev_t;
  92 
  93 /* States of Task Sensor */
  94 typedef enum
  95 {
  96     ST_BTN_XX_UP,
  97     ST_BTN_XX_FALLING,
  98     ST_BTN_XX_DOWN,
  99     ST_BTN_XX_RISING
 100 } task_sensor_st_t;
 101 
 102 /* Identifier of Task Sensor */
 103 typedef enum
 104 {
 105     ID_BTN_A,
 106     ID_BTN_B,
 107     ID_BTN_C,
 108     ID_BTN_D
 109 } task_sensor_id_t;
 110 
 111 typedef struct
 112 {
 113     task_sensor_id_t identifier;
 114     GPIO_TypeDef *gpio_port;
 115     uint16_t pin;
 116     GPIO_PinState pressed;
 117     uint32_t tick_max;
 118     task_sensor_ev_t signal_up;
 119     task_sensor_ev_t signal_down;
 120 } task_sensor_cfg_t;
 121 
 122 typedef struct
 123 {
 124     uint32_t tick;
 125     task_sensor_st_t state;
 126     task_sensor_ev_t event;
 127 } task_sensor_dta_t;
 128 
 129 /********************** external data declaration ****************************/
 130 extern task_sensor_dta_t task_sensor_dta_list[];
 131 
 132 /********************** external functions declaration ***********************/
 133 
 134 /********************** End of CPP guard *************************************/
 135 #ifdef __cplusplus
 136 }
 137 #endif
 138 
 139 #endif /* TASK_INC_TASK_SENSOR_ATTRIBUTE_H_ */
 140 
 141 /********************** end of file ******************************************/