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 […]
Category: Memory
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.
Functions
memset Sets the number of bytes specified to the value specified starting from the pointer.
enum
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()
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 […]
Buffers
Move buffer down one place Move buffer up one place Rolling sample buffer
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
Converting Variables
Convert float to bytes Convert bytes to float 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 bytes 0x1f, 0x85, 0x45, 0x41 will produce a float output of 12.345
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 […]