Skip to content

API List Page 4

Addio edited this page Mar 12, 2022 · 1 revision

Contents

DMA Macros

All DMA Macros can be located in "geneticc/list/geneticc_list.h

GENETICC_USE_DMA in "geneticc_config.h must be set to true to have DMA Macros/Functions available to you


DMA Macros

Array_DMA_CopyTo_List

Initializes a list, and copies an already existing array to the list via DMA.

Prototypes/Overloads

  • Array_DMA_CopyTo_List(array)
  • Array_DMA_CopyTo_List(array, length)
  • Array_DMA_CopyTo_List(array, length, populated_length)
  • Array_DMA_CopyTo_List(array, length, populated_length, elem_size)

Parameters

Name Type Optional Description
array ARRAY_PTR No Pointer to the start of the array.
length length_t Yes The length of the array.
populated_length length_t Yes The amount of elements currently in the array.
elem_size element_size_t Yes The size of a single element in the array. *Required if passing a pointer whos type does not represent the internal values. (ARRAY_PTR, void*)

Returns

LIST_PTR(list_t*)

A pointer to the newly allocated list.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_DMA_CopyTo_List(&array); 

/*Do other stuff*/


//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

Array_DMA_Copy_Init_List

Allocates and initializes a list, and then copies an already existing array to the list via DMA.

Prototypes/Overloads

  • Array_DMA_Copy_Init_List(array, out_list)
  • Array_DMA_Copy_Init_List(array, length, out_list)
  • Array_DMA_Copy_Init_List(array, length, populated_length, out_list)
  • Array_DMA_Copy_Init_List(array, length, populated_length, elem_size, out_list)

Parameters

Name Type Optional Description
array ARRAY_PTR No Pointer to the start of the array.
length length_t Yes The length of the array.
populated_length length_t Yes The amount of elements currently in the array.
elem_size element_size_t Yes The size of a single element in the array. *Required if passing a pointer whos type does not represent the internal values. (ARRAY_PTR, void*)
out_list LIST_PTR Yes The initialized list.

Returns

void

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

list_t list;

Array_DMA_Copy_Init_List(&array, &list); 

/*Do other stuff*/


//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_GetRange

Allocates a new list, and copies a range of values from the old list to the new via DMA.

Prototypes/Overloads

  • List_DMA_GetRange(list, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list of values that will be copied.
index index_t No The zero-based index at which to start copying values.
length length_t No The amount of elements to copy..

Returns

LIST_PTR

Pointer to the new list.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT * 2;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(&array); 

LIST_PTR range = List_DMA_GetRange(list, GENETICC_DMA_MIN_TRANSACTION_COUNT / 2, GENETICC_DMA_MIN_TRANSACTION_COUNT / 2);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_InsertRange

Inserts an array of values into a list, at the specified index, using DMA.

Prototypes/Overloads

  • List_DMA_InsertRange(list, range, index)
  • List_DMA_InsertRange(list, range, index, range_length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
range ARRAY_PTR No Pointer to the array of values to insert.
index index_t No The zero-based index at which to start inserting values.
length length_t No The amount of elements to insert.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array1[length];
int array2[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array1[i] = i;
	array2[i] = -i;
}

LIST_PTR list = Array_To_List(&array1); 

List_DMA_InsertRange(list, array2, GENETICC_DMA_MIN_TRANSACTION_COUNT / 2, GENETICC_DMA_MIN_TRANSACTION_COUNT);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_InsertList

Inserts a list of values into a another list, at the specified index, using DMA.

Prototypes/Overloads

  • List_DMA_InsertList_DMA(list, insert_list, index)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
insert_list LIST_PTR No Pointer to the list that will be inserted
index index_t No The zero-based index at which to start inserting values.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array1[length];
int array2[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array1[i] = i;
	array2[i] = -i;
}

LIST_PTR list1 = Array_To_List(&array1); 
LIST_PTR list2 = Array_To_List(&array2); 

List_DMA_InsertList(list1, list2 , GENETICC_DMA_MIN_TRANSACTION_COUNT / 2);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);

List_DMA_Insert

Inserts a list of values into a another list, at the specified index, using DMA.

Prototypes/Overloads

  • List_DMA_Insert(list, value, index)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
value Any No Value or pointer to a value.
index index_t No The zero-based index at which to insert the value.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT * 2;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(&array); 

//Even though only 4 bytes are being inserted,
//insert functions shuffle the memory around to achieve its goal.
List_DMA_Insert(list, 0x0abccdd, GENETICC_DMA_MIN_TRANSACTION_COUNT / 2);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);

List_DMA_AddRange

Inserts an array of values into a list, at the specified index, using DMA.

Prototypes/Overloads

  • List_DMA_AddRange(list, range)
  • List_DMA_AddRange(list, range, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
range ARRAY_PTR No Pointer to the array of values to add.
length length_t No The amount of elements to add.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array1[length];
int array2[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array1[i] = i;
	array2[i] = -i;
}

LIST_PTR list = Array_To_List(&array1); 

List_DMA_AddRange(list, array2, GENETICC_DMA_MIN_TRANSACTION_COUNT);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_AddList

Inserts a list of values into a another list, at the specified index, using DMA.

Prototypes/Overloads

  • List_DMA_AddList_DMA(list, add_list)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
add_list LIST_PTR No Pointer to the list that will be added to the end

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array1[length];
int array2[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array1[i] = i;
	array2[i] = -i;
}

LIST_PTR list1 = Array_To_List(&array1); 
LIST_PTR list2 = Array_To_List(&array2); 

List_DMA_AddList(list1, list2);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);

List_DMA_Add

Not recommended, DMA will only be used in rare cases and will cause a performance hit over regular List_Add

Adds a value to the end of a list, using DMA.

Prototypes/Overloads

  • List_DMA_Add(list, value)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
value Any No Value or pointer to a value.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT * 2;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(&array); 

List_DMA_Add(list, 0x0abccdd);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);

List_DMA_PrependRange

Inserts an array of values into a list, at the specified index, using DMA.

Prototypes/Overloads

  • List_DMA_PrependRange(list, range)
  • List_DMA_PrependRange(list, range, range_length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
range ARRAY_PTR No Pointer to the array of values to add.
length length_t No The amount of elements to add.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array1[length];
int array2[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array1[i] = i;
	array2[i] = -i;
}

LIST_PTR list = Array_To_List(&array1); 

List_DMA_PrependRange(list, array2);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_PrependList

Adds a list of values to the start of a list, using DMA.

Prototypes/Overloads

  • List_DMA_Prepend(list, value)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
prepend_list LIST_PTR No Pointer to the list that will be added to the start.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array1[length];
int array2[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array1[i] = i;
	array2[i] = -i;
}

LIST_PTR list1 = Array_To_List(&array1); 
LIST_PTR list2 = Array_To_List(&array2); 

List_DMA_PrependList(list1, list2);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);

List_DMA_Prepend

Adds a list of values to the start of a list, using DMA.

Prototypes/Overloads

  • List_DMA_Prepend(list, value)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list that will receive the values.
value Any No Value or pointer to a value.

Returns

bool

True if the DMA transfer was registered. False if there was no capacity in the list, or if the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT * 2;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(&array); 

List_DMA_Prepend(list, 0x0abccdd);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_RemoveRange

Removes a range of values from a list, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveRange(list, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
index index_t No The element to start removing at.
length length_t No How many elements to remove.

Returns

void

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

List_RemoveRange(list, GENETICC_DMA_MIN_TRANSACTION_COUNT / 4, GENETICC_DMA_MIN_TRANSACTION_COUNT / 10);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_RemoveAt

Removes an element from a list, at a specified index, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveAt(list, index)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
index index_t No The element to start removing at.

Returns

void

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

List_DMA_RemoveAt(list, GENETICC_DMA_MIN_TRANSACTION_COUNT / 10);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_Remove

Removes the first element from the list that matches value, using DMA.

Prototypes/Overloads

  • List_DMA_Remove(list, value)
  • List_DMA_Remove(list, value, *out_removed)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No The value to remove from the list.
out_removed bool* Yes Out parameter that returns true or false depending on if a value was removed.

Returns

bool

True if the DMA transfer was registered, or if there were no values to remove, out_removed will also be false. When False and out_removed true, the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

bool out_removed;
List_DMA_Remove(list, 100, &out_removed);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

if(out_removed)
{
        //Do more stuff
}

List_DMA_RemoveAll

Removes all elements from a list, that match the value, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveAll(list, value)
  • List_DMA_RemoveAll(list, value, *out_remove_count)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No The value used to determine what elements to remove from "list."
out_remove_count uint32_t Yes A count of how many values were removed.

Returns

bool

True if the DMA transfer was registered, or if there were no values to remove, out_remove_count will also be 0. When False and out_remove_count > 0, the maximum transfer count has been reached.

Example

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

uint32_t out_count;

List_DMA_RemoveAll(list, 0x0abbccdd, &out_count);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

if(out_count > 20)
{
       //Do stuff
}

List_DMA_RemoveMatch

Removes the first element in the list, that satisfies the predicate's condition, using DMA.

Prototypes/Overloads

  • List_DMA_Remove(list, predicate)
  • List_DMA_Remove(list, predicate, *out_removed)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.
out_removed bool* Yes Out parameter that returns true or false depending on if a value was removed.

Returns

bool

True or false depending on if an item was matched and removed.

Example

bool predicate(const ELEMENT_PTR element)
{
	return *(int*)element % 2 == 1;
}

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

List_DMA_RemoveMatch(list, predicate);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_RemoveAllMatching

Removes all elements in the list that satisfies the predicate's condition, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveAllMatching(list, predicate)
  • List_DMA_RemoveAllMatching(list, predicate, *out_remove_count)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.
out_remove_count uint32_t Yes A count of how many values were removed.

Returns

bool

True if the DMA transfer was registered, or if there were no values to remove, out_remove_count will also be 0. When False and out_remove_count > 0, the maximum transfer count has been reached.

Example

bool predicate(const ELEMENT_PTR element)
{
	return *(int*)element % 2 == 1;
}

int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

List_DMA_RemoveAllMatching(list, predicate);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);

List_DMA_RemoveMatch_Vargs

Removes the first element in the list, that satisfies the predicate's condition, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveMatch_Vargs(list, predicate, arg_count, ap)
  • List_DMA_RemoveMatch_Vargs(list, predicate, arg_count, ap, *out_removed)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.
out_removed bool* Yes True or false depending on if an item was matched and removed.

Returns

bool

True if the DMA transfer was registered, or if there were no values to remove, out_removed will also be false. When False and out_removed true, the maximum transfer count has been reached.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) % va_arg(ap, int) == va_arg(ap, int);
}


bool example(LIST_PTR  list, int arg_count, ...)
{
	va_list ap;
	va_start(ap, arg_count);
	return List_DMA_RemoveMatch_Vargs(list, predicate_args, arg_count, ap);	
}

void main()
{
int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

example(list, 10, 2, 1);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list);
}

List_DMA_RemoveAllMatching_Vargs

Removes all elements in the list that satisfies the predicate's condition, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveAllMatching_Vargs(list, predicate, arg_count, ap)
  • List_DMA_RemoveAllMatching_Vargs(list, predicate, arg_count, ap, *out_remove_count)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.
out_remove_count uint32_t Yes A count of how many values were removed.

Returns

uint32_t

Count of how many elements were removed from the list.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) % va_arg(ap, int) == va_arg(ap, int);
}


bool example(LIST_PTR  list, int arg_count, ...)
{
	va_list ap;
	va_start(ap, arg_count);
	return List_RemoveAllMatching_Vargs(list, predicate_args, arg_count, ap);	
}

void main()
{
int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

example(list, 2, 10, 1);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);
}

List_DMA_RemoveMatch_Args

Removes the first element in the list, that satisfies the predicate's condition, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveMatch_Args(list, predicate, *out_removed, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
out_removed bool* Yes True or false depending on if an item was matched and removed.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

bool

True if the DMA transfer was registered, or if there were no values to remove, out_removed will also be false. When False and out_removed true, the maximum transfer count has been reached.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) % va_arg(ap, int) == va_arg(ap, int);
}


void main()
{
int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

List_DMA_RemoveMatch_Args(list, predicate_args, NULL, 2, 5 4);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);
}

List_DMA_RemoveAllMatching_Args

Removes all elements in the list that satisfies the predicate's condition, using DMA.

Prototypes/Overloads

  • List_DMA_RemoveAllMatching_Args(list, predicate, *out_remove_count, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
out_remove_count uint32_t Yes A count of how many values were removed.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

uint32_t

Count of how many elements were removed from the list.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) % va_arg(ap, int) == va_arg(ap, int);
}

void main()
{
int length = GENETICC_DMA_MIN_TRANSACTION_COUNT;
int array[length];

//Fill the array with something
for(int i = 0; i < length ; i++)
{
	array[i] = i;
}

LIST_PTR list = Array_To_List(array);

List_DMA_RemoveAllMatching_Args(list, predicate_args, 2, 5, 4);

/*Do other stuff*/

//Wait for DMA transfer to finish.
geneticc_dma_wait_for_transfer(list1);
}