From eeb943acd61ab75e7804a8a740a00b636c473074 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Feb 2015 19:28:52 -0600 Subject: in nuttx/drivers/can.c can_open function: this line "dev->cd_ocount = tmp;" needs to be moved a few lines down otherwise the open count will only be incremented from 0 to 1. This causes problems when trying to open the can bus from two different tasks. SourceForge Patch #46 from Anonymous --- nuttx/drivers/can.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/nuttx/drivers/can.c b/nuttx/drivers/can.c index 278acbd4f..063576799 100644 --- a/nuttx/drivers/can.c +++ b/nuttx/drivers/can.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/can.c * - * Copyright (C) 2008-2009, 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -112,10 +112,11 @@ static const struct file_operations g_canops = can_read, /* read */ can_write, /* write */ 0, /* seek */ - can_ioctl /* ioctl */ + can_ioctl, /* ioctl */ #ifndef CONFIG_DISABLE_POLL - , 0 /* poll */ + 0, /* poll */ #endif + 0 /* unlink */ }; /**************************************************************************** @@ -182,14 +183,16 @@ static int can_open(FAR struct file *filep) /* Finally, Enable the CAN RX interrupt */ dev_rxint(dev, true); - - /* Save the new open count on success */ - - dev->cd_ocount = tmp; } + irqrestore(flags); } + + /* Save the new open count on success */ + + dev->cd_ocount = tmp; } + sem_post(&dev->cd_closesem); } @@ -336,9 +339,9 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, int msglen = CAN_MSGLEN(msg->cm_hdr.ch_dlc); if (nread + msglen > buflen) - { - break; - } + { + break; + } /* Copy the message to the user buffer */ @@ -409,7 +412,7 @@ static int can_xmit(FAR struct can_dev_s *dev) while (dev->cd_xmit.tx_queue != dev->cd_xmit.tx_tail && dev_txready(dev)) { - /* No.. The fifo should not be empty in this case */ + /* No.. The FIFO should not be empty in this case */ DEBUGASSERT(dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail); @@ -487,7 +490,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, nexttail = 0; } - /* If the XMIT fifo becomes full, then wait for space to become available */ + /* If the XMIT FIFO becomes full, then wait for space to become available */ while (nexttail == fifo->tx_head) { @@ -637,7 +640,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR struct inode *inode = filep->f_inode; FAR struct can_dev_s *dev = inode->i_private; - int ret = OK; + int ret = OK; canvdbg("cmd: %d arg: %ld\n", cmd, arg); -- cgit v1.2.3