Created
August 5, 2025 03:21
-
-
Save ultrasounder/46ae20e028ee7cd7b7193deef7fad144 to your computer and use it in GitHub Desktop.
Example (using FreeRTOS concepts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Event structure definition | |
| typedef struct { | |
| uint8_t event_type; | |
| uint16_t sensor_value; | |
| // Add other relevant data | |
| } system_event_t; | |
| // Global queue handle | |
| QueueHandle_t event_queue; | |
| // Initialize the queue in main() or setup function | |
| void initialize_system() { | |
| event_queue = xQueueCreate(10, sizeof(system_event_t)); // Queue for 10 events | |
| // Error handling if queue creation fails | |
| } | |
| // ISR (e.g., for a sensor reading) | |
| void EXTI_Handler() { | |
| system_event_t new_event; | |
| new_event.event_type = SENSOR_READING; | |
| new_event.sensor_value = read_sensor(); // Read sensor data | |
| // Send event to the queue | |
| xQueueSendFromISR(event_queue, &new_event, NULL); // No blocking in ISR | |
| // Clear interrupt flag | |
| } | |
| // Task for event processing | |
| void event_processing_task(void *pvParameters) { | |
| system_event_t received_event; | |
| while (1) { | |
| // Wait for an event to arrive (blocks indefinitely or with a timeout) | |
| if (xQueueReceive(event_queue, &received_event, portMAX_DELAY) == pdPASS) { | |
| // Process the received event | |
| switch (received_event.event_type) { | |
| case SENSOR_READING: | |
| // Process sensor data | |
| break; | |
| case FAULT_CONDITION: | |
| // Handle fault condition | |
| break; | |
| // ... other event types | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment