mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-05 22:24:47 +08:00
Add EEPROM read/write performance counters.
This commit is contained in:
@@ -66,6 +66,8 @@
|
|||||||
#include <nuttx/i2c.h>
|
#include <nuttx/i2c.h>
|
||||||
#include <nuttx/mtd.h>
|
#include <nuttx/mtd.h>
|
||||||
|
|
||||||
|
#include "systemlib/perf_counter.h"
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@@ -133,6 +135,9 @@ struct at24c_dev_s
|
|||||||
uint8_t addr; /* I2C address */
|
uint8_t addr; /* I2C address */
|
||||||
uint16_t pagesize; /* 32, 63 */
|
uint16_t pagesize; /* 32, 63 */
|
||||||
uint16_t npages; /* 128, 256, 512, 1024 */
|
uint16_t npages; /* 128, 256, 512, 1024 */
|
||||||
|
|
||||||
|
perf_counter_t perf_reads;
|
||||||
|
perf_counter_t perf_writes;
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
@@ -219,6 +224,7 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
|||||||
FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev;
|
FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev;
|
||||||
size_t blocksleft;
|
size_t blocksleft;
|
||||||
uint8_t addr[2];
|
uint8_t addr[2];
|
||||||
|
int ret;
|
||||||
|
|
||||||
struct i2c_msg_s msgv[2] =
|
struct i2c_msg_s msgv[2] =
|
||||||
{
|
{
|
||||||
@@ -262,8 +268,15 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
|||||||
addr[0] = (offset >> 8) & 0xff;
|
addr[0] = (offset >> 8) & 0xff;
|
||||||
msgv[1].buffer = buffer;
|
msgv[1].buffer = buffer;
|
||||||
|
|
||||||
while (I2C_TRANSFER(priv->dev, &msgv[0], 2) < 0)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
perf_begin(priv->perf_reads);
|
||||||
|
ret = I2C_TRANSFER(priv->dev, &msgv[0], 2);
|
||||||
|
perf_end(priv->perf_reads);
|
||||||
|
if (ret >= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
/* XXX probably want a bus reset in here and an eventual timeout */
|
/* XXX probably want a bus reset in here and an eventual timeout */
|
||||||
fvdbg("read stall");
|
fvdbg("read stall");
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
@@ -293,6 +306,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
|
|||||||
FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev;
|
FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev;
|
||||||
size_t blocksleft;
|
size_t blocksleft;
|
||||||
uint8_t buf[AT24XX_PAGESIZE+2];
|
uint8_t buf[AT24XX_PAGESIZE+2];
|
||||||
|
int ret;
|
||||||
|
|
||||||
struct i2c_msg_s msgv[1] =
|
struct i2c_msg_s msgv[1] =
|
||||||
{
|
{
|
||||||
@@ -330,8 +344,16 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
|
|||||||
buf[0] = (offset >> 8) & 0xff;
|
buf[0] = (offset >> 8) & 0xff;
|
||||||
memcpy(&buf[2], buffer, priv->pagesize);
|
memcpy(&buf[2], buffer, priv->pagesize);
|
||||||
|
|
||||||
while (I2C_TRANSFER(priv->dev, &msgv[0], 1) < 0)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
perf_begin(priv->perf_writes);
|
||||||
|
ret = I2C_TRANSFER(priv->dev, &msgv[0], 1);
|
||||||
|
perf_end(priv->perf_writes);
|
||||||
|
|
||||||
|
if (ret >= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
/* XXX probably want a bus reset in here and an eventual timeout */
|
/* XXX probably want a bus reset in here and an eventual timeout */
|
||||||
fvdbg("write stall");
|
fvdbg("write stall");
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
@@ -458,6 +480,9 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev)
|
|||||||
priv->mtd.bwrite = at24c_bwrite;
|
priv->mtd.bwrite = at24c_bwrite;
|
||||||
priv->mtd.ioctl = at24c_ioctl;
|
priv->mtd.ioctl = at24c_ioctl;
|
||||||
priv->dev = dev;
|
priv->dev = dev;
|
||||||
|
|
||||||
|
priv->perf_reads = perf_alloc(PC_ELAPSED, "EEPROM read");
|
||||||
|
priv->perf_writes = perf_alloc(PC_ELAPSED, "EEPROM write");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the implementation-specific state structure as the MTD device */
|
/* Return the implementation-specific state structure as the MTD device */
|
||||||
|
|||||||
Reference in New Issue
Block a user