From a179d57fbe6bdc000a8a0565a776363ff4b31041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Wed, 6 Dec 2023 18:27:29 +0100 Subject: [PATCH] Add MINP for soft motors Make it possible to set bits of the MSTA field for soft motors. Add a new input link, called MINP, beside the existing DINP and RINP MINP will read the new MSTA bits, but filter out the RA_DONE bit. The RA_DONE bit will be taken from DINP (as before) and the RA_DONE bit inside MINP will be ignored, preserving the RA_DONE coming from DINP Note that the MINP needs to follow the bit-definition in MSTA. It may update RA_PLUS_LS, RA_MINUS_LS. RA_HOMED or other bits may be set as well, whatever the application needs. MINP may be pointed to the output of a calc or transform record. --- motorApp/MotorSrc/motorRecord.dbd | 6 ++++++ motorApp/SoftMotorSrc/devSoft.cc | 17 +++++++++++++++++ motorApp/SoftMotorSrc/devSoft.h | 1 + motorApp/SoftMotorSrc/devSoftAux.cc | 20 ++++++++++++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/motorApp/MotorSrc/motorRecord.dbd b/motorApp/MotorSrc/motorRecord.dbd index be7c549de..82106dc6f 100644 --- a/motorApp/MotorSrc/motorRecord.dbd +++ b/motorApp/MotorSrc/motorRecord.dbd @@ -754,6 +754,12 @@ recordtype(motor) { special(SPC_MOD) interest(1) } + field(MINP,DBF_INLINK) { + prompt("MSTA Input Link") + promptgroup(GUI_COMMON) + special(SPC_MOD) + interest(1) + } field(RINP,DBF_INLINK) { prompt("RMP Input Link") promptgroup(GUI_COMMON) diff --git a/motorApp/SoftMotorSrc/devSoft.cc b/motorApp/SoftMotorSrc/devSoft.cc index 55d291384..6773f001f 100644 --- a/motorApp/SoftMotorSrc/devSoft.cc +++ b/motorApp/SoftMotorSrc/devSoft.cc @@ -254,6 +254,23 @@ void soft_dinp_func(struct motorRecord *mr, short newdinp) } } +void soft_minp_func(struct motorRecord *mr, short newminp) +{ + msta_field status; + unsigned int old_RA_DONE; + if (interruptAccept != TRUE) + return; + + status.All = mr->msta; + old_RA_DONE = status.Bits.RA_DONE; + Debug(5, "update(): old msta=0x%04x newminp=0x%04x for %s.\n", + mr->msta, (unsigned)newminp, mr->name); + + status.All = newminp; + status.Bits.RA_DONE = old_RA_DONE; + mr->msta = status.All; + soft_process(mr); +} void soft_rinp_func(struct motorRecord *mr, long newrinp) { diff --git a/motorApp/SoftMotorSrc/devSoft.h b/motorApp/SoftMotorSrc/devSoft.h index 470091cd2..4f99e2f04 100644 --- a/motorApp/SoftMotorSrc/devSoft.h +++ b/motorApp/SoftMotorSrc/devSoft.h @@ -57,6 +57,7 @@ struct motor_node { extern long soft_init(int); extern long soft_init_record(void *); extern void soft_dinp_func(struct motorRecord *, short); +extern void soft_minp_func(struct motorRecord *, short); extern void soft_rdbl_func(struct motorRecord *, double); extern void soft_rinp_func(struct motorRecord *, long); extern void soft_motor_callback(CALLBACK *); diff --git a/motorApp/SoftMotorSrc/devSoftAux.cc b/motorApp/SoftMotorSrc/devSoftAux.cc index 05a049622..289437628 100644 --- a/motorApp/SoftMotorSrc/devSoftAux.cc +++ b/motorApp/SoftMotorSrc/devSoftAux.cc @@ -66,6 +66,7 @@ static inline void Debug(int level, const char *format, ...) } STATIC void soft_dinp(struct event_handler_args); +STATIC void soft_minp(struct event_handler_args); STATIC void soft_rdbl(struct event_handler_args); STATIC void soft_rinp(struct event_handler_args); STATIC EPICSTHREADFUNC soft_motor_task(void *); @@ -78,6 +79,11 @@ STATIC void soft_dinp(struct event_handler_args args) soft_dinp_func((struct motorRecord *) args.usr, *((short *) args.dbr)); } +STATIC void soft_minp(struct event_handler_args args) +{ + soft_minp_func((struct motorRecord *) args.usr, *((short *) args.dbr)); +} + STATIC void soft_rdbl(struct event_handler_args args) { @@ -162,7 +168,7 @@ STATIC EPICSTHREADFUNC soft_motor_task(void *parm) { struct motorRecord *mr; struct motor_node *node; - chid dinp, rdbl, rinp; + chid dinp, minp, rdbl, rinp; epicsEventId wait_forever; epicsEventWait(soft_motor_sem); /* Wait for dbLockInitRecords() to execute. */ @@ -195,7 +201,17 @@ STATIC EPICSTHREADFUNC soft_motor_task(void *parm) { ptr->default_done_behavior = true; } - + if (((mr->minp.type == PV_LINK) || + (mr->minp.type == CA_LINK) || + (mr->minp.type == DB_LINK)) && + (mr->minp.value.pv_link.pvname != NULL)) + { + Debug(5, "devSoftAux::soft_motor_task: adding minp link for motor %s link=%s\n", mr->name, mr->minp.value.pv_link.pvname); + SEVCHK(ca_search(mr->minp.value.pv_link.pvname, &minp),"ca_search() failure"); + SEVCHK(ca_add_event(DBR_SHORT, minp, soft_minp, mr, NULL),"ca_add_event() failure"); + SEVCHK(ca_pend_io((float) 5.0), "MINP link failure"); + } + if ((mr->urip != 0) && ((mr->rdbl.type == PV_LINK) || (mr->rdbl.type == CA_LINK) ||