aboutsummaryrefslogtreecommitdiffstats
path: root/ucs2-lib/src/ucs_pmcmd.c
blob: d4055b029426a53c1077d372e110922fbfb3b169 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*------------------------------------------------------------------------------------------------*/
/* 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 Implementation of class CPmCommand
 *
 * \cond UCS_INTERNAL_DOC
 * \addtogroup  G_PM_CMD
 * @{
 */

/*------------------------------------------------------------------------------------------------*/
/* Includes                                                                                       */
/*------------------------------------------------------------------------------------------------*/
#include "ucs_pmcmd.h"
#include "ucs_misc.h"

/*------------------------------------------------------------------------------------------------*/
/* Implementation                                                                                 */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Constructor of CPmCommand class 
 *  \param  self    The instance
 *  \param  fifo    The dedicated FIFO
 *  \param  type    The port message type
 */
void Pmcmd_Ctor(CPmCommand *self, Pmp_FifoId_t fifo, Pmp_MsgType_t type)
{
    MISC_MEM_SET(self, 0, sizeof(*self));           /* setup attributes */
    self->memory.data_ptr = &self->data[0];
    self->tx_obj.lld_msg.memory_ptr = &self->memory;
    self->tx_obj.msg_ptr = NULL;                    /* label message as command by setting */
    self->tx_obj.owner_ptr = NULL;                  /* msg_ptr and owner_ptr to NULL */
    self->trigger = false;

    Pmp_SetPmhl(self->data, 3U);                    /* PMHL is always "3" for control/status messages */
    Pmp_SetFph(self->data, fifo, type);
}

/*! \brief  Retrieves reference to the LLD Tx message object required to call Pmch_Transmit()
 *  \param  self    The instance
 *  \return Returns a reference to the LLD Tx message object 
 */
Ucs_Lld_TxMsg_t* Pmcmd_GetLldTxObject(CPmCommand *self)
{
    return (Ucs_Lld_TxMsg_t*)(void*)self;
}

/*! \brief  Sets the content of a command/status message
 *  \param  self          The instance
 *  \param  sid           The sequence id
 *  \param  ext_type      The ExtType type
 *  \param  ext_code      The ExtType code
 *  \param  add_data_ptr  Additional payload data
 *  \param  add_data_sz   The size of additional payload data, valid values: 0..4
 */
void Pmcmd_SetContent(CPmCommand *self, uint8_t sid, uint8_t ext_type, uint8_t ext_code, uint8_t add_data_ptr[], uint8_t add_data_sz)
{
    if ((add_data_ptr != NULL) && (add_data_sz != 0U))
    {
        MISC_MEM_CPY(&self->data[6U], add_data_ptr, (size_t)add_data_sz);
    }

    self->memory.data_size = 6U + (uint16_t)add_data_sz;
    self->memory.total_size = 6U + (uint16_t)add_data_sz;

    Pmp_SetPml(self->data, 4U + add_data_sz);
    Pmp_SetSid(self->data, sid);
    Pmp_SetExtType(self->data, ext_type, ext_code);
}

/*! \brief   Updates the content of a command/status message
 *  \details The length and the content of the payload is not modified.
 *           It is important to call Pmcmd_SetContent() before.
 *  \param   self        The instance
 *  \param   sid         The sequence id
 *  \param   ext_type    The ExtType type
 *  \param   ext_code    The ExtType code
 */
void Pmcmd_UpdateContent(CPmCommand *self, uint8_t sid, uint8_t ext_type, uint8_t ext_code)
{
    Pmp_SetSid(self->data, sid);
    Pmp_SetExtType(self->data, ext_type, ext_code);
}

/*! \brief  Reserves the command object if it is available
 *  \param  self    The instance
 *  \return \c true if the command object is available, \c false
 *          if the command object is (still) in usage
 */
bool Pmcmd_Reserve(CPmCommand *self)
{
    bool succ = false;

    if (self->reserved == false)
    {
        self->reserved = true;
        succ = true;
    }
    return succ;
}

/*! \brief  Releases the command object after usage
 *  \param  self    The instance
 */
void Pmcmd_Release(CPmCommand *self)
{
    self->reserved = false;
}

/*! \brief  Sets or resets the trigger attribute
 *  \param  self    The instance
 *  \param  trigger The trigger value
 */
void Pmcmd_SetTrigger(CPmCommand *self, bool trigger)
{
    self->trigger = trigger;
}

/*! \brief  Returns the trigger value
 *  \param  self    The instance
 *  \return Returns \c true if the trigger attribute is set, otherwise \c false.
 */
bool Pmcmd_IsTriggered(CPmCommand *self)
{
    return self->trigger;
}

/*!
 * @}
 * \endcond
 */

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