struct

See also typedef, struct union. Example struct that will be used multiple times Example struct for use as one object Checking a struct size On 16bit and 32bit platforms your struct may end up being bigger in memory that the sum of its individual variables due to padding bytes. This can be a useful check […]

Read More

Static

A static variable inside a function keeps its value between calls. A static global variable or function is “seen” only in the file it’s declared in. You can have a variable or function in some other file and it will be treated as a different global variable or function, the linker won’t match the two.

Read More

Functions

memset Sets the number of bytes specified to the value specified starting from the pointer.

Read More

Malloc

Temporary memory example Functions malloc(size_t size) allocates the requested memory (size specified in bytes) and returns a pointer to it. realloc() free()

Read More

Endian

Endianness defines the location of byte 0 within a larger data structure. Little-endian The least significant byte of a 16-bit value is sent or stored before the most significant byte Bits7:0 | Bits15:8 A 32bit value is stored in a byte array as: Byte[3] | Byte[2] | Byte[1] | Byte[0] Big-endian The more significant byte […]

Read More

Pointers

Basic pointer usage char my_buffer[20]; //Declare an array char *p_buffer; //Declare a pointer p_buffer = &my_buffer[0]; //Load pointer *p_buffer++ = 'H'; //Write to the index 0 in the array *p_buffer++ = 'e'; //Write to the index 1 in the array  

Read More

Converting Variables

  Convert bytes to float union { float f; uint32_t ui32; } converted_value; converted_value.ui32 = ((uint32_t)byte_value[3] << 24) | ((uint32_t)byte_value[2] << 16) | ((uint32_t)byte_value[1] << 8) | (uint32_t)byte_value[0]; Note, if this appears not to work (you get zero out but with a valid float value in) then try reversing the byte order. Example The following input […]

Read More

Rolling memory buffer

Example Of Non Irq Function Fills Buffers and IRQ Function Empties Buffers This implemenation is based on the function sending the data being an irq which sends bits of the data irq calls and the function filling the data buffers being non irq and ensuring the operation is irq safe. #define FILE_DATA_NUM_OF_BUFFERS 4 #define FILE_DATA_BUFFER_LENGTH 512 […]

Read More