|
|
|
@@ -7,7 +7,7 @@
|
|
|
|
|
|
|
|
|
|
#include "cal_meas.h"
|
|
|
|
|
#include "SPI_Driv.h"
|
|
|
|
|
char sw_config_data[3] = {0x00,0x00,0x00};
|
|
|
|
|
u8 sw_config_data[3] = {0x00,0x00,0x00};
|
|
|
|
|
|
|
|
|
|
int Command_Parser(u8* recvbuffer, u8 len)
|
|
|
|
|
{
|
|
|
|
@@ -39,7 +39,7 @@ int Command_Parser(u8* recvbuffer, u8 len)
|
|
|
|
|
xil_printf("[D] Matched Command Freq Cal\r\n");
|
|
|
|
|
if (len > Freq_CMD_LEN + 1) //Do NOT forget the command header
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
|
|
|
|
|
xil_printf("[E] \r\n");
|
|
|
|
|
return XST_INVALID_PARAM;
|
|
|
|
|
}
|
|
|
|
@@ -82,63 +82,82 @@ int DC_Control(u8* idata)
|
|
|
|
|
u_rLoad = idata[5]; //1~18: Refer to SCH/Protocol
|
|
|
|
|
|
|
|
|
|
//Let's do some sanity check
|
|
|
|
|
//Slot
|
|
|
|
|
if ((u_slot > 4) || (u_slot == 0))
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[E] Illege Slot Num check Command! (Slot:1-4)\r\n");
|
|
|
|
|
cmdValid = -1;
|
|
|
|
|
}
|
|
|
|
|
//Dev Sel
|
|
|
|
|
if ((u_m_fun > 2) || (u_m_fun == 0))
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[E] Illege Dev Select check Command! (1:PMU/2:DPS)\r\n");
|
|
|
|
|
cmdValid = -2;
|
|
|
|
|
}
|
|
|
|
|
//Channel
|
|
|
|
|
if (u_m_fun == 1) //PMU
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if ((u_ch_Num < 1) || (u_ch_Num > 256))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
xil_printf("[E] Illege Channel! (PMU Ch:0x0001-0x0100)\r\n");
|
|
|
|
|
cmdValid = -2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((u_ch_Num < 1) || (u_ch_Num > 64))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
xil_printf("[E] Illege Channel! (PMU Ch:0x0001-0x0040)\r\n");
|
|
|
|
|
cmdValid = -3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//V/I Sel
|
|
|
|
|
if ((u_vi_Sel > 2) || (u_vi_Sel == 0))
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[E] Illege V/I Config check Command! (1:V/2:I)\r\n");
|
|
|
|
|
cmdValid = -3;
|
|
|
|
|
cmdValid = -5;
|
|
|
|
|
}
|
|
|
|
|
//RLoad Sel
|
|
|
|
|
if ((u_rLoad > 18) || (u_rLoad == 0))
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[E] Illege RLoad Select check Command! (RLoad:1-18)\r\n");
|
|
|
|
|
cmdValid = -4;
|
|
|
|
|
xil_printf("[E] Illege RLoad Select check Command! (RLoad:0x01-0x12)\r\n");
|
|
|
|
|
cmdValid = -6;
|
|
|
|
|
}
|
|
|
|
|
if (cmdValid != 1)
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
|
|
|
|
|
return XST_INVALID_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//DEBUG Printout
|
|
|
|
|
xil_printf("[D] We Got:\r\n[-]\tSlot: #%d\r\n",u_slot);
|
|
|
|
|
if (u_m_fun == 1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
xil_printf("[-]\tDevice Select: PMU\r\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[-]\tDevice Select: DPS\r\n");
|
|
|
|
|
}
|
|
|
|
|
xil_printf("[-]\tChannel Select: #%d\r\n",u_ch_Num);
|
|
|
|
|
if (u_vi_Sel == 1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
xil_printf("[-]\tDMM Measure Select: Voltage\r\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[-]\tDMM Measure Select: Current\r\n");
|
|
|
|
|
}
|
|
|
|
|
xil_printf("[-]\tRLoad Select: #%d\r\n",u_rLoad);
|
|
|
|
|
|
|
|
|
|
//Sanity Check Done
|
|
|
|
|
//Let's format the CPLD Reg Data
|
|
|
|
|
//Note here as the CPLD_Write() will smartly set the R/W bit to 1'b1, so no need to handle that here, addr is addr
|
|
|
|
|
switch (u_rLoad)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
{
|
|
|
|
|
reg_addr = 0x06;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
|
|
|
|
reg_addr = 0x07;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3:
|
|
|
|
|
{
|
|
|
|
|
reg_addr = 0x08;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4:
|
|
|
|
|
{
|
|
|
|
|
reg_addr = 0x09;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: //You should be here
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[E] Error Reaching Invaild Slot CPLD Formatting, Check PS Code!\r\n");
|
|
|
|
|
return XST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//As the structure of DC regs are the same, we can format the data uniformly
|
|
|
|
|
//Dev Sel
|
|
|
|
@@ -150,19 +169,66 @@ int DC_Control(u8* idata)
|
|
|
|
|
//V/I Sel
|
|
|
|
|
if (u_vi_Sel == 0x2)
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
|
|
|
|
|
reg_data = reg_data | 0x400000; //1:I/0:V
|
|
|
|
|
}
|
|
|
|
|
//RLoad Sel
|
|
|
|
|
reg_data = reg_data | (((u32)u_rLoad)<<20);
|
|
|
|
|
reg_data = reg_data | (((u32)u_rLoad)<<17);
|
|
|
|
|
//Channel Sel
|
|
|
|
|
reg_data = reg_data | u_ch_Num;
|
|
|
|
|
reg_data = reg_data |((u32)(u_ch_Num)<<1) | 0x1; //0x1:Slot_EN
|
|
|
|
|
|
|
|
|
|
Status = CPLD_Write(reg_addr, reg_data);
|
|
|
|
|
//We should clear out other slot's enable flag to prevent error
|
|
|
|
|
Status = 0;
|
|
|
|
|
//Note here as the CPLD_Write() will smartly set the R/W bit to 1'b1, so no need to handle that here, addr is addr
|
|
|
|
|
switch (u_slot)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Status = Status + CPLD_Write(0x07, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x08, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x09, 0x0);
|
|
|
|
|
reg_addr = 0x06;
|
|
|
|
|
Status = Status + CPLD_Write(reg_addr, reg_data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
|
|
|
|
Status = Status + CPLD_Write(0x06, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x08, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x09, 0x0);
|
|
|
|
|
reg_addr = 0x07;
|
|
|
|
|
Status = Status + CPLD_Write(reg_addr, reg_data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3:
|
|
|
|
|
{
|
|
|
|
|
Status = Status + CPLD_Write(0x06, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x07, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x09, 0x0);
|
|
|
|
|
reg_addr = 0x08;
|
|
|
|
|
Status = Status + CPLD_Write(reg_addr, reg_data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4:
|
|
|
|
|
{
|
|
|
|
|
Status = Status + CPLD_Write(0x06, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x07, 0x0);
|
|
|
|
|
Status = Status + CPLD_Write(0x08, 0x0);
|
|
|
|
|
reg_addr = 0x09;
|
|
|
|
|
Status = Status + CPLD_Write(reg_addr, reg_data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: //You should NOT be here
|
|
|
|
|
{
|
|
|
|
|
xil_printf("[E] Error Reaching Invaild Slot CPLD Formatting, Check PS Code!\r\n");
|
|
|
|
|
return XST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Status != XST_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
|
|
|
|
|
xil_printf("[E] Error Writing CPLD Reg! Check Log ABOVE!\r\n");
|
|
|
|
|
return XST_FAILURE;
|
|
|
|
|
}
|
|
|
|
@@ -191,16 +257,20 @@ int DC_Control(u8* idata)
|
|
|
|
|
int CPLD_Write(u8 addr,u32 data)
|
|
|
|
|
{
|
|
|
|
|
u16 reg_addr = addr | 0x80; //Write bit set to 1'b1
|
|
|
|
|
u8 reg_data[dat_width] = {0};
|
|
|
|
|
//Data Sanity Check
|
|
|
|
|
if ((data >> 24) > 0)
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
|
|
|
|
|
xil_printf("[E] CPLD data length should within 24 bits!\r\n");
|
|
|
|
|
return XST_INVALID_PARAM;
|
|
|
|
|
}
|
|
|
|
|
spi_write_onewire(reg_addr, sw_config_data, dat_width, CPLD_U1);
|
|
|
|
|
spi_write_onewire(reg_addr, sw_config_data, dat_width, CPLD_U2);
|
|
|
|
|
spi_write_onewire(reg_addr, sw_config_data, dat_width, CPLD_U3);
|
|
|
|
|
reg_data[0] = (u8)(data >> 16);
|
|
|
|
|
reg_data[1] = (u8)(((data)&0xff00)>>8);
|
|
|
|
|
reg_data[2] = (u8)data;
|
|
|
|
|
spi_write_onewire(reg_addr, reg_data, dat_width, CPLD_U1);
|
|
|
|
|
spi_write_onewire(reg_addr, reg_data, dat_width, CPLD_U2);
|
|
|
|
|
spi_write_onewire(reg_addr, reg_data, dat_width, CPLD_U3);
|
|
|
|
|
|
|
|
|
|
return XST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|