LVGL-simulation-example/main/src/FreeRTOS_Posix_Port.c
MootSeeker 0a8220a874
Add FreeRTOS Kernel and C++ Support to Simulator (#59)
* Add FreeRTOS

* Add FreeRTOS Task

* Update README.md

* Upgrade to C++

* Update Code to run multiple tasks

* Add ui folder

Add UI folder for SquareLine Studio files

* Update ui.cpp

* Add UI files to CMake from SquareLine Studio

Add UI files to CMake path.
UI folder setup so files from SquareLine Studio can be used.
Add more heap to debug SDL.

* Update README.md

* Add drop den menu test

* Add global include file

* remove cpp file to test stability

* Fixing wrong cmake configuration

remove ui files from here

* work

* Change project structure

Changed project structure and CMake file so freertos implementation will be activated when enabled in lv_conf.h

* Refactor project structure and CMake configuration, remove unused UI components

- Restructured the project and updated the CMake file to conditionally activate FreeRTOS based on lv_conf.h settings.
- Removed UI files and C++ files related to SquareLine Studio to improve project stability.
- Added a global include.
- Updated the README.md to reflect the changes.
- Increased heap size for debugging with SDL.

* Move to CPP file

Moved to cpp file created task with lv_thread_init()

* Update freertos_main.cpp

* Clean up code

Not using task notification, since pxTCD is always NULL

Changed back to LV_OS_NONE since user of this project has to device what he want to use

Commented freertos posix file with AI :)

Cleanup freertos_main.cpp as mentioned in PR

* Update README.md

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update README.md

* Update main/src/FreeRTOS_Posix_Port.c

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update main/src/main.c

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update README.md

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>

* Update README.md

* Update README.md

---------

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
2024-09-12 10:45:51 +02:00

93 lines
3.1 KiB
C

/**
* @file Event management with pthreads
* @brief Implementation of an event mechanism using POSIX threads.
* @date 2024-09-03
*/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
/* Structure representing an event, consisting of a condition variable and a mutex */
typedef struct Event
{
pthread_cond_t cond; /* Condition variable used to signal the event */
pthread_mutex_t mutex; /* Mutex to protect access to the condition variable */
} Event_t;
/**
* @brief Create an event object
*
* Allocates memory for an Event_t structure and initializes its condition variable and mutex.
*
* @param None
* @return Pointer to the created Event_t object, or NULL if memory allocation fails
*/
Event_t *event_create(void)
{
Event_t *event = (Event_t *)malloc(sizeof(Event_t)); /* Allocate memory for the event */
if (event) /* Check if allocation was successful */
{
pthread_cond_init(&event->cond, NULL); /* Initialize the condition variable */
pthread_mutex_init(&event->mutex, NULL); /* Initialize the mutex */
}
return event; /* Return the created event object */
}
// ........................................................................................................
/**
* @brief Delete an event object
*
* Destroys the condition variable and mutex associated with the event, then frees the memory.
*
* @param event Pointer to the Event_t object to be deleted
* @return None
*/
void event_delete(Event_t *event)
{
if (event) /* Check if the event object is valid */
{
pthread_cond_destroy(&event->cond); /* Destroy the condition variable */
pthread_mutex_destroy(&event->mutex); /* Destroy the mutex */
free(event); /* Free the memory allocated for the event object */
}
}
// ........................................................................................................
/**
* @brief Signal an event
*
* Signals the condition variable associated with the event, waking up any waiting threads.
*
* @param event Pointer to the Event_t object to be signaled
* @return None
*/
void event_signal(Event_t *event)
{
if (event) /* Check if the event object is valid */
{
pthread_mutex_lock(&event->mutex); /* Lock the mutex before signaling */
pthread_cond_signal(&event->cond); /* Signal the condition variable */
pthread_mutex_unlock(&event->mutex); /* Unlock the mutex after signaling */
}
}
// ........................................................................................................
/**
* @brief Wait for an event
*
* Waits for the condition variable associated with the event to be signaled.
*
* @param event Pointer to the Event_t object to wait for
* @return None
*/
void event_wait(Event_t *event)
{
if (event) /* Check if the event object is valid */
{
pthread_mutex_lock(&event->mutex); /* Lock the mutex before waiting */
pthread_cond_wait(&event->cond, &event->mutex); /* Wait for the condition variable to be signaled */
pthread_mutex_unlock(&event->mutex); /* Unlock the mutex after waiting */
}
}