FreeRTOS Tetris
|
Utilities required by other TUM_XXX files. More...
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Macros | |
#define | PRINT_ERROR(msg, ...) |
Typedefs | |
typedef void * | rbuf_handle_t |
A handle to a ring buffer object, created using rbuf_init() | |
Functions | |
int | tumUtilIsCurGLThread (void) |
Checks if the calling thread is the thread that currently holds the GL context. More... | |
void | tumUtilSetGLThread (void) |
The calling thread is registered as holding the current GL context. | |
char * | tumUtilPrependPath (char *path, char *file) |
Prepends a path string to a filename. More... | |
char * | tumUtilGetBinFolderPath (char *bin_path) |
Gets the execution folder of the current program, assumes that program is executing from a folder "bin". More... | |
FILE * | tumUtilFindResource (char *resource_name, const char *mode) |
Searches for a file in the RESOURCES_DIRECTORY and returns a FILE * if found. More... | |
char * | tumUtilFindResourcePath (char *resource_name) |
Similar to tumUtilFindResource() only returning the file's path instead of the opened FILE's reference. More... | |
rbuf_handle_t | rbuf_init (size_t item_size, size_t item_count) |
Initialized a ring buffer object with a certain number of objects of a given size. More... | |
rbuf_handle_t | rbuf_init_static (size_t item_size, size_t item_count, void *buffer) |
Initialized a ring buffer object with a certain number of objects of a given size into a statically allocated buffer. More... | |
void | rbuf_free (rbuf_handle_t rbuf) |
Frees a ring buffer. More... | |
void | rbuf_reset (rbuf_handle_t rbuf) |
Resets the ring buffer to it's initial state. More... | |
int | rbuf_put_buffer (rbuf_handle_t rbuf) |
Used when a reference to the next buffer item is already filled, incrementing the next buffer item should an item need to be retrieved. More... | |
int | rbuf_put (rbuf_handle_t rbuf, void *data) |
Fills the next available buffer slot, if a slot is free. More... | |
int | rbuf_fput (rbuf_handle_t rbuf, void *data) |
Fills the next available buffer, overwriting data if the ring buffer is full. More... | |
void * | rbuf_get_buffer (rbuf_handle_t rbuf) |
Returns a reference to the data of the next ring buffer entry. More... | |
int | rbuf_get (rbuf_handle_t rbuf, void *data) |
Returns a copy of the next buffer item's data. More... | |
unsigned char | rbuf_empty (rbuf_handle_t rbuf) |
Checks if the buffer is empty or not. More... | |
unsigned char | rbug_full (rbuf_handle_t rbuf) |
Checks if the buffer is full. More... | |
size_t | rbuf_size (rbuf_handle_t rbuf) |
Returns the number of elements currently stored in the ring buffer. More... | |
size_t | rbuf_capacity (rbuf_handle_t rbuf) |
Returns the maximum number of elements that the ring buffer can store. More... | |
Utilities required by other TUM_XXX files.
---------------------------------------------------------------------- Copyright (C) Alexander Hoffman, 2019 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. ----------------------------------------------------------------------
#define PRINT_ERROR | ( | msg, | |
... | |||
) |
size_t rbuf_capacity | ( | rbuf_handle_t | rbuf | ) |
Returns the maximum number of elements that the ring buffer can store.
rbuf | Handle to the ring buffer |
unsigned char rbuf_empty | ( | rbuf_handle_t | rbuf | ) |
Checks if the buffer is empty or not.
rbuf | Handle to the ring buffer |
int rbuf_fput | ( | rbuf_handle_t | rbuf, |
void * | data | ||
) |
Fills the next available buffer, overwriting data if the ring buffer is full.
rbuf | Handle to the ring buffer |
data | Reference to the data to be copied into the buffer |
void rbuf_free | ( | rbuf_handle_t | rbuf | ) |
Frees a ring buffer.
rbuf | Handle to the ring buffer |
int rbuf_get | ( | rbuf_handle_t | rbuf, |
void * | data | ||
) |
Returns a copy of the next buffer item's data.
rbuf | Handle to the ring buffer |
data | A reference to the allocated memory region into which the data should be copied |
void* rbuf_get_buffer | ( | rbuf_handle_t | rbuf | ) |
Returns a reference to the data of the next ring buffer entry.
Because only a reference is returned the contents of the buffer entry cannot be guarenteed
rbuf | Handle to the ring buffer |
rbuf_handle_t rbuf_init | ( | size_t | item_size, |
size_t | item_count | ||
) |
Initialized a ring buffer object with a certain number of objects of a given size.
item_size | The size, in bytes, of each ring buffer item |
item_count | The maximum number of items to be stored in the ring buffer |
rbuf_handle_t rbuf_init_static | ( | size_t | item_size, |
size_t | item_count, | ||
void * | buffer | ||
) |
Initialized a ring buffer object with a certain number of objects of a given size into a statically allocated buffer.
item_size | The size, in bytes, of each ring buffer item |
item_count | The maximum number of items to be stored in the ring buffer |
buffer | Reference to the statically allocated memory region that is to be used for storing the ring buffer |
int rbuf_put | ( | rbuf_handle_t | rbuf, |
void * | data | ||
) |
Fills the next available buffer slot, if a slot is free.
rbuf | Handle to the ring buffer |
data | Reference to the data to be copied into the buffer |
int rbuf_put_buffer | ( | rbuf_handle_t | rbuf | ) |
Used when a reference to the next buffer item is already filled, incrementing the next buffer item should an item need to be retrieved.
rbuf | Handle to the ring buffer |
void rbuf_reset | ( | rbuf_handle_t | rbuf | ) |
Resets the ring buffer to it's initial state.
rbuf | Handle to the ring buffer |
size_t rbuf_size | ( | rbuf_handle_t | rbuf | ) |
Returns the number of elements currently stored in the ring buffer.
rbuf | Handle to the ring buffer |
unsigned char rbug_full | ( | rbuf_handle_t | rbuf | ) |
Checks if the buffer is full.
rbuf | Handle to the ring buffer |
FILE* tumUtilFindResource | ( | char * | resource_name, |
const char * | mode | ||
) |
Searches for a file in the RESOURCES_DIRECTORY and returns a FILE * if found.
resource_name | Name of the file to be found |
mode | The reading mode to be used when opening the file, eg. "rw" |
char* tumUtilFindResourcePath | ( | char * | resource_name | ) |
Similar to tumUtilFindResource() only returning the file's path instead of the opened FILE's reference.
The found filename is stored in a statically allocated buffer and can be overwritten by subsequent calls to the functions
resource_name | Name of the file to be found |
char* tumUtilGetBinFolderPath | ( | char * | bin_path | ) |
Gets the execution folder of the current program, assumes that program is executing from a folder "bin".
bin_path | The program's binary's location, usually argv[0] |
int tumUtilIsCurGLThread | ( | void | ) |
Checks if the calling thread is the thread that currently holds the GL context.
char* tumUtilPrependPath | ( | char * | path, |
char * | file | ||
) |
Prepends a path string to a filename.
path | Path string to be prepended |
file | Filename to which the path string should be prepended |