refactor(device,fifo): 新增设备事件操作者参数

body
1.设备事件操作者参数,用于在设备事件中传递操作者信息,方便使用。
2.fifo获取剩余空间重命名为'space_get'。
This commit is contained in:
MacRsh
2024-05-13 22:04:37 +08:00
parent c50aa742a1
commit 8374a190b1
5 changed files with 20 additions and 16 deletions

View File

@@ -11,7 +11,7 @@
#ifdef MR_USE_PIN
#define _PIN_IS_VALID(_pin, _number) \
(((_number) >= 0) && ((_number) < (sizeof(_pin->pins) * 4)))
(((_number) >= 0) && ((_number) < (sizeof((_pin)->pins) * 4)))
#define _PIN_IS_RDONLY(_data, _number) \
(((_data)->pins[(_number) / 16] & (0x1 << (_number))) != 0)
#define _PIN_IS_WRONLY(_data, _number) \
@@ -29,7 +29,7 @@
#define _PIN_MODE_GET(_pin, _number) \
((uint32_t)((_pin)->pins[(_number) / 16] & (0x3 << (((_number) % 16) * 2))))
#define _PIN_IS_ENABLED(_pin, _number) \
(_PIN_MODE_GET(_pin, _number) != MR_PIN_MODE_NONE)
(_PIN_MODE_GET((_pin), _number) != MR_PIN_MODE_NONE)
MR_INLINE int _pin_configure_set(struct mr_pin *pin, int number,
const struct mr_pin_config *config)

View File

@@ -811,8 +811,8 @@ static int spi_device_ioctl(struct mr_device *device, int pos, int cmd,
int mr_spi_device_register(struct mr_spi_device *spi_device, const char *path,
int cs_pin, int cs_active, const char *spi_bus_name)
{
MR_ASSERT(spi_device != MR_NULL);
MR_ASSERT(path != MR_NULL);
MR_ASSERT(spi_device != NULL);
MR_ASSERT(path != NULL);
MR_ASSERT((cs_active >= MR_SPI_CS_ACTIVE_LOW) &&
(cs_active <= MR_SPI_CS_ACTIVE_NONE));
@@ -852,7 +852,7 @@ int mr_spi_device_register(struct mr_spi_device *spi_device, const char *path,
*/
int mr_spi_device_unregister(struct mr_spi_device *spi_device)
{
MR_ASSERT(spi_device != MR_NULL);
MR_ASSERT(spi_device != NULL);
/* Unregister the SPI device from the SPI bus */
return mr_device_unregister((struct mr_device *)spi_device);

View File

@@ -257,9 +257,10 @@ struct mr_descriptor
struct mr_device_event
{
uint32_t event: 31; /**< Event */
uint32_t private: 1; /**< Private flag */
uint32_t self: 1; /**< Self-defined flag */
void (*callback)(int descriptor, uint32_t event,
void *args); /**< Callback function */
void *args, void *op_data); /**< Callback function */
void *op_data; /**< Operator data */
};
/** @} */

View File

@@ -28,9 +28,10 @@ struct _device_event
uint32_t descriptor: 31; /**< Event descriptor */
uint32_t free: 1; /**< Free flag */
uint32_t event: 31; /**< Event */
uint32_t private: 1; /**< Private flag */
uint32_t self: 1; /**< Self-defined flag */
void (*callback)(int descriptor, uint32_t event,
void *args); /**< Callback function */
void *args, void *op_data); /**< Callback function */
void *op_data; /**< Operator data */
};
static struct mr_device _root_device = {
@@ -184,8 +185,9 @@ MR_INLINE int _device_event_create(struct mr_device *device, int descriptor,
_event->descriptor = descriptor;
_event->free = false;
_event->event = event->event;
_event->private = event->private;
_event->self = event->self;
_event->callback = event->callback;
_event->op_data = event->op_data;
mr_list_insert_before(&device->elist, &_event->list);
ret = MR_EOK;
@@ -283,8 +285,8 @@ MR_INLINE void _device_event_handler(const struct mr_device *device,
struct _device_event *_event =
MR_CONTAINER_OF(list, struct _device_event, list);
/* If the event is not private, take the mask */
event = (_event->private == false) ? event & MR_EVENT_MASK : event;
/* If the event is not self-defined, take the mask */
event = (_event->self == false) ? event & MR_EVENT_MASK : event;
/* Check if the event is free */
if (_event->free == true)
@@ -295,7 +297,8 @@ MR_INLINE void _device_event_handler(const struct mr_device *device,
/* Call the callback if the event matches */
if (_event->event == event)
{
_event->callback(_event->descriptor, _event->event, args);
_event->callback(_event->descriptor, _event->event, args,
_event->op_data);
/* Make the event free if it is in ISR */
if (_event->free == true)

View File

@@ -423,7 +423,7 @@ size_t mr_fifo_used_get(const struct mr_fifo *fifo)
*
* @return The free space.
*/
size_t mr_fifo_free_get(const struct mr_fifo *fifo)
size_t mr_fifo_space_get(const struct mr_fifo *fifo)
{
MR_ASSERT(fifo != NULL);
@@ -613,7 +613,7 @@ size_t mr_fifo_write(struct mr_fifo *fifo, const void *buf, size_t count)
uint8_t *_buf = (uint8_t *)buf;
/* Get free space, limit by count */
uint32_t free = mr_fifo_free_get(fifo);
uint32_t free = mr_fifo_space_get(fifo);
if (free < count)
{
count = free;
@@ -680,7 +680,7 @@ size_t mr_fifo_write_force(struct mr_fifo *fifo, const void *buf, size_t count)
}
/* Discard data that will be overwritten */
uint32_t free = mr_fifo_free_get(fifo);
uint32_t free = mr_fifo_space_get(fifo);
if (free < count)
{
mr_fifo_discard(fifo, count - free);