Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ultrasounder/921ac5815e06707587d64faa3d2a6273 to your computer and use it in GitHub Desktop.

Select an option

Save ultrasounder/921ac5815e06707587d64faa3d2a6273 to your computer and use it in GitHub Desktop.
Example (Binary Semaphore):
// 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