diff --git a/motorApp/SoftMotorSrc/devSoft.cc b/motorApp/SoftMotorSrc/devSoft.cc index 017fde5f..367aab3c 100644 --- a/motorApp/SoftMotorSrc/devSoft.cc +++ b/motorApp/SoftMotorSrc/devSoft.cc @@ -1,6 +1,6 @@ /* -FILENAME... devSoft.cc -USAGE... Motor record device level support for Soft channel. +FILENAME... devSoft.cc +USAGE... Motor record device level support for Soft channel. Version: $Revision$ Modified By: $Author$ @@ -28,55 +28,57 @@ HeadURL: $URL$ * ----------------- * * .00 02-06-02 rls - Don't process from events unless interruptAccept is TRUE. - * - When done transitions from false to true it is not - * communicated to the motor record until after the last - * readback update. - * - In soft_process(), call dbProcess() instead of directly - * calling motor record's process(). - * - In soft_rdbl_func(), reset motor record's target to actual - * position after last readback if motion was not initiated - * by this record. + * - When done transitions from false to true it is not + * communicated to the motor record until after the last + * readback update. + * - In soft_process(), call dbProcess() instead of directly + * calling motor record's process(). + * - In soft_rdbl_func(), reset motor record's target to actual + * position after last readback if motion was not initiated + * by this record. * .01 10-29-02 rls - LOCK field added to prevent synchronization due to - * changing readback. + * changing readback. * .02 06-16-03 rls Convert to R3.14.x. * .03 08-03-05 rls - Added debug messages. - * - Fix compiler error with "gcc version 3.4.2 20041017 (Red - * Hat 3.4.2-6.fc3)". + * - Fix compiler error with "gcc version 3.4.2 20041017 (Red + * Hat 3.4.2-6.fc3)". */ /* NOTES... -- Can't call CA functions until after dbLockInitRecords() has - been called and initialized lock sets. +- Can't call CA functions until after dbLockInitRecords() has been called and initialized lock sets. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include "motorRecord.h" -#include "motor.h" -#include "devSoft.h" +#include "motorRecord.h" +#include "motor.h" +#include "devSoft.h" -#include "epicsExport.h" -#include "errlog.h" +#include "epicsExport.h" +#include "errlog.h" /*----------------debugging-----------------*/ volatile int devSoftdebug = 0; -extern "C" {epicsExportAddress(int, devSoftdebug);} -static inline void Debug(int level, const char *format, ...) { - #ifdef DEBUG - if (level < devSoftdebug) { - va_list pVar; - va_start(pVar, format); - vprintf(format, pVar); - va_end(pVar); +extern "C" +{epicsExportAddress(int, devSoftdebug);} +static inline void Debug(int level, const char *format, ...) +{ +#ifdef DEBUG + if (level < devSoftdebug) + { + va_list pVar; + va_start(pVar, format); + vprintf(format, pVar); + va_end(pVar); } - #endif +#endif } static CALLBACK_VALUE update(struct motorRecord *); @@ -95,7 +97,7 @@ struct motor_dset devMotorSoft = end }; -extern "C" {epicsExportAddress(dset,devMotorSoft);} +extern "C" {epicsExportAddress(dset, devMotorSoft);} static CALLBACK_VALUE update(struct motorRecord *mr) { @@ -105,9 +107,9 @@ static CALLBACK_VALUE update(struct motorRecord *mr) #ifdef DMR_SOFTMOTOR_MODS if (ptr->load_position) { - mr->rmp = ptr->new_position; - mr->rep = ptr->new_position; - ptr->load_position = FALSE; + mr->rmp = ptr->new_position; + mr->rep = ptr->new_position; + ptr->load_position = FALSE; } #endif @@ -117,13 +119,13 @@ static CALLBACK_VALUE update(struct motorRecord *mr) if (ptr->dinp_value == SOFTMOVE || ptr->dinp_value == HARDMOVE) { - Debug(5, "update(): DMOV=0 for %s.\n", mr->name); - status.Bits.RA_DONE = 0; + Debug(5, "update(): DMOV=0 for %s.\n", mr->name); + status.Bits.RA_DONE = 0; } else { - Debug(5, "update(): DMOV=1 for %s.\n", mr->name); - status.Bits.RA_DONE = 1; + Debug(5, "update(): DMOV=1 for %s.\n", mr->name); + status.Bits.RA_DONE = 1; } mr->msta = status.All; return(ptr->callback_flag); @@ -142,11 +144,11 @@ static RTN_STATUS end(struct motorRecord *mr) if (ptr->default_done_behavior == YES) { - msta_field status; + msta_field status; - status.All = 0; - status.Bits.RA_DONE = 1; - mr->msta = status.All; + status.All = 0; + status.Bits.RA_DONE = 1; + mr->msta = status.All; } return(OK); } @@ -159,38 +161,38 @@ static RTN_STATUS build(motor_cmnd command, double *parms, struct motorRecord *m switch (command) { - case MOVE_ABS: - case MOVE_REL: - status = dbPutLink(&mr->out, DBR_DOUBLE, &mr->dval, 1); - break; + case MOVE_ABS: + case MOVE_REL: + status = dbPutLink(&mr->out, DBR_DOUBLE, &mr->dval, 1); + break; - case STOP_AXIS: - status = dbPutLink(&mr->stoo, DBR_SHORT, &stop, 1); - break; + case STOP_AXIS: + status = dbPutLink(&mr->stoo, DBR_SHORT, &stop, 1); + break; - case SET_HIGH_LIMIT: - case SET_LOW_LIMIT: - status = OK; - break; + case SET_HIGH_LIMIT: + case SET_LOW_LIMIT: + status = OK; + break; + + case LOAD_POS: + { + struct soft_private *ptr = (struct soft_private *) mr->dpvt; + msta_field msta; - case LOAD_POS: - { - struct soft_private *ptr = (struct soft_private *) mr->dpvt; - msta_field msta; - #ifdef DMR_SOFTMOTOR_MODS - ptr->load_position = TRUE; - ptr->new_position = *parms; + ptr->load_position = TRUE; + ptr->new_position = *parms; #endif - msta.All = 0; - msta.Bits.RA_DONE = 1; - mr->msta = msta.All; - callbackRequest(&ptr->callback); - } - break; + msta.All = 0; + msta.Bits.RA_DONE = 1; + mr->msta = msta.All; + callbackRequest(&ptr->callback); + } + break; - default: - status = ERROR; + default: + status = ERROR; } return(status == 0 ? OK : ERROR); } @@ -198,24 +200,24 @@ static RTN_STATUS build(motor_cmnd command, double *parms, struct motorRecord *m /* FUNCTION... void soft_dinp_func(struct motorRecord *, short) -USAGE... Update soft channel device input links and +USAGE... Update soft channel device input links and process soft channel motor record when done moving. LOGIC... IF DINP link value is FALSE. - IF this soft motor's DMOV is FALSE. - This is a soft motor initiated move. - Set SOFTMOVE indicator. - ELSE IF LOCK field set to NO. - This is NOT a soft motor initiated move. - Set HARDMOVE indicator. - Set soft motor's DMOV FALSE. - Set PostProcess (PP) TRUE. - ENDIF + IF this soft motor's DMOV is FALSE. + This is a soft motor initiated move. + Set SOFTMOVE indicator. + ELSE IF LOCK field set to NO. + This is NOT a soft motor initiated move. + Set HARDMOVE indicator. + Set soft motor's DMOV FALSE. + Set PostProcess (PP) TRUE. + ENDIF ELSE - IF DINP state is HARDMOVE. - Set PostProcess (PP) True. - Set DINP state to DONE. - Process soft channel record. + IF DINP state is HARDMOVE. + Set PostProcess (PP) True. + Set DINP state to DONE. + Process soft channel record. ENDIF */ void soft_dinp_func(struct motorRecord *mr, short newdinp) @@ -223,33 +225,33 @@ void soft_dinp_func(struct motorRecord *mr, short newdinp) struct soft_private *ptr = (struct soft_private *) mr->dpvt; if (interruptAccept != TRUE) - return; - + return; + /* Test for hard motor started moving or initialization. */ if (newdinp == 0) { - if (mr->dmov == FALSE) - { - Debug(5, "soft_dinp_func(): SOFTMOVE set for %s.\n", mr->name); - ptr->dinp_value = SOFTMOVE; - } - else if (mr->lock == menuYesNoNO) - { /* Hard motor is moving independent of soft motor. */ - Debug(5, "soft_dinp_func(): HARDMOVE set for %s.\n", mr->name); - ptr->dinp_value = HARDMOVE; - mr->dmov = FALSE; - db_post_events(mr, &mr->dmov, DBE_VAL_LOG); - mr->pp = TRUE; - db_post_events(mr, &mr->pp, DBE_VAL_LOG); - } + if (mr->dmov == FALSE) + { + Debug(5, "soft_dinp_func(): SOFTMOVE set for %s.\n", mr->name); + ptr->dinp_value = SOFTMOVE; + } + else if (mr->lock == menuYesNoNO) + { /* Hard motor is moving independent of soft motor. */ + Debug(5, "soft_dinp_func(): HARDMOVE set for %s.\n", mr->name); + ptr->dinp_value = HARDMOVE; + mr->dmov = FALSE; + db_post_events(mr, &mr->dmov, DBE_VAL_LOG); + mr->pp = TRUE; + db_post_events(mr, &mr->pp, DBE_VAL_LOG); + } } - else /* Hard motor is done moving. */ + else /* Hard motor is done moving. */ { - if (ptr->dinp_value == HARDMOVE) - mr->pp = TRUE; - ptr->dinp_value = DONE; - Debug(5, "soft_dinp_func(): Done moving set for %s.\n", mr->name); - soft_process(mr); /* Process in case there is no readback callback. */ + if (ptr->dinp_value == HARDMOVE) + mr->pp = TRUE; + ptr->dinp_value = DONE; + Debug(5, "soft_dinp_func(): Done moving set for %s.\n", mr->name); + soft_process(mr); /* Process in case there is no readback callback. */ } } @@ -257,50 +259,50 @@ void soft_dinp_func(struct motorRecord *mr, short newdinp) void soft_rinp_func(struct motorRecord *mr, long newrinp) { if (interruptAccept != TRUE) - return; - + return; + mr->rmp = newrinp; soft_process(mr); } void soft_rdbl_func(struct motorRecord *mr, double newrdbl) -{ +{ struct soft_private *ptr = (struct soft_private *) mr->dpvt; if (interruptAccept != TRUE) - return; + return; newrdbl = newrdbl / mr->mres; mr->rmp = NINT(newrdbl); Debug(5, "soft_rdbl_func(): updated RMP = %d for %s.\n", mr->rmp, mr->name); - + if (ptr->initialized == false) { - /* Reset Target to Actual position. */ - unsigned short mask = (DBE_VALUE | DBE_LOG); + /* Reset Target to Actual position. */ + unsigned short mask = (DBE_VALUE | DBE_LOG); - mr->dmov = FALSE; - db_post_events(mr, &mr->dmov, mask); - mr->pp = TRUE; - db_post_events(mr, &mr->pp, mask); + mr->dmov = FALSE; + db_post_events(mr, &mr->dmov, mask); + mr->pp = TRUE; + db_post_events(mr, &mr->pp, mask); - ptr->dinp_value = DONE; - ptr->initialized = true; - } + ptr->dinp_value = DONE; + ptr->initialized = true; + } soft_process(mr); } /* FUNCTION... static void soft_process(struct motorRecord *) -USAGE... Process the soft channel motor record. +USAGE... Process the soft channel motor record. LOGIC... - Lock soft channel record - call dbScanLock(). - Set call back flag to CALLBACK_DATA so readback will get updated. - Process soft channel record - call process(). - Unlock soft channel record - call dbScanUnlock(). + Lock soft channel record - call dbScanLock(). + Set call back flag to CALLBACK_DATA so readback will get updated. + Process soft channel record - call process(). + Unlock soft channel record - call dbScanUnlock(). */ static void soft_process(struct motorRecord *mr) @@ -309,7 +311,7 @@ static void soft_process(struct motorRecord *mr) dbScanLock((struct dbCommon *) mr); ptr->callback_flag = CALLBACK_DATA; - dbProcess((struct dbCommon *) mr); /* Process the soft channel record. */ + dbProcess((struct dbCommon *) mr); /* Process the soft channel record. */ ptr->callback_flag = NOTHING_DONE; dbScanUnlock((struct dbCommon *) mr); } @@ -317,8 +319,8 @@ static void soft_process(struct motorRecord *mr) /* FUNCTION... void soft_motor_callback(CALLBACK *) -USAGE... Process motor record after the following events: - - LOAD_POS motor command. +USAGE... Process motor record after the following events: + - LOAD_POS motor command. LOGIC... */ diff --git a/motorApp/SoftMotorSrc/devSoftAux.cc b/motorApp/SoftMotorSrc/devSoftAux.cc index f34d78d6..2fc7ffc3 100644 --- a/motorApp/SoftMotorSrc/devSoftAux.cc +++ b/motorApp/SoftMotorSrc/devSoftAux.cc @@ -1,6 +1,6 @@ /* -FILENAME... devSoftAux.cc -USAGE... Motor record device level support for Soft channel. +FILENAME... devSoftAux.cc +USAGE... Motor record device level support for Soft channel. Version: $Revision$ Modified By: $Author$ @@ -28,7 +28,7 @@ HeadURL: $URL$ * ----------------- * .01 06-16-03 rls Convert to R3.14.x. * .02 12-14-04 rls With EPICS R3.14.7 changes to epicsThread.h, need explicit - * #include + * #include * .03 2006-04-10 pnd Convert to linked lists to remove arbitrary maximum */ @@ -52,7 +52,7 @@ in the same file; each defines (redefines) the DBR's. #include "motor.h" #include "devSoft.h" -#define STATIC static +#define STATIC static STATIC void soft_dinp(struct event_handler_args); STATIC void soft_rdbl(struct event_handler_args); @@ -84,38 +84,38 @@ long soft_init(void *after) if (before_after == 0) { - epicsThreadId dbCaTask_tid; - unsigned int soft_motor_priority; - int retry = 0; + epicsThreadId dbCaTask_tid; + unsigned int soft_motor_priority; + int retry = 0; soft_motor_sem = epicsEventCreate(epicsEventEmpty); - ellInit(&soft_motor_list); + ellInit(&soft_motor_list); - /* - * Fix for DMOV processing before the last DRBV update; i.e., lower - * the priority of the "soft_motor" task below the priority of the - * "dbCaLink" task. - */ - while((dbCaTask_tid = epicsThreadGetId("dbCaLink")) == 0 && retry < 10) - { - epicsThreadSleep(0.1); - retry++; - } + /* + * Fix for DMOV processing before the last DRBV update; i.e., lower + * the priority of the "soft_motor" task below the priority of the + * "dbCaLink" task. + */ + while((dbCaTask_tid = epicsThreadGetId("dbCaLink")) == 0 && retry < 10) + { + epicsThreadSleep(0.1); + retry++; + } - if (dbCaTask_tid == 0) - { - errMessage(0, "cannot find dbCaLink task."); - return(ERROR); - } - soft_motor_priority = epicsThreadGetPriority(dbCaTask_tid); - soft_motor_priority -= 1; + if (dbCaTask_tid == 0) + { + errMessage(0, "cannot find dbCaLink task."); + return(ERROR); + } + soft_motor_priority = epicsThreadGetPriority(dbCaTask_tid); + soft_motor_priority -= 1; - soft_motor_id = epicsThreadCreate((char *) "soft_motor", soft_motor_priority, + soft_motor_id = epicsThreadCreate((char *) "soft_motor", soft_motor_priority, epicsThreadGetStackSize(epicsThreadStackBig), - (EPICSTHREADFUNC) soft_motor_task, NULL); + (EPICSTHREADFUNC) soft_motor_task, NULL); } else - epicsEventSignal(soft_motor_sem); /* Start soft_motor_task(). */ + epicsEventSignal(soft_motor_sem); /* Start soft_motor_task(). */ return(OK); } @@ -129,12 +129,11 @@ long soft_init_record(void *arg) int status = 0; list_entry = (struct motor_node *) malloc(sizeof(struct motor_node)); - if (!list_entry) { - return(ERROR); - } + if (!list_entry) + return(ERROR); list_entry->pmr = mr; - ellAdd(&soft_motor_list, (ELLNODE*)list_entry); + ellAdd(&soft_motor_list, (ELLNODE*) list_entry); /* Allocate space for private field. */ mr->dpvt = (struct soft_private *) malloc(sizeof(struct soft_private)); @@ -143,8 +142,7 @@ long soft_init_record(void *arg) ptr->initialized = false; cbptr = &ptr->callback; - callbackSetCallback((void (*)(struct callbackPvt *)) soft_motor_callback, - cbptr); + callbackSetCallback((void (*)(struct callbackPvt *)) soft_motor_callback, cbptr); callbackSetPriority(priorityMedium, cbptr); callbackSetUser(mr, cbptr); return ((long) status); @@ -158,44 +156,41 @@ STATIC EPICSTHREADFUNC soft_motor_task(void *parm) chid dinp, rdbl, rinp; epicsEventId wait_forever; - epicsEventWait(soft_motor_sem); /* Wait for dbLockInitRecords() to execute. */ - SEVCHK(ca_context_create(ca_enable_preemptive_callback), - "soft_motor_task: ca_context_create() error"); + epicsEventWait(soft_motor_sem); /* Wait for dbLockInitRecords() to execute. */ + SEVCHK(ca_context_create(ca_enable_preemptive_callback), "soft_motor_task: ca_context_create() error"); - while ((node = (struct motor_node *)ellGet(&soft_motor_list))) + while ((node = (struct motor_node *) ellGet(&soft_motor_list))) { - struct soft_private *ptr; + struct soft_private *ptr; - mr = node->pmr; - free(node); + mr = node->pmr; + free(node); - ptr = (struct soft_private *) mr->dpvt; - if (mr->dinp.value.constantStr == NULL) - { - ptr->default_done_behavior = true; - } - else - { - ptr->default_done_behavior = false; - SEVCHK(ca_search(mr->dinp.value.pv_link.pvname, &dinp), - "ca_search() failure"); - SEVCHK(ca_add_event(DBR_SHORT, dinp, soft_dinp, mr, NULL),"ca_add_event() failure"); - SEVCHK(ca_pend_io((float) 5.0), "DINP link failure"); - } + ptr = (struct soft_private *) mr->dpvt; + if (mr->dinp.value.constantStr == NULL) + ptr->default_done_behavior = true; + else + { + ptr->default_done_behavior = false; + SEVCHK(ca_search(mr->dinp.value.pv_link.pvname, &dinp), + "ca_search() failure"); + SEVCHK(ca_add_event(DBR_SHORT, dinp, soft_dinp, mr, NULL),"ca_add_event() failure"); + SEVCHK(ca_pend_io((float) 5.0), "DINP link failure"); + } - if (mr->urip != 0) - { - SEVCHK(ca_search(mr->rdbl.value.pv_link.pvname, &rdbl),"ca_search() failure"); - SEVCHK(ca_add_event(DBR_DOUBLE, rdbl, soft_rdbl, mr, NULL),"ca_add_event() failure"); - SEVCHK(ca_pend_io((float) 5.0), "RDBL link failure"); - } + if (mr->urip != 0) + { + SEVCHK(ca_search(mr->rdbl.value.pv_link.pvname, &rdbl),"ca_search() failure"); + SEVCHK(ca_add_event(DBR_DOUBLE, rdbl, soft_rdbl, mr, NULL),"ca_add_event() failure"); + SEVCHK(ca_pend_io((float) 5.0), "RDBL link failure"); + } - if (mr->rinp.value.constantStr != NULL) - { - SEVCHK(ca_search(mr->rinp.value.pv_link.pvname, &rinp),"ca_search() failure"); - SEVCHK(ca_add_event(DBR_LONG, rinp, soft_rinp, mr, NULL),"ca_add_event() failure"); - SEVCHK(ca_pend_io((float) 5.0), "RINP link failure"); - } + if (mr->rinp.value.constantStr != NULL) + { + SEVCHK(ca_search(mr->rinp.value.pv_link.pvname, &rinp),"ca_search() failure"); + SEVCHK(ca_add_event(DBR_LONG, rinp, soft_rinp, mr, NULL),"ca_add_event() failure"); + SEVCHK(ca_pend_io((float) 5.0), "RINP link failure"); + } } ellFree(&soft_motor_list); @@ -203,9 +198,9 @@ STATIC EPICSTHREADFUNC soft_motor_task(void *parm) thread, so as not to show up in the thread list as "SUSPENDED", which is usually a sign of a fault. */ wait_forever = epicsEventCreate(epicsEventEmpty); - if (wait_forever) { - epicsEventMustWait(wait_forever); - } + if (wait_forever) + epicsEventMustWait(wait_forever); + return(NULL); }