2018-06-24 22:46:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/iob/iob_navail.c
|
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 13:50:10 +01: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-24 22:46:12 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-06-24 22:46:12 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01: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-24 22:46:12 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2018-09-12 14:38:11 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2018-06-24 22:46:12 +02:00
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
|
|
|
|
#include "iob.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iob_navail
|
|
|
|
*
|
|
|
|
* Description:
|
2020-03-16 20:42:34 +01:00
|
|
|
* Return the number of available IOBs.
|
2018-06-24 22:46:12 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-12 14:38:11 +02: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 15:56:21 +02:00
|
|
|
ret = nxsem_get_value(&g_iob_sem, &navail);
|
2018-09-12 14:38:11 +02: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 14:58:07 +01:00
|
|
|
|
2019-01-26 16:56:27 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
}
|
2018-09-12 14:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
ret = navail;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-22 17:33:05 +02:00
|
|
|
* Name: iob_qentry_navail
|
2018-09-12 14:38:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the number of available IOB chains.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-22 17:33:05 +02:00
|
|
|
int iob_qentry_navail(void)
|
2018-06-24 22:46:12 +02:00
|
|
|
{
|
|
|
|
int navail = 0;
|
|
|
|
int ret;
|
|
|
|
|
2018-06-28 15:06:57 +02:00
|
|
|
#if CONFIG_IOB_NCHAINS > 0
|
2018-09-12 14:38:11 +02:00
|
|
|
/* Get the value of the IOB chain qentry counting semaphores */
|
|
|
|
|
2020-05-17 15:56:21 +02:00
|
|
|
ret = nxsem_get_value(&g_qentry_sem, &navail);
|
2018-06-24 22:46:12 +02:00
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
ret = navail;
|
2019-01-26 16:56:27 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
}
|
2018-06-24 22:46:12 +02:00
|
|
|
}
|
2018-09-12 14:38:11 +02:00
|
|
|
|
2018-06-28 15:06:57 +02:00
|
|
|
#else
|
|
|
|
ret = navail;
|
|
|
|
#endif
|
2018-06-24 22:46:12 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|