diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-02-08 17:25:29 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-02-08 17:25:29 +0000 |
commit | 4d38c9e58c3e7ffc7647b5729d77c91053bc49f7 (patch) | |
tree | 576daf7298d9450ab824fdb9a7626de65cd50d63 /nuttx/drivers/can.c | |
parent | ebff820250129b6361ff9de635578e07d11fe16c (diff) | |
download | px4-nuttx-4d38c9e58c3e7ffc7647b5729d77c91053bc49f7.tar.gz px4-nuttx-4d38c9e58c3e7ffc7647b5729d77c91053bc49f7.tar.bz2 px4-nuttx-4d38c9e58c3e7ffc7647b5729d77c91053bc49f7.zip |
Fix DM320 serial configuration problem
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@661 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/can.c')
-rw-r--r-- | nuttx/drivers/can.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/nuttx/drivers/can.c b/nuttx/drivers/can.c index 84db1eacf..e463b4e32 100644 --- a/nuttx/drivers/can.c +++ b/nuttx/drivers/can.c @@ -106,6 +106,7 @@ static int can_open(FAR struct file *filep) { FAR struct inode *inode = filep->f_inode; FAR struct can_dev_s *dev = inode->i_private; + ubyte tmp; int ret = OK; /* If the port is the middle of closing, wait until the close is finished */ @@ -121,29 +122,43 @@ static int can_open(FAR struct file *filep) * the device. */ - if (++dev->cd_ocount == 1) + tmp = dev->cd_ocount + 1; + if (tmp == 0) { - irqstate_t flags = irqsave(); + /* More than 255 opens; ubyte overflows to zero */ - /* Configure hardware interrupts */ + ret = -EMFILE; + } + else + { + /* Check if this is the first time that the driver has been opened. */ - ret = dev_setup(dev); - if (ret == OK) + if (tmp == 1) { - /* Mark the FIFOs empty */ + /* Yes.. perform one time hardware initialization. */ - dev->cd_xmit.cf_head = 0; - dev->cd_xmit.cf_tail = 0; - dev->cd_recv.cf_head = 0; - dev->cd_recv.cf_tail = 0; + irqstate_t flags = irqsave(); + ret = dev_setup(dev); + if (ret == OK) + { + /* Mark the FIFOs empty */ + + dev->cd_xmit.cf_head = 0; + dev->cd_xmit.cf_tail = 0; + dev->cd_recv.cf_head = 0; + dev->cd_recv.cf_tail = 0; - /* Finally, Enable CAN interrupt */ + /* Finally, Enable the CAN RX interrupt */ - dev_rxint(dev, TRUE); + dev_rxint(dev, TRUE); + + /* Save the new open count on success */ + + dev->cd_ocount = tmp; + } + irqrestore(flags); } - irqrestore(flags); } - sem_post(&dev->cd_closesem); } return ret; |