summaryrefslogtreecommitdiffstats
path: root/ucs2-lib/inc/ucs_amd.h
blob: 069b92f0ef488139b0d0d03862fae96cd4191a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*------------------------------------------------------------------------------------------------*/
/* UNICENS V2.1.0-3491                                                                            */
/* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
/*                                                                                                */
/* This program is free software: you can redistribute it and/or modify                           */
/* it under the terms of the GNU General Public License as published by                           */
/* the Free Software Foundation, either version 2 of the License, or                              */
/* (at your option) any later version.                                                            */
/*                                                                                                */
/* This program is distributed in the hope that it will be useful,                                */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
/* GNU General Public License for more details.                                                   */
/*                                                                                                */
/* You should have received a copy of the GNU General Public License                              */
/* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
/*                                                                                                */
/* You may also obtain this software under a propriety license from Microchip.                    */
/* Please contact Microchip for further information.                                              */
/*------------------------------------------------------------------------------------------------*/

/*!
 * \file
 * \brief Internal header file of Application Message Distributor
 *
 * \cond UCS_INTERNAL_DOC
 * \addtogroup G_AMD
 * @{
 */
#ifndef UCS_AMD_H
#define UCS_AMD_H

/*------------------------------------------------------------------------------------------------*/
/* Includes                                                                                       */
/*------------------------------------------------------------------------------------------------*/
#include "ucs_ams.h"
#include "ucs_base.h"
#include "ucs_amsmessage.h"

#ifdef __cplusplus
extern "C"
{
#endif

/*------------------------------------------------------------------------------------------------*/
/* Types                                                                                          */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Assignable function which is invoked as soon as an application message is received 
 *          completely and available in the Rx message queue
 *  \param  self    The instance
 */
typedef void (*Amd_RxMsgCompleteCb_t)(void *self);

/*! \brief  Assignable callback function which is able to read and modify the Rx message
 *  \param  self    The instance
 *  \param  msg_ptr Reference to the Rx message object
 */
typedef void (*Amd_RxModificationCb_t)(void *self, Ucs_AmsRx_Msg_t *msg_ptr);

/*------------------------------------------------------------------------------------------------*/
/* Class                                                                                          */
/*------------------------------------------------------------------------------------------------*/
/*! \brief      Application Message Service Class
 *  \details    Allows transmission and reception of MOST Application Messages
 */
typedef struct CAmd_
{
    CBase                  *base_ptr;                   /*!< \brief  Reference to basic services */
    CAms                   *ams_ptr;                    /*!< \brief  Reference to AMS */
#ifdef AMD_TX_DISTRIB
    CAmsMsgPool            *pool_ptr;                   /*!< \brief  Reference to AMS message pool */
    CInic                  *inic_ptr;                   /*!< \brief  Reference to INIC */
    CNetworkManagement     *net_ptr;                    /*!< \brief  Reference to network management */
#endif
    CService                service;                    /*!< \brief  Service object */
    bool                    started;                    /*!< \brief  Is \c true if the AMD is allowed
                                                         *           to distribute messages
                                                         */
    CMaskedObserver         event_observer;             /*!< \brief  Observes init complete event */
    CMaskedObserver         terminate_observer;         /*!< \brief  Observes events leading to termination */

    void                   *preprocess_inst_ptr;        /*!< \brief Reference to the message preprocessor */
    Amd_RxMsgCompleteCb_t   preprocess_fptr;            /*!< \brief Callback function which is invoked first 
                                                         *          on completed message reception 
                                                         */

    void                   *receive_inst_ptr;           /*!< \brief Reference to the message receiver */
    Amd_RxMsgCompleteCb_t   receive_fptr;               /*!< \brief Callback function which is invoked after 
                                                         *          the preprocessor has finished
                                                         */
#ifdef AMD_TX_DISTRIB
    CDlList                 tx_notify_queue;            /*!< \brief Queue to notify asynchronously a failed transmission */
#endif
    CDlList                 pre_queue;                  /*!< \brief Queue of messages for the preprocessor */
    CDlList                 rx_queue;                   /*!< \brief Queue of messages for the receiver */

    CDlList                *first_q_ptr;                /*!< \brief Reference where to queue the messages first */
    Amd_RxMsgCompleteCb_t   first_receive_fptr;         /*!< \brief Reference of the callback to be fired first */
    void                   *first_receive_inst_ptr;     /*!< \brief Reference to the first receiver */

    Amd_RxModificationCb_t  rx_modification_fptr;       /*!< \brief Callback function for message modification */
    void                   *rx_modification_inst_ptr;   /*!< \brief Callback reference for message modification */

} CAmd;

/*------------------------------------------------------------------------------------------------*/
/* Methods                                                                                        */
/*------------------------------------------------------------------------------------------------*/
extern void Amd_Ctor(CAmd *self, CBase *base_ptr, CAms *ams_ptr);
extern void Amd_AssignPreprocessor(CAmd *self, Amd_RxMsgCompleteCb_t callback_fptr, void *inst_ptr);
extern void Amd_AssignReceiver(CAmd *self, Amd_RxMsgCompleteCb_t callback_fptr, void *inst_ptr);
extern void Amd_RxAssignModificator(CAmd *self, Amd_RxModificationCb_t callback_fptr, void *inst_ptr);

extern Ucs_AmsRx_Msg_t* Amd_PrePeekMsg(CAmd *self);
extern void Amd_PreReleaseMsg(CAmd *self);
extern void Amd_PreForwardMsg(CAmd *self);

extern Ucs_AmsRx_Msg_t* Amd_RxPeekMsg(CAmd *self);
extern void Amd_RxReleaseMsg(CAmd *self);
extern uint16_t Amd_RxGetMsgCnt(CAmd *self);

#ifdef AMD_TX_DISTRIB
Ucs_Return_t Amd_TxSendMsg(CAmd *self, Ucs_AmsTx_Msg_t *msg_ptr, Amsg_TxCompleteSiaCb_t tx_complete_sia_fptr, 
                           Amsg_TxCompleteCb_t tx_complete_fptr, void* tx_complete_inst_ptr);
#endif

#ifdef __cplusplus
}               /* extern "C" */
#endif

#endif          /* UCS_AMD_H */

/*!
 * @}
 * \endcond
 */

/*------------------------------------------------------------------------------------------------*/
/* End of file                                                                                    */
/*------------------------------------------------------------------------------------------------*/