1.device设备默认集成收发FIFO。

This commit is contained in:
MacRsh
2023-09-21 16:58:58 +08:00
parent 827460f086
commit 8cead27e0e
2 changed files with 21 additions and 3 deletions

View File

@@ -16,7 +16,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <string.h>
#ifdef __cplusplus
@@ -244,12 +243,18 @@ enum mr_object_type
Mr_Object_Type_Module, /* Module object */
};
/**
* @def Object magic number
*/
#define MR_OBJECT_MAGIC 0x6D72 /* Mr object magic number */
/**
* @struct Object container
*/
struct mr_object_container
{
mr_uint32_t type; /* Object type */
mr_uint16_t type; /* Object type */
mr_uint16_t magic; /* Object magic number */
struct mr_list list; /* Container list */
};
typedef struct mr_object_container *mr_object_container_t; /* Type for container */
@@ -260,7 +265,8 @@ typedef struct mr_object_container *mr_object_container_t; /* Type for
struct mr_object
{
char name[MR_CFG_OBJECT_NAME_SIZE]; /* Object name */
mr_uint32_t type; /* Object type */
mr_uint16_t type; /* Object type */
mr_uint16_t magic; /* Object magic number */
struct mr_list list; /* Object list */
};
typedef struct mr_object *mr_object_t; /* Type for object */
@@ -351,6 +357,8 @@ struct mr_device
mr_uint8_t oflags; /* Open mode flags */
mr_uint8_t reserved; /* Reserved */
mr_size_t ref_count; /* Number of references */
struct mr_rb rx_fifo; /* Receive FIFO */
struct mr_rb tx_fifo; /* Transmit FIFO */
mr_err_t (*rx_cb)(mr_device_t device, void *args); /* Receive the completed callback */
mr_err_t (*tx_cb)(mr_device_t device, void *args); /* Send completion callback */

View File

@@ -61,6 +61,7 @@ mr_err_t mr_device_add(mr_device_t device,
mr_err_t ret = MR_ERR_OK;
MR_ASSERT(device != MR_NULL);
MR_ASSERT(device->object.magic != MR_OBJECT_MAGIC);
MR_ASSERT(name != MR_NULL);
MR_ASSERT(ops != MR_NULL);
@@ -69,6 +70,8 @@ mr_err_t mr_device_add(mr_device_t device,
device->sflags = sflags;
device->oflags = MR_DEVICE_OFLAG_CLOSED;
device->ref_count = 0;
mr_rb_init(&device->rx_fifo, MR_NULL, 0);
mr_rb_init(&device->tx_fifo, MR_NULL, 0);
device->rx_cb = MR_NULL;
device->tx_cb = MR_NULL;
@@ -109,8 +112,13 @@ mr_err_t mr_device_remove(mr_device_t device)
if (ret != MR_ERR_OK)
{
MR_DEBUG_D(DEBUG_TAG, "[%s] remove failed: [%d]\r\n", device->object.name, ret);
return ret;
}
/* Reset the device */
mr_rb_allocate_buffer(&device->rx_fifo, 0);
mr_rb_allocate_buffer(&device->tx_fifo, 0);
return ret;
}
@@ -191,6 +199,8 @@ mr_err_t mr_device_close(mr_device_t device)
/* Set the device status to closed */
device->oflags = MR_DEVICE_OFLAG_CLOSED;
mr_rb_reset(&device->rx_fifo);
mr_rb_reset(&device->tx_fifo);
device->rx_cb = MR_NULL;
device->tx_cb = MR_NULL;