int main() { __uint128_t *mem = calloc(1ULL << 30, 1); uint32_t blockExp = BLOCK_EXP; // Define this in Makefile to set memory size. printf("Access times for random read then write of %u byte blocks\n", 1 << (blockExp + 4)); // 16KiB random read/write test - 1/2 my L1 cache randomWrite(mem, 14, 30, blockExp); randomRead(mem, 14, 30, blockExp); randomReadWrite(mem, 14, 30, blockExp); printf("\n"); // 128KiB random read/write test - 1/2 my L2 cache randomWrite(mem, 17, 30, blockExp); randomRead(mem, 17, 30, blockExp); randomReadWrite(mem, 17, 30, blockExp); printf("\n"); // 4MiB random read/write test - 1/2 my L3 cache randomWrite(mem, 22, 30, blockExp); randomRead(mem, 22, 30, blockExp); randomReadWrite(mem, 22, 30, blockExp); printf("\n"); // 1GiB random read/write test - blow out of cache randomWrite(mem, 30, 30, blockExp); randomRead(mem, 30, 30, blockExp); randomReadWrite(mem, 30, 30, blockExp); return 0; }
/** * @brief Read 2 bytes from the I2C slave at the specified memory address and return them as an 16bit unsigned integer * @param device_address The address of the device to read from * @param start_address The memory address to read from * @return MSB 16bit unsigned integer */ uint16_t SoftwareI2C::read16(char device_address, char start_address) { char short_array[2] = {0, 0}; randomRead(device_address, start_address, short_array, 2 ); uint16_t value = 0; value = short_array[0] << 8; value |= short_array[1]; return value; }
/** * @brief Read 3 bytes from the I2C slave at the specified memory address and return them as an 32bit unsigned integer * @param device_address The address of the device to read from * @param start_address The memory address to read from * @return MSB 32bit unsigned integer */ uint32_t SoftwareI2C::read24(char device_address, char start_address) { char value_array[4] = {0, 0, 0}; randomRead(device_address, start_address, value_array, 3 ); uint32_t value = 0; value = value_array[0] << 16; value |= value_array[1] << 8; value |= value_array[2]; return value; }
/** * @brief Read 4 bytes from the I2C slave at the specified memory address and return them as an 32bit unsigned integer * @param device_address The address of the device to read from * @param start_address The memory address to read from * @return MSB 32bit unsigned integer */ uint32_t SoftwareI2C::read32(uint8_t device_address, uint8_t start_address) { uint8_t value_array[4] = {0, 0, 0, 0}; randomRead(device_address, start_address, value_array, 4 ); uint32_t value = 0; value = value_array[0] << 24; value |= value_array[1] << 16; value |= value_array[2] << 8; value |= value_array[3]; return value; }