I2C tool no longer hangs on dev command
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3930 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
13fd47b868
commit
725172c9d4
@ -147,7 +147,8 @@
|
|||||||
#define I2C_SR1_TIMEOUT (1 << 14) /* Bit 14: Timeout or Tlow Error */
|
#define I2C_SR1_TIMEOUT (1 << 14) /* Bit 14: Timeout or Tlow Error */
|
||||||
#define I2C_SR1_SMBALERT (1 << 15) /* Bit 15: SMBus Alert */
|
#define I2C_SR1_SMBALERT (1 << 15) /* Bit 15: SMBus Alert */
|
||||||
|
|
||||||
#define I2C_SR1_ERRORMASK (I2C_SR1_BERR|I2C_SR1_ARLO|I2C_SR1_AF|I2C_SR1_OVR|I2C_SR1_PECERR)
|
#define I2C_SR1_ERRORMASK (I2C_SR1_BERR|I2C_SR1_ARLO|I2C_SR1_AF|I2C_SR1_OVR|\
|
||||||
|
I2C_SR1_PECERR|I2C_SR1_TIMEOUT|I2C_SR1_SMBALERT)
|
||||||
|
|
||||||
/* Status register 2 */
|
/* Status register 2 */
|
||||||
|
|
||||||
|
@ -90,6 +90,16 @@
|
|||||||
|
|
||||||
#if defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2)
|
#if defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2)
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
************************************************************************************/
|
||||||
|
/* Configuration ********************************************************************/
|
||||||
|
/* Interrupt wait timeout in milliseconds */
|
||||||
|
|
||||||
|
#ifndef CONFIG_STM32_I2CTIMEOMS
|
||||||
|
# define CONFIG_STM32_I2CTIMEOMS 50
|
||||||
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@ -183,10 +193,27 @@ void inline stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev)
|
|||||||
|
|
||||||
int inline stm32_i2c_sem_waitisr(FAR struct i2c_dev_s *dev)
|
int inline stm32_i2c_sem_waitisr(FAR struct i2c_dev_s *dev)
|
||||||
{
|
{
|
||||||
while( sem_wait( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr ) != 0 ) {
|
struct timespec abstime;
|
||||||
ASSERT(errno == EINTR);
|
irqstate_t flags;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
flags = irqsave();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
(void)clock_settime(CLOCK_REALTIME, &abstime);
|
||||||
|
abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
|
||||||
|
if (abstime.tv_nsec > 1000 * 1000 * 1000)
|
||||||
|
{
|
||||||
|
abstime.tv_sec++;
|
||||||
|
abstime.tv_nsec -= 1000 * 1000 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = sem_timedwait(&((struct stm32_i2c_inst_s *)dev)->priv->sem_isr, &abstime);
|
||||||
}
|
}
|
||||||
return OK;
|
while (ret != OK && errno == EINTR);
|
||||||
|
|
||||||
|
irqrestore(flags);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline stm32_i2c_sem_post(FAR struct i2c_dev_s *dev)
|
void inline stm32_i2c_sem_post(FAR struct i2c_dev_s *dev)
|
||||||
@ -270,7 +297,7 @@ static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv)
|
|||||||
static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
||||||
{
|
{
|
||||||
uint32_t status = stm32_i2c_getstatus(priv);
|
uint32_t status = stm32_i2c_getstatus(priv);
|
||||||
|
|
||||||
#ifdef NON_ISR
|
#ifdef NON_ISR
|
||||||
static uint32_t isr_count = 0;
|
static uint32_t isr_count = 0;
|
||||||
static uint32_t old_status = 0xFFFF;
|
static uint32_t old_status = 0xFFFF;
|
||||||
@ -285,7 +312,7 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
|||||||
/* Was start bit sent */
|
/* Was start bit sent */
|
||||||
|
|
||||||
if (status & I2C_SR1_SB) {
|
if (status & I2C_SR1_SB) {
|
||||||
|
|
||||||
/* Get run-time data */
|
/* Get run-time data */
|
||||||
|
|
||||||
priv->ptr = priv->msgv->buffer;
|
priv->ptr = priv->msgv->buffer;
|
||||||
@ -315,7 +342,7 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
|||||||
|
|
||||||
else if (status & I2C_SR1_ADD10) {
|
else if (status & I2C_SR1_ADD10) {
|
||||||
/* \todo Finish 10-bit mode addressing */
|
/* \todo Finish 10-bit mode addressing */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Was address sent, continue with ether sending or reading data */
|
/* Was address sent, continue with ether sending or reading data */
|
||||||
@ -341,7 +368,7 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
|||||||
/* More bytes to read */
|
/* More bytes to read */
|
||||||
|
|
||||||
else if ( status & I2C_SR1_RXNE ) {
|
else if ( status & I2C_SR1_RXNE ) {
|
||||||
|
|
||||||
/* Read a byte, if dcnt goes < 0, then read dummy bytes to ack ISRs */
|
/* Read a byte, if dcnt goes < 0, then read dummy bytes to ack ISRs */
|
||||||
|
|
||||||
#ifdef NON_ISR
|
#ifdef NON_ISR
|
||||||
@ -376,6 +403,7 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (priv->dcnt<=0 && (status & I2C_SR1_BTF)) {
|
if (priv->dcnt<=0 && (status & I2C_SR1_BTF)) {
|
||||||
|
|
||||||
#ifdef NON_ISR
|
#ifdef NON_ISR
|
||||||
printf("BTF\n");
|
printf("BTF\n");
|
||||||
#endif
|
#endif
|
||||||
@ -641,6 +669,7 @@ int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int
|
|||||||
|
|
||||||
if (stm32_i2c_sem_waitisr(dev) == ERROR) {
|
if (stm32_i2c_sem_waitisr(dev) == ERROR) {
|
||||||
status = stm32_i2c_getstatus(inst->priv);
|
status = stm32_i2c_getstatus(inst->priv);
|
||||||
|
status_errno = ETIMEDOUT;
|
||||||
}
|
}
|
||||||
else status = inst->priv->status & 0xFFFF; /* clear SR2 (BUSY flag) as we've done successfully */
|
else status = inst->priv->status & 0xFFFF; /* clear SR2 (BUSY flag) as we've done successfully */
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user