Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ FreeRtos queue wrapper class #691

Draft
wants to merge 3 commits into
base: develop-pros-4
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/kapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
#define task_fn_t pros::task_fn_t
#define mutex_t pros::mutex_t
#define sem_t pros::c::sem_t
#define queue_t pros::c::queue_t
#define queue_t pros::queue_t
#endif

#define KDBG_FILENO 3
Expand Down
220 changes: 0 additions & 220 deletions include/pros/apix.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extern "C" {
/// \name RTOS Facilities
///@{

typedef void* queue_t;
typedef void* sem_t;

/**
Expand Down Expand Up @@ -418,225 +417,6 @@ bool sem_post(sem_t sem);
*/
uint32_t sem_get_count(sem_t sem);

/**
* Creates a queue.
*
* \param length
* The maximum number of items that the queue can contain.
* \param item_size
* The number of bytes each item in the queue will require.
*
* \return A handle to a newly created queue, or NULL if the queue cannot be
* created.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* printf("queue length: %d", queue_get_length(queue));
* }
* \endcode
*/
queue_t queue_create(uint32_t length, uint32_t item_size);

/**
* Posts an item to the front of a queue. The item is queued by copy, not by
* reference.
*
* \param queue
* The queue handle
* \param item
* A pointer to the item that will be placed on the queue.
* \param timeout
* Time to wait for space to become available. A timeout of 0 can be used
* to attempt to post without blocking. TIMEOUT_MAX can be used to block
* indefinitely.
*
* \return True if the item was preprended, false otherwise.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* printf("queue length: %d", queue_get_length(queue));
* }
*/
bool queue_prepend(queue_t queue, const void* item, uint32_t timeout);

/**
* Posts an item to the end of a queue. The item is queued by copy, not by
* reference.
*
* \param queue
* The queue handle
* \param item
* A pointer to the item that will be placed on the queue.
* \param timeout
* Time to wait for space to become available. A timeout of 0 can be used
* to attempt to post without blocking. TIMEOUT_MAX can be used to block
* indefinitely.
*
* \return True if the item was preprended, false otherwise.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* printf("queue length: %d", queue_get_length(queue));
* }
* \endcode
*/
bool queue_append(queue_t queue, const void* item, uint32_t timeout);

/**
* Receive an item from a queue without removing the item from the queue.
*
* \param queue
* The queue handle
* \param buffer
* Pointer to a buffer to which the received item will be copied
* \param timeout
* The maximum amount of time the task should block waiting for an item to receive should the queue be empty at
* the time of the call. TIMEOUT_MAX can be used to block indefinitely.
*
* \return True if an item was copied into the buffer, false otherwise.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* char* item = "Hello! this is a test";
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* char* recv = malloc(sizeof("Hello! this is a test"));
* queue_peek(queue, recv, 1000);
* printf("Queue: %s", recv);
* free(recv);
* }
* \endcode
*/
bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout);

/**
* Receive an item from the queue.
*
* \param queue
* The queue handle
* \param buffer
* Pointer to a buffer to which the received item will be copied
* \param timeout
* The maximum amount of time the task should block
* waiting for an item to receive should the queue be empty at the time
* of the call. queue_recv() will return immediately if timeout
* is zero and the queue is empty.
*
* \return True if an item was copied into the buffer, false otherwise.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* char* item = "Hello! this is a test";
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* char* recv = malloc(sizeof("Hello! this is a test"));
* queue_recv(queue, recv, 1000);
* printf("Queue: %s", recv);
* free(recv);
* }
* \endcode
*/
bool queue_recv(queue_t queue, void* const buffer, uint32_t timeout);

/**
* Return the number of messages stored in a queue.
*
* \param queue
* The queue handle.
*
* \return The number of messages available in the queue.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
*
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* printf("queue waiting: %d", queue_get_waiting(queue));
* }
* \endcode
*/
uint32_t queue_get_waiting(const queue_t queue);

/**
* Return the number of spaces left in a queue.
*
* \param queue
* The queue handle.
*
* \return The number of spaces available in the queue.
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
*
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* printf("queue available: %d", queue_get_available(queue));
* }
* \endcode
*/
uint32_t queue_get_available(const queue_t queue);

/**
* Delete a queue.
*
* \param queue
* Queue handle to delete
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* queue_delete(queue);
* }
* \endcode
*/
void queue_delete(queue_t queue);

/**
* Resets a queue to an empty state
*
* \param queue
* Queue handle to reset
*
* \b Example:
* \code
* void opcontrol(void) {
* queue_t queue = queue_create(10, sizeof(int));
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
* queue_prepend(queue, item, 1000);
* queue_append(queue, item, 1000);
* queue_reset(queue);
* }
* \endcode
*/
void queue_reset(queue_t queue);

///@}

/// \name Device Registration
///@{
Expand Down
Loading