Leonardo Pappagallo wrote: > Hi Jan > > >>In particular, in my program I need to know what is cycle number. >> >>Hmm, this is not yet exported, but it would be easy to add. Do you >>depend on the absolute, global value? Otherwise, maintaining your own >>counter would, of course, already work. > > > > I need the absolute, global value, it is included into SOF frame > > > > Thanks >
I just applied the attached patch to SVN. It should also work for your older release, just try patch -p1 -i waitoncycle_ex.patch in the RTnet root directory. The usage is as follows: struct rtmac_waitinfo waitinfo; waitinfo.type = RTMAC_WAIT_ON_DEFAULT; rt_dev_ioctl(tdma_device, RTMAC_RTIOC_WAITONCYCLE_EX, &waitinfo); cycle_number = waitinfo.cycle_no; I haven't tested it yet, so I depend on YOU to let me know if it works. Jan
Index: stack/include/rtmac.h =================================================================== --- stack/include/rtmac.h (Revision 939) +++ stack/include/rtmac.h (Arbeitskopie) @@ -3,7 +3,7 @@ * include/rtmac.h * * rtmac - real-time networking media access control subsystem - * Copyright (C) 2004 Jan Kiszka <[EMAIL PROTECTED]> + * Copyright (C) 2004, 2005 Jan Kiszka <[EMAIL PROTECTED]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,21 +28,34 @@ /* sub-classes: RTDM_CLASS_RTMAC */ -#define RTDM_SUBCLASS_TDMA 0 -#define RTDM_SUBCLASS_UNMANAGED 1 +#define RTDM_SUBCLASS_TDMA 0 +#define RTDM_SUBCLASS_UNMANAGED 1 -#define RTIOC_TYPE_RTMAC RTDM_CLASS_RTMAC - -/* RTmac Discipline IOCTLs */ -#define RTMAC_RTIOC_TIMEOFFSET _IOR(RTIOC_TYPE_RTMAC, 0x00, __s64) -#define RTMAC_RTIOC_WAITONCYCLE _IOW(RTIOC_TYPE_RTMAC, 0x01, int) +#define RTIOC_TYPE_RTMAC RTDM_CLASS_RTMAC + /* Common Cycle Types */ -#define RTMAC_WAIT_ON_DEFAULT 0x00 -#define RTMAC_WAIT_ON_XMIT 0x01 +#define RTMAC_WAIT_ON_DEFAULT 0x00 +#define RTMAC_WAIT_ON_XMIT 0x01 /* TDMA-specific Cycle Types */ -#define TDMA_WAIT_ON_SYNC 0x10 -#define TDMA_WAIT_ON_SOF TDMA_WAIT_ON_SYNC /* legacy support */ +#define TDMA_WAIT_ON_SYNC 0x10 +#define TDMA_WAIT_ON_SOF TDMA_WAIT_ON_SYNC /* legacy support */ + +/* RTMAC_RTIOC_WAITONCYCLE_EX control and status data */ +struct rtmac_waitinfo { + unsigned int type; + size_t ext_size; + unsigned long cycle_no; + char ext[0]; +}; + + +/* RTmac Discipline IOCTLs */ +#define RTMAC_RTIOC_TIMEOFFSET _IOR(RTIOC_TYPE_RTMAC, 0x00, __s64) +#define RTMAC_RTIOC_WAITONCYCLE _IOW(RTIOC_TYPE_RTMAC, 0x01, unsigned int) +#define RTMAC_RTIOC_WAITONCYCLE_EX _IOWR(RTIOC_TYPE_RTMAC, 0x02, \ + struct rtmac_waitinfo) + #endif /* __RTMAC_H_ */ Index: stack/rtmac/tdma/tdma_dev.c =================================================================== --- stack/rtmac/tdma/tdma_dev.c (Revision 939) +++ stack/rtmac/tdma/tdma_dev.c (Arbeitskopie) @@ -63,12 +63,28 @@ } +static int wait_on_sync(struct tdma_dev_ctx *tdma_ctx, + rtdm_event_t *sync_event) +{ + int ret; + + + RTDM_EXECUTE_ATOMICALLY( + tdma_ctx->cycle_waiter = rtdm_task_current(); + ret = rtdm_event_wait(sync_event); + tdma_ctx->cycle_waiter = NULL; + ); + return ret; +} + + static int tdma_dev_ioctl(struct rtdm_dev_context *context, rtdm_user_info_t *user_info, int request, void *arg) { struct tdma_dev_ctx *ctx = (struct tdma_dev_ctx *)context->dev_private; struct tdma_priv *tdma; nanosecs_t offset; + unsigned int type; rtdm_lockctx_t lock_ctx; int ret; @@ -99,14 +115,40 @@ ((int)arg != TDMA_WAIT_ON_SYNC)) return -EINVAL; - RTDM_EXECUTE_ATOMICALLY( - ctx->cycle_waiter = rtdm_task_current(); - ret = rtdm_event_wait(&tdma->sync_event); - ctx->cycle_waiter = NULL; - ); + return wait_on_sync(ctx, &tdma->sync_event); - return ret; + case RTMAC_RTIOC_WAITONCYCLE_EX: + if (!rtdm_in_rt_context()) + return -EACCES; + if (user_info) { + if (!rtdm_rw_user_ok(user_info, arg, + sizeof(struct rtmac_waitinfo)) || + rtdm_copy_from_user(user_info, &type, arg, + sizeof(unsigned int))) + return -EFAULT; + } else + type = ((struct rtmac_waitinfo *)arg)->type; + + if ((type != RTMAC_WAIT_ON_DEFAULT) && + (type != TDMA_WAIT_ON_SYNC)) + return -EINVAL; + + ret = wait_on_sync(ctx, &tdma->sync_event); + if (ret) + return ret; + + if (user_info) { + if (rtdm_copy_to_user(user_info, &tdma->current_cycle, + &((struct rtmac_waitinfo *)arg)->cycle_no, + sizeof(unsigned long))) + return -EFAULT; + } else + ((struct rtmac_waitinfo *)arg)->cycle_no = + tdma->current_cycle; + + return 0; + default: return -ENOTTY; }
signature.asc
Description: OpenPGP digital signature