drivers/can/can.c: Fix errors with pointers when using internal OS interface (#118)

Author: Gregory Nutt <gnutt@nuttx.org>

    Run all .c and .h files in last PR through tools/nxstyle and correct all coding standard complaints.

Author: Oleg <ev.mipt@gmail.com>

    * Fix CAN driver to work with internal OS interfaces.  Store internal file pointer in f_priv and use it then to distinct readers (See issue #111)
    * Store reader pointer in f_priv instead of filep
    * Don't need in filep in can_reader_s
This commit is contained in:
Oleg 2020-01-17 09:46:39 -06:00 committed by Gregory Nutt
parent e0cd10b7d5
commit 41efa2ae72
2 changed files with 36 additions and 53 deletions

View File

@ -390,7 +390,7 @@ static FAR struct can_reader_s *init_can_reader(FAR struct file *filep)
reader->fifo.rx_tail = 0;
nxsem_init(&reader->fifo.rx_sem, 0, 1);
reader->filep = filep;
filep->f_priv = reader;
return reader;
}
@ -509,7 +509,8 @@ static int can_close(FAR struct file *filep)
list_for_every_safe(&dev->cd_readers, node, tmp)
{
if (((FAR struct can_reader_s *)node)->filep == filep)
if (((FAR struct can_reader_s *)node) ==
((FAR struct can_reader_s *)filep->f_priv))
{
list_delete(node);
kmm_free(node);
@ -517,6 +518,8 @@ static int can_close(FAR struct file *filep)
}
}
filep->f_priv = NULL;
/* Decrement the references to the driver. If the reference count will
* decrement to 0, then uninitialize the driver.
*/
@ -574,7 +577,6 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer,
FAR struct inode *inode = filep->f_inode;
FAR struct can_dev_s *dev = inode->i_private;
FAR struct can_reader_s *reader = NULL;
FAR struct list_node *node;
FAR struct can_rxfifo_s *fifo;
size_t nread;
irqstate_t flags;
@ -630,16 +632,8 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer,
}
#endif /* CONFIG_CAN_ERRORS */
list_for_every(&dev->cd_readers, node)
{
if (((FAR struct can_reader_s *) node)->filep == filep)
{
reader = (FAR struct can_reader_s *)node;
break;
}
}
DEBUGASSERT(reader != NULL);
DEBUGASSERT(filep->f_priv != NULL);
reader = (FAR struct can_reader_s *)filep->f_priv;
fifo = &reader->fifo;
@ -1027,7 +1021,6 @@ static int can_poll(FAR struct file *filep, FAR struct pollfd *fds,
FAR struct inode *inode = (FAR struct inode *)filep->f_inode;
FAR struct can_dev_s *dev = (FAR struct can_dev_s *)inode->i_private;
FAR struct can_reader_s *reader = NULL;
FAR struct list_node *node;
pollevent_t eventset;
int ndx;
int ret;
@ -1042,16 +1035,8 @@ static int can_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
#endif
list_for_every(&dev->cd_readers, node)
{
if (((FAR struct can_reader_s *)node)->filep == filep)
{
reader = (FAR struct can_reader_s *)node;
break;
}
}
DEBUGASSERT(reader != NULL);
DEBUGASSERT(filep->f_priv != NULL);
reader = (FAR struct can_reader_s *)filep->f_priv;
/* Get exclusive access to the poll structures */

View File

@ -561,7 +561,6 @@ struct can_reader_s
{
struct list_node list;
sem_t read_sem;
FAR struct file *filep;
struct can_rxfifo_s fifo; /* Describes receive FIFO */
};
@ -590,6 +589,7 @@ struct can_dev_s
};
/* Structures used with ioctl calls */
/* CANIOC_RTR: */
struct canioc_rtr_s
@ -598,8 +598,9 @@ struct canioc_rtr_s
FAR struct can_msg_s *ci_msg; /* The location to return the RTR response */
};
/* CANIOC_GET_BITTIMING/CANIOC_SET_BITTIMING: */
/* Bit time = Tquanta * (Sync_Seg + Prop_Seq + Phase_Seg1 + Phase_Seg2)
/* CANIOC_GET_BITTIMING/CANIOC_SET_BITTIMING:
*
* Bit time = Tquanta * (Sync_Seg + Prop_Seq + Phase_Seg1 + Phase_Seg2)
* = Tquanta * (TSEG1 + TSEG2 + 1)
* Where
* TSEG1 = Prop_Seq + Phase_Seg1
@ -614,8 +615,9 @@ struct canioc_bittiming_s
uint8_t bt_sjw; /* Synchronization Jump Width in time quanta */
};
/* CANIOC_GET_CONNMODES/CANIOC_SET_CONNMODES: */
/* A CAN device may support loopback and silent mode. Both modes may not be
/* CANIOC_GET_CONNMODES/CANIOC_SET_CONNMODES:
*
* A CAN device may support loopback and silent mode. Both modes may not be
* settable independently.
*/
@ -654,11 +656,7 @@ struct canioc_stdfilter_s
};
/************************************************************************************
* Public Data
************************************************************************************/
/************************************************************************************
* Public Functions
* Public Function Prototypes
************************************************************************************/
#undef EXTERN