Multidimensional Arrays Array length See sizeof()
Category: Memory
Buffers
Move buffer down one place Move buffer up one place Rolling sample buffer
Constants
Float A value with decimal places is interpreted as double by default. Use f to specify as float literal, e,g, Unsigned ‘u’ or ‘U’ to indicate an unsigned constant, like 33u‘ul’ or ‘UL’ to indicate an unsigned long constant, like 32767ul
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
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 […]
enum
Functions
memset Sets the number of bytes specified to the value specified starting from the pointer.
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()
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
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 […]