/* * Stub_IntADC.c * * Created on: May 23, 2018 * Author: avi */ #include #include #include #include #include #include #include #include #include #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_uart.h" #include "Drivers/USB_Communication/USBCDCD.h" #include "MessageContainer.pb-c.h" #include "Stub_Status.h" #include "drivers/FPGA/FPGA.h" #include "drivers/adc_sampling/adc.h" #include void Stub_IntADCReadRequest(MessageContainer* requestContainer) { uint32_t status = FAILED; unsigned short data; MessageContainer responseContainer; StubIntADCReadRequest* request = stub_int_adcread_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); status = PASSED; StubIntADCReadResponse response = STUB_INT_ADCREAD_RESPONSE__INIT; status_response(status,&response.status, &response.statusword ,&response.has_statusword); uint32_t temp2 = request->adc_device; if((temp2 & 0x8000) == 0x8000) { request->adc_device = (request->adc_device & 0x1F) ;//the max id is 0x14 (remove the 0x8000) if(request->adc_device == 0x02)//CHAN_DISPENSE_PRESSURE_1 { response.sampling_in_bits = (ADC_GetReading(ADC_CTL_CH2)<<16) | ADC_GetReading(ADC_CTL_CH3); //ISPENSE_PRESSURE_1 <<16 | DISPENSE_PRESSURE_2 response.voltage_sampling_mv = (ADC_GetReading(ADC_CTL_CH4)<<16) | ADC_GetReading(ADC_CTL_CH5); //ISPENSE_PRESSURE_3 <<16 | DISPENSE_PRESSURE_4 } else if(request->adc_device == 0x06)//CHAN_DISPENSE_PRESSURE_5 { response.sampling_in_bits = (ADC_GetReading(ADC_CTL_CH6)<<16) | ADC_GetReading(ADC_CTL_CH7); //ISPENSE_PRESSURE_5 <<16 | DISPENSE_PRESSURE_6 response.voltage_sampling_mv = (ADC_GetReading(ADC_CTL_CH8)<<16) | ADC_GetReading(ADC_CTL_CH9); //ISPENSE_PRESSURE_7 <<16 | DISPENSE_PRESSURE_8 } response.adc_device = request->adc_device; response.has_adc_device = true; response.has_sampling_in_bits = true; response.has_voltage_sampling_mv = true; } else { #ifndef RUN_AS_MAIN_JIG ADCAcquireInit(); //SysCtlDelay(10000); delayUs(500); ADCAcquireStart(0,1); //SysCtlDelay(10000); delayUs(500); ADC_TriggerCollection(); //SysCtlDelay(10000); delayUs(500); ADC0SS0Handler(); //SysCtlDelay(100000); delayms(1); #endif request->adc_device = (request->adc_device & 0x1F) ;//the max id is 0x14 data = ADC_GetReading((ADC_TYPE) request->adc_device); response.adc_device = request->adc_device; response.has_adc_device = true; response.sampling_in_bits = data; response.has_sampling_in_bits = true; float temp= 0; temp = 4096 - data; temp *= 3; temp *= 1000; //move to mv temp /= 4096; response.voltage_sampling_mv = 3000 - temp; response.has_voltage_sampling_mv = true; } responseContainer = createContainer(MESSAGE_TYPE__StubIntADCReadResponse, requestContainer->token, true, &response, &stub_int_adcread_response__pack, &stub_int_adcread_response__get_packed_size); stub_int_adcread_request__free_unpacked(request,NULL); //------------------------------------------------------------------------------------------- uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); free(responseContainer.data.data); SendChars((char*)container_buffer, container_size); }