summaryrefslogtreecommitdiffstats
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

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /*
/*------------------------------------------------------------------------------------------------*/
/* 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                                                                                    */
/*------------------------------------------------------------------------------------------------*/