|
From: <pa...@us...> - 2003-08-09 19:43:13
|
Update of /cvsroot/emc/rtapi/src/rtapi
In directory sc8-pr-cvs1:/tmp/cvs-serv31130
Modified Files:
rtai_rtapi.c rtapi.h rtl_rtapi.c rtl_ulapi.c sim_rtapi.c
sim_ulapi.c ulapi.h
Log Message:
/proc entry added
Index: rtai_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_rtapi.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** rtai_rtapi.c 5 Aug 2003 03:51:00 -0000 1.13
--- rtai_rtapi.c 9 Aug 2003 19:43:09 -0000 1.14
***************
*** 8,16 ****
#include <linux/module.h>
#include <linux/kernel.h>
! #include <linux/slab.h> /* replaces malloc.h in recent kernels */
#include <rtai.h>
#include <rtai_sched.h>
#include <rtai_shm.h>
#include <rtai_fifos.h>
#ifndef KERNEL_VERSION
--- 8,18 ----
#include <linux/module.h>
#include <linux/kernel.h>
! #include <linux/proc_fs.h> /* So we can use the /proc file system */
! #include <linux/slab.h> /* replaces malloc.h in recent kernels */
#include <rtai.h>
#include <rtai_sched.h>
#include <rtai_shm.h>
#include <rtai_fifos.h>
+ #include <rtai_proc_fs.h> /* handy proc_fs print macros */
#ifndef KERNEL_VERSION
***************
*** 72,79 ****
static int fifo_usage_count = 0;
static int int_usage_count = 0;
!
/* Flag used to keep track of timer state */
static int timer_running = 0;
/* Priority functions. RTAI uses 0 as the highest priority, as the
number increases, the actual priority of the task decreases. */
--- 74,105 ----
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. */
+ #ifdef CONFIG_PROC_FS
+ static int proc_read(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+ {
+ PROC_PRINT_VARS;
+ PROC_PRINT("******* RTAI rtapi usage *******\n");
+ PROC_PRINT(" Version = $Revision$\n");
+ PROC_PRINT(" Tasks running = %i\n", task_usage_count);
+ PROC_PRINT(" Shared memory = %i\n", shmem_usage_count);
+ PROC_PRINT(" FIFO count = %i\n", fifo_usage_count);
+ 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");
+ PROC_PRINT_DONE;
+ }
+ #endif
+
/* Priority functions. RTAI uses 0 as the highest priority, as the
number increases, the actual priority of the task decreases. */
***************
*** 120,127 ****
-
static int rtapi_init(void)
{
! rtapi_print("RTAPI: Initing\n");
task_usage_count = 0;
shmem_usage_count = 0;
--- 146,161 ----
static int rtapi_init(void)
{
! /* register a proc entry */
! #ifdef CONFIG_PROC_FS
! create_proc_read_entry("rtai/rtapi", /* name */
! 0, /* default mode */
! NULL, /* parent dir */
! proc_read, /* function */
! NULL /* client data */
! );
! #endif
! rtapi_print_dbg(VERBOSE, "RTAPI: Initing\n");
task_usage_count = 0;
shmem_usage_count = 0;
***************
*** 137,157 ****
static int rtapi_exit(void)
{
! if (task_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d task(s) allocated but not deleted", task_usage_count);
}
! if (shmem_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d shared memory block(s) allocated but not deleted", shmem_usage_count);
}
! if (sem_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d semaphores(s) allocated but not deleted", sem_usage_count);
}
! if (fifo_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d fifo(s) allocated but not deleted", fifo_usage_count);
}
! if (int_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d interrupt handler(s) installed but not removed", int_usage_count);
}
! if (timer_running != 0 ) {
stop_rt_timer();
}
rtapi_print("RTAPI: Shutting down\n");
--- 171,206 ----
static int rtapi_exit(void)
{
! /* Remove proc dir entry */
! #ifdef CONFIG_PROC_FS
! remove_proc_entry("rtai/rtapi", NULL);
! #endif
! if (task_usage_count != 0) {
! rtapi_print_dbg(VERBOSE,
! "RTAPI: ERROR: %d task(s) allocated but not deleted\n",
! task_usage_count);
}
! if (shmem_usage_count != 0) {
! rtapi_print_dbg(VERBOSE,
! "RTAPI: ERROR: %d shared memory block(s) allocated but not deleted\n",
! shmem_usage_count);
}
! if (sem_usage_count != 0) {
! rtapi_print_dbg(VERBOSE,
! "RTAPI: ERROR: %d semaphores(s) allocated but not deleted\n",
! sem_usage_count);
}
! if (fifo_usage_count != 0) {
! rtapi_print_dbg(VERBOSE,
! "RTAPI: ERROR: %d fifo(s) allocated but not deleted\n",
! fifo_usage_count);
}
! if (int_usage_count != 0) {
! rtapi_print_dbg(VERBOSE,
! "RTAPI: ERROR: %d interrupt handler(s) installed but not removed\n",
! int_usage_count);
}
! if (timer_running != 0) {
stop_rt_timer();
+ rt_free_timer();
}
rtapi_print("RTAPI: Shutting down\n");
***************
*** 175,191 ****
/* limit to a maximum of 1 second (note that RTLinux only
! allows 0.01 second, so for portability, callers should
! always ask for 0.01 second or less */
! if ( nsecs > 1000000000L ) {
return RTAPI_INVAL;
}
- if ( VERBOSE ) {
- rtapi_print ( "RTAPI: clock_set_period ( %ld )\n", nsecs );
- }
timer_running = 1;
rt_set_periodic_mode();
! start_rt_timer(nano2count((RTIME) nsecs));
return RTAPI_SUCCESS;
}
--- 224,242 ----
/* limit to a maximum of 1 second (note that RTLinux only
! allows 0.01 second, so for portability, callers should
! always ask for 0.01 second or less */
! if (nsecs > 1000000000L) {
return RTAPI_INVAL;
}
timer_running = 1;
rt_set_periodic_mode();
! timer_period = start_rt_timer(nano2count((RTIME) nsecs));
!
! rtapi_print_dbg(VERBOSE,
! "RTAPI: clock_set_period ( %ld ) - Actual = %inSec\n",
! nsecs, timer_period);
!
return RTAPI_SUCCESS;
}
***************
*** 219,225 ****
task_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_task %p, count = %d\n", task, task_usage_count );
! }
return RTAPI_SUCCESS;
--- 270,275 ----
task_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_task %p, count = %d\n", task,
! task_usage_count);
return RTAPI_SUCCESS;
***************
*** 243,249 ****
task_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_task %p, count = %d\n", task, task_usage_count );
! }
return RTAPI_SUCCESS;
--- 293,298 ----
task_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_task %p, count = %d\n", task,
! task_usage_count);
return RTAPI_SUCCESS;
***************
*** 301,307 ****
}
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: start_task %p\n", task );
! }
return RTAPI_SUCCESS;
--- 350,354 ----
}
! rtapi_print_dbg(VERBOSE, "RTAPI: start_task %p\n", task);
return RTAPI_SUCCESS;
***************
*** 325,331 ****
return RTAPI_FAIL;
}
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: stop_task %p\n", task );
! }
return RTAPI_SUCCESS;
--- 372,376 ----
return RTAPI_FAIL;
}
! rtapi_print_dbg(VERBOSE, "RTAPI: stop_task %p\n", task);
return RTAPI_SUCCESS;
***************
*** 465,471 ****
shmem_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_shmem %p, key = %d, count = %d\n", shmem, key, shmem_usage_count );
! }
return RTAPI_SUCCESS;
--- 510,515 ----
shmem_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_shmem %p, key = %d, count = %d\n",
! shmem, key, shmem_usage_count);
return RTAPI_SUCCESS;
***************
*** 508,514 ****
shmem_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_shmem %p, count = %d\n", shmem, shmem_usage_count );
! }
return RTAPI_SUCCESS;
--- 552,557 ----
shmem_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_shmem %p, count = %d\n", shmem,
! shmem_usage_count);
return RTAPI_SUCCESS;
***************
*** 532,535 ****
--- 575,592 ----
+ void rtapi_print_dbg(int dbg, const char *fmt, ...)
+ {
+ va_list args;
+ enum { BUFFERLEN = 256 };
+ static char buffer[BUFFERLEN];
+
+ if (dbg < debug) {
+ va_start(args, fmt);
+ vsprintf(buffer, fmt, args);
+ rt_printk(buffer);
+ va_end(args);
+ }
+ }
+
void rtapi_outb(unsigned char byte, unsigned int port)
{
***************
*** 556,566 ****
}
}
/* increment the usage counter */
int_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: assign_interrupt_handler for int %d, count = %d\n", irq, int_usage_count );
! }
return RTAPI_SUCCESS;
--- 613,626 ----
}
}
+ rtapi_print_dbg(VERBOSE,
+ "\n\nRTAPI: assign_interrupt_handler for int %d, count = %d\n",
+ irq, int_usage_count);
/* increment the usage counter */
int_usage_count++;
! rtapi_print_dbg(VERBOSE,
! "RTAPI: assign_interrupt_handler for int %d, count = %d\n",
! irq, int_usage_count);
return RTAPI_SUCCESS;
***************
*** 581,587 ****
int_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: free_interrupt_handler for int %d, count = %d\n", irq, int_usage_count );
! }
return RTAPI_SUCCESS;
--- 641,647 ----
int_usage_count--;
! rtapi_print_dbg(VERBOSE,
! "RTAPI: free_interrupt_handler for int %d, count = %d\n",
! irq, int_usage_count);
return RTAPI_SUCCESS;
***************
*** 642,648 ****
sem_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_sem %p, count = %d\n", sem, sem_usage_count );
! }
return RTAPI_SUCCESS;
--- 702,707 ----
sem_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_sem %p, count = %d\n", sem,
! sem_usage_count);
return RTAPI_SUCCESS;
***************
*** 669,675 ****
sem_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_sem %p, count = %d\n", sem, sem_usage_count );
! }
return RTAPI_SUCCESS;
--- 728,733 ----
sem_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_sem %p, count = %d\n", sem,
! sem_usage_count);
return RTAPI_SUCCESS;
***************
*** 767,773 ****
fifo_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_fifo %p, count = %d\n", fifo, fifo_usage_count );
! }
return RTAPI_SUCCESS;
--- 825,830 ----
fifo_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_fifo %p, count = %d\n", fifo,
! fifo_usage_count);
return RTAPI_SUCCESS;
***************
*** 794,800 ****
fifo_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_fifo %p, count = %d\n", fifo, fifo_usage_count );
! }
return RTAPI_SUCCESS;
--- 851,856 ----
fifo_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_fifo %p, count = %d\n", fifo,
! fifo_usage_count);
return RTAPI_SUCCESS;
Index: rtapi.h
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** rtapi.h 5 Aug 2003 03:51:00 -0000 1.12
--- rtapi.h 9 Aug 2003 19:43:09 -0000 1.13
***************
*** 4,16 ****
/** These status codes are returned by many RTAPI functions. */
! #define RTAPI_SUCCESS 0 /* call successfull */
! #define RTAPI_UNSUP -1 /* function not supported */
! #define RTAPI_BADH -2 /* bad task, shmem, sem, or fifo handle */
! #define RTAPI_INVAL -3 /* invalid argument*/
! #define RTAPI_NOMEM -4 /* not enough memory */
! #define RTAPI_PERM -5 /* permission denied */
! #define RTAPI_BUSY -6 /* resource is busy or locked */
! #define RTAPI_NOTFND -7 /* object not found */
! #define RTAPI_FAIL -8 /* operation failed */
/* flags for the rtapi_task_start() call */
--- 4,16 ----
/** These status codes are returned by many RTAPI functions. */
! #define RTAPI_SUCCESS 0 /* call successfull */
! #define RTAPI_UNSUP -1 /* function not supported */
! #define RTAPI_BADH -2 /* bad task, shmem, sem, or fifo handle */
! #define RTAPI_INVAL -3 /* invalid argument */
! #define RTAPI_NOMEM -4 /* not enough memory */
! #define RTAPI_PERM -5 /* permission denied */
! #define RTAPI_BUSY -6 /* resource is busy or locked */
! #define RTAPI_NOTFND -7 /* object not found */
! #define RTAPI_FAIL -8 /* operation failed */
/* flags for the rtapi_task_start() call */
***************
*** 23,30 ****
* In fact, don't even count on handles always being pointers. */
! typedef struct rtapi_task *rtapi_task_handle;
! typedef struct rtapi_shmem *rtapi_shmem_handle;
! typedef struct rtapi_sem *rtapi_sem_handle;
! typedef struct rtapi_fifo *rtapi_fifo_handle;
--- 23,30 ----
* In fact, don't even count on handles always being pointers. */
! typedef struct rtapi_task *rtapi_task_handle;
! typedef struct rtapi_shmem *rtapi_shmem_handle;
! typedef struct rtapi_sem *rtapi_sem_handle;
! typedef struct rtapi_fifo *rtapi_fifo_handle;
***************
*** 56,63 ****
* 'rtapi_prio_next_lower(previous)'. */
! extern int rtapi_prio_highest( void );
! extern int rtapi_prio_lowest( void );
! extern int rtapi_prio_next_higher( int prio );
! extern int rtapi_prio_next_lower( int prio );
--- 56,63 ----
* 'rtapi_prio_next_lower(previous)'. */
! extern int rtapi_prio_highest(void);
! extern int rtapi_prio_lowest(void);
! extern int rtapi_prio_next_higher(int prio);
! extern int rtapi_prio_next_lower(int prio);
***************
*** 86,90 ****
* subsequent calls that need to act on the task. */
! extern int rtapi_task_new( rtapi_task_handle *taskptr );
--- 86,90 ----
* subsequent calls that need to act on the task. */
! extern int rtapi_task_new(rtapi_task_handle * taskptr);
***************
*** 96,100 ****
* should not attempt to delete itself! */
! extern int rtapi_task_delete( rtapi_task_handle task );
--- 96,100 ----
* should not attempt to delete itself! */
! extern int rtapi_task_delete(rtapi_task_handle task);
***************
*** 124,133 ****
*/
! extern int rtapi_task_start( rtapi_task_handle task,
! void (*taskcode)( int ),
! int arg, int prio,
! unsigned long int stacksize,
! unsigned long int period_nsec,
! unsigned char uses_fp );
--- 124,133 ----
*/
! extern int rtapi_task_start(rtapi_task_handle task,
! void (*taskcode) (int),
! int arg, int prio,
! unsigned long int stacksize,
! unsigned long int period_nsec,
! unsigned char uses_fp);
***************
*** 137,141 ****
* task - a task should not attempt to stop itself! */
! extern int rtapi_task_stop( rtapi_task_handle task );
--- 137,141 ----
* task - a task should not attempt to stop itself! */
! extern int rtapi_task_stop(rtapi_task_handle task);
***************
*** 145,150 ****
* itself. Returns a status code. */
! extern int rtapi_task_pause( rtapi_task_handle task );
! extern int rtapi_task_resume( rtapi_task_handle task );
--- 145,150 ----
* itself. Returns a status code. */
! extern int rtapi_task_pause(rtapi_task_handle task);
! extern int rtapi_task_resume(rtapi_task_handle task);
***************
*** 154,159 ****
* status code. */
! extern int rtapi_task_set_period( rtapi_task_handle task,
! unsigned long int period_nsec );
--- 154,159 ----
* status code. */
! extern int rtapi_task_set_period(rtapi_task_handle task,
! unsigned long int period_nsec);
***************
*** 164,168 ****
* Returns a status code. */
! extern int rtapi_wait( void );
--- 164,168 ----
* Returns a status code. */
! extern int rtapi_wait(void);
***************
*** 170,174 ****
/* the current task. Call only from a task. Returns a status code. */
! extern int rtapi_task_get_handle( rtapi_task_handle *taskptr );
--- 170,174 ----
/* the current task. Call only from a task. Returns a status code. */
! extern int rtapi_task_get_handle(rtapi_task_handle * taskptr);
***************
*** 184,189 ****
* Returns a status code. */
! extern int rtapi_shmem_new( int key, unsigned int size,
! rtapi_shmem_handle *shmemptr );
--- 184,189 ----
* Returns a status code. */
! extern int rtapi_shmem_new(int key, unsigned int size,
! rtapi_shmem_handle * shmemptr);
***************
*** 191,195 ****
* shared memory block 'mbuf'. Returns a status code. */
! extern int rtapi_shmem_getptr ( rtapi_shmem_handle shmem, void **ptr );
--- 191,195 ----
* shared memory block 'mbuf'. Returns a status code. */
! extern int rtapi_shmem_getptr(rtapi_shmem_handle shmem, void **ptr);
***************
*** 197,201 ****
* Returns a status code. */
! extern int rtapi_shmem_delete( rtapi_shmem_handle shmem );
--- 197,201 ----
* Returns a status code. */
! extern int rtapi_shmem_delete(rtapi_shmem_handle shmem);
***************
*** 208,212 ****
* can take a fairly long time, depending on the format string and OS. */
! extern void rtapi_print( const char *fmt, ... );
--- 208,219 ----
* 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, ...);
***************
*** 214,218 ****
* Note: This function does nothing on the simulated RTOS. */
! extern void rtapi_outb( unsigned char byte, unsigned int port );
--- 221,225 ----
* Note: This function does nothing on the simulated RTOS. */
! extern void rtapi_outb(unsigned char byte, unsigned int port);
***************
*** 220,224 ****
* Note: This function always returns zero on the simulated RTOS. */
! extern unsigned char rtapi_inb( unsigned int port );
--- 227,231 ----
* Note: This function always returns zero on the simulated RTOS. */
! extern unsigned char rtapi_inb(unsigned int port);
***************
*** 229,234 ****
* code. Note: The simulated RTOS does not support interrupts. */
! extern int rtapi_assign_interrupt_handler( unsigned int irq,
! void (*handler) (void) );
--- 236,241 ----
* code. Note: The simulated RTOS does not support interrupts. */
! extern int rtapi_assign_interrupt_handler(unsigned int irq,
! void (*handler) (void));
***************
*** 239,243 ****
* Returns RTAPI_SUCCESS or RTAPI_INVAL. */
! extern int rtapi_free_interrupt_handler( unsigned int irq );
--- 246,250 ----
* Returns RTAPI_SUCCESS or RTAPI_INVAL. */
! extern int rtapi_free_interrupt_handler(unsigned int irq);
***************
*** 246,251 ****
* handlers assigned to them. Returns a status code. */
! extern int rtapi_enable_interrupt( unsigned int irq );
! extern int rtapi_disable_interrupt( unsigned int irq );
--- 253,258 ----
* handlers assigned to them. Returns a status code. */
! extern int rtapi_enable_interrupt(unsigned int irq);
! extern int rtapi_disable_interrupt(unsigned int irq);
***************
*** 255,259 ****
* Returns a status code. */
! extern int rtapi_sem_new( rtapi_sem_handle *semptr );
--- 262,266 ----
* Returns a status code. */
! extern int rtapi_sem_new(rtapi_sem_handle * semptr);
***************
*** 262,266 ****
* resume execution. Returns a status code. */
! extern int rtapi_sem_delete( rtapi_sem_handle sem );
--- 269,273 ----
* resume execution. Returns a status code. */
! extern int rtapi_sem_delete(rtapi_sem_handle sem);
***************
*** 269,273 ****
* higher priority task will begin to run. Returns a status code. */
! extern int rtapi_sem_give( rtapi_sem_handle sem );
--- 276,280 ----
* higher priority task will begin to run. Returns a status code. */
! extern int rtapi_sem_give(rtapi_sem_handle sem);
***************
*** 277,281 ****
* until the semaphore is unlocked, then it returns RTAPI_SUCCESS. */
! extern int rtapi_sem_take( rtapi_sem_handle sem );
--- 284,288 ----
* until the semaphore is unlocked, then it returns RTAPI_SUCCESS. */
! extern int rtapi_sem_take(rtapi_sem_handle sem);
***************
*** 286,290 ****
* decide how to deal with the situation. */
! extern int rtapi_sem_try( rtapi_sem_handle sem );
--- 293,297 ----
* decide how to deal with the situation. */
! extern int rtapi_sem_try(rtapi_sem_handle sem);
***************
*** 296,301 ****
* code. */
! extern int rtapi_fifo_new( int key, unsigned long int size,
! rtapi_fifo_handle *fifoptr );
--- 303,308 ----
* code. */
! extern int rtapi_fifo_new(int key, unsigned long int size,
! rtapi_fifo_handle * fifoptr);
***************
*** 303,307 ****
* It destroys the fifo 'fifo'. Returns a status code. */
! extern int rtapi_fifo_delete( rtapi_fifo_handle fifo );
--- 310,314 ----
* It destroys the fifo 'fifo'. Returns a status code. */
! extern int rtapi_fifo_delete(rtapi_fifo_handle fifo);
***************
*** 312,317 ****
* available, and return that count (which could be zero). */
! extern int rtapi_fifo_read( rtapi_fifo_handle fifo,
! char *buf, unsigned long int size);
--- 319,324 ----
* available, and return that count (which could be zero). */
! extern int rtapi_fifo_read(rtapi_fifo_handle fifo,
! char *buf, unsigned long int size);
***************
*** 322,327 ****
* bytes as it can and return that count (which may be zero). */
! extern int rtapi_fifo_write( rtapi_fifo_handle fifo,
! char *buf, unsigned long int size);
--- 329,334 ----
* bytes as it can and return that count (which may be zero). */
! extern int rtapi_fifo_write(rtapi_fifo_handle fifo,
! char *buf, unsigned long int size);
Index: rtl_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtl_rtapi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rtl_rtapi.c 5 Aug 2003 03:51:00 -0000 1.3
--- rtl_rtapi.c 9 Aug 2003 19:43:09 -0000 1.4
***************
*** 8,12 ****
#include <linux/module.h>
#include <linux/kernel.h>
! #include <linux/slab.h> /* replaces malloc.h in recent kernels */
#include <rtl.h> /* top level config */
#include <rtl_sched.h> /* rtl_getschedclock(),
--- 8,12 ----
#include <linux/module.h>
#include <linux/kernel.h>
! #include <linux/slab.h> /* replaces malloc.h in recent kernels */
#include <rtl.h> /* top level config */
#include <rtl_sched.h> /* rtl_getschedclock(),
***************
*** 48,53 ****
int magic; /* to check for valid handle */
pthread_t ostask; /* OS specific task data */
! int arg; /* argument for task function */
! void (*taskcode)( int ); /* pointer to task function */
};
--- 48,53 ----
int magic; /* to check for valid handle */
pthread_t ostask; /* OS specific task data */
! int arg; /* argument for task function */
! void (*taskcode) (int); /* pointer to task function */
};
***************
*** 86,89 ****
--- 86,93 ----
static int timer_running = 0;
+ int debug = 1;
+ MODULE_PARM(debug, "i");
+ MODULE_PARM_DESC(debug, "Sets the verbosity of the debug prints");
+
/* maximum number of tasks */
#define RTAPI_MAX_TASKS 64
***************
*** 150,154 ****
int_usage_count = 0;
timer_running = 0;
! for ( n = 0 ; n < RTAPI_MAX_TASKS ; n++ ) {
task_array[n] = NULL;
}
--- 154,158 ----
int_usage_count = 0;
timer_running = 0;
! for (n = 0; n < RTAPI_MAX_TASKS; n++) {
task_array[n] = NULL;
}
***************
*** 159,181 ****
static int rtapi_exit(void)
{
! if (task_usage_count != 0 ) {
rtapi_print("RTAPI: ERROR: %d task(s) allocated but not deleted",
! task_usage_count);
}
! if (shmem_usage_count != 0 ) {
rtapi_print("RTAPI: ERROR: %d shmem block(s) allocated but not deleted",
! shmem_usage_count);
}
! if (sem_usage_count != 0 ) {
rtapi_print("RTAPI: ERROR: %d semaphores(s) allocated but not deleted",
! sem_usage_count);
}
! if (fifo_usage_count != 0 ) {
rtapi_print("RTAPI: ERROR: %d fifo(s) allocated but not deleted",
! fifo_usage_count);
}
! if (int_usage_count != 0 ) {
rtapi_print("RTAPI: ERROR: %d IRQ handler(s) installed but not removed",
! int_usage_count);
}
rtapi_print("RTAPI: Shutting down\n");
--- 163,185 ----
static int rtapi_exit(void)
{
! if (task_usage_count != 0) {
rtapi_print("RTAPI: ERROR: %d task(s) allocated but not deleted",
! task_usage_count);
}
! if (shmem_usage_count != 0) {
rtapi_print("RTAPI: ERROR: %d shmem block(s) allocated but not deleted",
! shmem_usage_count);
}
! if (sem_usage_count != 0) {
rtapi_print("RTAPI: ERROR: %d semaphores(s) allocated but not deleted",
! sem_usage_count);
}
! if (fifo_usage_count != 0) {
rtapi_print("RTAPI: ERROR: %d fifo(s) allocated but not deleted",
! fifo_usage_count);
}
! if (int_usage_count != 0) {
rtapi_print("RTAPI: ERROR: %d IRQ handler(s) installed but not removed",
! int_usage_count);
}
rtapi_print("RTAPI: Shutting down\n");
***************
*** 197,226 ****
int rtapi_clock_set_period(unsigned long int nsecs)
{
! int retval;
/* The RTL implementation of setclockmode is lame. If you
! specify a period that is too high, (like 1 second) it prints
! a message to the system log file, but instead of returning
! an error code, it sets the timer to 100Hz and returns success!
! If that's not bad enough, subsequent calls to set the period
! 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. */
! if ( nsecs > 10000000L ) {
return RTAPI_INVAL;
}
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: clock_set_period ( %ld )\n", nsecs );
! }
timer_running = 1;
retval = rtl_setclockmode(rtl_getschedclock(),
! RTL_CLOCK_MODE_PERIODIC, nsecs);
! if ( retval != 0 ) {
return RTAPI_INVAL;
}
--- 201,229 ----
int rtapi_clock_set_period(unsigned long int nsecs)
{
! int retval;
/* The RTL implementation of setclockmode is lame. If you
! specify a period that is too high, (like 1 second) it prints
! a message to the system log file, but instead of returning
! an error code, it sets the timer to 100Hz and returns success!
! If that's not bad enough, subsequent calls to set the period
! 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. */
! if (nsecs > 10000000L) {
return RTAPI_INVAL;
}
! rtapi_print_dbg(VERBOSE, "RTAPI: clock_set_period ( %ld )\n", nsecs);
!
timer_running = 1;
retval = rtl_setclockmode(rtl_getschedclock(),
! RTL_CLOCK_MODE_PERIODIC, nsecs);
! if (retval != 0) {
return RTAPI_INVAL;
}
***************
*** 246,253 ****
/* find empty spot in task array */
n = 0;
! while ( ( n < RTAPI_MAX_TASKS ) && ( task_array[n] != NULL ) ) {
n++;
}
! if ( n == RTAPI_MAX_TASKS ) {
return RTAPI_NOMEM;
}
--- 249,256 ----
/* find empty spot in task array */
n = 0;
! while ((n < RTAPI_MAX_TASKS) && (task_array[n] != NULL)) {
n++;
}
! if (n == RTAPI_MAX_TASKS) {
return RTAPI_NOMEM;
}
***************
*** 271,278 ****
task_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_task %p, count = %d\n",
! task, task_usage_count );
! }
return RTAPI_SUCCESS;
--- 274,279 ----
task_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_task %p, count = %d\n", task,
! task_usage_count);
return RTAPI_SUCCESS;
***************
*** 294,306 ****
/* find entry in task array */
n = 0;
! while ( ( n < RTAPI_MAX_TASKS ) && ( task_array[n] != task ) ) {
n++;
}
! if ( n == RTAPI_MAX_TASKS ) {
return RTAPI_INVAL;
}
/* this is from Fred's original code - it appears to stop the
! task, but the task should already be stopped... is it needed? */
pthread_cancel(task->ostask);
pthread_join(task->ostask, NULL);
--- 295,307 ----
/* find entry in task array */
n = 0;
! while ((n < RTAPI_MAX_TASKS) && (task_array[n] != task)) {
n++;
}
! if (n == RTAPI_MAX_TASKS) {
return RTAPI_INVAL;
}
/* this is from Fred's original code - it appears to stop the
! task, but the task should already be stopped... is it needed? */
pthread_cancel(task->ostask);
pthread_join(task->ostask, NULL);
***************
*** 316,323 ****
task_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_task %p, count = %d\n",
! task, task_usage_count );
! }
return RTAPI_SUCCESS;
--- 317,322 ----
task_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_task %p, count = %d\n",
! task, task_usage_count);
return RTAPI_SUCCESS;
***************
*** 329,340 ****
/* we solve this with a wrapper function that meets pthread's needs */
! static void *wrapper ( void *arg )
{
! rtapi_task_handle task;
/* use the argument to point to the task data */
task = arg;
/* call the task function with the task argument */
! (task->taskcode)( task->arg );
/* done */
return NULL;
--- 328,339 ----
/* we solve this with a wrapper function that meets pthread's needs */
! static void *wrapper(void *arg)
{
! rtapi_task_handle task;
/* use the argument to point to the task data */
task = arg;
/* call the task function with the task argument */
! (task->taskcode) (task->arg);
/* done */
return NULL;
***************
*** 366,370 ****
/* set up task attributes */
retval = pthread_attr_init(&attr);
! if ( retval != 0 ) {
return RTAPI_NOMEM;
}
--- 365,369 ----
/* set up task attributes */
retval = pthread_attr_init(&attr);
! if (retval != 0) {
return RTAPI_NOMEM;
}
***************
*** 372,389 ****
sched_param.sched_priority = prio;
retval = pthread_attr_setschedparam(&attr, &sched_param);
! if ( retval != 0 ) {
return RTAPI_INVAL;
}
/* set up the task itself */
/* create the thread - use the wrapper function, pass it a pointer
! to the task structure so it can call the actual task function */
task->taskcode = taskcode;
task->arg = arg;
! retval = pthread_create(&(task->ostask), &attr, wrapper, (void *)task );
! if ( retval != 0 ) {
! if ( retval == EAGAIN ) {
return RTAPI_NOMEM;
}
! if ( retval == EPERM ) {
return RTAPI_PERM;
}
--- 371,388 ----
sched_param.sched_priority = prio;
retval = pthread_attr_setschedparam(&attr, &sched_param);
! if (retval != 0) {
return RTAPI_INVAL;
}
/* set up the task itself */
/* create the thread - use the wrapper function, pass it a pointer
! to the task structure so it can call the actual task function */
task->taskcode = taskcode;
task->arg = arg;
! retval = pthread_create(&(task->ostask), &attr, wrapper, (void *) task);
! if (retval != 0) {
! if (retval == EAGAIN) {
return RTAPI_NOMEM;
}
! if (retval == EPERM) {
return RTAPI_PERM;
}
***************
*** 392,396 ****
pthread_setfp_np(task->ostask, (int) uses_fp);
retval = pthread_setschedparam(task->ostask, SCHED_FIFO, &sched_param);
! if ( retval != 0 ) {
return RTAPI_FAIL;
}
--- 391,395 ----
pthread_setfp_np(task->ostask, (int) uses_fp);
retval = pthread_setschedparam(task->ostask, SCHED_FIFO, &sched_param);
! if (retval != 0) {
return RTAPI_FAIL;
}
***************
*** 400,404 ****
/* start the task in periodic mode */
retval = pthread_make_periodic_np(task->ostask,
! gethrtime()+period_nsec, (hrtime_t)period_nsec);
if (retval != 0) {
return RTAPI_FAIL;
--- 399,404 ----
/* start the task in periodic mode */
retval = pthread_make_periodic_np(task->ostask,
! gethrtime() + period_nsec,
! (hrtime_t) period_nsec);
if (retval != 0) {
return RTAPI_FAIL;
***************
*** 412,418 ****
}
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: start_task %p\n", task );
! }
return RTAPI_SUCCESS;
--- 412,416 ----
}
! rtapi_print_dbg(VERBOSE, "RTAPI: start_task %p\n", task);
return RTAPI_SUCCESS;
***************
*** 437,443 ****
}
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: stop_task %p\n", task );
! }
return RTAPI_SUCCESS;
--- 435,439 ----
}
! rtapi_print_dbg(VERBOSE, "RTAPI: stop_task %p\n", task);
return RTAPI_SUCCESS;
***************
*** 497,501 ****
retval = pthread_make_periodic_np(*((pthread_t *) task),
! gethrtime() + period_nsec, period_nsec);
if (retval != 0) {
return RTAPI_FAIL;
--- 493,497 ----
retval = pthread_make_periodic_np(*((pthread_t *) task),
! gethrtime() + period_nsec, period_nsec);
if (retval != 0) {
return RTAPI_FAIL;
***************
*** 512,516 ****
! int rtapi_task_get_handle(rtapi_task_handle *taskptr)
{
int n;
--- 508,512 ----
! int rtapi_task_get_handle(rtapi_task_handle * taskptr)
{
int n;
***************
*** 526,533 ****
/* find entry in task array */
n = 0;
! while ( ( n < RTAPI_MAX_TASKS ) && ( task_array[n]->ostask != task_id ) ) {
n++;
}
! if ( n == RTAPI_MAX_TASKS ) {
return RTAPI_INVAL;
}
--- 522,529 ----
/* find entry in task array */
n = 0;
! while ((n < RTAPI_MAX_TASKS) && (task_array[n]->ostask != task_id)) {
n++;
}
! if (n == RTAPI_MAX_TASKS) {
return RTAPI_INVAL;
}
***************
*** 551,555 ****
*/
! #define KEYSTR_LEN 16 /* larger than number of digits in MAX_INT */
static void genstr(unsigned int i, char *str)
--- 547,551 ----
*/
! #define KEYSTR_LEN 16 /* larger than number of digits in MAX_INT */
static void genstr(unsigned int i, char *str)
***************
*** 612,619 ****
shmem_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_shmem %p, key = %d, count = %d\n",
! shmem, key, shmem_usage_count );
! }
return RTAPI_SUCCESS;
--- 608,613 ----
shmem_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_shmem %p, key = %d, count = %d\n",
! shmem, key, shmem_usage_count);
return RTAPI_SUCCESS;
***************
*** 661,668 ****
shmem_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_shmem %p, count = %d\n",
! shmem, shmem_usage_count );
! }
return RTAPI_SUCCESS;
--- 655,660 ----
shmem_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_shmem %p, count = %d\n",
! shmem, shmem_usage_count);
return RTAPI_SUCCESS;
***************
*** 686,689 ****
--- 678,696 ----
+ void rtapi_print_dbg(int dbg, const char *fmt, ...)
+ {
+ va_list args;
+ enum { BUFFERLEN = 256 };
+ static char buffer[BUFFERLEN];
+
+ if (dbg < debug) {
+ va_start(args, fmt);
+ vsprintf(buffer, fmt, args);
+ rtl_printf(buffer);
+ va_end(args);
+ }
+ }
+
+
void rtapi_outb(unsigned char byte, unsigned int port)
{
***************
*** 702,706 ****
! int rtapi_assign_interrupt_handler(unsigned int irq, void (*handler)(void) )
{
int retval;
--- 709,713 ----
! int rtapi_assign_interrupt_handler(unsigned int irq, void (*handler) (void))
{
int retval;
***************
*** 724,731 ****
int_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: assign_intr_handler for int %d, count = %d\n",
! irq, int_usage_count );
! }
return RTAPI_SUCCESS;
--- 731,737 ----
int_usage_count++;
! rtapi_print_dbg(VERBOSE,
! "RTAPI: assign_intr_handler for int %d, count = %d\n", irq,
! int_usage_count);
return RTAPI_SUCCESS;
***************
*** 751,758 ****
int_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: free_intr_handler for int %d, count = %d\n",
! irq, int_usage_count );
! }
return RTAPI_SUCCESS;
--- 757,763 ----
int_usage_count--;
! rtapi_print_dbg(VERBOSE,
! "RTAPI: free_intr_handler for int %d, count = %d\n", irq,
! int_usage_count);
return RTAPI_SUCCESS;
***************
*** 805,809 ****
/* ask the OS to initialize the semaphore */
retval = sem_init(&(sem->ossem), 0, 0);
! if ( retval != 0 ) {
kfree(sem);
return RTAPI_FAIL;
--- 810,814 ----
/* ask the OS to initialize the semaphore */
retval = sem_init(&(sem->ossem), 0, 0);
! if (retval != 0) {
kfree(sem);
return RTAPI_FAIL;
***************
*** 819,826 ****
sem_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_sem %p, count = %d\n",
! sem, sem_usage_count );
! }
return RTAPI_SUCCESS;
--- 824,829 ----
sem_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_sem %p, count = %d\n", sem,
! sem_usage_count);
return RTAPI_SUCCESS;
***************
*** 847,854 ****
sem_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_sem %p, count = %d\n",
! sem, sem_usage_count );
! }
return RTAPI_SUCCESS;
--- 850,855 ----
sem_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_sem %p, count = %d\n", sem,
! sem_usage_count);
return RTAPI_SUCCESS;
***************
*** 946,953 ****
fifo_usage_count++;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_fifo %p, count = %d\n",
! fifo, fifo_usage_count );
! }
return RTAPI_SUCCESS;
--- 947,952 ----
fifo_usage_count++;
! rtapi_print_dbg(VERBOSE, "RTAPI: new_fifo %p, count = %d\n", fifo,
! fifo_usage_count);
return RTAPI_SUCCESS;
***************
*** 974,981 ****
fifo_usage_count--;
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_fifo %p, count = %d\n",
! fifo, fifo_usage_count );
! }
return RTAPI_SUCCESS;
--- 973,978 ----
fifo_usage_count--;
! rtapi_print_dbg(VERBOSE, "RTAPI: delete_fifo %p, count = %d\n",
! fifo, fifo_usage_count);
return RTAPI_SUCCESS;
Index: rtl_ulapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtl_ulapi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rtl_ulapi.c 5 Aug 2003 03:51:00 -0000 1.3
--- rtl_ulapi.c 9 Aug 2003 19:43:09 -0000 1.4
***************
*** 90,99 ****
char keystr[KEYSTR_LEN];
! printf ( "ulapi_shmem_new: entry\n" );
/* validate shmemptr */
if (shmemptr == NULL) {
return ULAPI_INVAL;
}
! printf ( "ulapi_shmem_new: pointer OK\n" );
/* alloc space for shmem structure */
shmem = malloc(sizeof(struct ulapi_shmem));
--- 90,99 ----
char keystr[KEYSTR_LEN];
! printf("ulapi_shmem_new: entry\n");
/* validate shmemptr */
if (shmemptr == NULL) {
return ULAPI_INVAL;
}
! printf("ulapi_shmem_new: pointer OK\n");
/* alloc space for shmem structure */
shmem = malloc(sizeof(struct ulapi_shmem));
***************
*** 101,110 ****
return ULAPI_NOMEM;
}
! printf ( "ulapi_shmem_new: allocated struct\n" );
/* convert key to a string */
genstr((unsigned int) key, keystr);
/* now get shared memory block from OS */
! printf ( "ulapi_shmem_new: converted key\n" );
shmem->mem = mbuff_alloc(keystr, size);
if (shmem->mem == NULL) {
--- 101,110 ----
return ULAPI_NOMEM;
}
! printf("ulapi_shmem_new: allocated struct\n");
/* convert key to a string */
genstr((unsigned int) key, keystr);
/* now get shared memory block from OS */
! printf("ulapi_shmem_new: converted key\n");
shmem->mem = mbuff_alloc(keystr, size);
if (shmem->mem == NULL) {
***************
*** 112,116 ****
return ULAPI_NOMEM;
}
! printf ( "ulapi_shmem_new: opened shmbuf\n" );
/* label as a valid shmem structure */
--- 112,116 ----
return ULAPI_NOMEM;
}
! printf("ulapi_shmem_new: opened shmbuf\n");
/* label as a valid shmem structure */
Index: sim_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/sim_rtapi.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** sim_rtapi.c 4 Aug 2003 06:00:25 -0000 1.5
--- sim_rtapi.c 9 Aug 2003 19:43:09 -0000 1.6
***************
*** 20,38 ****
struct rtapi_task {
! int magic; /* to check for valid handle */
! pthread_t id; /* OS specific task identifier */
! int arg; /* argument for task function */
! void (*taskcode)( int ); /* pointer to task function */
! };
struct rtapi_shmem {
! int magic; /* to check for valid handle */
! int key; /* key to shared memory area */
! int id; /* OS identifier for shmem */
! unsigned long int size; /* size of shared memory area */
! void *mem; /* pointer to the memory */
! };
! #define TASK_MAGIC 21979 /* random numbers used as signatures */
#define SHMEM_MAGIC 25453
--- 20,38 ----
struct rtapi_task {
! int magic; /* to check for valid handle */
! pthread_t id; /* OS specific task identifier */
! int arg; /* argument for task function */
! void (*taskcode) (int); /* pointer to task function */
! };
struct rtapi_shmem {
! int magic; /* to check for valid handle */
! int key; /* key to shared memory area */
! int id; /* OS identifier for shmem */
! unsigned long int size; /* size of shared memory area */
! void *mem; /* pointer to the memory */
! };
! #define TASK_MAGIC 21979 /* random numbers used as signatures */
#define SHMEM_MAGIC 25453
***************
*** 82,89 ****
int rtapi_init(void)
{
! int n;
/* clear the task array - if magic doesn't contain the magic
number, that means that array entry is empty */
! for ( n = 0 ; n < MAX_TASKS ; n++ )
task_array[n].magic = 0;
--- 82,89 ----
int rtapi_init(void)
{
! int n;
/* clear the task array - if magic doesn't contain the magic
number, that means that array entry is empty */
! for (n = 0; n < MAX_TASKS; n++)
task_array[n].magic = 0;
***************
*** 104,114 ****
! int rtapi_task_new( rtapi_task_handle *taskptr )
{
! int n;
! rtapi_task_handle task;
/* validate taskptr */
! if ( taskptr == NULL )
return RTAPI_INVAL;
--- 104,114 ----
! int rtapi_task_new(rtapi_task_handle * taskptr)
{
! int n;
! rtapi_task_handle task;
/* validate taskptr */
! if (taskptr == NULL)
return RTAPI_INVAL;
***************
*** 120,127 ****
atomic test and set for the magic number. Not tonight! */
n = 0;
! while ( ( n < MAX_TASKS ) &&
! ( task_array[n].magic == TASK_MAGIC ) )
n++;
! if ( n == MAX_TASKS )
return RTAPI_NOMEM;
task = &(task_array[n]);
--- 120,126 ----
atomic test and set for the magic number. Not tonight! */
n = 0;
! while ((n < MAX_TASKS) && (task_array[n].magic == TASK_MAGIC))
n++;
! if (n == MAX_TASKS)
return RTAPI_NOMEM;
task = &(task_array[n]);
***************
*** 138,147 ****
! int rtapi_task_delete( rtapi_task_handle task )
{
/* validate task handle */
! if ( task == NULL )
return RTAPI_BADH;
! if ( task->magic != TASK_MAGIC )
return RTAPI_BADH;
--- 137,146 ----
! int rtapi_task_delete(rtapi_task_handle task)
{
/* validate task handle */
! if (task == NULL)
return RTAPI_BADH;
! if (task->magic != TASK_MAGIC)
return RTAPI_BADH;
***************
*** 156,167 ****
/* we solve this with a wrapper function that meets pthread's needs */
! static void *wrapper ( void *arg )
{
! rtapi_task_handle task;
/* use the argument to point to the task data */
task = arg;
/* call the task function with the task argument */
! (task->taskcode)( task->arg );
/* done */
return NULL;
--- 155,166 ----
/* we solve this with a wrapper function that meets pthread's needs */
! static void *wrapper(void *arg)
{
! rtapi_task_handle task;
/* use the argument to point to the task data */
task = arg;
/* call the task function with the task argument */
! (task->taskcode) (task->arg);
/* done */
return NULL;
***************
*** 169,178 ****
! int rtapi_task_start( rtapi_task_handle task,
! void (*taskcode)( int ),
! int arg, int prio,
! unsigned long int stacksize,
! unsigned long int period_nsec,
! unsigned char uses_fp )
{
int retval;
--- 168,176 ----
! int rtapi_task_start(rtapi_task_handle task,
! void (*taskcode) (int),
! int arg, int prio,
! unsigned long int stacksize,
! unsigned long int period_nsec, unsigned char uses_fp)
{
int retval;
***************
*** 181,210 ****
/* validate task handle */
! if ( task == NULL )
return RTAPI_BADH;
! if ( task->magic != TASK_MAGIC )
return RTAPI_BADH;
/* check requested priority */
! if ( ( prio < rtapi_prio_highest() ) ||
! ( prio > rtapi_prio_lowest() ) )
return RTAPI_INVAL;
/* get default thread attributes */
! pthread_attr_init( &attr );
/* set priority */
sched_param.sched_priority = prio;
! pthread_attr_setschedparam( &attr, &sched_param );
/* create the thread - use the wrapper function, pass it a pointer
! to the task structure so it can call the actual task function */
task->taskcode = taskcode;
task->arg = arg;
! retval = pthread_create( &(task->id), &attr, wrapper, (void *)task );
! if ( retval != 0 )
return RTAPI_NOMEM;
! retval = pthread_setschedparam( task->id, SCHED_FIFO, &sched_param);
! if ( retval != 0 )
/* need to be root to set SCHED_FIFO */
return RTAPI_PERM;
--- 179,207 ----
/* validate task handle */
! if (task == NULL)
return RTAPI_BADH;
! if (task->magic != TASK_MAGIC)
return RTAPI_BADH;
/* check requested priority */
! if ((prio < rtapi_prio_highest()) || (prio > rtapi_prio_lowest()))
return RTAPI_INVAL;
/* get default thread attributes */
! pthread_attr_init(&attr);
/* set priority */
sched_param.sched_priority = prio;
! pthread_attr_setschedparam(&attr, &sched_param);
/* create the thread - use the wrapper function, pass it a pointer
! to the task structure so it can call the actual task function */
task->taskcode = taskcode;
task->arg = arg;
! retval = pthread_create(&(task->id), &attr, wrapper, (void *) task);
! if (retval != 0)
return RTAPI_NOMEM;
! retval = pthread_setschedparam(task->id, SCHED_FIFO, &sched_param);
! if (retval != 0)
/* need to be root to set SCHED_FIFO */
return RTAPI_PERM;
***************
*** 213,272 ****
! int rtapi_task_stop( rtapi_task_handle task )
{
! int retval;
/* validate task handle */
! if ( task == NULL )
return RTAPI_BADH;
! if ( task->magic != TASK_MAGIC )
return RTAPI_BADH;
! retval = pthread_cancel( task->id );
! if ( retval != 0 )
return RTAPI_FAIL;
return RTAPI_SUCCESS;
}
! int rtapi_task_pause( rtapi_task_handle task )
{
/* validate task handle */
! if ( task == NULL )
return RTAPI_BADH;
! if ( task->magic != TASK_MAGIC )
return RTAPI_BADH;
/* FIXME - Fred originally had this function return success.
! I changed it to return Not Supported. Is that right? */
return RTAPI_UNSUP;
}
! int rtapi_task_resume( rtapi_task_handle task )
{
/* validate task handle */
! if ( task == NULL )
return RTAPI_BADH;
! if ( task->magic != TASK_MAGIC )
return RTAPI_BADH;
/* FIXME - Fred originally had this function return success.
! I changed it to return Not Supported. Is that right? */
return RTAPI_UNSUP;
}
! int rtapi_task_set_period( rtapi_task_handle task,
! unsigned long int period_nsec )
{
/* validate task handle */
! if ( task == NULL )
return RTAPI_BADH;
! if ( task->magic != TASK_MAGIC )
return RTAPI_BADH;
/* FIXME - Fred originally had this function return success.
! I changed it to return Not Supported. Is that right? */
return RTAPI_UNSUP;
}
--- 210,269 ----
! int rtapi_task_stop(rtapi_task_handle task)
{
! int retval;
/* validate task handle */
! if (task == NULL)
return RTAPI_BADH;
! if (task->magic != TASK_MAGIC)
return RTAPI_BADH;
! retval = pthread_cancel(task->id);
! if (retval != 0)
return RTAPI_FAIL;
return RTAPI_SUCCESS;
}
! int rtapi_task_pause(rtapi_task_handle task)
{
/* validate task handle */
! if (task == NULL)
return RTAPI_BADH;
! if (task->magic != TASK_MAGIC)
return RTAPI_BADH;
/* FIXME - Fred originally had this function return success.
! I changed it to return Not Supported. Is that right? */
return RTAPI_UNSUP;
}
! int rtapi_task_resume(rtapi_task_handle task)
{
/* validate task handle */
! if (task == NULL)
return RTAPI_BADH;
! if (task->magic != TASK_MAGIC)
return RTAPI_BADH;
/* FIXME - Fred originally had this function return success.
! I changed it to return Not Supported. Is that right? */
return RTAPI_UNSUP;
}
! int rtapi_task_set_period(rtapi_task_handle task,
! unsigned long int period_nsec)
{
/* validate task handle */
! if (task == NULL)
return RTAPI_BADH;
! if (task->magic != TASK_MAGIC)
return RTAPI_BADH;
/* FIXME - Fred originally had this function return success.
! I changed it to return Not Supported. Is that right? */
return RTAPI_UNSUP;
}
***************
*** 282,292 ****
! int rtapi_task_get_handle( rtapi_task_handle *taskptr )
{
! int n;
! pthread_t task_id;
/* validate taskptr */
! if ( taskptr == NULL )
return RTAPI_INVAL;
--- 279,289 ----
! int rtapi_task_get_handle(rtapi_task_handle * taskptr)
{
! int n;
! pthread_t task_id;
/* validate taskptr */
! if (taskptr == NULL)
return RTAPI_INVAL;
***************
*** 296,302 ****
/* search task array for a matching entry */
n = 0;
! while ( n < MAX_TASKS ) {
! if ( ( task_array[n].magic == TASK_MAGIC ) &&
! ( task_array[n].id == task_id ) ) {
/* found it */
*taskptr = &(task_array[n]);
--- 293,298 ----
/* search task array for a matching entry */
n = 0;
! while (n < MAX_TASKS) {
! if ((task_array[n].magic == TASK_MAGIC) && (task_array[n].id == task_id)) {
/* found it */
*taskptr = &(task_array[n]);
***************
*** 309,336 ****
! int rtapi_shmem_new( int key, unsigned int size,
! rtapi_shmem_handle *shmemptr )
{
! rtapi_shmem_handle shmem;
/* validate shmemptr */
! if ( shmemptr == NULL )
return RTAPI_INVAL;
/* alloc space for shmem structure */
! shmem = malloc( sizeof(struct rtapi_shmem) );
! if ( shmem == NULL )
return RTAPI_NOMEM;
/* now get shared memory block from OS */
! shmem->id = shmget( (key_t) key, (int) size, IPC_CREAT | 0666 );
! if ( shmem->id == -1 ) {
! free ( shmem );
return RTAPI_NOMEM;
}
/* and map it into process space */
! shmem->mem = shmat( shmem->id, 0, 0);
! if ( (int)(shmem->mem) == -1 ) {
! free ( shmem );
return RTAPI_NOMEM;
}
--- 305,331 ----
! int rtapi_shmem_new(int key, unsigned int size, rtapi_shmem_handle * shmemptr)
{
! rtapi_shmem_handle shmem;
/* validate shmemptr */
! if (shmemptr == NULL)
return RTAPI_INVAL;
/* alloc space for shmem structure */
! shmem = malloc(sizeof(struct rtapi_shmem));
! if (shmem == NULL)
return RTAPI_NOMEM;
/* now get shared memory block from OS */
! shmem->id = shmget((key_t) key, (int) size, IPC_CREAT | 0666);
! if (shmem->id == -1) {
! free(shmem);
return RTAPI_NOMEM;
}
/* and map it into process space */
! shmem->mem = shmat(shmem->id, 0, 0);
! if ((int) (shmem->mem) == -1) {
! free(shmem);
return RTAPI_NOMEM;
}
***************
*** 348,357 ****
! int rtapi_shmem_getptr ( rtapi_shmem_handle shmem, void **ptr )
{
/* validate shmem handle */
! if ( shmem == NULL )
return RTAPI_BADH;
! if ( shmem->magic != SHMEM_MAGIC )
return RTAPI_BADH;
--- 343,352 ----
! int rtapi_shmem_getptr(rtapi_shmem_handle shmem, void **ptr)
{
/* validate shmem handle */
! if (shmem == NULL)
return RTAPI_BADH;
! if (shmem->magic != SHMEM_MAGIC)
return RTAPI_BADH;
***************
*** 362,381 ****
! int rtapi_shmem_delete( rtapi_shmem_handle shmem )
{
! struct shmid_ds d;
! int r1, r2;
/* validate shmem handle */
! if ( shmem == NULL )
return RTAPI_BADH;
! if ( shmem->magic != SHMEM_MAGIC )
return RTAPI_BADH;
/* unmap the shared memory */
! r1 = shmdt( shmem->mem );
/* destroy the shared memory */
! r2 = shmctl( shmem->id, IPC_RMID, &d );
/* FIXME - Fred had the first two arguments reversed. I changed
them to match the shmctl man page on my machine. Since his way
--- 357,376 ----
! int rtapi_shmem_delete(rtapi_shmem_handle shmem)
{
! struct shmid_ds d;
! int r1, r2;
/* validate shmem handle */
! if (shmem == NULL)
return RTAPI_BADH;
! if (shmem->magic != SHMEM_MAGIC)
return RTAPI_BADH;
/* unmap the shared memory */
! r1 = shmdt(shmem->mem);
/* destroy the shared memory */
! r2 = shmctl(shmem->id, IPC_RMID, &d);
/* FIXME - Fred had the first two arguments reversed. I changed
them to match the shmctl man page on my machine. Since his way
***************
*** 385,391 ****
/* free the shmem structure */
shmem->magic = 0;
! free ( shmem );
! if ( ( r1 != 0 ) || ( r2 != 0 ) )
return RTAPI_FAIL;
return RTAPI_SUCCESS;
--- 380,386 ----
/* free the shmem structure */
shmem->magic = 0;
! free(shmem);
! if ((r1 != 0) || (r2 != 0))
return RTAPI_FAIL;
return RTAPI_SUCCESS;
***************
*** 402,405 ****
--- 397,411 ----
}
+
+ void rtapi_print_dbg(int dbg, const char *fmt, ...)
+ {
+ va_list args;
+
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+ }
+
+
void rtapi_outb(unsigned char byte, unsigned int port)
{
***************
*** 426,435 ****
}
! int rtapi_enable_interrupt( unsigned int irq )
{
return RTAPI_UNSUP;
}
! int rtapi_disable_interrupt( unsigned int irq )
{
return RTAPI_UNSUP;
--- 432,441 ----
}
! int rtapi_enable_interrupt(unsigned int irq)
{
return RTAPI_UNSUP;
}
! int rtapi_disable_interrupt(unsigned int irq)
{
return RTAPI_UNSUP;
***************
*** 439,463 ****
/* FIXME - no support for semaphores */
! int rtapi_sem_new( rtapi_sem_handle *semptr )
{
return RTAPI_UNSUP;
}
! int rtapi_sem_delete( rtapi_sem_handle sem )
{
return RTAPI_UNSUP;
}
! int rtapi_sem_give( rtapi_sem_handle sem )
{
return RTAPI_UNSUP;
}
! int rtapi_sem_take( rtapi_sem_handle sem )
{
return RTAPI_UNSUP;
}
! int rtapi_sem_try( rtapi_sem_handle sem )
{
return RTAPI_UNSUP;
--- 445,469 ----
/* FIXME - no support for semaphores */
! int rtapi_sem_new(rtapi_sem_handle * semptr)
{
return RTAPI_UNSUP;
}
! int rtapi_sem_delete(rtapi_sem_handle sem)
{
return RTAPI_UNSUP;
}
! int rtapi_sem_give(rtapi_sem_handle sem)
{
return RTAPI_UNSUP;
}
! int rtapi_sem_take(rtapi_sem_handle sem)
{
return RTAPI_UNSUP;
}
! int rtapi_sem_try(rtapi_sem_handle sem)
{
return RTAPI_UNSUP;
***************
*** 467,493 ****
/* FIXME - no support for fifos */
! int rtapi_fifo_new( int key, unsigned long int size,
! rtapi_fifo_handle *fifoptr )
{
return RTAPI_UNSUP;
}
! int rtapi_fifo_delete( rtapi_fifo_handle fifo )
{
return RTAPI_UNSUP;
}
! int rtapi_fifo_read( rtapi_fifo_handle fifo,
! char *buf, unsigned long int size)
{
return RTAPI_UNSUP;
}
! int rtapi_fifo_write( rtapi_fifo_handle fifo,
! char *buf, unsigned long int size)
{
return RTAPI_UNSUP;
}
-
-
-
--- 473,495 ----
/* FIXME - no support for fifos */
! int rtapi_fifo_new(int key, unsigned long int size,
! rtapi_fifo_handle * fifoptr)
{
return RTAPI_UNSUP;
}
! int rtapi_fifo_delete(rtapi_fifo_handle fifo)
{
return RTAPI_UNSUP;
}
! int rtapi_fifo_read(rtapi_fifo_handle fifo, char *buf, unsigned long int size)
{
return RTAPI_UNSUP;
}
! int rtapi_fifo_write(rtapi_fifo_handle fifo,
! char *buf, unsigned long int size)
{
return RTAPI_UNS...
[truncated message content] |