mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
Fix a semphore overflow problem in the CAN driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3890 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -2002,3 +2002,6 @@
|
|||||||
and bit fields within all Kinetis registers.
|
and bit fields within all Kinetis registers.
|
||||||
* configs/twr-k60n512: Add support for the Kinetis K60 Tower board
|
* configs/twr-k60n512: Add support for the Kinetis K60 Tower board
|
||||||
(TWR-K60N512).
|
(TWR-K60N512).
|
||||||
|
* drivers/can.c: Fixe a semaphore overflow problem in the CAN driver
|
||||||
|
(reported by Li Zhouy (Lzzy)).
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -50,6 +50,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
@@ -443,7 +444,11 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, size_t
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
DEBUGASSERT(dev->cd_ntxwaiters < 255);
|
||||||
|
dev->cd_ntxwaiters++;
|
||||||
ret = sem_wait(&fifo->cf_sem);
|
ret = sem_wait(&fifo->cf_sem);
|
||||||
|
dev->cd_ntxwaiters--;
|
||||||
|
|
||||||
if (ret < 0 && errno != EINTR)
|
if (ret < 0 && errno != EINTR)
|
||||||
{
|
{
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
@@ -750,9 +755,12 @@ int can_txdone(FAR struct can_dev_s *dev)
|
|||||||
/* Send the next message in the FIFO */
|
/* Send the next message in the FIFO */
|
||||||
|
|
||||||
ret = can_xmit(dev);
|
ret = can_xmit(dev);
|
||||||
if (ret == OK)
|
|
||||||
|
/* Are there any threads waiting for space in the TX FIFO? */
|
||||||
|
|
||||||
|
if (ret == OK && dev->cd_ntxwaiters > 0)
|
||||||
{
|
{
|
||||||
/* Inform any waiting threads that new xmit space is available */
|
/* Yes.. Inform them that new xmit space is available */
|
||||||
|
|
||||||
ret = sem_post(&dev->cd_xmit.cf_sem);
|
ret = sem_post(&dev->cd_xmit.cf_sem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ struct can_dev_s
|
|||||||
{
|
{
|
||||||
uint8_t cd_ocount; /* The number of times the device has been opened */
|
uint8_t cd_ocount; /* The number of times the device has been opened */
|
||||||
uint8_t cd_npendrtr; /* Number of pending RTR messages */
|
uint8_t cd_npendrtr; /* Number of pending RTR messages */
|
||||||
|
uint8_t cd_ntxwaiters; /* Number of threads waiting to enqueue a message */
|
||||||
sem_t cd_closesem; /* Locks out new opens while close is in progress */
|
sem_t cd_closesem; /* Locks out new opens while close is in progress */
|
||||||
sem_t cd_recvsem; /* Used to wakeup user waiting for space in cd_recv.buffer */
|
sem_t cd_recvsem; /* Used to wakeup user waiting for space in cd_recv.buffer */
|
||||||
struct can_fifo_s cd_xmit; /* Describes transmit FIFO */
|
struct can_fifo_s cd_xmit; /* Describes transmit FIFO */
|
||||||
|
|||||||
Reference in New Issue
Block a user