/* * usb_reg_rw.c * * Created on: 14-Apr-2023 * Author: pushpkant */ #include "ltcusb_raw_rw.h" #include /** @todo defined rv build for application, to be removed in library.*/ #define RV_BUILD #ifdef GNU_BUILD #include #include static void * temp_reg = NULL; #endif LtcUSB_reg ltcUSB_raw_reg; /* * The symbol is provided by the makefile. It will not resolve inside the * project. */ const uint32_t ltcusb_addr_max = USB_ADDRESS_MAX; // @suppress("Symbol is not resolved") int ltcusb_raw_read() { if(ltcUSB_raw_reg.address > ltcusb_addr_max) { return -1; } volatile uint32_t* value = (void *)ltcUSB_raw_reg.address; ltcUSB_raw_reg.value = (*value); return 0; } int ltcusb_raw_write() { if(ltcUSB_raw_reg.address > ltcusb_addr_max) { return -1; } volatile uint32_t* value = (void *)ltcUSB_raw_reg.address; *value = ltcUSB_raw_reg.value; return 0; } void *reg_setup(uintptr_t register_offset) { void *data; #ifdef RV_BUILD ltcUSB_raw_reg.address = register_offset + USB_ADDRESS_OFFSET; #endif #ifdef GNU_BUILD // Allocate the maximum size for USB controller if(temp_reg == NULL) { temp_reg = malloc(USB_ADDRESS_OFFSET); if(temp_reg == NULL) { return NULL; } memset(temp_reg, 0x00, USB_ADDRESS_OFFSET); } ltcUSB_raw_reg.address = (uintptr_t)temp_reg + register_offset; #endif /* * Update the value from hardware at the setup. This will omit the first * read operation. */ ltcusb_raw_read(); data = <cUSB_raw_reg.value; return data; } int ltcusb_fifo_write(uintptr_t fifo_addr, uint32_t data) { if(fifo_addr == 0x00) { return -1; } volatile uint32_t* value = (void*)(fifo_addr); *value = data; return 0; } int ltcusb_fifo_read(uintptr_t fifo_addr, uint32_t *data) { if(fifo_addr == 0x00) { return -1; } volatile uintptr_t* value = (void*)(fifo_addr); *data = *value; return 0; } int ltcusb_mem_read(uintptr_t addr, uint32_t* data) { volatile uint32_t* value = (void*)addr; *data = *value; return 0; } int ltcusb_mem_write(uintptr_t addr, uint32_t data) { volatile uint32_t* value = (void*)addr; *value = data; return 0; } int ltcusb_mem_write2(uintptr_t addr, void* data) { uint32_t* t_data = (uint32_t*)data; volatile uint32_t* value = (void*)addr; *value = *t_data; return 0; } int ltcusb_mem_read2(uintptr_t addr, void* data) { uint32_t* t_data = (uint32_t*)data; volatile uint32_t* value = (void*)addr; *t_data = *value; return 0; }