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-06-19 22:56:52 +08:00
|
|
|
#include <micro_private.h>
|
2015-05-22 04:29:22 +08:00
|
|
|
#include <k_pipe_util.h>
|
2015-05-23 03:19:28 +08:00
|
|
|
#include <string.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
#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-06-29 23:05:32 +08:00
|
|
|
void myfreetimer(struct k_timer **ppTimer)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
if (*ppTimer) {
|
2015-06-12 03:05:30 +08:00
|
|
|
_k_timer_delist(*ppTimer);
|
2015-04-11 07:44:37 +08:00
|
|
|
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-26 01:18:47 +08:00
|
|
|
memcpy(*out, 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) {
|
2015-07-08 02:06:55 +08:00
|
|
|
iSize += (pReader->Args.pipe_xfer_req.iSizeTotal -
|
|
|
|
pReader->Args.pipe_xfer_req.iSizeXferred);
|
2015-04-11 07:44:37 +08:00
|
|
|
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) {
|
2015-07-08 02:06:55 +08:00
|
|
|
iSize += (pWriter->Args.pipe_xfer_req.iSizeTotal -
|
|
|
|
pWriter->Args.pipe_xfer_req.iSizeXferred);
|
2015-04-11 07:44:37 +08:00
|
|
|
pWriter = pWriter->Forw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return iSize;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:25:04 +08:00
|
|
|
K_PIPE_OPTION _k_pipe_option_get(K_ARGS_ARGS *pChxxx)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-07-08 02:06:55 +08:00
|
|
|
return (K_PIPE_OPTION)(pChxxx->pipe_xfer_req.ReqInfo.Params & _ALL_OPT);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:28:03 +08:00
|
|
|
void _k_pipe_option_set(K_ARGS_ARGS *pChxxx, K_PIPE_OPTION option)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-06-30 01:46:57 +08:00
|
|
|
/* Ensure that only the pipe option bits are modified */
|
2015-07-08 02:06:55 +08:00
|
|
|
pChxxx->pipe_xfer_req.ReqInfo.Params &= (~_ALL_OPT);
|
|
|
|
pChxxx->pipe_xfer_req.ReqInfo.Params |= (option & _ALL_OPT);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:29:56 +08:00
|
|
|
REQ_TYPE _k_pipe_request_type_get(K_ARGS_ARGS *pChxxx)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-07-08 02:06:55 +08:00
|
|
|
return (REQ_TYPE)(pChxxx->pipe_xfer_req.ReqInfo.Params & _ALLREQ);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:31:46 +08:00
|
|
|
void _k_pipe_request_type_set(K_ARGS_ARGS *pChxxx, REQ_TYPE ReqType)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-06-30 01:46:57 +08:00
|
|
|
/* Ensure that only the request type bits are modified */
|
2015-07-08 02:06:55 +08:00
|
|
|
pChxxx->pipe_xfer_req.ReqInfo.Params &= (~_ALLREQ);
|
|
|
|
pChxxx->pipe_xfer_req.ReqInfo.Params |= (ReqType & _ALLREQ);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-27 02:45:39 +08:00
|
|
|
TIME_TYPE _k_pipe_time_type_get(K_ARGS_ARGS *pChxxx)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-07-08 02:06:55 +08:00
|
|
|
return (TIME_TYPE)(pChxxx->pipe_xfer_req.ReqInfo.Params & _ALLTIME);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-27 02:48:18 +08:00
|
|
|
void _k_pipe_time_type_set(K_ARGS_ARGS *pChxxx, TIME_TYPE TimeType)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-06-30 01:46:57 +08:00
|
|
|
/* Ensure that only the time type bits are modified */
|
2015-07-08 02:06:55 +08:00
|
|
|
pChxxx->pipe_xfer_req.ReqInfo.Params &= (~_ALLTIME);
|
|
|
|
pChxxx->pipe_xfer_req.ReqInfo.Params |= (TimeType & _ALLTIME);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-07-08 04:28:49 +08:00
|
|
|
void _k_pipe_request_status_set(struct _pipe_xfer_req_arg *pipe_xfer_req,
|
|
|
|
PIPE_REQUEST_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-07-08 04:28:49 +08:00
|
|
|
if (XFER_IDLE == pipe_xfer_req->Status /* current (old) status */
|
2015-05-21 02:05:38 +08:00
|
|
|
&& (XFER_BUSY | TERM_XXX) & Status /* new status */) {
|
2015-07-08 04:28:49 +08:00
|
|
|
(pipe_xfer_req->ReqInfo.ChRef.pPipe->Count)++;
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
#endif
|
2015-07-08 04:28:49 +08:00
|
|
|
pipe_xfer_req->Status = Status;
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|