DemoPublic/MCU/DevDriverDemo/Demo0.c

141 lines
2.2 KiB
C

/**
* @file Demo0.c
* @author Rick Chan
* @brief
* @version 0.1
* @date 2020-08-01
*
* @copyright Copyright (c) 2020
*
*/
#include "Device.h"
typedef struct DEMO0_OBJ
{
// Some private data for instance
uint8_t ID;
}ST_DEMO0_OBJ;
ST_DEMO0_OBJ Demo0Obj[2];
static EU_ERR Demo0Init(ST_DEVICE* dev)
{
ST_DEMO0_OBJ* obj = (ST_DEMO0_OBJ*)dev->Prv;
if(&Demo0Obj[0]==obj)
{
// Do something.
return EC_OK;
}
else if(&Demo0Obj[1]==obj)
{
// Do something.
return EC_OK;
}
return EC_ERESOURCES;
}
static EU_ERR Demo0Open(ST_DEVICE* dev)
{
ST_DEMO0_OBJ* obj = (ST_DEMO0_OBJ*)dev->Prv;
if(&Demo0Obj[0]==obj)
{
// Do something.
return EC_OK;
}
else if(&Demo0Obj[1]==obj)
{
// Do something.
return EC_OK;
}
return EC_ERESOURCES;
}
/**
* @brief
*
* @param dev
* @param ex contains additional control information.
* @param buf data pointer to be write.
* @param nbytes data size.
* @param timeout
* @return int64_t real size readed.
*/
static int64_t Demo0Read(ST_DEVICE* dev, void* ex, void* buf, int64_t nbytes, uint32_t timeout)
{
ST_DEMO0_OBJ* obj = (ST_DEMO0_OBJ*)dev->Prv;
int64_t rsize;
UNUSED(timeout);
if(&Demo0Obj[0]==obj)
{
// Do something.
return nbytes;
}
else if(&Demo0Obj[1]==obj)
{
// Do something.
return nbytes;
}
return EC_EPAM;
}
/**
* @brief Same as Demo0Read
*
* @param dev
* @param ex Same as Demo0Read
* @param buf
* @param nbytes
* @param timeout
* @return int64_t
*/
static int64_t Demo0Write(ST_DEVICE* dev, void* ex, void* buf, int64_t nbytes, uint32_t timeout)
{
ST_MFIS_OBJ* obj = (ST_MFIS_OBJ*)dev->Prv;
UNUSED(timeout);
if(&Demo0Obj[0]==obj)
{
// Do something.
return nbytes;
}
else if(&Demo0Obj[1]==obj)
{
// Do something.
return nbytes;
}
return EC_EPAM;
}
ST_DEVICE Demo0[2] = {
{
.Init = Demo0Init,
.Open = Demo0Open,
.Close = NULL,
.Read = Demo0Read,
.Write = Demo0Write,
.Seek = NULL,
.IOCtl = NULL,
.PwCtl = NULL,
.EnInt = NULL,
.DisInt = NULL,
.Prv = (void*)&Demo0Obj[0],
},
{
.Init = Demo0Init,
.Open = Demo0Open,
.Close = NULL,
.Read = Demo0Read,
.Write = Demo0Write,
.Seek = NULL,
.IOCtl = NULL,
.PwCtl = NULL,
.EnInt = NULL,
.DisInt = NULL,
.Prv = (void*)&Demo0Obj[1],
}
};