mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 07:23:33 +08:00
Implement a simple byte loopback server on I2C for more testing.
This commit is contained in:
+4
-5
@@ -78,7 +78,6 @@ static DMA_HANDLE tx_dma;
|
|||||||
uint8_t rx_buf[64];
|
uint8_t rx_buf[64];
|
||||||
unsigned rx_len;
|
unsigned rx_len;
|
||||||
uint8_t tx_buf[64];
|
uint8_t tx_buf[64];
|
||||||
unsigned tx_len;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DIR_NONE = 0,
|
DIR_NONE = 0,
|
||||||
@@ -210,6 +209,9 @@ i2c_rx_complete(DMA_HANDLE handle, uint8_t status, void *arg)
|
|||||||
{
|
{
|
||||||
rx_len = sizeof(rx_buf) - stm32_dmaresidual(rx_dma);
|
rx_len = sizeof(rx_buf) - stm32_dmaresidual(rx_dma);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < rx_len; i++)
|
||||||
|
tx_buf[i] = rx_buf[i] + 1;
|
||||||
|
|
||||||
/* XXX handle reception */
|
/* XXX handle reception */
|
||||||
i2c_rx_setup();
|
i2c_rx_setup();
|
||||||
}
|
}
|
||||||
@@ -217,7 +219,6 @@ i2c_rx_complete(DMA_HANDLE handle, uint8_t status, void *arg)
|
|||||||
static void
|
static void
|
||||||
i2c_tx_setup(void)
|
i2c_tx_setup(void)
|
||||||
{
|
{
|
||||||
tx_len = 0;
|
|
||||||
stm32_dmasetup(tx_dma, (uintptr_t)&rDR, (uintptr_t)&tx_buf[0], sizeof(tx_buf),
|
stm32_dmasetup(tx_dma, (uintptr_t)&rDR, (uintptr_t)&tx_buf[0], sizeof(tx_buf),
|
||||||
DMA_CCR_DIR |
|
DMA_CCR_DIR |
|
||||||
DMA_CCR_MINC |
|
DMA_CCR_MINC |
|
||||||
@@ -229,9 +230,7 @@ i2c_tx_setup(void)
|
|||||||
static void
|
static void
|
||||||
i2c_tx_complete(DMA_HANDLE handle, uint8_t status, void *arg)
|
i2c_tx_complete(DMA_HANDLE handle, uint8_t status, void *arg)
|
||||||
{
|
{
|
||||||
tx_len = sizeof(tx_buf) - stm32_dmaresidual(tx_dma);
|
/* XXX handle transmit-done */
|
||||||
|
|
||||||
/* XXX handle reception */
|
|
||||||
i2c_tx_setup();
|
i2c_tx_setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,13 @@ int i2c_main(int argc, char *argv[])
|
|||||||
int ret = transfer(PX4_I2C_OBDEV_PX4IO, (uint8_t *)&val, sizeof(val), NULL, 0);
|
int ret = transfer(PX4_I2C_OBDEV_PX4IO, (uint8_t *)&val, sizeof(val), NULL, 0);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
errx(1, "transfer failed");
|
errx(1, "send failed - %d", ret);
|
||||||
exit(0);
|
|
||||||
|
ret = transfer(PX4_I2C_OBDEV_PX4IO, NULL, 0, (uint8_t *)&val, sizeof(val));
|
||||||
|
if (ret)
|
||||||
|
errx(1, "recive failed - %d", ret);
|
||||||
|
|
||||||
|
errx(0, "got 0x%08x", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
Reference in New Issue
Block a user