From 691afb933fba9fee5896ea3829c7d1128fb320af Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Fri, 6 Dec 2024 21:01:02 +0100 Subject: [PATCH] server changes for hbridge --- src/lib/rp-daq-lib.c | 32 +++++++++++++++++- src/lib/rp-daq-lib.h | 2 ++ src/server/control.c | 2 +- src/server/scpi_commands.c | 66 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/lib/rp-daq-lib.c b/src/lib/rp-daq-lib.c index 2e3ecc12..821cb013 100644 --- a/src/lib/rp-daq-lib.c +++ b/src/lib/rp-daq-lib.c @@ -653,7 +653,7 @@ int setResyncDAC(int8_t value, int channel, int index) { return -1; int bitpos = 14; - // Reset bits are in the 14th bit of the respective DAC channel -> 14 and 30 + // Reset bits are in the 14th bit of the respective DAC channel -> 14 and 30 int offset = 8 * index + channel; // clear the bit *((int16_t *)(pdm_cfg + offset)) &= ~(1u << bitpos); @@ -1225,6 +1225,36 @@ char* getPinFromInternalPINNumber(const uint32_t pinNumber) { } } +int getDIOHBridge(const char* pin) { + int pinInternal = getInternalPINNumber(pin); + if(pinInternal < 0) { + return -3; + } + + uint32_t register_value = *((uint8_t *)(cfg + 11)); + register_value = ((register_value & (0x1 << (pinInternal))) >> (pinInternal)); + + return register_value; +} + +int setDIOHBridge(const char* pin, int value) { + int pinInternal = getInternalPINNumber(pin); + if(pinInternal < 0) { + return -3; + } + + if(value == DIO_OUT) { + *((uint8_t *)(cfg + 11)) &= ~(0x1 << (pinInternal)); + } else if(value == DIO_IN) { + *((uint8_t *)(cfg + 11)) |= (0x1 << (pinInternal)); + } else { + return -1; + } + + return 0; +} + + int getDIODirection(const char* pin) { int pinInternal = getInternalPINNumber(pin); if(pinInternal < 0) { diff --git a/src/lib/rp-daq-lib.h b/src/lib/rp-daq-lib.h index 9dc8378f..e608591b 100644 --- a/src/lib/rp-daq-lib.h +++ b/src/lib/rp-daq-lib.h @@ -174,6 +174,8 @@ extern int getDIODirection(const char*); extern int setDIODirection(const char*, int); extern int setDIO(const char*, int); extern int getDIO(const char*); +extern int getDIOHBridge(const char*); +extern int setDIOHBridge(const char*, int); extern int setTriggerMode(int); extern int getTriggerMode(); extern int setTriggerPropagation(int); diff --git a/src/server/control.c b/src/server/control.c index 3e662510..d0e86c8c 100644 --- a/src/server/control.c +++ b/src/server/control.c @@ -129,7 +129,7 @@ bool getSequenceEnableValue(sequenceData_t *seqData, int seqStep, int channel) { bool getSequenceResyncValue(sequenceData_t *seqData, int seqStep, int channel) { bool result = false; - int numChan = numSlowDACChan > 2 ? 2 : numSlowDACChan; + int numChan = numSlowDACChan > 2 ? 2 : numSlowDACChan; if (seqData->resyncLUT != NULL && channel < numChan) { int localStep = seqStep % seqData->numStepsPerRepetition; result = seqData->resyncLUT[localStep * numChan + channel]; diff --git a/src/server/scpi_commands.c b/src/server/scpi_commands.c index b7308745..dd31c1f1 100644 --- a/src/server/scpi_commands.c +++ b/src/server/scpi_commands.c @@ -722,6 +722,68 @@ static scpi_result_t RP_DIO_GetDIOOutputP(scpi_t * context) { return RP_DIO_GetDIOOutput(context, true); } + + + +static scpi_result_t RP_DIO_SetDIOHBridge(scpi_t * context, bool pinSide) { + int32_t numbers[1]; + SCPI_CommandNumbers(context, numbers, 1, 1); + int pin_number = numbers[0]; + char pin[8]; + pinSide ? sprintf(pin, "DIO%d_P", pin_number) : sprintf(pin, "DIO%d_N", pin_number); + + int32_t DIO_pin_output_selection; + if (!SCPI_ParamChoice(context, onoff_modes, &DIO_pin_output_selection, TRUE)) { + return returnSCPIBool(context, false); + } + + int result = setDIOHBridge(pin, DIO_pin_output_selection); + if (result < 0) { + return returnSCPIBool(context, false); + } + + return returnSCPIBool(context, true); +} + +static scpi_result_t RP_DIO_SetDIOHBridgeN(scpi_t * context) { + return RP_DIO_SetDIOHBridge(context, false); +} + +static scpi_result_t RP_DIO_SetDIOHBridgeP(scpi_t * context) { + return RP_DIO_SetDIOHBridge(context, true); +} + +static scpi_result_t RP_DIO_GetDIOHBridge(scpi_t * context, bool pinSide) { + int32_t numbers[1]; + SCPI_CommandNumbers(context, numbers, 1, 1); + int pin_number = numbers[0]; + char pin[8]; + pinSide ? sprintf(pin, "DIO%d_P", pin_number) : sprintf(pin, "DIO%d_N", pin_number); + + int result = getDIOHBridge(pin); + + if (result < 0) { + return returnSCPIBool(context, false); + } + + const char* name; + SCPI_ChoiceToName(onoff_modes, result, &name); + SCPI_ResultText(context, name); + + return SCPI_RES_OK; +} + +static scpi_result_t RP_DIO_GetDIOHBridgeN(scpi_t * context) { + return RP_DIO_GetDIOHBridge(context, false); +} + +static scpi_result_t RP_DIO_GetDIOHBridgeP(scpi_t * context) { + return RP_DIO_GetDIOHBridge(context, true); +} + + + + static scpi_result_t RP_GetWatchdogMode(scpi_t * context) { const char * name; @@ -1791,6 +1853,10 @@ const scpi_command_t scpi_commands[] = { {.pattern = "RP:DIO:Pin#:SideP", .callback = RP_DIO_SetDIOOutputP,}, {.pattern = "RP:DIO:Pin#:SideN?", .callback = RP_DIO_GetDIOOutputN,}, {.pattern = "RP:DIO:Pin#:SideP?", .callback = RP_DIO_GetDIOOutputP,}, + {.pattern = "RP:DIO:Pin#:SideN:HBridge", .callback = RP_DIO_SetDIOHBridgeN,}, + {.pattern = "RP:DIO:Pin#:SideP:HBridge", .callback = RP_DIO_SetDIOHBridgeP,}, + {.pattern = "RP:DIO:Pin#:SideN:HBridge?", .callback = RP_DIO_GetDIOHBridgeN,}, + {.pattern = "RP:DIO:Pin#:SideP:HBridge?", .callback = RP_DIO_GetDIOHBridgeP,}, {.pattern = "RP:WatchDogMode", .callback = RP_SetWatchdogMode,}, {.pattern = "RP:WatchDogMode?", .callback = RP_GetWatchdogMode,}, {.pattern = "RP:TRIGger:ALiVe", .callback = RP_SetKeepAliveReset,},