/*******************************************************************************
 * Copyright (c) 2018 Renesas Electronics Corporation. All rights reserved.
 *
 * DESCRIPTION   : memory access driver
 ******************************************************************************/
 
#include <stdint.h>

void mem_write8(uintptr_t addr, uint8_t data)
{
	*(volatile uint8_t*)addr = data;
}
uint8_t mem_read8(uintptr_t addr)
{
	return (*(volatile uint8_t*)addr);
}

void mem_write16(uintptr_t addr, uint16_t data)
{
	*(volatile uint16_t*)addr = data;
}
uint16_t mem_read16(uintptr_t addr)
{
	return (*(volatile uint16_t*)addr);
}

void mem_write32(uintptr_t addr, uint32_t data)
{
	*(volatile uint32_t*)addr = data;
}
uint32_t mem_read32(uintptr_t addr)
{
	return (*(volatile uint32_t*)addr);
}

void mem_write64(uintptr_t addr, uint64_t data)
{
	*(volatile uint64_t*)addr = data;
}
uint64_t mem_read64(uintptr_t addr)
{
	return (*(volatile uint64_t*)addr);
}

void mem_bitclrset32(uintptr_t addr, uint32_t clr, uint32_t set)
{
	mem_write32(addr, (mem_read32(addr) & ~clr) | set);
}
