📄 media.h
字号:
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support - ROUSSET -
* ----------------------------------------------------------------------------
* Copyright (c) 2006, Atmel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaiimer below.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer below in the documentation and/or
* other materials provided with the distribution.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
/*
$Id: media.h 198 2006-10-30 10:01:09Z jjoannic $
*/
#ifndef _MEDIA_H
#define _MEDIA_H
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
//! \brief Operation result code returned by media methods
#define MED_STATUS_SUCCESS 0x00
#define MED_STATUS_ERROR 0x01
#define MED_STATUS_BUSY 0x02
//! \brief Media statuses
#define MED_STATE_READY 0x00
#define MED_STATE_BUSY 0x01
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
typedef struct _S_media S_media;
typedef unsigned char (*S_media_write)(S_media *pMedia,
unsigned int dAddress,
void *pData,
unsigned int dLength,
Callback_f fCallback,
void *pArgument);
typedef unsigned char (*S_media_read)(S_media *pMedia,
unsigned int dAddress,
void *pData,
unsigned int dLength,
Callback_f fCallback,
void *pArgument);
typedef bool (*S_media_pending)(S_media *pMedia);
typedef void (*S_media_handler)(S_media *pMedia);
//! \brief Media transfer
//! \see Callback_f
typedef struct {
void *pData; //!< Pointer to the data buffer
unsigned int dAddress; //!< Address where to read/write the data
unsigned int dLength; //!< Size of the data to read/write
Callback_f fCallback; //!< Callback to invoke when the transfer finishes
void *pArgument; //!< Callback argument
} S_media_transfer;
//! \brief Media object
//! \see S_media_transfer
typedef struct _S_media {
S_media_write fWrite; //!< Write method
S_media_read fRead; //!< Read method
S_media_pending fPending; //!< Interrupt pending? method
S_media_handler fHandler; //!< Interrupt handler
unsigned int dBaseAddress; //!< Base address of media
unsigned int dSize; //!< Size of media
S_media_transfer sTransfer; //!< Current transfer operation
void *pInterface; //!< Pointer to the physical interface used
unsigned char bState; //!< Status of media
} S_media;
//------------------------------------------------------------------------------
// Inline Functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//! \brief Writes data on a media
//! \param pMedia Pointer to a S_media instance
//! \param dAddress Address at which to write
//! \param pData Pointer to the data to write
//! \param dLength Size of the data buffer
//! \param fCallback Optional pointer to a callback function to invoke when
//! the write operation terminates
//! \param pArgument Optional argument for the callback function
//! \return Operation result code
//! \see Callback_f
//------------------------------------------------------------------------------
static inline unsigned char MED_Write(S_media *pMedia,
unsigned int dAddress,
void *pData,
unsigned int dLength,
Callback_f fCallback,
void *pArgument)
{
return pMedia->fWrite(pMedia, dAddress, pData,
dLength, fCallback, pArgument);
}
//------------------------------------------------------------------------------
//! \brief Reads a specified amount of data from a media
//! \param pMedia Pointer to a S_media instance
//! \param dAddress Address of the data to read
//! \param pData Pointer to the buffer in which to store the retrieved
//! data
//! \param dLength Length of the buffer
//! \param fCallback Optional pointer to a callback function to invoke when
//! the operation is finished
//! \param pArgument Optional pointer to an argument for the callback
//! \return Operation result code
//! \see Callback_f
//------------------------------------------------------------------------------
static inline unsigned char MED_Read(S_media *pMedia,
unsigned int dAddress,
void *pData,
unsigned int dLength,
Callback_f fCallback,
void *pArgument)
{
return pMedia->fRead(pMedia, dAddress, pData,
dLength, fCallback, pArgument);
}
//------------------------------------------------------------------------------
//! \brief Checks if the media interrupt is currently pending
//! \param pMedia Pointer to the S_media instance
//! \return true if the interrupt is pending, false otherwise
//------------------------------------------------------------------------------
static inline bool MED_Pending(S_media *pMedia)
{
return pMedia->fPending(pMedia);
}
//------------------------------------------------------------------------------
//! \brief Invokes the interrupt handler of the specified media
//! \param pMedia Pointer to the S_media instance to use
//------------------------------------------------------------------------------
static inline void MED_Handler(S_media *pMedia)
{
pMedia->fHandler(pMedia);
}
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern void MED_HandleAll(S_media *pMedia, unsigned char bNumMedia);
#endif // _MEDIA_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -