XHAL block interface.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16278 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
adb5cded74
commit
746d8e1f21
|
@ -8,6 +8,21 @@
|
|||
</imports>
|
||||
<public>
|
||||
<types>
|
||||
<typedef name="hal_blk_info_t">
|
||||
<brief>Type of structure representing a block device information.</brief>
|
||||
<basetype ctype="struct hal_blk_info" />
|
||||
</typedef>
|
||||
<struct name="hal_blk_info">
|
||||
<brief>Block device information structure.</brief>
|
||||
<fields>
|
||||
<field name="blk_size" ctype="uint32_t">
|
||||
<brief>Block size in bytes, usually 512.</brief>
|
||||
</field>
|
||||
<field name="blk_num" ctype="uint32_t">
|
||||
<brief>Total number of blocks.</brief>
|
||||
</field>
|
||||
</fields>
|
||||
</struct>
|
||||
<interface name="block_io" namespace="chn"
|
||||
ancestorname="base_interface" descr="block device">
|
||||
<brief>Base block device interface.</brief>
|
||||
|
@ -16,20 +31,82 @@
|
|||
<consts>
|
||||
</consts>
|
||||
<methods>
|
||||
<method name="blkIsInserted" shortname="is_inserted" ctype="bool">
|
||||
<method name="blkIsInserted" shortname="is_inserted"
|
||||
ctype="bool">
|
||||
<brief>Removable media detection.</brief>
|
||||
<return>The media state.</return>
|
||||
<retval value="false">If media not inserted.</retval>
|
||||
<retval value="true">If media is inserted.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkIsWriteProtected" shortname="is_protected" ctype="bool">
|
||||
<method name="blkIsWriteProtected"
|
||||
shortname="is_protected" ctype="bool">
|
||||
<brief>Returns the media write protection status.</brief>
|
||||
<return>The media state.</return>
|
||||
<retval value="false">If media is writable.</retval>
|
||||
<retval value="true">If media is not writable.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkConnect" shortname="connect"
|
||||
ctype="bool">
|
||||
<brief>Connection to the block device.</brief>
|
||||
<return>The operation status.</return>
|
||||
<retval value="false">If the operation succeeded.</retval>
|
||||
<retval value="true">If the operation failed.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkDisonnect" shortname="disconnect"
|
||||
ctype="bool">
|
||||
<brief>Disconnection from the block device.</brief>
|
||||
<return>The operation status.</return>
|
||||
<retval value="false">If the operation succeeded.</retval>
|
||||
<retval value="true">If the operation failed.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkRead" shortname="read" ctype="bool">
|
||||
<brief>Reads one or more blocks.</brief>
|
||||
<param name="startblk" ctype="uint32_t">Initial block to read.
|
||||
</param>
|
||||
<param name="buffer" ctype="uint8_t *">Pointer to the read buffer.
|
||||
</param>
|
||||
<param name="n" ctype="uint32_t">Number of blocks to read.
|
||||
</param>
|
||||
<return>The operation status.</return>
|
||||
<retval value="false">If the operation succeeded.</retval>
|
||||
<retval value="true">If the operation failed.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkWrite" shortname="write" ctype="bool">
|
||||
<brief>Writes one or more blocks.</brief>
|
||||
<param name="startblk" ctype="uint32_t">Initial block to write.
|
||||
</param>
|
||||
<param name="buffer" ctype="const uint8_t *">Pointer to the write
|
||||
buffer.
|
||||
</param>
|
||||
<param name="n" ctype="uint32_t">Number of blocks to write.
|
||||
</param>
|
||||
<return>The operation status.</return>
|
||||
<retval value="false">If the operation succeeded.</retval>
|
||||
<retval value="true">If the operation failed.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkSync" shortname="sync" ctype="bool">
|
||||
<brief>Synchronization with asynchronous write operations.</brief>
|
||||
<return>The operation status.</return>
|
||||
<retval value="false">If the operation succeeded.</retval>
|
||||
<retval value="true">If the operation failed.</retval>
|
||||
<api />
|
||||
</method>
|
||||
<method name="blkGetInfo" shortname="getinfo"
|
||||
ctype="bool">
|
||||
<brief>Writes one or more blocks.</brief>
|
||||
<param name="bdip" ctype="hal_blk_info_t *">Device information buffer
|
||||
pointer.</param>
|
||||
<return>The operation status.</return>
|
||||
<retval value="false">If the operation succeeded.</retval>
|
||||
<retval value="true">If the operation failed.</retval>
|
||||
<api />
|
||||
</method>
|
||||
</methods>
|
||||
</interface>
|
||||
</types>
|
||||
|
|
|
@ -296,7 +296,7 @@ static inline halfreq_t halClockGetPointX(halclkpt_t clkpt) {
|
|||
//#include "hal_streams.h"
|
||||
#include "hal_channels.h"
|
||||
//#include "hal_files.h"
|
||||
//#include "hal_ioblock.h"
|
||||
#include "hal_block_io.h"
|
||||
//#include "hal_mmcsd.h"
|
||||
//#include "hal_persistent.h"
|
||||
//#include "hal_flash.h"
|
||||
|
|
|
@ -47,6 +47,25 @@
|
|||
/* Module data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of structure representing a block device information.
|
||||
*/
|
||||
typedef struct hal_blk_info hal_blk_info_t;
|
||||
|
||||
/**
|
||||
* @brief Block device information structure.
|
||||
*/
|
||||
struct hal_blk_info {
|
||||
/**
|
||||
* @brief Block size in bytes, usually 512.
|
||||
*/
|
||||
uint32_t blk_size;
|
||||
/**
|
||||
* @brief Total number of blocks.
|
||||
*/
|
||||
uint32_t blk_num;
|
||||
};
|
||||
|
||||
/**
|
||||
* @interface block_io_i
|
||||
* @extends base_interface_i.
|
||||
|
@ -74,6 +93,13 @@ struct block_io_vmt {
|
|||
/* From base_interface_i.*/
|
||||
/* From block_io_i.*/
|
||||
bool (*is_inserted)(void *ip);
|
||||
bool (*is_protected)(void *ip);
|
||||
bool (*connect)(void *ip);
|
||||
bool (*disconnect)(void *ip);
|
||||
bool (*read)(void *ip, uint32_t startblk, uint8_t *buffer, uint32_t n);
|
||||
bool (*write)(void *ip, uint32_t startblk, const uint8_t *buffer, uint32_t n);
|
||||
bool (*sync)(void *ip);
|
||||
bool (*getinfo)(void *ip, hal_blk_info_t *bdip);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -125,6 +151,155 @@ static inline bool blkIsInserted(void *ip) {
|
|||
|
||||
return self->vmt->is_inserted(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Returns the media write protection status.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @return The media state.
|
||||
* @retval false If media is writable.
|
||||
* @retval true If media is not writable.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkIsWriteProtected(void *ip) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->is_protected(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Connection to the block device.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @return The operation status.
|
||||
* @retval false If the operation succeeded.
|
||||
* @retval true If the operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkConnect(void *ip) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->connect(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Disconnection from the block device.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @return The operation status.
|
||||
* @retval false If the operation succeeded.
|
||||
* @retval true If the operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkDisonnect(void *ip) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->disconnect(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Reads one or more blocks.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @param startblk Initial block to read.
|
||||
* @param buffer Pointer to the read buffer.
|
||||
* @param n Number of blocks to read.
|
||||
* @return The operation status.
|
||||
* @retval false If the operation succeeded.
|
||||
* @retval true If the operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkRead(void *ip, uint32_t startblk, uint8_t *buffer,
|
||||
uint32_t n) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->read(ip, startblk, buffer, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Writes one or more blocks.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @param startblk Initial block to write.
|
||||
* @param buffer Pointer to the write buffer.
|
||||
* @param n Number of blocks to write.
|
||||
* @return The operation status.
|
||||
* @retval false If the operation succeeded.
|
||||
* @retval true If the operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkWrite(void *ip, uint32_t startblk, const uint8_t *buffer,
|
||||
uint32_t n) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->write(ip, startblk, buffer, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Synchronization with asynchronous write operations.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @return The operation status.
|
||||
* @retval false If the operation succeeded.
|
||||
* @retval true If the operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkSync(void *ip) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->sync(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof block_io_i
|
||||
* @public
|
||||
*
|
||||
* @brief Writes one or more blocks.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p block_io_i instance.
|
||||
* @param bdip Device information buffer pointer.
|
||||
* @return The operation status.
|
||||
* @retval false If the operation succeeded.
|
||||
* @retval true If the operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline bool blkGetInfo(void *ip, hal_blk_info_t *bdip) {
|
||||
block_io_i *self = (block_io_i *)ip;
|
||||
|
||||
return self->vmt->getinfo(ip, bdip);
|
||||
}
|
||||
/** @} */
|
||||
|
||||
#endif /* HAL_BLOCK_IO_H */
|
||||
|
|
Loading…
Reference in New Issue