From 910e6496164fd508c4da0828ae24eab406f4d319 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 4 Mar 2016 10:28:13 -0600 Subject: [PATCH] Add a debug assertion for logic error in previous commit --- arch/arm/src/samv7/sam_mcan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/src/samv7/sam_mcan.c b/arch/arm/src/samv7/sam_mcan.c index ff39a274ac7..f3c570be282 100644 --- a/arch/arm/src/samv7/sam_mcan.c +++ b/arch/arm/src/samv7/sam_mcan.c @@ -1558,6 +1558,17 @@ static void mcan_buffer_reserve(FAR struct sam_mcan_s *priv) if (sval != tffl) { candbg("ERROR: TX FIFO reports %d but txfsem is %d\n", tffl, sval); + + /* REVISIT: The following is dangerous and non-standard usage of the + * semaphore count. It can only work if the count is non-negative. + * If the count because negative, then forcing it to a non-negative + * value will cause the system to hang. + * + * A proper solution might be a loop that calls sem_post() or sem_wait() + * repeteadly to adjust the count. + */ + + DEBUGASSERT(priv->txfsem.count >= 0); sem_init(&priv->txfsem, 0, tffl); } #endif