vTaskDelayUntil improvement (#77)

* vTaskDelayUntil improvement

* suggestions implemented

* xTaskDelayUntil #define added

* doc small fix

* small formatting stuff

* more small formatting stuff

* Update lexicon.txt

Co-authored-by: Carl Lundin <53273776+lundinc2@users.noreply.github.com>
Co-authored-by: Carl Lundin <lundinc@amazon.com>
diff --git a/include/task.h b/include/task.h
index 730deec..75e324d 100644
--- a/include/task.h
+++ b/include/task.h
@@ -781,7 +781,7 @@
 /**
  * task. h
  * <pre>
- * void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
+ * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  * </pre>
  *
  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
@@ -799,7 +799,7 @@
  * each time it executes].
  *
  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
- * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
+ * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  * unblock.
  *
  * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
@@ -808,13 +808,16 @@
  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  * task was last unblocked.  The variable must be initialised with the current time
  * prior to its first use (see the example below).  Following this the variable is
- * automatically updated within vTaskDelayUntil ().
+ * automatically updated within xTaskDelayUntil ().
  *
  * @param xTimeIncrement The cycle time period.  The task will be unblocked at
- * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the
+ * time *pxPreviousWakeTime + xTimeIncrement.  Calling xTaskDelayUntil with the
  * same xTimeIncrement parameter value will cause the task to execute with
  * a fixed interface period.
  *
+ * @return Value which can be used to check whether the task was actually delayed.
+ * Will be pdTRUE if the task way delayed and pdFALSE otherwise.
+ *
  * Example usage:
  * <pre>
  * // Perform an action every 10 ticks.
@@ -823,22 +826,28 @@
  * TickType_t xLastWakeTime;
  * const TickType_t xFrequency = 10;
  *
- *   // Initialise the xLastWakeTime variable with the current time.
- *   xLastWakeTime = xTaskGetTickCount ();
- *   for( ;; )
- *   {
- *       // Wait for the next cycle.
- *       vTaskDelayUntil( &xLastWakeTime, xFrequency );
+ *     // Initialise the xLastWakeTime variable with the current time.
+ *     xLastWakeTime = xTaskGetTickCount ();
+ *	   for( ;; )
+ *	   {
+ *	       // Wait for the next cycle.
+ *		   BaseType_t xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
  *
- *       // Perform action here.
- *   }
+ *		   // Perform action here. xWasDelayed value can be used to determine
+ *		   // whether a deadline was missed if the code here took too long.
+ *     }
  * }
  * </pre>
- * \defgroup vTaskDelayUntil vTaskDelayUntil
+ * \defgroup xTaskDelayUntil xTaskDelayUntil
  * \ingroup TaskCtrl
  */
-void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
-                      const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
+BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime, 
+                            const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
+#define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement )   \
+{                                                               \
+	xTaskDelayUntil ( pxPreviousWakeTime , xTimeIncrement );    \
+}
+
 
 /**
  * task. h
diff --git a/lexicon.txt b/lexicon.txt
index 8cb6e9f..2e6e9a9 100644
--- a/lexicon.txt
+++ b/lexicon.txt
@@ -2976,6 +2976,7 @@
 xtaskcreaterestricted
 xtaskcreaterestrictedstatic
 xtaskcreatestatic
+xtaskdelayuntil
 xtaskdetails
 xtaskendscheduler
 xtaskgetapplicationtasktag
@@ -3076,6 +3077,7 @@
 xvtorconst
 xwaitforallbits
 xwantedsize
+xwasdelayed
 xwritevalue
 xxr
 xyieldpending
diff --git a/tasks.c b/tasks.c
index cbd23b9..16322e1 100644
--- a/tasks.c
+++ b/tasks.c
@@ -1246,7 +1246,7 @@
 

 #if ( INCLUDE_vTaskDelayUntil == 1 )

 

-    void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime,

+    BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,

                           const TickType_t xTimeIncrement )

     {

         TickType_t xTimeToWake;

@@ -1324,6 +1324,8 @@
         {

             mtCOVERAGE_TEST_MARKER();

         }

+        

+        return xShouldDelay;

     }

 

 #endif /* INCLUDE_vTaskDelayUntil */