Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions drivers/can/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ static int can_close(FAR struct file *filep)
return ret;
}

flags = enter_critical_section(); /* Disable interrupts */

list_for_every(&dev->cd_readers, node)
{
if (((FAR struct can_reader_s *)node) ==
Expand Down Expand Up @@ -341,11 +343,10 @@ static int can_close(FAR struct file *filep)

/* Free the IRQ and disable the CAN device */

flags = enter_critical_section(); /* Disable interrupts */
dev_shutdown(dev); /* Disable the CAN */
leave_critical_section(flags);
dev_shutdown(dev); /* Disable the CAN */

errout:
leave_critical_section(flags);
nxmutex_unlock(&dev->cd_closelock);
return ret;
}
Expand Down Expand Up @@ -719,15 +720,10 @@ static inline ssize_t can_rtrread(FAR struct file *filep,
{
FAR struct can_dev_s *dev = filep->f_inode->i_private;
FAR struct can_rtrwait_s *wait = NULL;
irqstate_t flags;
int i;
int sval;
int ret = -ENOMEM;

/* Disable interrupts through this operation */

flags = enter_critical_section();

/* Find an available slot in the pending RTR list */

for (i = 0; i < CONFIG_CAN_NPENDINGRTR; i++)
Expand Down Expand Up @@ -801,7 +797,6 @@ static inline ssize_t can_rtrread(FAR struct file *filep,
}
}

leave_critical_section(flags);
return ret;
}

Expand All @@ -815,9 +810,14 @@ static int can_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
FAR struct can_dev_s *dev = inode->i_private;
FAR struct can_reader_s *reader = filep->f_priv;
int ret = OK;
irqstate_t flags;

caninfo("cmd: %d arg: %ld\n", cmd, arg);

/* Disable interrupts through this operation */

flags = enter_critical_section();

/* Handle built-in ioctl commands */

switch (cmd)
Expand Down Expand Up @@ -913,6 +913,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}

leave_critical_section(flags);
return ret;
}

Expand Down Expand Up @@ -1120,13 +1121,16 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr,
{
FAR struct can_rxfifo_s *fifo;
FAR struct list_node *node;
irqstate_t flags;
int nexttail;
int ret = -ENOMEM;
int i;
int sval;

caninfo("ID: %" PRId32 " DLC: %d\n", (uint32_t)hdr->ch_id, hdr->ch_dlc);

flags = enter_critical_section();

/* Check if adding this new message would over-run the drivers ability to
* enqueue read data.
*/
Expand Down Expand Up @@ -1256,6 +1260,7 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr,
poll_notify(dev->cd_fds, CONFIG_CAN_NPOLLWAITERS, POLLIN);
}

leave_critical_section(flags);
return ret;
}

Expand Down Expand Up @@ -1332,10 +1337,13 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr,
int can_txdone(FAR struct can_dev_s *dev)
{
int ret = -ENOENT;
irqstate_t flags;

caninfo("xmit head: %d queue: %d tail: %d\n",
dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, dev->cd_xmit.tx_tail);

flags = enter_critical_section();

/* Verify that the xmit FIFO is not empty */

if (dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail)
Expand Down Expand Up @@ -1379,6 +1387,7 @@ int can_txdone(FAR struct can_dev_s *dev)
}
}

leave_critical_section(flags);
return ret;
}

Expand Down Expand Up @@ -1443,11 +1452,14 @@ int can_txdone(FAR struct can_dev_s *dev)
int can_txready(FAR struct can_dev_s *dev)
{
int ret = -ENOENT;
irqstate_t flags;

caninfo("xmit head: %d queue: %d tail: %d waiters: %d\n",
dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, dev->cd_xmit.tx_tail,
dev->cd_ntxwaiters);

flags = enter_critical_section();

/* Verify that the xmit FIFO is not empty. This is safe because interrupts
* are always disabled when calling into can_xmit(); this cannot collide
* with ongoing activity from can_write().
Expand Down Expand Up @@ -1495,6 +1507,7 @@ int can_txready(FAR struct can_dev_s *dev)
#endif
}

leave_critical_section(flags);
return ret;
}
#endif /* CONFIG_CAN_TXREADY */
Expand Down