Flesh out unfinished lock() method implementations in al SPI drivers

This commit is contained in:
Gregory Nutt
2016-01-24 09:15:57 -06:00
parent b7cbbab761
commit 52109ade2d
4 changed files with 93 additions and 25 deletions
+32 -15
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/z80/src/ez80/ez80_spi.c
*
* Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Copyright (C) 2009-2010, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@
#include <sys/types.h>
#include <stdint.h>
#include <semaphore.h>
#include <assert.h>
#include <errno.h>
#include <arch/board/board.h>
@@ -85,33 +87,32 @@ static void spi_recvblock(FAR struct spi_dev_s *dev, FAR uint8_t *buffer,
static const struct spi_ops_s g_spiops =
{
spi_lock,
ez80_spiselect, /* select: Provided externally by board logic */
ez80_spiselect, /* select: Provided externally by board logic */
spi_setfrequency,
spi_setmode,
NULL, /* setbits: Variable number of bits not implemented */
NULL, /* setbits: Variable number of bits not implemented */
#ifdef CONFIG_SPI_HWFEATURES
NULL, /* hwfeatures: Not supported */
NULL, /* hwfeatures: Not supported */
#endif
ez80_spistatus, /* status: Provided externally by board logic */
ez80_spistatus, /* status: Provided externally by board logic */
#ifdef CONFIG_SPI_CMDDATA
ez80_spicmddata,
#endif
spi_send,
spi_sndblock,
spi_recvblock,
0 /* registercallback: Not yet implemented */
0 /* registercallback: Not yet implemented */
};
/* This supports is only a single SPI bus/port. If you port this to an
* architecture with multiple SPI busses/ports, then the following must
* become an array with one 'struct spi_dev_s' instance per bus.
* architecture with multiple SPI busses/ports, then (1) you must create
* a structure, say ez80_spidev_s, containing both struct spi_dev_s and
* the mutual exclusion semaphored, and (2) the following must become an
* array with one 'struct spi_dev_s' instance per bus.
*/
static struct spi_dev_s g_spidev = { &g_spiops };
/****************************************************************************
* Public Data
****************************************************************************/
static struct spi_dev_s g_spidev = {&g_spiops};
static sem_t g_exclsem = SEM_INITIALIZER(1); /* For mutually exclusive access */
/****************************************************************************
* Private Functions
@@ -140,9 +141,25 @@ static struct spi_dev_s g_spidev = { &g_spiops };
static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{
/* Not implemented */
if (lock)
{
/* Take the semaphore (perhaps waiting) */
return -ENOSYS;
while (sem_wait(&g_exclsem) != 0)
{
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/
DEBUGASSERT(errno == EINTR);
}
}
else
{
(void)sem_post(&g_exclsem);
}
return OK;
}
/****************************************************************************