/* * ltcusb_command.c * * Created on: 20-Jul-2023 * Author: vivek */ #include "ltcusb_command.h" #include "rv_delay.h" int DEPCFG_cmd(uint32_t ep_number, uint32_t parameter2, DEPCFG_Par1* param1, DEPCFG_Par0* param0) { uint8_t* data = (uint8_t*)(param1); uint32_t* parameter1 = (uint32_t*)data; uint8_t* param0_data = (uint8_t*)(param0); uint32_t* parameter0 = (uint32_t*)param0_data; uint32_t parameter_get = 0x00; // setting the parameter2 if(depcmdpar_set(ep_number, 2, parameter2) != 0) { return -1; } if(depcmdpar_get(ep_number, 2, ¶meter_get) != 0) { return -2; } if(parameter_get != parameter2) { return -3; } // setting the parameter1 if(depcmdpar_set(ep_number, 1, *parameter1) != 0) { return -1; } if(depcmdpar_get(ep_number, 1, ¶meter_get) != 0) { return -2; } if(parameter_get != *parameter1) { return -3; } // setting the parameter0 if(depcmdpar_set(ep_number, 0, *parameter0) != 0) { return -1; } if(depcmdpar_get(ep_number, 0, ¶meter_get) != 0) { return -2; } if(parameter_get != *parameter0) { return -3; } return execute_command(DEPCFG_cmdtyp, ep_number); } int DEPXFERCFG_cmd(uint32_t ep_number) { uint32_t parameter_get = 0x00; const uint16_t number_xfer_resources = 1; if(depcmdpar_set(ep_number, 0, (uint32_t)(number_xfer_resources)) != 0) { return -1; } if(depcmdpar_get(ep_number, 0, ¶meter_get) != 0) { return -2; } if(parameter_get != number_xfer_resources) { return -3; } return execute_command(DEPXFERCFG_cmdtyp, ep_number); } int DEPSSTALL_cmd(uint32_t ep_number) { return execute_command(DEPSSTALL_cmdtyp, ep_number); } int DEPCSTALL_cmd(uint32_t ep_number) { return execute_command(DEPCSTALL_cmdtyp, ep_number); } int DEPSTRTXFER_cmd(uint32_t ep_number, DEPSTRTXFER_Par1* param1, DEPSTRTXFER_Par0* param0) { uint8_t* data = (uint8_t*)(param1); uint32_t* parameter1 = (uint32_t*)data; uint8_t* param0_data = (uint8_t*)(param0); uint32_t* parameter0 = (uint32_t*)param0_data; // setting the parameter1 if(depcmdpar_set(ep_number, 1, *parameter1) != 0) { return -1; } // setting the parameter0 if(depcmdpar_set(ep_number, 0, *parameter0) != 0) { return -2; } return execute_command(DEPSTRTXFER_cmdtyp, ep_number); } int DEPENDXFER_cmd(uint32_t ep_number) { return execute_command(DEPENDXFER_cmdtyp, ep_number); } int DEPSTARTCFG_cmd(unsigned int ep_number) { return execute_command(DEPSTARTCFG_cmdtyp, ep_number); } int execute_command(Command_type cmdtyp, uint32_t endpoint_number) { uint32_t value = 0; BITMASK_SET(value, (cmdtyp & DEPCMD_BIT_3_0_CMDTYPE_MASK)); BIT_SET(value, DEPCMD_BIT_10_CMDACT); if(cmdtyp == DEPENDXFER_cmdtyp) { BIT_SET(value, DEPCMD_BIT_8_CMDIOC); BIT_SET(value, DEPCMD_BIT_11_HIPRI_FORCERM); } uintptr_t addr = (DEPCMD_OFFSET + 0x10 * endpoint_number) | USB_ADDRESS_OFFSET; ltcusb_mem_write(addr,value); ltcusb_mem_read(addr, &value); while((BIT_CHECK(value,DEPCMD_BIT_10_CMDACT)) == TRUE) { ltcusb_mem_read(addr, &value); } // static DEPCMD_data data; // // data.CMDIOC = 0; // data.reserved_7_4 = 0; // data.reserved_9 = 0; // data.HIPRI_FORCERM = 0; // data.CMDSTATUS = 0; // data.COMMANDPARAM = 0; // // // data.CMDTYP = cmdtyp; // // data.CMDACT = 1; // // if(cmdtyp == DEPENDXFER_cmdtyp) // { // data.CMDIOC = 1; // data.HIPRI_FORCERM = 1; // } // // uintptr_t addr = (DEPCMD_OFFSET + 0x10 * endpoint_number) | USB_ADDRESS_OFFSET; // // ltcusb_mem_write2(addr,&data); // // ltcusb_mem_read2(addr,&data); // // while(data.CMDACT == 1) // { // ltcusb_mem_read2(addr,&data); // } return 0; }