|
From: <jmk...@us...> - 2003-08-10 21:13:07
|
Update of /cvsroot/emc/rtapi/src/rtapi In directory sc8-pr-cvs1:/tmp/cvs-serv11923/src/rtapi Modified Files: rtai_rtapi.c rtai_ulapi.c rtapi.h rtl_rtapi.c rtl_ulapi.c ulapi.h Log Message: misc changes, work in progress Index: rtai_rtapi.c =================================================================== RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_rtapi.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** rtai_rtapi.c 9 Aug 2003 21:44:53 -0000 1.15 --- rtai_rtapi.c 10 Aug 2003 21:13:04 -0000 1.16 *************** *** 1,7 **** ! /* ! rtai_rtapi.c - Implementations of RT API functions declared in rtapi.h, for RTAI - */ #include <stdarg.h> /* va_* */ --- 1,42 ---- ! /** RTAPI is a library providing a uniform API for several real time * ! * operating systems. As of ver 2.0, RTLinux and RTAI are supported. */ ! ! /** This file, 'rtai_rtapi.c', implements the realtime portion of the * ! * API for the RTAI platform. The realtime API is defined in rtapi.h, * ! * which includes documentation for the API functions. The non-real- * ! * time portion of the API is defined in ulapi.h and implemented in * ! * rtai_ulapi.c (for the RTAI platform). */ ! ! /** Copyright (C) 2003 John Kasunich * ! * <jmkasunich AT users DOT sourceforge DOT net> * ! * Copyright (C) 2003 Paul Corner * ! * <paul_c AT users DOT sourceforge DOT net> * ! * This library is based on version 1.0, which was released into * ! * the public domain by its author, Fred Proctor. Thanks Fred! */ ! ! /* This library is free software; you can redistribute it and/or * ! * modify it under the terms of version 2 of the GNU General Public * ! * License as published by the Free Software Foundation. * ! * This library is distributed in the hope that it will be useful, but * ! * WITHOUT ANY WARRANTY; without even the implied warranty of * ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * ! * General Public License for more details. * ! * * ! * You should have received a copy of the GNU General Public License * ! * along with this library; if not, write to the Free Software * ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */ ! ! /** THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR * ! * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE * ! * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of * ! * harming persons must have provisions for completely removing power * ! * from all motors, etc, before persons enter any danger area. All * ! * machinery must be designed to comply with local and national safety * ! * codes, and the authors of this software can not, and do not, take * ! * any responsibility for such compliance. */ ! ! /** This code was written as part of the EMC HAL project. For more * ! * information, go to www.linuxcnc.org. */ #include <stdarg.h> /* va_* */ *************** *** 27,30 **** --- 62,69 ---- #endif + #ifdef MODULE_LICENSE + MODULE_LICENSE("GPL"); + #endif + /* declare vsprintf() explicitly instead of including all of <stdio.h>, since we don't need all of it and it may cause problems */ *************** *** 69,72 **** --- 108,112 ---- /* Usage counters to keep track of new/delete calls */ + static int rtapi_usage_count = 0; static int task_usage_count = 0; static int shmem_usage_count = 0; *************** *** 74,84 **** static int fifo_usage_count = 0; static int int_usage_count = 0; ! static unsigned int timer_period = 0; /* Flag used to keep track of timer state */ static int timer_running = 0; ! int debug = 1; ! MODULE_PARM(debug, "i"); ! MODULE_PARM_DESC(debug, "Sets the verbosity of the debug prints"); /* Internal function for the proc_fs system. */ --- 114,127 ---- static int fifo_usage_count = 0; static int int_usage_count = 0; ! static int timer_period = 0; /* Flag used to keep track of timer state */ static int timer_running = 0; ! int rtapi_msg_level; /* global used for message printing */ ! ! static int msg; /* short name, for use in insmod command */ ! MODULE_PARM(msg, "i"); ! MODULE_PARM_DESC(msg, "Verbosity, higher value = more messages (default=7)"); ! /* Internal function for the proc_fs system. */ *************** *** 90,93 **** --- 133,137 ---- PROC_PRINT("******* RTAI rtapi usage *******\n"); PROC_PRINT(" Version = $Revision$\n"); + PROC_PRINT(" Modules Loaded = %i\n", rtapi_usage_count); PROC_PRINT(" Tasks running = %i\n", task_usage_count); PROC_PRINT(" Shared memory = %i\n", shmem_usage_count); *************** *** 95,99 **** PROC_PRINT(" Semaphores used = %i\n", sem_usage_count); PROC_PRINT("Active Interrupts = %i\n", int_usage_count); ! PROC_PRINT(" Timer period = %inSec\n", timer_period); PROC_PRINT(" Timer status = %i\n", timer_running); PROC_PRINT("\n"); --- 139,143 ---- PROC_PRINT(" Semaphores used = %i\n", sem_usage_count); PROC_PRINT("Active Interrupts = %i\n", int_usage_count); ! PROC_PRINT(" Timer period = %i nSec\n", timer_period); PROC_PRINT(" Timer status = %i\n", timer_running); PROC_PRINT("\n"); *************** *** 102,151 **** #endif ! /* Priority functions. RTAI uses 0 as the highest priority, as the ! number increases, the actual priority of the task decreases. */ ! ! int rtapi_prio_highest(void) ! { ! return 0; ! } ! ! int rtapi_prio_lowest(void) { ! return RT_LOWEST_PRIORITY; } ! ! int rtapi_prio_next_higher(int prio) { ! /* return a valid priority for out of range arg */ ! if (prio <= rtapi_prio_highest()) { ! return rtapi_prio_highest(); ! } ! if (prio > rtapi_prio_lowest()) { ! return rtapi_prio_lowest(); ! } ! ! /* return next higher priority for in-range arg */ ! return prio - 1; } ! int rtapi_prio_next_lower(int prio) { ! /* return a valid priority for out of range arg */ ! if (prio >= rtapi_prio_lowest()) { ! return rtapi_prio_lowest(); ! } ! if (prio < rtapi_prio_highest()) { ! return rtapi_prio_highest(); ! } ! /* return next lower priority for in-range arg */ ! return prio + 1; ! } ! - static int rtapi_init(void) - { /* register a proc entry */ #ifdef CONFIG_PROC_FS --- 146,173 ---- #endif ! /* For RTAI, all init is done when the rtapi kernel module ! is insmoded. The rtapi_init() and rtapi_exit() functions ! do nothing. For other RTOSes, things might be different, ! especially if the RTOS does not use modules. */ ! int rtapi_init (void) { ! rtapi_usage_count++; ! return RTAPI_SUCCESS; } ! int rtapi_exit (void) { ! rtapi_usage_count--; ! return RTAPI_SUCCESS; } + /* here is where the real init happens */ ! int init_module(void) { ! /* get the message level from insmod command line */ ! rtapi_msg_level = msg; /* register a proc entry */ #ifdef CONFIG_PROC_FS *************** *** 169,173 **** ! static int rtapi_exit(void) { /* Remove proc dir entry */ --- 191,195 ---- ! void cleanup_module (void) { /* Remove proc dir entry */ *************** *** 209,220 **** ! int init_module(void) { ! return (rtapi_init()); } ! void cleanup_module(void) { ! rtapi_exit(); } --- 231,280 ---- ! ! ! ! ! ! /* Priority functions. RTAI uses 0 as the highest priority, as the ! number increases, the actual priority of the task decreases. */ ! ! int rtapi_prio_highest(void) { ! return 0; } ! ! int rtapi_prio_lowest(void) { ! return RT_LOWEST_PRIORITY; ! } ! ! ! int rtapi_prio_next_higher(int prio) ! { ! /* return a valid priority for out of range arg */ ! if (prio <= rtapi_prio_highest()) { ! return rtapi_prio_highest(); ! } ! if (prio > rtapi_prio_lowest()) { ! return rtapi_prio_lowest(); ! } ! ! /* return next higher priority for in-range arg */ ! return prio - 1; ! } ! ! ! int rtapi_prio_next_lower(int prio) ! { ! /* return a valid priority for out of range arg */ ! if (prio >= rtapi_prio_lowest()) { ! return rtapi_prio_lowest(); ! } ! if (prio < rtapi_prio_highest()) { ! return rtapi_prio_highest(); ! } ! /* return next lower priority for in-range arg */ ! return prio + 1; } *************** *** 236,243 **** rtapi_print_dbg(VERBOSE, ! "RTAPI: clock_set_period ( %ld ) - Actual = %inSec\n", nsecs, timer_period); ! return RTAPI_SUCCESS; } --- 296,303 ---- rtapi_print_dbg(VERBOSE, ! "RTAPI: clock_set_period ( %ld ) - Actual = %i nSec\n", nsecs, timer_period); ! return timer_period; } *************** *** 415,440 **** to suspend(). */ retval = rt_task_resume(&(task->ostask)); - if (retval != 0) { - return RTAPI_FAIL; - } - return RTAPI_SUCCESS; - } - - - int rtapi_task_set_period(rtapi_task_handle task, - unsigned long int period_nsec) - { - int retval; - - /* validate task handle */ - if (task == NULL) { - return RTAPI_BADH; - } - if (task->magic != TASK_MAGIC) { - return RTAPI_BADH; - } - - retval = rt_task_make_periodic(&(task->ostask), rt_get_time(), - nano2count((RTIME) period_nsec)); if (retval != 0) { return RTAPI_FAIL; --- 475,478 ---- Index: rtai_ulapi.c =================================================================== RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_ulapi.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rtai_ulapi.c 10 Aug 2003 12:07:05 -0000 1.4 --- rtai_ulapi.c 10 Aug 2003 21:13:04 -0000 1.5 *************** *** 1,7 **** ! /* ! rtai_ulapi.c - Implementation of user-level API to RTAI modules - */ #include <stdio.h> /* sprintf() */ #include <stddef.h> /* NULL, needed for rtai_shm.h */ --- 1,43 ---- ! /** RTAPI is a library providing a uniform API for several real time * ! * operating systems. As of ver 2.0, RTLinux and RTAI are supported. */ ! ! /** This file, 'rtai_ulapi.c', implements the non-realtime portion of * ! * the API for the RTAI platform. The non-realtime API is defined in * ! * ulapi.h, which includes documentation for the API functions. The * ! * realtime portion of the API is defined in rtapi.h and implemented * ! * in rtai_rtapi.c (for the RTAI platform). */ ! ! /** Copyright (C) 2003 John Kasunich * ! * <jmkasunich AT users DOT sourceforge DOT net> * ! * Copyright (C) 2003 Paul Corner * ! * <paul_c AT users DOT sourceforge DOT net> * ! * This library is based on version 1.0, which was released into * ! * the public domain by its author, Fred Proctor. Thanks Fred! */ ! ! /* This library is free software; you can redistribute it and/or * ! * modify it under the terms of version 2.1 of the GNU Lesser General * ! * Public License as published by the Free Software Foundation. * ! * This library is distributed in the hope that it will be useful, but * ! * WITHOUT ANY WARRANTY; without even the implied warranty of * ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * ! * Lesser General Public License for more details. * ! * * ! * You should have received a copy of the GNU General Lesser Public * ! * License along with this library; if not, write to the Free Software * ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */ ! ! /** THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR * ! * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE * ! * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of * ! * harming persons must have provisions for completely removing power * ! * from all motors, etc, before persons enter any danger area. All * ! * machinery must be designed to comply with local and national safety * ! * codes, and the authors of this software can not, and do not, take * ! * any responsibility for such compliance. */ ! ! /** This code was written as part of the EMC HAL project. For more * ! * information, go to www.linuxcnc.org. */ ! #include <stdio.h> /* sprintf() */ #include <stddef.h> /* NULL, needed for rtai_shm.h */ *************** *** 230,234 **** } ! /* get whatever data is available */ retval = write(fifo->fd, buf, size); if (retval < 0) { --- 266,270 ---- } ! /* put whatever data will fit */ retval = write(fifo->fd, buf, size); if (retval < 0) { Index: rtapi.h =================================================================== RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** rtapi.h 9 Aug 2003 19:43:09 -0000 1.13 --- rtapi.h 10 Aug 2003 21:13:04 -0000 1.14 *************** *** 2,5 **** --- 2,45 ---- #define RTAPI_H + /** RTAPI is a library providing a uniform API for several real time * + * operating systems. As of ver 2.0, RTLinux and RTAI are supported. */ + + /** This file, 'rtapi.h', defines the API as seen by realtime tasks. * + * The non-realtime version of the API is defined in 'ulapi.h'. The * + * realtime interface is implemented in files named 'xxx_rtapi.c', * + * where xxx is the RTOS. Likewise, the non-realtime interface is * + * implemented in files named 'xxx_ulapi.c' */ + + /** Copyright (C) 2003 John Kasunich * + * <jmkasunich AT users DOT sourceforge DOT net> * + * Copyright (C) 2003 Paul Corner * + * <paul_c AT users DOT sourceforge DOT net> * + * This library is based on version 1.0, which was released into * + * the public domain by its author, Fred Proctor. Thanks Fred! */ + + /* This library is free software; you can redistribute it and/or * + * modify it under the terms of version 2.1 of the GNU Lesser General * + * Public License as published by the Free Software Foundation. * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */ + + /** THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR * + * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE * + * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of * + * harming persons must have provisions for completely removing power * + * from all motors, etc, before persons enter any danger area. All * + * machinery must be designed to comply with local and national safety * + * codes, and the authors of this software can not, and do not, take * + * any responsibility for such compliance. */ + + /** This code was written as part of the EMC HAL project. For more * + * information, go to www.linuxcnc.org. */ + /** These status codes are returned by many RTAPI functions. */ *************** *** 13,24 **** #define RTAPI_NOTFND -7 /* object not found */ #define RTAPI_FAIL -8 /* operation failed */ ! /* flags for the rtapi_task_start() call */ ! #define RTAPI_NO_FP 0 ! #define RTAPI_USES_FP 1 /** Typedefs for object handles. The structs to which these handles * * refer are private, and may vary from one RTOS to another. * - * In fact, don't even count on handles always being pointers. */ --- 53,62 ---- #define RTAPI_NOTFND -7 /* object not found */ #define RTAPI_FAIL -8 /* operation failed */ + #define RTAPI_LATE -9 /* task could not start when requested */ ! /* NOTE: RTAPI assumes that ints are at least 32 bits long */ /** Typedefs for object handles. The structs to which these handles * * refer are private, and may vary from one RTOS to another. * * In fact, don't even count on handles always being pointers. */ *************** *** 29,48 **** ! /** 'rtapi_init() sets up the RTAPI. It must be called before calling * ! * any rtapi functions. Returns a status code, as defined above. */ ! /* extern int rtapi_init( void ); */ - /** 'ulapi_exit()' shuts down and cleans up the user space interface * - * to the RTAPI. It must be called before program exit. Returns a * - * status code. */ ! /* extern int rtapi_exit( void ); */ ! /** The mapping of actual priority to priority number depends on the * ! * RTOS. The 'rtapi_prio_xxxx()' functions provide a portable way to * ! * determine priority. Priorities range from 'rtapi_prio_lowest()' * * to 'rtapi_prio_highest()', inclusive. To use this API, use one of * * two methods: * --- 67,124 ---- ! /*********************************************************************** ! * GENERAL PURPOSE FUNCTIONS * ! ************************************************************************/ ! /** 'rtapi_init() sets up the RTAPI. It must be called by any module * ! * that intends to use the API, before any other RTAPI calls. Returns a * ! * status code, as defined above. Increments a usage count. */ + extern int rtapi_init(void); ! /** 'rtapi_exit()' shuts down and cleans up the RTAPI. It must be * ! * called prior to exit by any module that called rtapi_init. Returns * ! * a status code. Decrements the usage count maintined by rtapi_init. */ + extern int rtapi_exit(void); ! ! /** 'rtapi_print()' prints a printf style message. Depending on the * ! * RTOS, the message may be printed to stdout, or to the kernel message * ! * log, etc. The calling syntax and format string is similar to printf * ! * except that floating point and longlongs may not be supported. For * ! * some RTOS's, a 256 byte buffer is used, so the format line and * ! * arguments should not produce a line more than 255 bytes long. Does * ! * not block, but can take a fairly long time, depending on the format * ! * string and OS. */ ! ! extern void rtapi_print(const char *fmt, ...); ! ! ! /** 'rtapi_print_dbg()' prints debug messages. Works like rtapi_print * ! * but only prints if 'level' is less than 'rtapi_msg_level'. * ! * 'rtapi_msg_level' is a global. The default is 7, but it may be * ! * changed. The rtapi uses the same levels for its own messages. * ! * The defines below are used for rtapi messages, and recommended for * ! * user messages as well. */ ! ! extern int rtapi_msg_level; ! ! #define RTAPI_MSG_ERR 3 ! #define RTAPI_MSG_WARN 4 ! #define RTAPI_MSG_INFO 6 ! #define RTAPI_MSG_DBG 7 ! ! extern void rtapi_print_msg(int level, const char *fmt, ...); ! ! ! /*********************************************************************** ! * TASK RELATED FUNCTIONS * ! ************************************************************************/ ! ! /** The 'rtapi_prio_xxxx()' functions provide a portable way to set * ! * task priority. The mapping of actual priority to priority number * ! * depends on the RTOS. Priorities range from 'rtapi_prio_lowest()' * * to 'rtapi_prio_highest()', inclusive. To use this API, use one of * * two methods: * *************** *** 65,83 **** * All task periods, whether specified when starting the task, or * * changed later, will be rounded to an integer multiple of the * ! * period set by 'rtapi_clock_set_period()'. Note that there is only * ! * one hardware clock in the PC, and this call stops and resets it. * ! * So this function only needs to be called once, even if there are * ! * multiple realtime tasks in multiple kernel modules. Calling this * * function after realtime tasks have been started may disrupt the * ! * tasks. Returns a status code. The upper limit for the timer period * ! * may be as low as 0.01 seconds, so be sure to check for errors. */ extern int rtapi_clock_set_period(unsigned long int nsecs); ! /** rtapi_get_time returns the time in nano seconds since the timer * ! * started. Returns an integer value as a 2^63 value. */ extern long long int rtapi_get_time(void); /** 'rtapi_task_new()' is the first step in creating a task. Allocs * * and initializes internal rtapi and rtos data related to the task. * --- 141,168 ---- * All task periods, whether specified when starting the task, or * * changed later, will be rounded to an integer multiple of the * ! * period set by 'rtapi_clock_set_period()'. Note that there may be * ! * only one hardware clock in the system, and this call may stop and * ! * resets it. So this function only needs to be called once, even if * ! * there are multiple realtime tasks in multiple modules. Calling this * * function after realtime tasks have been started may disrupt the * ! * tasks. If the call fails, it returns a negative status code. On * ! * success, it either returns 0, or (if the RTOS supports it), the * ! * actual period, which may not be exactly what was requested. The * ! * upper and lower limits for the timer period are RTOS dependent, so * ! * be sure to check for errors. */ extern int rtapi_clock_set_period(unsigned long int nsecs); ! ! /** rtapi_get_time returns the current time in nanoseconds. Depending * ! * on the RTOS, this may be time since boot, or time since the clock * ! * period was set, or some other time. Its absolute value means * ! * nothing, but it is monotonically increasing (at least for the first * ! * 200 years or so), and can be used to schedule future events, or to * ! * time the duration of some activity. Returns a 2^63 value. */ extern long long int rtapi_get_time(void); + /** 'rtapi_task_new()' is the first step in creating a task. Allocs * * and initializes internal rtapi and rtos data related to the task. * *************** *** 107,113 **** * priority functions above. * * 'stacksize' is the amount of stack to be reserved for the task - be * ! * generous, hardware interrupts may use the same stack. 'period_nsec' * ! * is the task period in nanoseconds, which will be rounded to the * ! * nearest multiple of the global clock period. * * If non-zero, 'uses_fp' tells the OS that the task uses floating * * point so it can save the FPU registers on a task switch. Failing * --- 192,213 ---- * priority functions above. * * 'stacksize' is the amount of stack to be reserved for the task - be * ! * generous, hardware interrupts may use the same stack. * ! * 'period_nsec' is the task period in nanoseconds, which will be * ! * rounded to the nearest multiple of the global clock period. If * ! * 'period_nsec' is zero, the task is non-periodic. It will be started * ! * immediately (does not use 'when'), and run until it returns, pauses, * ! * or makes a blocking call. * ! * 'when' is the desired start time for the task. If zero, the task * ! * will start immediately. Otherwise, the task will be scheduled to * ! * start at the appropriate time. If the RTOS doesn't support starting * ! * tasks at a specific time, it will return RTAPI_UNSUP and the task * ! * will not be started. Otherwise, the task will be scheduled to start * ! * at the desired time. If the desired time has already passed, the * ! * function will return RTAPI_LATE, and the task start time is unknown. * ! * Be advised that some RTOSs may execute the task once as soon as it * ! * is scheduled, even if it is not to start until some time in the * ! * future. Tasks should use flags or another mechanism to prevent them * ! * from doing anything prematurely. 'when' uses time as returned by * ! * rtapi_get_time(). * * If non-zero, 'uses_fp' tells the OS that the task uses floating * * point so it can save the FPU registers on a task switch. Failing * *************** *** 118,126 **** * (preferred) or within a realtime task. May block. */ ! /* FIXME - Fred, you have code in the implementations of this function ! that takes special action when 'period_nsec' is zero. What did you have ! in mind with that? Non-periodic tasks that simply run until they either ! return, pause, wait, or block? ! */ extern int rtapi_task_start(rtapi_task_handle task, --- 218,223 ---- * (preferred) or within a realtime task. May block. */ ! #define RTAPI_NO_FP 0 ! #define RTAPI_USES_FP 1 extern int rtapi_task_start(rtapi_task_handle task, *************** *** 129,132 **** --- 226,230 ---- unsigned long int stacksize, unsigned long int period_nsec, + unsigned long long when, unsigned char uses_fp); *************** *** 149,161 **** - /** 'rtapi_task_set_period()' sets the period of a task. The new * - * period is 'period_nsec', rounded to the nearest integer multiple of * - * the global period as set by 'rtapi_clock_set_period()'. Returns a * - * status code. */ - - extern int rtapi_task_set_period(rtapi_task_handle task, - unsigned long int period_nsec); - - /** 'rtapi_wait()' suspends execution of the current task until the * * next period. At the beginning of the next period, execution will * --- 247,250 ---- *************** *** 173,176 **** --- 262,269 ---- + /*********************************************************************** + * SHARED MEMORY RELATED FUNCTIONS * + ************************************************************************/ + /** 'rtapi_shmem_new()' allocates a block of shared memory. 'key' * * identifies the memory block, all modules wishing to access the same * *************** *** 200,259 **** ! /** 'rtapi_print()' prints a printf style message. Depending on the * ! * RTOS, the message may be printed to stdout, or to the kernel message * ! * log, etc. The calling syntax and format string is similar to printf * ! * except that floating point may not be supported. For some RTOS's, * ! * a 256 byte buffer is used, so the format line and arguments should * ! * not produce a line more than 255 bytes long. Does not block, but * ! * can take a fairly long time, depending on the format string and OS. */ ! ! extern void rtapi_print(const char *fmt, ...); ! ! ! /** 'rtapi_print_dbg()' prints a printf style message similar to * ! * to rtapi_print. If debug is less than the value used when the rtapi * ! * was loaded, then the message is printed. */ ! ! extern void rtapi_print_dbg(int debug, const char *fmt, ...); ! ! ! /** 'rtapi_outb() writes 'byte' to 'port'. * ! * Note: This function does nothing on the simulated RTOS. */ ! ! extern void rtapi_outb(unsigned char byte, unsigned int port); ! ! ! /** 'rtapi_inb() gets a byte from 'port'. Returns the byte. * ! * Note: This function always returns zero on the simulated RTOS. */ ! ! extern unsigned char rtapi_inb(unsigned int port); ! ! ! /** 'rtapi_assign_interrupt_handler()' is used to set up a handler for * ! * a hardware interrupt. 'irq' is the interrupt number, and 'handler' * ! * is a pointer to a function taking no arguements and returning void. * ! * 'handler will be called when the interrupt occurs. Returns a status * ! * code. Note: The simulated RTOS does not support interrupts. */ ! ! extern int rtapi_assign_interrupt_handler(unsigned int irq, ! void (*handler) (void)); ! ! ! /** 'rtapi_free_interrupt_handler()' removes an interrupt handler that * ! * was previously installed by rtapi_assign_interrupt_handler(). 'irq' * ! * is the interrupt number. Removing a realtime module without freeing * ! * any handlers it has installed will almost certainly crash the box. * ! * Returns RTAPI_SUCCESS or RTAPI_INVAL. */ ! ! extern int rtapi_free_interrupt_handler(unsigned int irq); ! ! ! /** 'rtapi_enable_interrupt()' and 'rtapi_disable_interrupt()' are * ! * are used to enable and disable interrupts, presumably ones that have * ! * handlers assigned to them. Returns a status code. */ ! ! extern int rtapi_enable_interrupt(unsigned int irq); ! extern int rtapi_disable_interrupt(unsigned int irq); ! /** 'rtapi_sem_new()' creates a realtime semaphore. On success, * --- 293,299 ---- ! /*********************************************************************** ! * SEMAPHORE RELATED FUNCTIONS * ! ************************************************************************/ /** 'rtapi_sem_new()' creates a realtime semaphore. On success, * *************** *** 296,299 **** --- 336,343 ---- + /*********************************************************************** + * FIFO RELATED FUNCTIONS * + ************************************************************************/ + /** 'rtapi_fifo_new()' creates a realtime fifo. 'key' identifies the * * fifo, all modules wishing to access the same fifo must use the same * *************** *** 332,335 **** --- 376,425 ---- char *buf, unsigned long int size); + + /*********************************************************************** + * INTERRUPT RELATED FUNCTIONS * + ************************************************************************/ + + /** 'rtapi_assign_interrupt_handler()' is used to set up a handler for * + * a hardware interrupt. 'irq' is the interrupt number, and 'handler' * + * is a pointer to a function taking no arguements and returning void. * + * 'handler will be called when the interrupt occurs. Returns a status * + * code. Note: The simulated RTOS does not support interrupts. */ + + extern int rtapi_assign_interrupt_handler(unsigned int irq, + void (*handler) (void)); + + + /** 'rtapi_free_interrupt_handler()' removes an interrupt handler that * + * was previously installed by rtapi_assign_interrupt_handler(). 'irq' * + * is the interrupt number. Removing a realtime module without freeing * + * any handlers it has installed will almost certainly crash the box. * + * Returns RTAPI_SUCCESS or RTAPI_INVAL. */ + + extern int rtapi_free_interrupt_handler(unsigned int irq); + + + /** 'rtapi_enable_interrupt()' and 'rtapi_disable_interrupt()' are * + * are used to enable and disable interrupts, presumably ones that have * + * handlers assigned to them. Returns a status code. */ + + extern int rtapi_enable_interrupt(unsigned int irq); + extern int rtapi_disable_interrupt(unsigned int irq); + + + /*********************************************************************** + * I/O RELATED FUNCTIONS * + ************************************************************************/ + + /** 'rtapi_outb() writes 'byte' to 'port'. * + * Note: This function does nothing on the simulated RTOS. */ + + extern void rtapi_outb(unsigned char byte, unsigned int port); + + + /** 'rtapi_inb() gets a byte from 'port'. Returns the byte. * + * Note: This function always returns zero on the simulated RTOS. */ + + extern unsigned char rtapi_inb(unsigned int port); #endif /* RTAPI_H */ Index: rtl_rtapi.c =================================================================== RCS file: /cvsroot/emc/rtapi/src/rtapi/rtl_rtapi.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rtl_rtapi.c 9 Aug 2003 19:43:09 -0000 1.4 --- rtl_rtapi.c 10 Aug 2003 21:13:04 -0000 1.5 *************** *** 5,8 **** --- 5,21 ---- */ + /* This code is hereby released into the public domain. */ + /* NO GUARANTEE OF ANY KIND IS PROVIDED. THE CREATERS OF THIS */ + /* CODE ACCEPT ABSOLUTELY NO LIABILITY FOR ANY HARM OR LOSSES */ + /* RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE TO RELY ON */ + /* SOFTWARE ALONE FOR SAFETY. Any machinery capable of harming */ + /* persons should have provisions for positively removing power */ + /* from all motors, etc, before persons enter any danger area. */ + + /* This code was written as part of the EMC project. For more */ + /* information, go to www.linuxcnc.org. */ + + /* Authors: Fred Proctor, John Kasunich, Paul Corner */ + #include <stdarg.h> /* va_* */ #include <linux/module.h> *************** *** 33,36 **** --- 46,54 ---- #endif + #ifdef MODULE_LICENSE + MODULE_LICENSE("GPL and additional rights"); + /* The additional rights are you can do anything you want. */ + #endif + /* declare vsprintf() explicitly instead of including all of <stdio.h>, since we don't need all of it and it may cause problems */ *************** *** 210,215 **** of a task are corrupted, such that you can ask for a 1 second task, and instead get one that runs every 0.01 sec, with no ! error codes or other way of detecting it. Stupid! To avoid ! this we only allow a timer period of 0.01 seconds or less. Note that you can still run tasks at slower rates, but the timer must run at least 100Hz. */ --- 228,233 ---- of a task are corrupted, such that you can ask for a 1 second task, and instead get one that runs every 0.01 sec, with no ! error codes or other way of detecting it. To avoid this ! we only allow a timer period of 0.01 seconds or less. Note that you can still run tasks at slower rates, but the timer must run at least 100Hz. */ *************** *** 472,497 **** } retval = pthread_wakeup_np(task->ostask); - if (retval != 0) { - return RTAPI_FAIL; - } - return RTAPI_SUCCESS; - } - - - int rtapi_task_set_period(rtapi_task_handle task, - unsigned long int period_nsec) - { - int retval; - - /* validate task handle */ - if (task == NULL) { - return RTAPI_BADH; - } - if (task->magic != TASK_MAGIC) { - return RTAPI_BADH; - } - - retval = pthread_make_periodic_np(*((pthread_t *) task), - gethrtime() + period_nsec, period_nsec); if (retval != 0) { return RTAPI_FAIL; --- 490,493 ---- Index: rtl_ulapi.c =================================================================== RCS file: /cvsroot/emc/rtapi/src/rtapi/rtl_ulapi.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rtl_ulapi.c 9 Aug 2003 19:43:09 -0000 1.4 --- rtl_ulapi.c 10 Aug 2003 21:13:04 -0000 1.5 *************** *** 4,7 **** --- 4,22 ---- Implementation of user-level API to RTL modules */ + + /* This code is hereby released into the public domain. */ + /* NO GUARANTEE OF ANY KIND IS PROVIDED. THE CREATERS OF THIS */ + /* CODE ACCEPT ABSOLUTELY NO LIABILITY FOR ANY HARM OR LOSSES */ + /* RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE TO RELY ON */ + /* SOFTWARE ALONE FOR SAFETY. Any machinery capable of harming */ + /* persons should have provisions for positively removing power */ + /* from all motors, etc, before persons enter any danger area. */ + + /* This code was written as part of the EMC project. For more */ + /* information, go to www.linuxcnc.org. */ + + /* Authors: Fred Proctor, John Kasunich, Paul Corner */ + + #include <stdio.h> /* sprintf() */ #include <stddef.h> /* size_t, needed by mbuff.h */ *************** *** 255,259 **** /* get whatever data is available */ retval = read(fifo->fd, buf, size); ! if (retval < 0) { return ULAPI_FAIL; } --- 270,274 ---- /* get whatever data is available */ retval = read(fifo->fd, buf, size); ! if (retval <= 0) { return ULAPI_FAIL; } *************** *** 278,282 **** } ! /* get whatever data is available */ retval = write(fifo->fd, buf, size); if (retval < 0) { --- 293,297 ---- } ! /* put whatever data will fit */ retval = write(fifo->fd, buf, size); if (retval < 0) { Index: ulapi.h =================================================================== RCS file: /cvsroot/emc/rtapi/src/rtapi/ulapi.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ulapi.h 9 Aug 2003 19:43:09 -0000 1.6 --- ulapi.h 10 Aug 2003 21:13:04 -0000 1.7 *************** *** 2,5 **** --- 2,45 ---- #define ULAPI_H + /** RTAPI is a library providing a uniform API for several real time * + * operating systems. As of ver 2.0, RTLinux and RTAI are supported. */ + + /** This file, 'ulapi.h', defines the API as seen by non-realtime * + * programs running in user space. The realtime version of the API is * + * defined in 'rtapi.h'. The non-realtime interface is implemented in * + * files named 'xxx_ulapi.c', where xxx is the RTOS. Likewise, the * + * realtime interface is implemented in files named 'xxx_rtapi.c' */ + + /** Copyright (C) 2003 John Kasunich * + * <jmkasunich AT users DOT sourceforge DOT net> * + * Copyright (C) 2003 Paul Corner * + * <paul_c AT users DOT sourceforge DOT net> * + * This library is based on version 1.0, which was released into * + * the public domain by its author, Fred Proctor. Thanks Fred! */ + + /* This library is free software; you can redistribute it and/or * + * modify it under the terms of version 2.1 of the GNU Lesser General * + * Public License as published by the Free Software Foundation. * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */ + + /** THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR * + * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE * + * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of * + * harming persons must have provisions for completely removing power * + * from all motors, etc, before persons enter any danger area. All * + * machinery must be designed to comply with local and national safety * + * codes, and the authors of this software can not, and do not, take * + * any responsibility for such compliance. */ + + /** This code was written as part of the EMC HAL project. For more * + * information, go to www.linuxcnc.org. */ + /** These status codes are returned by many ULAPI functions. */ *************** *** 17,21 **** /** Typedefs for object handles. The structs to which these handles * ! * refer are private, and may vary from one RTOS to another. */ typedef struct ulapi_shmem *ulapi_shmem_handle; --- 57,62 ---- /** Typedefs for object handles. The structs to which these handles * ! * refer are private, and may vary from one RTOS to another. * ! * In fact, don't even count on handles always being pointers. */ typedef struct ulapi_shmem *ulapi_shmem_handle; *************** *** 23,26 **** --- 64,71 ---- + /*********************************************************************** + * GENERAL PURPOSE FUNCTIONS * + ************************************************************************/ + /** 'ulapi_init() sets up the user space interface to the RTAPI. It * * must be called before calling any ulapi functions. Returns a statis * *************** *** 37,40 **** --- 82,89 ---- + /*********************************************************************** + * SHARED MEMORY RELATED FUNCTIONS * + ************************************************************************/ + /** 'ulapi_shmem_new()' allocates a block of shared memory. 'key' * * identifies the memory block, all modules wishing to access the same * *************** *** 61,64 **** --- 110,117 ---- extern int ulapi_shmem_delete(ulapi_shmem_handle shmem); + + /*********************************************************************** + * FIFO RELATED FUNCTIONS * + ************************************************************************/ /** 'ulapi_fifo_new()' opens a fifo for communication with realtime * |