|
From: <jmk...@us...> - 2003-08-20 08:35:40
|
Update of /cvsroot/emc/rtapi/src/rtapi
In directory sc8-pr-cvs1:/tmp/cvs-serv10049/src/rtapi
Modified Files:
rtai_rtapi.c rtai_ulapi.c rtapi.h rtapi_common.h ulapi.h
Added Files:
rtapi_proc.h
Log Message:
moved proc stuff from rtapi_common.h to rtapi_proc.h, put most rtapi internal data in shared memory and put corresponding decls in rtapi_common.h
--- NEW FILE: rtapi_proc.h ---
#ifndef RTAPI_PROC_H
#define RTAPI_PROC_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_proc.h', contains code that implements several
/proc filesystem entries that can display the status of the RTAPI.
This code is common to both the RTAI and RTLinux implementations,
and most likely to any other implementations under Linux. This
data is INTERNAL to the RTAPI implementation, and should not be
included in any application modules. This data also applies
only to kernel modules, and should be included only in the
real-time portion of the implementation. Items that are common
to both the realtime and user-space portions of the implementation
are in rtapi_common.h.
*/
/** 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.
*/
#include <linux/proc_fs.h>
#ifdef CONFIG_PROC_FS
/* proc print macros - Contributed by: Erwin Rol (er...@mu...)
and shamelessly ripped from rtai_proc_fs.h, part of the RTAI
project. See http://www.rtai.org for more details.
macro that holds the local variables that
we use in the PROC_PRINT_* macros. We have
this macro so we can add variables with out
changing the users of this macro, of course
only when the names don't colide!
*/
#define PROC_PRINT_VARS \
off_t pos = 0; \
off_t begin = 0; \
int len = 0 /* no ";" */
/* macro that prints in the procfs read buffer.
this macro expects the function arguments to be
named as follows.
static int FOO(char *page, char **start,
off_t off, int count, int *eof, void *data) */
#define PROC_PRINT(fmt,args...) \
len += sprintf(page + len , fmt, ##args); \
pos += len; \
if(pos < off) { \
len = 0; \
begin = pos; \
} \
if(pos > off + count) \
goto done;
/* macro to leave the read function from another
place than at the end. */
#define PROC_PRINT_RETURN \
*eof = 1; \
goto done // no ";"
/* macro that should only used once at the end of the
read function, to return from another place in the
read function use the PROC_PRINT_RETURN macro. */
#define PROC_PRINT_DONE \
*eof = 1; \
done: \
*start = page + (off - begin); \
len -= (off - begin); \
if(len > count) \
len = count; \
if(len < 0) \
len = 0; \
return len // no ";"
/* Internal function for the proc_fs system. */
/* FIXME - according to my book, this interface is only available
for 2.4 kernels. I'm afraid this code will break on 2.0 or 2.2
The current implimentation may well break on a 2.2 series kernel,
but the process is the same...
*/
static struct proc_dir_entry *rtapi_dir = 0; /* /proc/rtapi directory */
static struct proc_dir_entry *status_file = 0; /* /proc/rtapi/status */
static struct proc_dir_entry *tasks_file = 0; /* /proc/rtapi/tasks */
static struct proc_dir_entry *shmem_file = 0; /* /proc/rtapi/shmem */
static struct proc_dir_entry *sems_file = 0; /* /proc/rtapi/sems */
static struct proc_dir_entry *fifos_file = 0; /* /proc/rtapi/fifos */
static struct proc_dir_entry *debug_file = 0; /* /proc/rtapi/debug */
/** The following are callback functions for the /proc filesystem
When someone reads a /proc file, the appropriate function below
is called, and it must generate output for the reader on the fly.
These functions use the MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT
macros to make sure the RTAPI module is not removed while servicing
a /proc request.
*/
static int proc_read_status(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
PROC_PRINT_VARS;
MOD_INC_USE_COUNT;
PROC_PRINT("******* RTAPI STATUS ********\n");
PROC_PRINT(" RT Modules = %i\n", rtapi_data->rt_module_count);
PROC_PRINT(" UL Modules = %i\n", rtapi_data->ul_module_count);
PROC_PRINT(" Tasks = %i/%i\n", rtapi_data->task_count, RTAPI_MAX_TASKS);
PROC_PRINT("Shared memory = %i/%i\n", rtapi_data->shmem_count, RTAPI_MAX_SHMEMS);
PROC_PRINT(" FIFOs = %i/%i\n", rtapi_data->fifo_count, RTAPI_MAX_FIFOS);
PROC_PRINT(" Semaphores = %i/%i\n", rtapi_data->sem_count, RTAPI_MAX_SEMS);
PROC_PRINT(" Interrupts = %i\n", rtapi_data->irq_count);
if (rtapi_data->timer_running) {
PROC_PRINT(" Timer status = Running\n");
PROC_PRINT(" Timer period = %li nSec\n", rtapi_data->timer_period);
} else {
PROC_PRINT(" Timer status = Stopped\n");
}
PROC_PRINT("Message level = %i\n", rtapi_msg_level);
PROC_PRINT("\n");
MOD_DEC_USE_COUNT;
PROC_PRINT_DONE;
}
static int proc_read_tasks(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int n;
char *state_str;
PROC_PRINT_VARS;
MOD_INC_USE_COUNT;
PROC_PRINT("******** RTAPI TASKS ********\n");
PROC_PRINT("ID State Code\n");
for (n = 1; n <= RTAPI_MAX_TASKS; n++) {
if (task_array[n].state != EMPTY) {
switch (task_array[n].state) {
case PAUSED:
state_str = "PAUSED ";
break;
case PERIODIC:
state_str = "PERIODIC";
break;
case FREERUN:
state_str = "FREE RUN";
break;
case ENDED:
state_str = "ENDED ";
break;
default:
state_str = "UNKNOWN ";
break;
}
PROC_PRINT("%02d %s %p\n", n, state_str, task_array[n].taskcode);
}
}
PROC_PRINT("\n");
MOD_DEC_USE_COUNT;
PROC_PRINT_DONE;
}
static int proc_read_shmem(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int n;
PROC_PRINT_VARS;
MOD_INC_USE_COUNT;
PROC_PRINT("**** RTAPI SHARED MEMORY ****\n");
PROC_PRINT("ID Users Key Size\n");
PROC_PRINT(" RT/UL \n");
for ( n = 1 ; n <= RTAPI_MAX_SHMEMS ; n++ ) {
if ( shmem_array[n].key != 0 ) {
PROC_PRINT("%02d %2d/%-2d %-10d %-10lu\n",
n, shmem_array[n].rtusers, shmem_array[n].ulusers,
shmem_array[n].key, shmem_array[n].size);
}
}
PROC_PRINT("\n");
MOD_DEC_USE_COUNT;
PROC_PRINT_DONE;
}
static int proc_read_sems(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int n;
PROC_PRINT_VARS;
MOD_INC_USE_COUNT;
PROC_PRINT("***** RTAPI SEMAPHORES ******\n");
PROC_PRINT("ID Users Key\n");
for (n = 1; n <= RTAPI_MAX_SEMS; n++) {
if (sem_array[n].users != 0) {
PROC_PRINT("%02d %3d %-10d\n",
n, sem_array[n].users, sem_array[n].key);
}
}
PROC_PRINT("\n");
MOD_DEC_USE_COUNT;
PROC_PRINT_DONE;
}
static int proc_read_fifos(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int n;
char *state_str;
PROC_PRINT_VARS;
MOD_INC_USE_COUNT;
PROC_PRINT("******** RTAPI FIFOS ********\n");
PROC_PRINT("ID State Key Size\n");
for (n = 1; n <= RTAPI_MAX_FIFOS; n++) {
if (fifo_array[n].state != UNUSED) {
switch (fifo_array[n].state) {
case HAS_READER:
state_str = "R-";
break;
case HAS_WRITER:
state_str = "-W";
break;
case HAS_BOTH:
state_str = "RW";
break;
default:
state_str = "UNKNOWN ";
break;
}
PROC_PRINT("%02d %s %-10d %-10ld\n",
n, state_str, fifo_array[n].key, fifo_array[n].size);
}
}
PROC_PRINT("\n");
MOD_DEC_USE_COUNT;
PROC_PRINT_DONE;
}
static int proc_read_debug(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
PROC_PRINT_VARS;
MOD_INC_USE_COUNT;
PROC_PRINT("******* RTAPI MESSAGES ******\n");
PROC_PRINT(" Message Level = %i\n", rtapi_msg_level);
PROC_PRINT(" ERROR messages = %s\n",
rtapi_msg_level > RTAPI_MSG_ERR ? "ON" : "OFF");
PROC_PRINT("WARNING messages = %s\n",
rtapi_msg_level > RTAPI_MSG_WARN ? "ON" : "OFF");
PROC_PRINT(" INFO messages = %s\n",
rtapi_msg_level > RTAPI_MSG_INFO ? "ON" : "OFF");
PROC_PRINT(" DEBUG messages = %s\n",
rtapi_msg_level > RTAPI_MSG_DBG ? "ON" : "OFF");
PROC_PRINT("\n");
MOD_DEC_USE_COUNT;
PROC_PRINT_DONE;
}
static int proc_write_debug(struct file *file,
const char *buffer,
unsigned long count, void *data)
{
char c;
MOD_INC_USE_COUNT;
/* copy 1 byte from user space */
if (copy_from_user(&c, buffer, 1)) {
MOD_DEC_USE_COUNT;
return -1;
}
/* check it is a digit */
if (isdigit(c)) {
/* convert to a number */
rtapi_msg_level = (int) (c - '0');
}
/* tell whoever called us that we used all the data, even
though we really only used the first byte */
MOD_DEC_USE_COUNT;
return count;
}
/** proc_init() initializes the /proc filesystem entries,
creating the directory and files, and linking them
to the appropriate callback functions. This function
is called from the init_module() function of the
RTAPI implementation.
*/
static int proc_init(void)
{
/* create the rtapi directory "/proc/rtapi" */
rtapi_dir = create_proc_entry("rtapi", S_IFDIR, NULL);
if (rtapi_dir == 0) {
return -1;
}
// rtapi_dir->owner = THIS_MODULE;
/* create read only file "/proc/rtapi/status" */
status_file = create_proc_entry("status", S_IRUGO, rtapi_dir);
if (status_file == NULL) {
return -1;
}
status_file->read_proc = proc_read_status;
/* create read only file "/proc/rtapi/tasks" */
tasks_file = create_proc_entry("tasks", S_IRUGO, rtapi_dir);
if (tasks_file == NULL) {
return -1;
}
tasks_file->read_proc = proc_read_tasks;
/* create read only file "/proc/rtapi/shmem" */
shmem_file = create_proc_entry("shmem", S_IRUGO, rtapi_dir);
if (shmem_file == NULL) {
return -1;
}
shmem_file->read_proc = proc_read_shmem;
/* create read only file "/proc/rtapi/sems" */
sems_file = create_proc_entry("sems", S_IRUGO, rtapi_dir);
if (sems_file == NULL) {
return -1;
}
sems_file->read_proc = proc_read_sems;
/* create read only file "/proc/rtapi/fifos" */
fifos_file = create_proc_entry("fifos", S_IRUGO, rtapi_dir);
if (fifos_file == NULL) {
return -1;
}
fifos_file->read_proc = proc_read_fifos;
/* create read/write file "/proc/rtapi/debug" */
debug_file = create_proc_entry("debug", S_IRUGO | S_IWUGO, rtapi_dir);
if (debug_file == NULL) {
return -1;
}
// debug_file->owner = THIS_MODULE;
debug_file->data = NULL;
debug_file->read_proc = proc_read_debug;
debug_file->write_proc = proc_write_debug;
return 0;
}
/** proc_clean() is called from the cleanup_module function of
of the RTAPI implementation. It removes the rtapi entries
from the /proc filesystem. Failing to remove a /proc
entry before the module is removed may cause kernel panics.
*/
static void proc_clean(void)
{
/* remove /proc entries, only if they exist */
if (rtapi_dir != NULL) {
if (status_file != NULL) {
remove_proc_entry("status", rtapi_dir);
status_file = NULL;
}
if (tasks_file != NULL) {
remove_proc_entry("tasks", rtapi_dir);
tasks_file = NULL;
}
if (shmem_file != NULL) {
remove_proc_entry("shmem", rtapi_dir);
shmem_file = NULL;
}
if (sems_file != NULL) {
remove_proc_entry("sems", rtapi_dir);
sems_file = NULL;
}
if (fifos_file != NULL) {
remove_proc_entry("fifos", rtapi_dir);
fifos_file = NULL;
}
if (debug_file != NULL) {
remove_proc_entry("debug", rtapi_dir);
debug_file = NULL;
}
remove_proc_entry("rtapi", NULL);
}
}
#endif /* CONFIG_PROC_FS */
#endif /* RTAPI_COMMON_H */
Index: rtai_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_rtapi.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** rtai_rtapi.c 19 Aug 2003 17:29:50 -0000 1.29
--- rtai_rtapi.c 20 Aug 2003 03:16:21 -0000 1.30
***************
*** 1,41 ****
! /** 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 *
[...1126 lines suppressed...]
*** 1105,1113 ****
/* decrement the usage counter */
! int_usage_count--;
rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: free_interrupt_handler for int %d, count = %d\n",
! irq, int_usage_count);
return RTAPI_SUCCESS;
--- 1160,1168 ----
/* decrement the usage counter */
! rtapi_data->irq_count--;
rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: free_interrupt_handler for int %d, count = %d\n",
! irq, rtapi_data->irq_count);
return RTAPI_SUCCESS;
Index: rtai_ulapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_ulapi.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** rtai_ulapi.c 19 Aug 2003 17:29:50 -0000 1.7
--- rtai_ulapi.c 20 Aug 2003 03:16:21 -0000 1.8
***************
*** 1,41 ****
! /** 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. */
--- 1,46 ----
! /** 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.
! */
***************
*** 48,80 ****
#include <rtai_shm.h> /* rtai_malloc,free() */
#include <malloc.h> /* malloc(), free() */
- #include "ulapi.h"
! /* These structs hold data associated with objects like tasks, etc. */
! /* Task handles are pointers to these structs. */
!
! struct ulapi_shmem {
! int magic; /* to check for valid handle */
! int key; /* key to shared memory area */
! unsigned long int size; /* size of shared memory area */
! void *mem; /* pointer to the memory */
! };
!
! struct ulapi_fifo {
! int magic; /* to check for valid handle */
! int key; /* key to fifo */
! int fd; /* file descripter for fifo */
! int mode; /* O_RDONLY or O_WRONLY */
! unsigned long int size; /* size of fifo area */
! };
!
! #define SHMEM_MAGIC 25453 /* random numbers used as signatures */
! #define FIFO_MAGIC 10293
int ulapi_init(void)
{
! /* does nothing, for now */
return ULAPI_SUCCESS;
}
--- 53,91 ----
#include <rtai_shm.h> /* rtai_malloc,free() */
#include <malloc.h> /* malloc(), free() */
! #include "ulapi.h" /* public ULAPI decls */
! #include "rtapi_common.h" /* private RTAPI/ULAPI decls */
! /* resource data unique to this process */
! static void *shmem_addr_array[RTAPI_MAX_SHMEMS+1];
! static int fifo_fd_array[RTAPI_MAX_FIFOS+1];
int ulapi_init(void)
{
! int n;
!
! /* get shared memory block from OS and save its address */
! rtapi_data = rtai_malloc(RTAPI_KEY, sizeof(rtapi_data_t));
! if (rtapi_data == NULL) {
! return ULAPI_NOMEM;
! }
! /* perform a global init if needed */
! init_rtapi_data ( rtapi_data );
! /* set up local pointers to global data */
! task_array = rtapi_data->task_array;
! shmem_array = rtapi_data->shmem_array;
! sem_array = rtapi_data->sem_array;
! fifo_array = rtapi_data->fifo_array;
! irq_array = rtapi_data->irq_array;
! /* perform local init */
! for (n = 0; n <= RTAPI_MAX_SHMEMS; n++) {
! shmem_addr_array[n] = NULL;
! }
! /* update module count */
! mutex_get ( &(rtapi_data->mutex) );
! rtapi_data->ul_module_count++;
! mutex_give ( &(rtapi_data->mutex) );
return ULAPI_SUCCESS;
}
***************
*** 83,247 ****
int ulapi_exit(void)
{
! /* does nothing, for now */
return ULAPI_SUCCESS;
}
! int ulapi_shmem_new(int key, unsigned long int size,
! ulapi_shmem_handle * shmemptr)
{
! ulapi_shmem_handle shmem;
! /* validate shmemptr */
! if (shmemptr == NULL) {
return ULAPI_INVAL;
}
! /* alloc space for shmem structure */
! shmem = malloc(sizeof(struct ulapi_shmem));
! if (shmem == NULL) {
! return ULAPI_NOMEM;
}
! /* now get shared memory block from OS */
! shmem->mem = rtai_malloc(key, size);
! if (shmem->mem == NULL) {
! free(shmem);
return ULAPI_NOMEM;
}
!
! /* label as a valid shmem structure */
! shmem->magic = SHMEM_MAGIC;
! /* fill in the other fields */
! shmem->size = size;
shmem->key = key;
!
! /* return handle to the caller */
! *shmemptr = shmem;
! return ULAPI_SUCCESS;
}
! int ulapi_shmem_getptr(ulapi_shmem_handle shmem, void **ptr)
{
! /* validate shmem handle */
! if (shmem == NULL) {
! return ULAPI_BADH;
}
! if (shmem->magic != SHMEM_MAGIC) {
! return ULAPI_BADH;
}
! /* pass memory address back to caller */
! *ptr = shmem->mem;
return ULAPI_SUCCESS;
-
}
! int ulapi_shmem_delete(ulapi_shmem_handle shmem)
{
! /* validate shmem handle */
! if (shmem == NULL) {
! return ULAPI_BADH;
}
! if (shmem->magic != SHMEM_MAGIC) {
! return ULAPI_BADH;
}
! /* free the shared memory */
! rtai_free(shmem->key, shmem->mem);
!
! /* free the shmem structure */
! shmem->magic = 0;
! free(shmem);
return ULAPI_SUCCESS;
}
! int ulapi_fifo_new(int key, unsigned long int size, char mode,
! ulapi_fifo_handle * fifoptr)
{
- ulapi_fifo_handle fifo;
- int retval, flags;
enum { DEVSTR_LEN = 256 };
char devstr[DEVSTR_LEN];
! /* validate fifoptr */
! if (fifoptr == NULL) {
return ULAPI_INVAL;
}
! /* alloc space for fifo structure */
! fifo = malloc(sizeof(struct ulapi_fifo));
! if (fifo == NULL) {
! return ULAPI_NOMEM;
}
- /* determine system name for fifo */
- sprintf(devstr, "/dev/rtf%d", key);
-
/* determine mode for fifo */
if (mode == 'R') {
flags = O_RDONLY;
! } else {
! if (mode == 'W') {
! flags = O_WRONLY;
! }
!
! else {
! return ULAPI_INVAL;
}
}
/* open the fifo */
! retval = open(devstr, flags);
! if (retval < 0) {
/* open failed */
- free(fifo);
return ULAPI_NOTFND;
}
!
! /* label as a valid fifo structure */
! fifo->magic = FIFO_MAGIC;
! /* fill in the rest of the struct */
fifo->key = key;
! fifo->fd = retval;
! fifo->mode = flags;
!
! /* return handle to the caller */
! *fifoptr = fifo;
! return ULAPI_SUCCESS;
}
! int ulapi_fifo_delete(ulapi_fifo_handle fifo)
{
! /* validate fifo handle */
! if (fifo == NULL) {
! return ULAPI_BADH;
}
! if (fifo->magic != FIFO_MAGIC) {
! return ULAPI_BADH;
}
! /* close the fifo */
! if (close(fifo->fd) < 0) {
! return ULAPI_NOTFND;
}
! /* free the fifo structure */
! fifo->magic = 0;
! free(fifo);
return ULAPI_SUCCESS;
-
}
! int ulapi_fifo_read(ulapi_fifo_handle fifo, char *buf, unsigned long int size)
{
int retval;
! /* validate fifo handle */
! if (fifo == NULL) {
! return ULAPI_BADH;
! }
! if (fifo->magic != FIFO_MAGIC) {
! return ULAPI_BADH;
}
! if (fifo->mode != O_RDONLY) {
! return ULAPI_UNSUP;
}
/* get whatever data is available */
! retval = read(fifo->fd, buf, size);
if (retval <= 0) {
return ULAPI_FAIL;
--- 94,401 ----
int ulapi_exit(void)
{
! if (rtapi_data == NULL) {
! /* no inited */
! return ULAPI_INVAL;
! }
! /* do cleanup here, nothing implemented yet */
!
! /* update module count */
! mutex_get ( &(rtapi_data->mutex) );
! rtapi_data->ul_module_count--;
! mutex_give ( &(rtapi_data->mutex) );
return ULAPI_SUCCESS;
}
! /***********************************************************************
! * SHARED MEMORY RELATED FUNCTIONS *
! ************************************************************************/
!
! int ulapi_shmem_new(int key, unsigned long int size)
{
! int n;
! int shmem_id;
! shmem_data *shmem;
! /* key must be non-zero, and also cannot match the key that RTAPI uses */
! if (( key == 0 ) || ( key == RTAPI_KEY )) {
return ULAPI_INVAL;
}
! /* check if a block is already open for this key */
! for ( n = 1; n <= RTAPI_MAX_SHMEMS ; n++ ) {
! if ( shmem_array[n].key == key ) {
! /* found a match */
! shmem_id = n;
! shmem = &(shmem_array[n]);
! /* is it big enough? */
! if (shmem->size < size) {
! return ULAPI_INVAL;
! }
! /* yes, has this process already mapped it? */
! if (shmem_addr_array[shmem_id] != 0 ) {
! /* can't map twice */
! return ULAPI_FAIL;
! }
! /* no, map it */
! shmem_addr_array[shmem_id] = rtai_malloc(key, shmem->size);
! if (shmem_addr_array[shmem_id] == NULL) {
! /* map failed */
! return ULAPI_NOMEM;
! }
! /* update usage data */
! shmem->ulusers++;
! /* done */
! return shmem_id;
! }
}
! /* find empty spot in shmem array */
! n = 1;
! while ((n <= RTAPI_MAX_SHMEMS) &&
! (shmem_array[n].key != 0)) {
! n++;
! }
! if (n > RTAPI_MAX_SHMEMS) {
! /* no room */
! return ULAPI_LIMIT;
! }
! /* we have space for the block data */
! shmem_id = n;
! shmem = &(shmem_array[n]);
! /* now get shared memory block from OS and save its address */
! shmem_addr_array[shmem_id] = rtai_malloc(key, size);
! if (shmem_addr_array[shmem_id] == NULL) {
return ULAPI_NOMEM;
}
! /* fill in the data */
shmem->key = key;
! shmem->rtusers = 0;
! shmem->ulusers = 1;
! shmem->size = size;
! rtapi_data->shmem_count++;
! /* done */
! return shmem_id;
}
! int ulapi_shmem_delete(int shmem_id)
{
! shmem_data *shmem;
!
! /* validate shmem ID */
! if ((shmem_id < 1) || (shmem_id > RTAPI_MAX_SHMEMS)) {
! return ULAPI_BADID;
}
! /* point to the shmem's data */
! shmem = &(shmem_array[shmem_id]);
! /* is the block valid? */
! if (shmem->key == 0 ) {
! return ULAPI_BADID;
}
! /* unmap the block */
! rtai_free(shmem->key, shmem_addr_array[shmem_id]);
! shmem_addr_array[shmem_id] = NULL;
! /* update data */
! shmem->ulusers--;
! /* is somebody else still using the block? */
! if ((shmem->ulusers > 0 ) || (shmem->rtusers > 0 )) {
! /* yes, we're done for now */
! return ULAPI_SUCCESS;
! }
! /* update the data array and usage count */
! shmem->key = 0;
! shmem->size = 0;
! rtapi_data->shmem_count--;
return ULAPI_SUCCESS;
}
! int ulapi_shmem_getptr(int shmem_id, void **ptr)
{
! /* validate shmem ID */
! if ((shmem_id < 1) || (shmem_id > RTAPI_MAX_SHMEMS)) {
! return ULAPI_BADID;
}
! /* is the block mapped? */
! if (shmem_addr_array[shmem_id] == NULL ) {
! return ULAPI_BADID;
}
! /* pass memory address back to caller */
! *ptr = shmem_addr_array[shmem_id];
return ULAPI_SUCCESS;
}
!
! int ulapi_fifo_new(int key, unsigned long int size, char mode)
{
enum { DEVSTR_LEN = 256 };
char devstr[DEVSTR_LEN];
+ int n, flags;
+ int fifo_id;
+ fifo_data *fifo;
! /* key must be non-zero */
! if ( key == 0 ) {
return ULAPI_INVAL;
}
! /* mode must be "R" or "W" */
! if (( mode != 'R' ) && ( mode != 'W' )) {
! return ULAPI_INVAL;
}
/* determine mode for fifo */
if (mode == 'R') {
flags = O_RDONLY;
! }
! else /* mode == 'W' */ {
! flags = O_WRONLY;
! }
! /* check if a fifo already exists for this key */
! for ( n = 1; n <= RTAPI_MAX_FIFOS ; n++ ) {
! if ((fifo_array[n].state != UNUSED) && (fifo_array[n].key == key)) {
! /* found a match */
! fifo_id = n;
! fifo = &(fifo_array[n]);
! /* is the desired mode available */
! if ( mode == 'R' ) {
! if ( fifo->state & HAS_READER ) {
! return ULAPI_BUSY;
! }
! /* determine system name for fifo */
! sprintf(devstr, "/dev/rtf%d", fifo_id);
! /* open the fifo */
! fifo_fd_array[fifo_id] = open(devstr, flags);
! if (fifo_fd_array[fifo_id] < 0) {
! /* open failed */
! return ULAPI_NOTFND;
! }
! /* fifo opened, update status */
! fifo->state |= HAS_READER;
! return fifo_id;
! }
! else /* mode == 'W' */ {
! if ( fifo->state & HAS_WRITER ) {
! return ULAPI_BUSY;
! }
! /* determine system name for fifo */
! sprintf(devstr, "/dev/rtf%d", fifo_id);
! /* open the fifo */
! fifo_fd_array[fifo_id] = open(devstr, flags);
! if (fifo_fd_array[fifo_id] < 0) {
! /* open failed */
! return ULAPI_NOTFND;
! }
! /* fifo opened, update status */
! fifo->state |= HAS_WRITER;
! return fifo_id;
! }
}
}
+ /* find empty spot in fifo array */
+ n = 1;
+ while ((n <= RTAPI_MAX_FIFOS) &&
+ (fifo_array[n].state != UNUSED)) {
+ n++;
+ }
+ if (n > RTAPI_MAX_FIFOS) {
+ /* no room */
+ return ULAPI_LIMIT;
+ }
+ /* we have a free ID for the fifo */
+ fifo_id = n;
+ fifo = &(fifo_array[n]);
+ /* determine system name for fifo */
+ sprintf(devstr, "/dev/rtf%d", fifo_id);
/* open the fifo */
! fifo_fd_array[fifo_id] = open(devstr, flags);
! if (fifo_fd_array[fifo_id] < 0) {
/* open failed */
return ULAPI_NOTFND;
}
! /* the fifo has been created, update data */
! if ( mode == 'R' ) {
! fifo->state = HAS_READER;
! }
! else /* mode == 'W' */ {
! fifo->state = HAS_WRITER;
! }
fifo->key = key;
! fifo->size = size;
! rtapi_data->fifo_count++;
! /* done */
! return fifo_id;
}
! int ulapi_fifo_delete(int fifo_id, char mode)
{
! fifo_data *fifo;
!
! /* validate fifo ID */
! if ((fifo_id < 1) || (fifo_id > RTAPI_MAX_FIFOS)) {
! return ULAPI_BADID;
}
! /* point to the fifo's data */
! fifo = &(fifo_array[fifo_id]);
! /* is the fifo valid? */
! if (fifo->state == UNUSED ) {
! return ULAPI_BADID;
}
! /* check fifo state */
! if ( mode == 'R' ) {
! if (( fifo->state & HAS_READER ) == 0 ) {
! return ULAPI_INVAL;
! }
! /* close the fifo */
! if (close(fifo_id) < 0) {
! return ULAPI_NOTFND;
! }
! /* update fifo state */
! fifo->state &= ~HAS_READER;
}
! else if ( mode == 'W' ) {
! if (( fifo->state & HAS_WRITER ) == 0 ) {
! return ULAPI_INVAL;
! }
! /* close the fifo */
! if (close(fifo_id) < 0) {
! return ULAPI_NOTFND;
! }
! /* update fifo state */
! fifo->state &= ~HAS_WRITER;
! }
! else {
! return ULAPI_INVAL;
! }
! /* is somebody else still using the fifo */
! if ( fifo->state != UNUSED ) {
! /* yes, done for now */
! return ULAPI_SUCCESS;
! }
! /* no other users, update the data array and usage count */
! fifo->state = UNUSED;
! fifo->key = 0;
! fifo->size = 0;
! rtapi_data->fifo_count--;
return ULAPI_SUCCESS;
}
!
! int ulapi_fifo_read(int fifo_id, char *buf, unsigned long int size)
{
int retval;
! fifo_data *fifo;
!
! /* validate fifo ID */
! if ((fifo_id < 1) || (fifo_id > RTAPI_MAX_FIFOS)) {
! return ULAPI_BADID;
}
! /* point to the fifo's data */
! fifo = &(fifo_array[fifo_id]);
! /* is the fifo valid? */
! if ((fifo->state & HAS_READER) == 0 ) {
! return ULAPI_BADID;
}
/* get whatever data is available */
! retval = read(fifo_fd_array[fifo_id], buf, size);
if (retval <= 0) {
return ULAPI_FAIL;
***************
*** 251,272 ****
}
! int ulapi_fifo_write(ulapi_fifo_handle fifo,
! char *buf, unsigned long int size)
{
int retval;
! /* validate fifo handle */
! if (fifo == NULL) {
! return ULAPI_BADH;
! }
! if (fifo->magic != FIFO_MAGIC) {
! return ULAPI_BADH;
}
! if (fifo->mode != O_WRONLY) {
! return ULAPI_UNSUP;
}
-
/* put whatever data will fit */
! retval = write(fifo->fd, buf, size);
if (retval < 0) {
return ULAPI_FAIL;
--- 405,425 ----
}
! int ulapi_fifo_write(int fifo_id, char *buf, unsigned long int size)
{
int retval;
+ fifo_data *fifo;
! /* validate fifo ID */
! if ((fifo_id < 1) || (fifo_id > RTAPI_MAX_FIFOS)) {
! return ULAPI_BADID;
}
! /* point to the fifo's data */
! fifo = &(fifo_array[fifo_id]);
! /* is the fifo valid? */
! if ((fifo->state & HAS_WRITER) == 0 ) {
! return ULAPI_BADID;
}
/* put whatever data will fit */
! retval = write(fifo_fd_array[fifo_id], buf, size);
if (retval < 0) {
return ULAPI_FAIL;
Index: rtapi.h
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** rtapi.h 19 Aug 2003 17:29:50 -0000 1.25
--- rtapi.h 20 Aug 2003 03:16:21 -0000 1.26
***************
*** 66,70 ****
/** '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);
--- 66,71 ----
/** '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. Call
! only from within init/cleanup code, not from realtime tasks.
*/
extern int rtapi_init(void);
***************
*** 74,78 ****
called prior to exit by any module that called rtapi_init.
Returns a status code. Decrements the usage count maintained
! by rtapi_init.
*/
extern int rtapi_exit(void);
--- 75,80 ----
called prior to exit by any module that called rtapi_init.
Returns a status code. Decrements the usage count maintained
! by rtapi_init. Call only from within init/cleanup code, not
! from realtime tasks.
*/
extern int rtapi_exit(void);
***************
*** 86,90 ****
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, ...);
--- 88,93 ----
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. May be called from
! init/cleanup code, and from within realtime tasks.
*/
extern void rtapi_print(const char *fmt, ...);
***************
*** 95,99 ****
'rtapi_msg_level' is a global. The default is 7, but it may be
changed. The defines below are used for RTAPI messages, and are
! recommended for user messages as well.
*/
extern int rtapi_msg_level;
--- 98,103 ----
'rtapi_msg_level' is a global. The default is 7, but it may be
changed. The defines below are used for RTAPI messages, and are
! recommended for user messages as well. May be called from
! init/cleanup code, and from within realtime tasks.
*/
extern int rtapi_msg_level;
***************
*** 109,130 ****
************************************************************************/
- /* OLD VERSION */
-
- /** The clock period is the basic time interval for realtime tasks
- 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
- reset 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. */
-
- /* NEW VERSION */
-
/** 'rtapi_clock_set_period() sets the basic time interval for realtime
tasks. All periodic tasks will run at an integer multiple of this
--- 113,116 ----
***************
*** 140,144 ****
no effect. Calling 'rtapi_clock_set_period() with 'nsecs' set to
zero queries the clock, returning the current clock period, or zero
! if the clock has not yet been started.
*/
extern long int rtapi_clock_set_period(long int nsecs);
--- 126,131 ----
no effect. Calling 'rtapi_clock_set_period() with 'nsecs' set to
zero queries the clock, returning the current clock period, or zero
! if the clock has not yet been started. Call only from within
! init/cleanup code, not from realtime tasks.
*/
extern long int rtapi_clock_set_period(long int nsecs);
***************
*** 152,155 ****
--- 139,143 ----
Returns a 2^63 value. The resolution of the returned value may
be as good as one nano-second, or as poor as several microseconds.
+ May be called from init/cleanup code, and from within realtime tasks.
*/
extern long long int rtapi_get_time(void);
***************
*** 164,168 ****
called befure using 'rtapi_sleep()' to make sure the required delays
can be achieved. The actual resolution of the delay may be as good
! as one nano-second, or as bad as a several microseconds.
*/
extern void rtapi_sleep(long int nsec);
--- 152,157 ----
called befure using 'rtapi_sleep()' to make sure the required delays
can be achieved. The actual resolution of the delay may be as good
! as one nano-second, or as bad as a several microseconds. May be
! called from init/cleanup code, and from within realtime tasks.
*/
extern void rtapi_sleep(long int nsec);
***************
*** 193,196 ****
--- 182,188 ----
for each task of the next highest priority, set their priorities
to 'rtapi_prio_next_lower(previous)'.
+
+ Call these functions only from within init/cleanup code, not from
+ realtime tasks.
*/
extern int rtapi_prio_highest(void);
***************
*** 219,222 ****
--- 211,215 ----
definitely does not use floating point, setting 'uses_fp' to
RTAPI_NO_FP saves a few microseconds per task switch.
+ Call only from within init/cleanup code, not from realtime tasks.
*/
#define RTAPI_NO_FP 0
***************
*** 231,236 ****
associated with 'task', and does any other cleanup needed. If
the task has been started, you should pause it before deleting
! it. Returns a status code. Call from within init or cleanup
! code, or from another task. A task cannot delete itself!
*/
extern int rtapi_task_delete(int task_id);
--- 224,229 ----
associated with 'task', and does any other cleanup needed. If
the task has been started, you should pause it before deleting
! it. Returns a status code. Call only from within init/cleanup
! code, not from realtime tasks.
*/
extern int rtapi_task_delete(int task_id);
***************
*** 252,255 ****
--- 245,249 ----
at a specific time, it will return RTAPI_UNSUP and the task will not
be started.
+ Call only from within init/cleanup code, not from realtime tasks.
*/
#define RTAPI_NOW 0
***************
*** 262,266 ****
next period. The task must be periodic, if not, the result is
undefined. The function will return at the beginning of the
! next period. Call only from within a task.
*/
extern void rtapi_wait(void);
--- 256,260 ----
next period. The task must be periodic, if not, the result is
undefined. The function will return at the beginning of the
! next period. Call only from within a realtime task.
*/
extern void rtapi_wait(void);
***************
*** 276,279 ****
--- 270,274 ----
resume when the function unblocks.
3) it is returned to the "paused" state by rtapi_task_pause().
+ May be called from init/cleanup code, and from within realtime tasks.
*/
extern int rtapi_task_resume(int task_id);
***************
*** 285,289 ****
or cleanup code, not just from the task that is to be paused.
The task will resume execution when either rtapi_task_resume() or
! rtapi_task_start() is called.
*/
extern int rtapi_task_pause(int task_id);
--- 280,285 ----
or cleanup code, not just from the task that is to be paused.
The task will resume execution when either rtapi_task_resume() or
! rtapi_task_start() is called. May be called from init/cleanup code,
! and from within realtime tasks.
*/
extern int rtapi_task_pause(int task_id);
***************
*** 291,295 ****
/** 'rtapi_task_self()' returns the task ID of the current task.
! May return a negative error code if called from outside a task.
*/
extern int rtapi_task_self(void);
--- 287,291 ----
/** 'rtapi_task_self()' returns the task ID of the current task.
! Call only from a realtime task.
*/
extern int rtapi_task_self(void);
***************
*** 307,312 ****
it returns a positive integer ID, which is used for all subsequent
calls dealing with the block. On failure it returns a negative
! error code. To get a pointer to the shared memory, pass the ID
! to 'rtapi_shmem_getptr()'.
*/
extern int rtapi_shmem_new(int key, unsigned long int size);
--- 303,308 ----
it returns a positive integer ID, which is used for all subsequent
calls dealing with the block. On failure it returns a negative
! error code. Call only from within init/cleanup code, not from
! realtime tasks.
*/
extern int rtapi_shmem_new(int key, unsigned long int size);
***************
*** 314,323 ****
/** 'rtapi_shmem_delete()' frees the shared memory block associated
! with 'shmem_id'. Returns a status code.
*/
extern int rtapi_shmem_delete(int shmem_id);
/** 'rtapi_shmem_getptr()' sets '*ptr' to point to shared memory block
! associated with 'shmem_id'. Returns a status code.
*/
extern int rtapi_shmem_getptr(int shmem_id, void **ptr);
--- 310,321 ----
/** 'rtapi_shmem_delete()' frees the shared memory block associated
! with 'shmem_id'. Returns a status code. Call only from within
! init/cleanup code, not from realtime tasks.
*/
extern int rtapi_shmem_delete(int shmem_id);
/** 'rtapi_shmem_getptr()' sets '*ptr' to point to shared memory block
! associated with 'shmem_id'. Returns a status code. May be called
! from init/cleanup code, and from within realtime tasks.
*/
extern int rtapi_shmem_getptr(int shmem_id, void **ptr);
***************
*** 333,337 ****
returns a positive integer ID, which is used for all subsequent
calls dealing with the semaphore. On failure it returns a negative
! error code.
*/
extern int rtapi_sem_new(int key);
--- 331,336 ----
returns a positive integer ID, which is used for all subsequent
calls dealing with the semaphore. On failure it returns a negative
! error code. Call only from within init/cleanup code, not from
! realtime tasks.
*/
extern int rtapi_sem_new(int key);
***************
*** 340,344 ****
/** 'rtapi_sem_delete()' is the counterpart to 'rtapi_sem_new()'. It
discards the semaphore associated with 'sem_id'. Any tasks blocked
! on 'sem' will resume execution. Returns a status code.
*/
extern int rtapi_sem_delete(int sem_id);
--- 339,344 ----
/** 'rtapi_sem_delete()' is the counterpart to 'rtapi_sem_new()'. It
discards the semaphore associated with 'sem_id'. Any tasks blocked
! on 'sem' will resume execution. Returns a status code. Call only
! from within init/cleanup code, not from realtime tasks.
*/
extern int rtapi_sem_delete(int sem_id);
***************
*** 348,351 ****
--- 348,352 ----
is blocked on the semaphore, the calling task will block and the
higher priority task will begin to run. Returns a status code.
+ May be called from init/cleanup code, and from within realtime tasks.
*/
extern int rtapi_sem_give(int sem_id);
***************
*** 356,359 ****
--- 357,361 ----
immediately. If the semaphore is locked, the calling task blocks
until the semaphore is unlocked, then it returns RTAPI_SUCCESS.
+ Call only from within a realtime task.
*/
extern int rtapi_sem_take(int sem_id);
***************
*** 364,368 ****
is unlocked, it returns RTAPI_SUCCESS. If the semaphore is locked
it does not block, instead it returns RTAPI_BUSY, and the caller
! can decide how to deal with the situation.
*/
extern int rtapi_sem_try(int sem_id);
--- 366,371 ----
is unlocked, it returns RTAPI_SUCCESS. If the semaphore is locked
it does not block, instead it returns RTAPI_BUSY, and the caller
! can decide how to deal with the situation. Call only from within
! a realtime task.
*/
extern int rtapi_sem_try(int sem_id);
***************
*** 379,382 ****
--- 382,386 ----
returns a positive integer ID, which is used for subsequent calls
dealing with the fifo. On failure, returns a negative error code.
+ Call only from within init/cleanup code, not from realtime tasks.
*/
***************
*** 390,393 ****
--- 394,398 ----
It closes the fifo associated with 'fifo_ID'. 'mode' is the mode
that was specified when the fifo was created. Returns status code.
+ Call only from within init/cleanup code, not from realtime tasks.
*/
extern int rtapi_fifo_delete(int fifo_id, char mode);
***************
*** 411,415 ****
Returns the number of bytes actually read, or RTAPI_BADH. Does not
block. If 'size' bytes are not available, it will read whatever is
! available, and return that count (which could be zero).
*/
extern int rtapi_fifo_read(int fifo_id, char *buf, unsigned long int size);
--- 416,421 ----
Returns the number of bytes actually read, or RTAPI_BADH. Does not
block. If 'size' bytes are not available, it will read whatever is
! available, and return that count (which could be zero). Call only
! from within a realtime task.
*/
extern int rtapi_fifo_read(int fifo_id, char *buf, unsigned long int size);
***************
*** 420,424 ****
actually written, or RTAPI_BADH. Does not block. If 'size' bytes
of space are not available in the fifo, it will write as many bytes
! as it can and return that count (which may be zero).
*/
extern int rtapi_fifo_write(int fifo_id, char *buf, unsigned long int size);
--- 426,431 ----
actually written, or RTAPI_BADH. Does not block. If 'size' bytes
of space are not available in the fifo, it will write as many bytes
! as it can and return that count (which may be zero). Call only from
! within a realtime task.
*/
extern int rtapi_fifo_write(int fifo_id, char *buf, unsigned long int size);
***************
*** 434,437 ****
--- 441,445 ----
'handler will be called when the interrupt occurs. Returns a status
code. Note: The simulated RTOS does not support interrupts.
+ Call only from within init/cleanup code, not from realtime tasks.
*/
extern int rtapi_assign_interrupt_handler(unsigned int irq,
***************
*** 443,447 ****
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);
--- 451,456 ----
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. Call only from within
! init/cleanup code, not from realtime tasks.
*/
extern int rtapi_free_interrupt_handler(unsigned int irq);
***************
*** 450,454 ****
/** '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);
--- 459,465 ----
/** '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. May be
! called from init/cleanup code, and from within realtime tasks.
!
*/
extern int rtapi_enable_interrupt(unsigned int irq);
***************
*** 459,463 ****
************************************************************************/
! /** 'rtapi_outb() writes 'byte' to 'port'.
Note: This function does nothing on the simulated RTOS.
Note: Many platforms provide an inline outb() that is faster.
--- 470,475 ----
************************************************************************/
! /** 'rtapi_outb() writes 'byte' to 'port'. May be called from
! init/cleanup code, and from within realtime tasks.
Note: This function does nothing on the simulated RTOS.
Note: Many platforms provide an inline outb() that is faster.
***************
*** 466,534 ****
! /** 'rtapi_inb() gets a byte from 'port'. Returns the byte.
Note: This function always returns zero on the simulated RTOS.
Note: Many platforms provide an inline inb() that is faster.
*/
extern unsigned char rtapi_inb(unsigned int port);
-
- /***********************************************************************
- * PROC_FS MACROS *
- ************************************************************************/
- #include <linux/proc_fs.h>
-
- /* proc print macros - Contributed by: Erwin Rol (er...@mu...)
- and shamelessly ripped from rtai_proc_fs.h, part of the RTAI project.
- See http://www.rtai.org for more details.
-
- macro that holds the local variables that
- we use in the PROC_PRINT_* macros. We have
- this macro so we can add variables with out
- changing the users of this macro, of course
- only when the names don't colide! */
-
- #define PROC_PRINT_VARS \
- off_t pos = 0; \
- off_t begin = 0; \
- int len = 0 /* no ";" */
-
- /* macro that prints in the procfs read buffer.
- this macro expects the function arguments to be
- named as follows.
- static int FOO(char *page, char **start,
- off_t off, int count, int *eof, void *data) */
-
- #define PROC_PRINT(fmt,args...) \
- len += sprintf(page + len , fmt, ##args); \
- pos += len; \
- if(pos < off) { \
- len = 0; \
- begin = pos; \
- } \
- if(pos > off + count) \
- goto done;
-
- /* macro to leave the read function for a other
- place than at the end. */
- #define PROC_PRINT_RETURN \
- *eof = 1; \
- goto done // no ";"
-
- /* macro that should only used ones at the end of the
- read function, to return from a other place in the
- read function use the PROC_PRINT_RETURN macro. */
- #define PROC_PRINT_DONE \
- *eof = 1; \
- done: \
- *start = page + (off - begin); \
- len -= (off - begin); \
- if(len > count) \
- len = count; \
- if(len < 0) \
- len = 0; \
- return len // no ";"
-
- /***********************************************************************
- * End of rtapi.h *
- ************************************************************************/
#endif /* RTAPI_H */
--- 478,487 ----
! /** 'rtapi_inb() gets a byte from 'port'. Returns the byte. May
! be called from init/cleanup code, and from within realtime tasks.
Note: This function always returns zero on the simulated RTOS.
Note: Many platforms provide an inline inb() that is faster.
*/
extern unsigned char rtapi_inb(unsigned int port);
#endif /* RTAPI_H */
Index: rtapi_common.h
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi_common.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rtapi_common.h 19 Aug 2003 17:29:51 -0000 1.1
--- rtapi_common.h 20 Aug 2003 03:16:21 -0000 1.2
***************
*** 3,10 ****
/** 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_common.h', contains data structures and functions
! used by the rtapi internally. Do NOT include this file in any user app. */
/** Copyright (C) 2003 John Kasunich
--- 3,17 ----
/** 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_common.h', contains typedefs and other items
! common to both the realtime and non-realtime portions of the
! implementation. These items are also common to both the RTAI
! and RTLinux implementations, and most likely to any other
! implementations in the Linux environment. This data is INTERNAL
! to the RTAPI implementation, and should not be included in any
! application modules.
! */
/** Copyright (C) 2003 John Kasunich
***************
*** 12,17 ****
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
--- 19,26 ----
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
***************
*** 25,30 ****
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
--- 34,40 ----
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
***************
*** 34,133 ****
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 <linux/proc_fs.h>
!
! static int msg = 7; /* short name, for use in insmod command */
!
! /* module information */
! MODULE_PARM(msg, "i");
! MODULE_PARM_DESC(msg, "debug message level (default=7)");
! MODULE_AUTHOR("John Kasunich, Fred Proctor, & Paul Corner");
!
! /* proc print macros - Contributed by: Erwin Rol (er...@mu...)
! and shamelessly ripped from rtai_proc_fs.h, part of the RTAI project.
! See http://www.rtai.org for more details.
!
! macro that holds the local variables that
! we use in the PROC_PRINT_* macros. We have
! this macro so we can add variables with out
! changing the users of this macro, of course
! only when the names don't colide! */
!
! #define PROC_PRINT_VARS \
! off_t pos = 0; \
! off_t begin = 0; \
! int len = 0 /* no ";" */
!
! /* macro that prints in the procfs read buffer.
! this macro expects the function arguments to be
! named as follows.
! static int FOO(char *page, char **start,
! off_t off, int count, int *eof, void *data) */
!
! #define PROC_PRINT(fmt,args...) \
! len += sprintf(page + len , fmt, ##args); ...
[truncated message content] |