tangzz98 3 anni fa
parent
commit
314c00dfe0
3 ha cambiato i file con 89 aggiunte e 0 eliminazioni
  1. 16 0
      FreeRTOS/include/queue.h
  2. 16 0
      FreeRTOS/include/semphr.h
  3. 57 0
      FreeRTOS/queue.c

+ 16 - 0
FreeRTOS/include/queue.h

@@ -147,6 +147,22 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
                               TickType_t xTicksToWait,
                               TickType_t xTicksToWait,
                               const BaseType_t xCopyPosition );
                               const BaseType_t xCopyPosition );
 
 
+/**
+ * queue. h
+ * @code{c}
+ * void vQueueDelete( QueueHandle_t xQueue );
+ * @endcode
+ *
+ * Delete a queue - freeing all the memory allocated for storing of items
+ * placed on the queue.
+ *
+ * @param xQueue A handle to the queue to be deleted.
+ *
+ * \defgroup vQueueDelete vQueueDelete
+ * \ingroup QueueManagement
+ */
+void vQueueDelete( QueueHandle_t xQueue );
+
 /*
 /*
  * For internal use only.  Use xSemaphoreCreateMutex(),
  * For internal use only.  Use xSemaphoreCreateMutex(),
  * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling

+ 16 - 0
FreeRTOS/include/semphr.h

@@ -366,4 +366,20 @@ typedef QueueHandle_t SemaphoreHandle_t;
     #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore )    xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )
     #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore )    xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )
 #endif /* configSUPPORT_STATIC_ALLOCATION */
 #endif /* configSUPPORT_STATIC_ALLOCATION */
 
 
+/**
+ * semphr. h
+ * @code{c}
+ * void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );
+ * @endcode
+ *
+ * Delete a semaphore.  This function must be used with care.  For example,
+ * do not delete a mutex type semaphore if the mutex is held by a task.
+ *
+ * @param xSemaphore A handle to the semaphore to be deleted.
+ *
+ * \defgroup vSemaphoreDelete vSemaphoreDelete
+ * \ingroup Semaphores
+ */
+#define vSemaphoreDelete( xSemaphore )                   vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
+
 #endif /* SEMAPHORE_H */
 #endif /* SEMAPHORE_H */

+ 57 - 0
FreeRTOS/queue.c

@@ -234,3 +234,60 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
     return rt_err_to_freertos( err );
     return rt_err_to_freertos( err );
 }
 }
 /*-----------------------------------------------------------*/
 /*-----------------------------------------------------------*/
+
+void vQueueDelete( QueueHandle_t xQueue )
+{
+    Queue_t * const pxQueue = xQueue;
+    struct rt_ipc_object *pipc;
+    rt_uint8_t type;
+
+    configASSERT( pxQueue );
+
+    pipc = pxQueue->rt_ipc;
+    RT_ASSERT( pipc != RT_NULL );
+    type = rt_object_get_type( &pipc->parent );
+#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
+    if ( rt_object_is_systemobject( ( rt_object_t ) pipc ) )
+#endif
+    {
+    #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+        if ( type == RT_Object_Class_Mutex )
+        {
+            rt_mutex_detach( ( rt_mutex_t ) pipc );
+        }
+        else if ( type == RT_Object_Class_Semaphore )
+        {
+            rt_sem_detach( ( rt_sem_t ) pipc );
+        }
+        else if ( type == RT_Object_Class_MailBox )
+        {
+            rt_mb_detach( ( rt_mailbox_t ) pipc );
+        }
+    #endif
+#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
+    }
+    else
+    {
+#endif
+    #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+        if ( type == RT_Object_Class_Mutex )
+        {
+            rt_mutex_delete( ( rt_mutex_t ) pipc );
+        }
+        else if ( type == RT_Object_Class_Semaphore )
+        {
+            rt_sem_delete( ( rt_sem_t ) pipc );
+        }
+        else if ( type == RT_Object_Class_MailBox )
+        {
+            rt_mb_delete( ( rt_mailbox_t ) pipc );
+        }
+        else
+        {
+            return;
+        }
+        RT_KERNEL_FREE( pxQueue );
+    #endif
+    }
+}
+/*-----------------------------------------------------------*/