Why no 'chSemSignalS' function?

Discussions and support about ChibiOS/RT, the free embedded RTOS.
User avatar
russian
Posts: 364
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 16 times
Been thanked: 14 times

Why no 'chSemSignalS' function?

Postby russian » Sat Aug 10, 2019 10:48 pm

How wrong are the things I am doing if I need chSemSignalS function?

Here is my universal wake function which works both in I and not-I context, also works regardless if we are in locked context or not:

Code: Select all

// ChibiOS does not offer this function so that's a copy-paste of 'chSemSignal' without locking
void chSemSignalS(semaphore_t *sp) {

  chDbgCheck(sp != NULL);

  chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
              ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
              "inconsistent semaphore");
  if (++sp->cnt <= (cnt_t)0) {
    chSchWakeupS(queue_fifo_remove(&sp->queue), MSG_OK);
  }
}

/**
 * @details Wake up driver. Will cause output register update
 */
static int tle8888_wake_driver(struct tle8888_priv *chip)
{
   int wasLocked = lockAnyContext();
   if (isIsrContext()) {
      // this is for normal runtime
      chSemSignalI(&tle8888_wake);
   } else {
      // this is for start-up to not hang up
      chSemSignalS(&tle8888_wake);
   }
   if (!wasLocked) {
      unlockAnyContext();
   }
   return 0;
}
http://rusefi.com/ - electronic fuel injection

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Why no 'chSemSignalS' function?

Postby Giovanni » Sun Aug 11, 2019 4:58 am

Hi,

Code: Select all

syssts_t sts = chSysGetStatusAndLockX()
chSemSignalI(...);
chSysRestoreStatusX(sts)


This should work too.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 28 guests