2015-05-22 04:29:22 +08:00
|
|
|
/* k_pipe_util.c */
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997-2014 Wind River Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1) Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2) Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3) Neither the name of Wind River Systems nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2015-04-22 02:52:50 +08:00
|
|
|
#include <minik.h>
|
2015-05-22 04:29:22 +08:00
|
|
|
#include <k_pipe_util.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
#include <string_s.h>
|
|
|
|
#include <toolchain.h>
|
|
|
|
#include <sections.h>
|
|
|
|
#include <misc/__assert.h>
|
|
|
|
|
2015-05-20 22:32:20 +08:00
|
|
|
#define _ALL_OPT (0x000000FF)
|
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
void DeListWaiter(struct k_args *pReqProc)
|
|
|
|
{
|
|
|
|
__ASSERT_NO_MSG(NULL != pReqProc->Head);
|
|
|
|
REMOVE_ELM(pReqProc);
|
|
|
|
pReqProc->Head = NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-12 03:25:03 +08:00
|
|
|
void myfreetimer(struct k_timer * *ppTimer)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
if (*ppTimer) {
|
|
|
|
delist_timer(*ppTimer);
|
|
|
|
FREETIMER(*ppTimer);
|
|
|
|
*ppTimer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 08:05:01 +08:00
|
|
|
/* adapted from mailbox implementation of copypacket() */
|
|
|
|
void mycopypacket(struct k_args **out, struct k_args *in)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-04-21 08:05:01 +08:00
|
|
|
GETARGS(*out);
|
2015-05-21 02:05:38 +08:00
|
|
|
k_memcpy_s(*out, sizeof(struct k_args), in, sizeof(struct k_args));
|
2015-04-21 08:05:01 +08:00
|
|
|
(*out)->Ctxt.args = in;
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CalcFreeReaderSpace(struct k_args *pReaderList)
|
|
|
|
{
|
|
|
|
int iSize = 0;
|
2015-04-15 06:15:52 +08:00
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
if (pReaderList) {
|
|
|
|
struct k_args *pReader = pReaderList;
|
|
|
|
while (pReader != NULL) {
|
|
|
|
iSize += (pReader->Args.ChProc.iSizeTotal -
|
|
|
|
pReader->Args.ChProc.iSizeXferred);
|
|
|
|
pReader = pReader->Forw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return iSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CalcAvailWriterData(struct k_args *pWriterList)
|
|
|
|
{
|
|
|
|
int iSize = 0;
|
2015-04-15 06:15:52 +08:00
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
if (pWriterList) {
|
|
|
|
struct k_args *pWriter = pWriterList;
|
|
|
|
while (pWriter != NULL) {
|
|
|
|
iSize += (pWriter->Args.ChProc.iSizeTotal -
|
|
|
|
pWriter->Args.ChProc.iSizeXferred);
|
|
|
|
pWriter = pWriter->Forw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return iSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
K_PIPE_OPTION ChxxxGetChOpt(K_ARGS_ARGS * pChxxx)
|
|
|
|
{
|
|
|
|
return (K_PIPE_OPTION)(pChxxx->ChProc.ReqInfo.Params & _ALL_OPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChxxxSetChOpt(K_ARGS_ARGS *pChxxx, K_PIPE_OPTION option)
|
|
|
|
{
|
|
|
|
pChxxx->ChProc.ReqInfo.Params &=
|
|
|
|
(~_ALL_OPT); /* clear destination field */
|
|
|
|
pChxxx->ChProc.ReqInfo.Params |=
|
2015-05-21 02:05:38 +08:00
|
|
|
(option & _ALL_OPT); /* make sure we do not screw up other fields */
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
REQ_TYPE ChxxxGetReqType(K_ARGS_ARGS *pChxxx)
|
|
|
|
{
|
|
|
|
return (REQ_TYPE)(pChxxx->ChProc.ReqInfo.Params & _ALLREQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChxxxSetReqType(K_ARGS_ARGS *pChxxx, REQ_TYPE ReqType)
|
|
|
|
{
|
|
|
|
pChxxx->ChProc.ReqInfo.Params &=
|
|
|
|
(~_ALLREQ); /* clear destination field */
|
|
|
|
pChxxx->ChProc.ReqInfo.Params |=
|
2015-05-21 02:05:38 +08:00
|
|
|
(ReqType & _ALLREQ); /* make sure we do not screw up other fields */
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TIME_TYPE ChxxxGetTimeType(K_ARGS_ARGS *pChxxx)
|
|
|
|
{
|
|
|
|
return (TIME_TYPE)(pChxxx->ChProc.ReqInfo.Params & _ALLTIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChxxxSetTimeType(K_ARGS_ARGS *pChxxx,
|
|
|
|
TIME_TYPE TimeType)
|
|
|
|
{
|
|
|
|
pChxxx->ChProc.ReqInfo.Params &=
|
|
|
|
(~_ALLTIME); /* clear destination field */
|
|
|
|
pChxxx->ChProc.ReqInfo.Params |=
|
2015-05-21 02:05:38 +08:00
|
|
|
(TimeType & _ALLTIME); /* make sure we do not screw up other fields */
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CHREQ_STATUS ChReqGetStatus(struct k_chproc *pChProc)
|
|
|
|
{
|
|
|
|
return pChProc->Status;
|
|
|
|
}
|
|
|
|
|
2015-05-21 02:05:38 +08:00
|
|
|
void ChReqSetStatus(struct k_chproc *pChProc, CHREQ_STATUS Status)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_OBJECT_MONITOR
|
2015-05-21 02:05:38 +08:00
|
|
|
/*
|
|
|
|
* if transition XFER_IDLE --> XFER_BUSY, TERM_XXX
|
|
|
|
* increment channel counter
|
|
|
|
*/
|
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
if (XFER_IDLE == pChProc->Status /* current (old) status */
|
2015-05-21 02:05:38 +08:00
|
|
|
&& (XFER_BUSY | TERM_XXX) & Status /* new status */) {
|
2015-04-11 07:44:37 +08:00
|
|
|
(pChProc->ReqInfo.ChRef.pPipe->Count)++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
pChProc->Status = Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ChReqSizeXferred(struct k_chproc *pChProc)
|
|
|
|
{
|
|
|
|
return pChProc->iSizeXferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ChReqSizeLeft(struct k_chproc *pChProc)
|
|
|
|
{
|
|
|
|
return (pChProc->iSizeTotal - pChProc->iSizeXferred);
|
|
|
|
}
|