⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alarm.c

📁 xenomai 很好的linux实时补丁
💻 C
📖 第 1 页 / 共 2 页
字号:
    xeno_mark_deleted(alarm); unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_alarm_start(RT_ALARM *alarm,RTIME value,RTIME interval) * @brief Start an alarm. * * Program the trigger date of an alarm object. An alarm can be either * periodic or oneshot, depending on the reload value passed to this * routine. The given alarm must have been previously created by a * call to rt_alarm_create(). * * Alarm handlers are always called on behalf of Xenomai's internal timer * tick handler, so the Xenomai services which can be called from such * handlers are restricted to the set of services available on behalf * of any ISR. * * This service overrides any previous setup of the expiry date and * reload interval for the given alarm. * * @param alarm The descriptor address of the affected alarm. * * @param value The relative date of the initial alarm shot, expressed * in clock ticks (see note). * * @param interval The reload value of the alarm. It is a periodic * interval value to be used for reprogramming the next alarm shot, * expressed in clock ticks (see note). If @a interval is equal to * TM_INFINITE, the alarm will not be reloaded after it has expired. * * @return 0 is returned upon success. Otherwise: * * - -EINVAL is returned if @a alarm is not a alarm descriptor. * * Environments: * * This service can be called from: * * - Kernel module initialization/cleanup code * - Interrupt service routine * - Kernel-based task * - User-space task * * Rescheduling: never. * * @note This service is sensitive to the current operation mode of * the system timer, as defined by the rt_timer_start() service. In * periodic mode, clock ticks are interpreted as periodic jiffies. In * oneshot mode, clock ticks are interpreted as nanoseconds. */int rt_alarm_start (RT_ALARM *alarm,		    RTIME value,		    RTIME interval){    int err = 0;    spl_t s;    xnlock_get_irqsave(&nklock,s);    alarm = xeno_h2obj_validate(alarm,XENO_ALARM_MAGIC,RT_ALARM);    if (!alarm)        {        err = xeno_handle_error(alarm,XENO_ALARM_MAGIC,RT_ALARM);        goto unlock_and_exit;        }    xntimer_start(&alarm->timer_base,value,interval); unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_alarm_stop(RT_ALARM *alarm) * @brief Stop an alarm. * * Disarm an alarm object previously armed using rt_alarm_start() so * that it will not trigger until is is re-armed. * * @param alarm The descriptor address of the released alarm. * * @return 0 is returned upon success. Otherwise: * * - -EINVAL is returned if @a alarm is not a alarm descriptor. * * - -EIDRM is returned if @a alarm is a deleted alarm descriptor. * * Environments: * * This service can be called from: * * - Kernel module initialization/cleanup code * - Interrupt service routine * - Kernel-based task * - User-space task * * Rescheduling: never. */int rt_alarm_stop (RT_ALARM *alarm){    int err = 0;    spl_t s;    xnlock_get_irqsave(&nklock,s);    alarm = xeno_h2obj_validate(alarm,XENO_ALARM_MAGIC,RT_ALARM);    if (!alarm)        {        err = xeno_handle_error(alarm,XENO_ALARM_MAGIC,RT_ALARM);        goto unlock_and_exit;        }    xntimer_stop(&alarm->timer_base); unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_alarm_inquire(RT_ALARM *alarm, RT_ALARM_INFO *info) * @brief Inquire about an alarm. * * Return various information about the status of a given alarm. * * @param alarm The descriptor address of the inquired alarm. * * @param info The address of a structure the alarm information will * be written to. * * The expiration date returned in the information block is converted * to the current time unit. The special value TM_INFINITE is returned * if @a alarm is currently inactive/stopped. In single-shot mode, it * might happen that the alarm has already expired when this service * is run (even if the associated handler has not been fired yet); in * such a case, 1 is returned. * * @return 0 is returned and status information is written to the * structure pointed at by @a info upon success. Otherwise: * * - -EINVAL is returned if @a alarm is not a alarm descriptor. * * - -EIDRM is returned if @a alarm is a deleted alarm descriptor. * * Environments: * * This service can be called from: * * - Kernel module initialization/cleanup code * - Interrupt service routine * - Kernel-based task * - User-space task * * Rescheduling: never. */int rt_alarm_inquire (RT_ALARM *alarm,                      RT_ALARM_INFO *info){    int err = 0;    spl_t s;    xnlock_get_irqsave(&nklock,s);    alarm = xeno_h2obj_validate(alarm,XENO_ALARM_MAGIC,RT_ALARM);    if (!alarm)        {        err = xeno_handle_error(alarm,XENO_ALARM_MAGIC,RT_ALARM);        goto unlock_and_exit;        }        strcpy(info->name,alarm->name);    info->expiration = xntimer_get_timeout(&alarm->timer_base);    info->expiries = alarm->expiries; unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_alarm_create(RT_ALARM *alarm,const char *name) * @brief Create an alarm object from user-space. * * Initializes an alarm object from a user-space application.  Alarms * can be made periodic or oneshot, depending on the reload interval * value passed to rt_alarm_start() for them. In this mode, the basic * principle is to define some alarm server task which routinely waits * for the next incoming alarm event through the rt_alarm_wait() * syscall. * * @param alarm The address of an alarm descriptor Xenomai will use to * store the alarm-related data.  This descriptor must always be valid * while the alarm is active therefore it must be allocated in * permanent memory. * * @param name An ASCII string standing for the symbolic name of the * alarm. When non-NULL and non-empty, this string is copied to a safe * place into the descriptor, and passed to the registry package if * enabled for indexing the created alarm. * * @return 0 is returned upon success. Otherwise: * * - -ENOMEM is returned if the system fails to get enough dynamic * memory from the global real-time heap in order to register the * alarm. * * - -EEXIST is returned if the @a name is already in use by some * registered object. * * - -EPERM is returned if this service was called from an * asynchronous context. * * Environments: * * This service can be called from: * * - User-space task * * Rescheduling: possible. * * @note It is possible to combine kernel-based alarm handling with * waiter threads pending on the same alarm object from user-space * through the rt_alarm_wait() service. For this purpose, the * rt_alarm_handler() routine which is internally invoked to wake up * alarm servers in user-space is accessible to user-provided alarm * handlers in kernel space, and should be called from there in order * to unblock any thread sleeping on the rt_alarm_wait() service. *//** * @fn int rt_alarm_wait(RT_ALARM *alarm) * @brief Wait for the next alarm shot. * * This user-space only call allows the current task to suspend * execution until the specified alarm triggers. The priority of the * current task is raised above all other Xenomai tasks - except those * also undergoing an alarm or interrupt wait (see rt_intr_wait()) - * so that it would preempt any of them under normal circumstances * (i.e. no scheduler lock). * * @param alarm The descriptor address of the awaited alarm. * * @return 0 is returned upon success. Otherwise: * * - -EINVAL is returned if @a alarm is not an alarm descriptor. * * - -EPERM is returned if this service was called from a context * which cannot sleep (e.g. interrupt, non-realtime or scheduler * locked). * * - -EIDRM is returned if @a alarm is a deleted alarm descriptor, * including if the deletion occurred while the caller was waiting for * its next shot. * * - -EINTR is returned if rt_task_unblock() has been called for the * current task before the next alarm shot. * * Environments: * * This service can be called from: * * - User-space task * * Rescheduling: always. *//*@}*/EXPORT_SYMBOL(rt_alarm_create);EXPORT_SYMBOL(rt_alarm_delete);EXPORT_SYMBOL(rt_alarm_start);EXPORT_SYMBOL(rt_alarm_stop);EXPORT_SYMBOL(rt_alarm_inquire);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -