STM32 Traffic Control
Loading...
Searching...
No Matches
queue.c File Reference

Circular queue Implementation for managing traffic light requests. More...

#include "uart.h"
#include "queue.h"
#include "controller.h"
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "stm32f446xx.h"

Functions

bool queue_is_empty ()
 Check if the traffic light request queue is empty.
bool queue_is_full ()
 Check if the traffic light request queue is full.
void queue_enqueue (uint32_t lightPair)
 Add a traffic light pair request to the queue.
int32_t queue_dequeue ()
 Remove and return the next traffic light pair request.

Detailed Description

Circular queue Implementation for managing traffic light requests.

This module provides a simple circular queue to hold traffic light pair requests. It supports enqueueing new requests and dequeueing the next request for processing.

Note
This queue implementation is not safe for concurrent access from interrupts or multiple threads. -> Maybe thread or mutex could solve this

Function Documentation

◆ queue_dequeue()

int32_t queue_dequeue ( void )

Remove and return the next traffic light pair request.

Retrieves the front element of the queue and updates the queue pointers. Returns -1 if the queue is empty.

Returns
ID of the next traffic light pair, or -1 if the queue is empty.

◆ queue_enqueue()

void queue_enqueue ( uint32_t lightPair)

Add a traffic light pair request to the queue.

If the queue is not full, the request is added at the rear of the queue. The queue is circular and wraps around automatically.

Parameters
lightPairID of the traffic light pair to enqueue.

◆ queue_is_empty()

bool queue_is_empty ( void )

Check if the traffic light request queue is empty.

◆ queue_is_full()

bool queue_is_full ( void )

Check if the traffic light request queue is full.