AVRdebug() added; control transfers can cope with IN buffers

This commit is contained in:
Chris Esposito 2018-01-11 18:11:28 +11:00
parent ada5e6c0e6
commit 22224bfd6f
8 changed files with 52 additions and 7 deletions

View File

@ -307,6 +307,8 @@ void genericUsbDriver::setGain(double newGain){
void genericUsbDriver::avrDebug(void){
usbSendControl(0xc0, 0xa0, 0, 0, sizeof(unified_debug), NULL);
qDebug() << "unified debug is of size" << sizeof(unified_debug);
/*
#ifndef PLATFORM_ANDROID
unified_debug *udsPtr = (unified_debug *) inBuffer;

View File

@ -37,13 +37,13 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
uint16_t Value;
uint16_t Index;
uint16_t Length;
unsigned char *LDATA;
//Interals
unsigned char *controlBuffer;
//To export:
unsigned char inBuffer[INPUT_BUFFER_SIZE];
mwSize dims[2] = {1,INPUT_BUFFER_SIZE};
unsigned char *out_ptr;
//Parse Inputs
HANDLE_CHAR_RAW_IN = mxArrayToString(prhs[0]);
@ -65,16 +65,36 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
sscanf(INDEX_RAW_IN, "%4x", &Index);
LENGTH_RAW_IN = mxArrayToString(prhs[6]);
sscanf(LENGTH_RAW_IN, "%4x", &Length);
sscanf(LENGTH_RAW_IN, "%4x", &Length);
//Allocate buffer memory if it's an IN transaction. Set it to an input pointer if it's an OUT.
if(Request & 0x80){
controlBuffer = mxMalloc(INPUT_BUFFER_SIZE);
} else controlBuffer = mxGetData(prhs[7]);
controlBuffer = mxGetData(prhs[7]);
//Send the packet
int error;
mexPrintf("Length = %hu\n", Length);
error = libusb_control_transfer(handle, RequestType, Request, Value, Index, controlBuffer, Length, 4000);
if(error<0){
mexPrintf("Error number: %d\n", error);
mexPrintf("libusb_control_transfer FAILED with error %s", libusb_error_name(error));
mexPrintf("libusb_control_transfer FAILED with error %s\n", libusb_error_name(error));
}
plhs[0] = mxCreateNumericArray(2, dims, mxUINT8_CLASS, mxREAL);
//Setup function output.
int n;
out_ptr = mxMalloc(INPUT_BUFFER_SIZE);
//Copy data , even if it's not an IN transaction.
for (n=0;n<INPUT_BUFFER_SIZE;n++){
out_ptr[n] = controlBuffer[n];
}
plhs[0] = mxCreateNumericArray(2, dims, mxUINT8_CLASS, mxREAL);
mxSetData(plhs[0], out_ptr);
return;
}

View File

@ -1,6 +1,8 @@
clear all
clc
#https://docs.google.com/document/d/1ZDO1RTarQTNB6Pdfi_T4YukL51oYan_kk_teb1cu6-o/edit?usp=sharing
__addpaths;
__load_globals;
fflush(stdout);
@ -13,6 +15,10 @@ if(isequal(usb_handle, "0000000000000000"))
return;
end
fprintf("\nSending AVR Debug Command...\n");
fflush(stdout);
labrador_send_debug_command(usb_handle, usb_context);
fprintf("\nSetting Device Mode to 2 (Scope CH1 and CH2) with gain 8...\n");
fflush(stdout);
labrador_set_device_mode(usb_handle, usb_context, 2, 8);
@ -35,5 +41,4 @@ labrador_set_psu_voltage(usb_handle, usb_context, 8.8);
fprintf("\nExiting Libusb...\n");
fflush(stdout);
mex_usb_exit(usb_handle, usb_context);
mex_usb_exit(usb_handle, usb_context);

View File

@ -0,0 +1,18 @@
function [] = labrador_send_debug_command(usb_handle, usb_context);
SIZE_OF_UNIFIED_DEBUG = 27;
USB_Control_IN_data = mex_usb_send_control(usb_handle, usb_context, 'c0', 'a0', '0', '0', dec2hex(SIZE_OF_UNIFIED_DEBUG), []);
USB_Control_IN_data
debugtext = char(USB_Control_IN_data(1:9)) ;
trfcnt0 = uint16(USB_Control_IN_data(10)) + 255 * uint16(USB_Control_IN_data(11));
trfcnt1 = uint16(USB_Control_IN_data(12)) + 255 * uint16(USB_Control_IN_data(13));
medianTrfcnt = uint16(USB_Control_IN_data(14)) + 255 * uint16(USB_Control_IN_data(15));
outOfRange = uint16(USB_Control_IN_data(16)) + 255 * uint16(USB_Control_IN_data(17));
counter = uint16(USB_Control_IN_data(18)) + 255 * uint16(USB_Control_IN_data(19));
dma_ch0_cnt = uint16(USB_Control_IN_data(20)) + 255 * uint16(USB_Control_IN_data(21));
dma_ch1_cnt = uint16(USB_Control_IN_data(22)) + 255 * uint16(USB_Control_IN_data(23));
fprintf("debugtext = %s\ntrfcnt0 = %d\ntrfcnt1 = %d\nmedianTrfcnt = %d\noutOfRange = %d\ncounter = %d\ndma_ch0_cnt = %d\ndma_ch1_cnt = %d\n",debugtext, trfcnt0, trfcnt1, medianTrfcnt, outOfRange, counter, dma_ch0_cnt, dma_ch1_cnt);

Binary file not shown.