2018-06-25 04:46:12 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/iob/iob_navail.c
|
|
|
|
*
|
2021-02-08 20:50:10 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-06-25 04:46:12 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-06-25 04:46:12 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-06-25 04:46:12 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2018-09-12 20:38:11 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2018-06-25 04:46:12 +08:00
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
|
|
|
|
#include "iob.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iob_navail
|
|
|
|
*
|
|
|
|
* Description:
|
2020-03-17 03:42:34 +08:00
|
|
|
* Return the number of available IOBs.
|
2018-06-25 04:46:12 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-12 20:38:11 +08:00
|
|
|
int iob_navail(bool throttled)
|
|
|
|
{
|
|
|
|
int navail = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
#if CONFIG_IOB_NBUFFERS > 0
|
|
|
|
/* Get the value of the IOB counting semaphores */
|
|
|
|
|
2020-05-17 21:56:21 +08:00
|
|
|
ret = nxsem_get_value(&g_iob_sem, &navail);
|
2018-09-12 20:38:11 +08:00
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
ret = navail;
|
|
|
|
|
|
|
|
#if CONFIG_IOB_THROTTLE > 0
|
|
|
|
/* Subtract the throttle value is so requested */
|
|
|
|
|
|
|
|
if (throttled)
|
|
|
|
{
|
|
|
|
ret -= CONFIG_IOB_THROTTLE;
|
|
|
|
}
|
|
|
|
#endif
|
2020-02-13 21:58:07 +08:00
|
|
|
|
2019-01-26 23:56:27 +08:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
}
|
2018-09-12 20:38:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
ret = navail;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-22 23:33:05 +08:00
|
|
|
* Name: iob_qentry_navail
|
2018-09-12 20:38:11 +08:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the number of available IOB chains.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-22 23:33:05 +08:00
|
|
|
int iob_qentry_navail(void)
|
2018-06-25 04:46:12 +08:00
|
|
|
{
|
|
|
|
int navail = 0;
|
|
|
|
int ret;
|
|
|
|
|
2018-06-28 21:06:57 +08:00
|
|
|
#if CONFIG_IOB_NCHAINS > 0
|
2018-09-12 20:38:11 +08:00
|
|
|
/* Get the value of the IOB chain qentry counting semaphores */
|
|
|
|
|
2020-05-17 21:56:21 +08:00
|
|
|
ret = nxsem_get_value(&g_qentry_sem, &navail);
|
2018-06-25 04:46:12 +08:00
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
ret = navail;
|
2019-01-26 23:56:27 +08:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
}
|
2018-06-25 04:46:12 +08:00
|
|
|
}
|
2018-09-12 20:38:11 +08:00
|
|
|
|
2018-06-28 21:06:57 +08:00
|
|
|
#else
|
|
|
|
ret = navail;
|
|
|
|
#endif
|
2018-06-25 04:46:12 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|