|
From: <jmk...@us...> - 2003-08-15 20:47:53
|
Update of /cvsroot/emc/rtapi/src/rtapi
In directory sc8-pr-cvs1:/tmp/cvs-serv2354/src/rtapi
Modified Files:
rtai_rtapi.c rtapi.h
Log Message:
Finished converting rtai_rtapi.c, added watchdog example.
Index: rtai_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_rtapi.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** rtai_rtapi.c 14 Aug 2003 04:08:26 -0000 1.23
--- rtai_rtapi.c 15 Aug 2003 20:45:13 -0000 1.24
***************
*** 78,85 ****
/* These structs hold data associated with objects like tasks, etc. */
! typedef enum { EMPTY, PAUSED, PERIODIC, FREERUN, ENDED } state_t;
typedef struct {
! state_t state; /* task state */
void *taskcode; /* task code */
RT_TASK *ostask; /* pointer to OS specific task data */
--- 78,85 ----
/* These structs hold data associated with objects like tasks, etc. */
! typedef enum { EMPTY = 0, PAUSED, PERIODIC, FREERUN, ENDED } task_state_t;
typedef struct {
! task_state_t state; /* task state */
void *taskcode; /* task code */
RT_TASK *ostask; /* pointer to OS specific task data */
***************
*** 99,110 ****
} sem_data;
! struct rtapi_fifo {
! int magic; /* to check for valid handle */
int key; /* key to fifo */
- int fd; /* file descripter for fifo */
unsigned long int size; /* size of fifo area */
! };
!
! #define FIFO_MAGIC 10293
/* maximum number of various resources */
--- 99,113 ----
} sem_data;
! typedef enum { UNUSED = 0,
! HAS_READER = 1,
! HAS_WRITER = 2,
! HAS_BOTH = 3 } fifo_state_t; /* used as bitmasks */
!
! typedef struct {
! fifo_state_t state; /* task state */
int key; /* key to fifo */
unsigned long int size; /* size of fifo area */
! int fd; /* file descripter for fifo */
! } fifo_data;
/* maximum number of various resources */
***************
*** 119,123 ****
static shmem_data shmem_array[RTAPI_MAX_SHMEMS+1];
static sem_data sem_array[RTAPI_MAX_SEMS+1];
! static rtapi_fifo_handle fifo_array[RTAPI_MAX_FIFOS+1];
/* Usage counters to keep track of new/delete calls */
--- 122,126 ----
static shmem_data shmem_array[RTAPI_MAX_SHMEMS+1];
static sem_data sem_array[RTAPI_MAX_SEMS+1];
! static fifo_data fifo_array[RTAPI_MAX_FIFOS+1];
/* Usage counters to keep track of new/delete calls */
***************
*** 133,136 ****
--- 136,140 ----
/* global used for message printing */
int rtapi_msg_level;
+ char *rev_str; /* version of RTAPI */
static int msg = 7; /* short name, for use in insmod command */
***************
*** 151,154 ****
--- 155,159 ----
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 */
***************
*** 157,175 ****
{
PROC_PRINT_VARS;
! PROC_PRINT("******* RTAI rtapi usage *******\n");
! PROC_PRINT(" Version = $Revision$\n");
! PROC_PRINT(" Modules Loaded = %i\n", rtapi_usage_count);
! PROC_PRINT(" Tasks running = %i/%i\n", task_usage_count, RTAPI_MAX_TASKS);
! PROC_PRINT(" Shared memory = %i/%i\n", shmem_usage_count, RTAPI_MAX_SHMEMS);
! PROC_PRINT(" FIFO count = %i/%i\n", fifo_usage_count, RTAPI_MAX_FIFOS);
! PROC_PRINT(" Semaphores used = %i/%i\n", sem_usage_count, RTAPI_MAX_SEMS);
! PROC_PRINT("Active Interrupts = %i\n", int_usage_count);
! PROC_PRINT(" Timer period = %li nSec\n", timer_period);
if (timer_running) {
! PROC_PRINT(" Timer status = Running\n");
} else {
! PROC_PRINT(" Timer status = Stopped\n");
}
! PROC_PRINT(" Message level = %i\n", rtapi_msg_level);
PROC_PRINT("\n");
PROC_PRINT_DONE;
--- 162,181 ----
{
PROC_PRINT_VARS;
! PROC_PRINT("******* RTAPI STATUS ********\n");
! PROC_PRINT(" Platform = RTAI\n");
! PROC_PRINT(" Version = %s\n", rev_str);
! PROC_PRINT(" Modules = %i\n", rtapi_usage_count);
! PROC_PRINT(" Tasks = %i/%i\n", task_usage_count, RTAPI_MAX_TASKS);
! PROC_PRINT("Shared memory = %i/%i\n", shmem_usage_count, RTAPI_MAX_SHMEMS);
! PROC_PRINT(" FIFOs = %i/%i\n", fifo_usage_count, RTAPI_MAX_FIFOS);
! PROC_PRINT(" Semaphores = %i/%i\n", sem_usage_count, RTAPI_MAX_SEMS);
! PROC_PRINT(" Interrupts = %i\n", int_usage_count);
if (timer_running) {
! PROC_PRINT(" Timer status = Running\n");
! PROC_PRINT(" Timer period = %li nSec\n", timer_period);
} else {
! PROC_PRINT(" Timer status = Stopped\n");
}
! PROC_PRINT("Message level = %i\n", rtapi_msg_level);
PROC_PRINT("\n");
PROC_PRINT_DONE;
***************
*** 184,188 ****
PROC_PRINT_VARS;
! PROC_PRINT("******* RTAPI TASKS *******\n");
PROC_PRINT("ID State Code\n");
for ( n = 1 ; n <= RTAPI_MAX_TASKS ; n++ ) {
--- 190,194 ----
PROC_PRINT_VARS;
! PROC_PRINT("******** RTAPI TASKS ********\n");
PROC_PRINT("ID State Code\n");
for ( n = 1 ; n <= RTAPI_MAX_TASKS ; n++ ) {
***************
*** 239,243 ****
PROC_PRINT_VARS;
! PROC_PRINT("***** RTAPI SEMAPHORES *****\n");
PROC_PRINT("ID Users Key\n");
for ( n = 1 ; n <= RTAPI_MAX_SEMS ; n++ ) {
--- 245,249 ----
PROC_PRINT_VARS;
! PROC_PRINT("***** RTAPI SEMAPHORES ******\n");
PROC_PRINT("ID Users Key\n");
for ( n = 1 ; n <= RTAPI_MAX_SEMS ; n++ ) {
***************
*** 252,260 ****
static int proc_read_debug(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
PROC_PRINT_VARS;
! PROC_PRINT("RTAPI Debug Message Level: %i\n\n", rtapi_msg_level);
PROC_PRINT_DONE;
}
--- 258,310 ----
+ 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;
+ 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");
+ PROC_PRINT_DONE;
+ }
+
+
static int proc_read_debug(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
PROC_PRINT_VARS;
! 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");
PROC_PRINT_DONE;
}
***************
*** 318,321 ****
--- 368,378 ----
}
sems_file->owner = THIS_MODULE;
+ /* create read only file "/proc/rtapi/fifos" using convenience function */
+ fifos_file = create_proc_read_entry("fifos", 0444, rtapi_dir,
+ proc_read_fifos, NULL);
+ if ( fifos_file == NULL) {
+ return -1;
+ }
+ fifos_file->owner = THIS_MODULE;
/* create read/write file "/proc/rtapi/debug" using regular function */
debug_file = create_proc_entry("debug", 0644, rtapi_dir );
***************
*** 334,348 ****
/* remove /proc entries, only if they exist */
if (rtapi_dir != NULL) {
- if (debug_file != NULL) {
- remove_proc_entry("debug", rtapi_dir);
- debug_file = NULL;
- }
if (status_file != NULL) {
remove_proc_entry("status", rtapi_dir);
status_file = NULL;
}
! if (sems_file != NULL) {
! remove_proc_entry("sems", rtapi_dir);
! sems_file = NULL;
}
if (shmem_file != NULL) {
--- 391,401 ----
/* 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) {
***************
*** 350,356 ****
shmem_file = NULL;
}
! if (tasks_file != NULL) {
! remove_proc_entry("tasks", rtapi_dir);
! tasks_file = NULL;
}
remove_proc_entry("rtapi", NULL);
--- 403,417 ----
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);
***************
*** 380,384 ****
rtapi_usage_count++;
/* MOD_INC_USE_COUNT;*/
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: init called, module count = %d\n",
rtapi_usage_count);
return RTAPI_SUCCESS;
--- 441,445 ----
rtapi_usage_count++;
/* MOD_INC_USE_COUNT;*/
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: init called, module count = %d\n",
rtapi_usage_count);
return RTAPI_SUCCESS;
***************
*** 397,401 ****
}
/* MOD_DEC_USE_COUNT;*/
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: exit called, module count = %d\n",
rtapi_usage_count);
return RTAPI_SUCCESS;
--- 458,462 ----
}
/* MOD_DEC_USE_COUNT;*/
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: exit called, module count = %d\n",
rtapi_usage_count);
return RTAPI_SUCCESS;
***************
*** 411,417 ****
--- 472,485 ----
/* get the message level from insmod command line */
rtapi_msg_level = msg;
+ /* CVS automatically updates this string */
+ rev_str = "$Revision$";
+ /* extract the revision number from it */
+ rev_str += 11;
+ rev_str[5] = '\0';
/* say hello */
+ rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: Version %s\n", rev_str);
rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: Initing\n");
#ifdef CONFIG_PROC_FS
+ /* set up /proc/rtapi */
if ( proc_init() != 0 ) {
rtapi_print_msg(RTAPI_MSG_WARN, "Could not activate /proc entries\n");
***************
*** 436,440 ****
}
for (n = 0; n <= RTAPI_MAX_FIFOS; n++) {
! fifo_array[n] = NULL;
}
/* zero all the counters */
--- 504,509 ----
}
for (n = 0; n <= RTAPI_MAX_FIFOS; n++) {
! fifo_array[n].state = UNUSED;
! fifo_array[n].size = 0;
}
/* zero all the counters */
***************
*** 469,476 ****
"RTAPI: WARNING: %d fifo(s) allocated but not deleted\n",
fifo_usage_count);
! /* clean up leftover fifos (start at 1, we don't use task ID 0 */
for (n = 1; n <= RTAPI_MAX_FIFOS; n++) {
! if (fifo_array[n] != NULL) {
! rtapi_fifo_delete(fifo_array[n]);
}
}
--- 538,546 ----
"RTAPI: WARNING: %d fifo(s) allocated but not deleted\n",
fifo_usage_count);
! /* clean up leftover fifos (start at 1, we don't use fifo ID 0 */
for (n = 1; n <= RTAPI_MAX_FIFOS; n++) {
! if (fifo_array[n].state != UNUSED) {
! rtapi_fifo_delete(n, 'W');
! rtapi_fifo_delete(n, 'R');
}
}
***************
*** 510,515 ****
}
if (rtapi_usage_count != 0) {
! rtapi_print_msg(RTAPI_MSG_ERR,
! "RTAPI: ERROR: %d modules called init() but not exit()\n",
rtapi_usage_count);
}
--- 580,585 ----
}
if (rtapi_usage_count != 0) {
! rtapi_print_msg(RTAPI_MSG_WARN,
! "RTAPI: WARN: %d modules called init() but not exit()\n",
rtapi_usage_count);
}
***************
*** 581,585 ****
timer_period = count2nano(start_rt_timer(nano2count((RTIME) nsecs)));
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: clock_set_period requested: %d actual: %d\n",
nsecs, timer_period);
--- 651,655 ----
timer_period = count2nano(start_rt_timer(nano2count((RTIME) nsecs)));
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: clock_set_period requested: %d actual: %d\n",
nsecs, timer_period);
***************
*** 694,698 ****
task_usage_count++;
/* announce the birth of a brand new baby task */
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: new_task id: %02d, count: %d, code: %p\n",
task_id, task_usage_count, taskcode);
/* and return the ID to the proud parent */
--- 764,768 ----
task_usage_count++;
/* announce the birth of a brand new baby task */
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: new_task id: %02d, count: %d, code: %p\n",
task_id, task_usage_count, taskcode);
/* and return the ID to the proud parent */
***************
*** 737,741 ****
task_usage_count--;
/* done */
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: delete_task id: %02d, count: %d\n",
task_id, task_usage_count);
return RTAPI_SUCCESS;
--- 807,811 ----
task_usage_count--;
/* done */
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_task id: %02d, count: %d\n",
task_id, task_usage_count);
return RTAPI_SUCCESS;
***************
*** 782,786 ****
/* ok, task is started (or at least scheduled to start) */
task->state = PERIODIC;
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: start_task id: %02d\n", task_id);
return retval;
}
--- 852,856 ----
/* ok, task is started (or at least scheduled to start) */
task->state = PERIODIC;
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: start_task id: %02d\n", task_id);
return retval;
}
***************
*** 895,899 ****
shmem->users++;
/* announce another user for this shmem */
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: new_shmem id: %02d, users: %d, key: %d, size %lu\n",
shmem_id, shmem->users, key, size);
--- 965,969 ----
shmem->users++;
/* announce another user for this shmem */
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: new_shmem id: %02d, users: %d, key: %d, size %lu\n",
shmem_id, shmem->users, key, size);
***************
*** 925,929 ****
shmem_usage_count++;
/* announce the birth of a brand new baby shmem */
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: new_shmem id: %02d, count: %d, key: %d, size: %lu\n",
shmem_id, shmem_usage_count, key, size);
--- 995,999 ----
shmem_usage_count++;
/* announce the birth of a brand new baby shmem */
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: new_shmem id: %02d, count: %d, key: %d, size: %lu\n",
shmem_id, shmem_usage_count, key, size);
***************
*** 951,955 ****
if (shmem->users > 0 ) {
/* yes, we're done for now */
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: delete_shmem id: %02d, users: %d\n",
shmem_id, shmem->users);
return RTAPI_SUCCESS;
--- 1021,1025 ----
if (shmem->users > 0 ) {
/* yes, we're done for now */
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_shmem id: %02d, users: %d\n",
shmem_id, shmem->users);
return RTAPI_SUCCESS;
***************
*** 963,967 ****
shmem->mem = NULL;
shmem_usage_count--;
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: delete_shmem id: %02d, count: %d\n",
shmem_id, shmem_usage_count);
return RTAPI_SUCCESS;
--- 1033,1037 ----
shmem->mem = NULL;
shmem_usage_count--;
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_shmem id: %02d, count: %d\n",
shmem_id, shmem_usage_count);
return RTAPI_SUCCESS;
***************
*** 1011,1015 ****
sem->users++;
/* announce another user for this semaphore */
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: new_sem id: %02d, users: %d, key: %d\n",
sem_id, sem->users, key);
--- 1081,1085 ----
sem->users++;
/* announce another user for this semaphore */
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: new_sem id: %02d, users: %d, key: %d\n",
sem_id, sem->users, key);
***************
*** 1037,1041 ****
sem_usage_count++;
/* announce the birth of a brand new baby semaphore */
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: new_sem id: %02d, count: %d, key: %d\n",
sem_id, sem_usage_count, key);
--- 1107,1111 ----
sem_usage_count++;
/* announce the birth of a brand new baby semaphore */
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: new_sem id: %02d, count: %d, key: %d\n",
sem_id, sem_usage_count, key);
***************
*** 1063,1067 ****
if (sem->users > 0 ) {
/* yes, we're done for now */
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: delete_sem id: %02d, users: %d\n",
sem_id, sem->users);
return RTAPI_SUCCESS;
--- 1133,1137 ----
if (sem->users > 0 ) {
/* yes, we're done for now */
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_sem id: %02d, users: %d\n",
sem_id, sem->users);
return RTAPI_SUCCESS;
***************
*** 1073,1077 ****
sem->key = 0;
sem_usage_count--;
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: delete_sem id: %02d, count: %d\n",
sem_id, sem_usage_count);
return RTAPI_SUCCESS;
--- 1143,1147 ----
sem->key = 0;
sem_usage_count--;
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_sem id: %02d, count: %d\n",
sem_id, sem_usage_count);
return RTAPI_SUCCESS;
***************
*** 1145,1250 ****
************************************************************************/
! int rtapi_fifo_new(int key, unsigned long int size,
! rtapi_fifo_handle * fifoptr)
{
! rtapi_fifo_handle fifo;
! int retval;
! int n;
! /* validate fifoptr */
! if (fifoptr == NULL) {
return RTAPI_INVAL;
}
/* find empty spot in fifo array */
! n = 0;
! while ((n < RTAPI_MAX_FIFOS) && (fifo_array[n] != NULL)) {
n++;
}
! if (n == RTAPI_MAX_FIFOS) {
! return RTAPI_NOMEM;
! }
! /* alloc space for fifo structure */
! fifo = kmalloc(sizeof(struct rtapi_fifo), GFP_USER);
! if (fifo == NULL) {
! return RTAPI_NOMEM;
}
/* create the fifo */
! retval = rtf_create(key, size);
/* rtf_create() returns 0 on success */
if (retval != 0) {
/* create failed */
- kfree(fifo);
if (retval == ENOMEM) {
/* couldn't allocate memory */
return RTAPI_NOMEM;
}
! return RTAPI_INVAL;
}
- /* add to fifo array */
- fifo_array[n] = fifo;
- /* label as a valid fifo structure */
- fifo->magic = FIFO_MAGIC;
- /* fill in the rest of the struct */
fifo->key = key;
! fifo->fd = key;
! /* increment the usage counter */
fifo_usage_count++;
! /* return handle to the caller */
! *fifoptr = fifo;
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: new_fifo %p, count = %d\n",
! fifo, fifo_usage_count);
! return RTAPI_SUCCESS;
}
! int rtapi_fifo_delete(rtapi_fifo_handle fifo)
{
! int n;
! /* validate fifo handle */
! if (fifo == NULL) {
! return RTAPI_BADH;
}
! if (fifo->magic != FIFO_MAGIC) {
! return RTAPI_BADH;
}
! /* find entry in fifo array */
! n = 0;
! while ((n < RTAPI_MAX_FIFOS) && (fifo_array[n] != fifo)) {
! n++;
}
! if (n == RTAPI_MAX_FIFOS) {
return RTAPI_INVAL;
}
! /* call the OS to destroy the fifo */
! rtf_destroy(fifo->fd);
! /* mark the array entry unused */
! fifo_array[n] = NULL;
! fifo->magic = 0;
! /* free the fifo structure */
! kfree(fifo);
! /* decrement the usage counter */
fifo_usage_count--;
! rtapi_print_msg(RTAPI_MSG_INFO, "RTAPI: delete_fifo %p, count = %d\n",
! fifo, fifo_usage_count);
return RTAPI_SUCCESS;
}
! int rtapi_fifo_read(rtapi_fifo_handle fifo, char *buf, unsigned long int size)
{
int retval;
! /* validate fifo handle */
! if (fifo == NULL) {
! return RTAPI_BADH;
}
! if (fifo->magic != FIFO_MAGIC) {
! return RTAPI_BADH;
}
/* get whatever data is available */
retval = rtf_get(fifo->fd, &buf, size);
if (retval < 0) {
! return RTAPI_INVAL;
}
return retval;
--- 1215,1379 ----
************************************************************************/
! int rtapi_fifo_new(int key, unsigned long int size, char mode)
{
! int n, retval;
! int fifo_id;
! fifo_data *fifo;
! /* key must be non-zero */
! if ( key == 0 ) {
! return RTAPI_INVAL;
! }
! /* mode must be "R" or "W" */
! if (( mode != 'R' ) && ( mode != 'W' )) {
return RTAPI_INVAL;
}
+ /* 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 RTAPI_BUSY;
+ }
+ /* available, update status */
+ fifo->state |= HAS_READER;
+ /* announce */
+ rtapi_print_msg(RTAPI_MSG_DBG,
+ "RTAPI: new_fifo id: %02d, add reader\n", fifo_id);
+ return fifo_id;
+ }
+ else /* mode == 'W' */ {
+ if ( fifo->state & HAS_WRITER ) {
+ return RTAPI_BUSY;
+ }
+ /* available, update status */
+ fifo->state |= HAS_WRITER;
+ /* announce */
+ rtapi_print_msg(RTAPI_MSG_DBG,
+ "RTAPI: new_fifo id: %02d, add writer\n", fifo_id);
+ 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 RTAPI_LIMIT;
}
+ /* we have space for the fifo */
+ fifo_id = n;
+ fifo = &(fifo_array[n]);
/* create the fifo */
! retval = rtf_create(fifo_id, size);
/* rtf_create() returns 0 on success */
if (retval != 0) {
/* create failed */
if (retval == ENOMEM) {
/* couldn't allocate memory */
return RTAPI_NOMEM;
}
! /* some other failure */
! return RTAPI_FAIL;
! }
! /* 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;
! fifo->fd = fifo_id;
fifo_usage_count++;
! /* announce a new fifo */
! rtapi_print_msg(RTAPI_MSG_DBG,
! "RTAPI: new_fifo id: %02d, count: %d, mode %c, key: %d, size: %ld\n",
! fifo_id, fifo_usage_count, mode, key, size);
! /* and return the ID */
! return fifo_id;
}
! int rtapi_fifo_delete(int fifo_id, char mode)
{
! fifo_data *fifo;
! /* validate sem ID */
! if ((fifo_id < 1) || (fifo_id > RTAPI_MAX_FIFOS)) {
! return RTAPI_BADID;
}
! /* point to the fifo's data */
! fifo = &(fifo_array[fifo_id]);
! /* is the fifo valid? */
! if (fifo->state == UNUSED ) {
! return RTAPI_BADID;
}
! /* update fifo state */
! if ( mode == 'R' ) {
! if (( fifo->state & HAS_READER ) == 0 ) {
! return RTAPI_INVAL;
! }
! fifo->state &= ~HAS_READER;
}
! else if ( mode == 'W' ) {
! if (( fifo->state & HAS_WRITER ) == 0 ) {
! return RTAPI_INVAL;
! }
! fifo->state &= ~HAS_WRITER;
! }
! else {
return RTAPI_INVAL;
}
! /* is somebody else still using the fifo */
! if ( fifo->state != UNUSED ) {
! /* yes, done for now */
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_fifo id: %02d, for %c\n",
! fifo_id, mode);
! return RTAPI_SUCCESS;
! }
! /* no other users, call the OS to destroy the fifo */
! /* OS returns open count, loop until truly destroyed */
! while ( rtf_destroy(fifo->fd) > 0 );
! /* update the data array and usage count */
! fifo->state = UNUSED;
! fifo->key = 0;
! fifo->size = 0;
! fifo->fd = 0;
fifo_usage_count--;
! rtapi_print_msg(RTAPI_MSG_DBG, "RTAPI: delete_fifo id: %02d, count: %d\n",
! fifo_id, fifo_usage_count);
return RTAPI_SUCCESS;
}
! int rtapi_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 RTAPI_BADID;
}
! /* point to the fifo's data */
! fifo = &(fifo_array[fifo_id]);
! /* is the fifo valid? */
! if (fifo->state == UNUSED ) {
! return RTAPI_BADID;
}
/* get whatever data is available */
retval = rtf_get(fifo->fd, &buf, size);
if (retval < 0) {
! return RTAPI_FAIL;
}
return retval;
***************
*** 1252,1268 ****
! int rtapi_fifo_write(rtapi_fifo_handle fifo, char *buf,
! unsigned long int size)
{
int retval;
! /* validate fifo handle */
! if (fifo == NULL) {
! return RTAPI_BADH;
}
! if (fifo->magic != FIFO_MAGIC) {
! return RTAPI_BADH;
}
! /* get whatever data is available */
retval = rtf_put(fifo->fd, buf, size);
if (retval < 0) {
--- 1381,1400 ----
! int rtapi_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 RTAPI_BADID;
}
! /* point to the fifo's data */
! fifo = &(fifo_array[fifo_id]);
! /* is the fifo valid? */
! if (fifo->state == UNUSED ) {
! return RTAPI_BADID;
}
! /* put as much data as possible */
retval = rtf_put(fifo->fd, buf, size);
if (retval < 0) {
***************
*** 1291,1295 ****
int_usage_count++;
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: assign_interrupt_handler for int %d, count = %d\n",
irq, int_usage_count);
--- 1423,1427 ----
int_usage_count++;
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: assign_interrupt_handler for int %d, count = %d\n",
irq, int_usage_count);
***************
*** 1311,1315 ****
int_usage_count--;
! rtapi_print_msg(RTAPI_MSG_INFO,
"RTAPI: free_interrupt_handler for int %d, count = %d\n",
irq, int_usage_count);
--- 1443,1447 ----
int_usage_count--;
! rtapi_print_msg(RTAPI_MSG_DBG,
"RTAPI: free_interrupt_handler for int %d, count = %d\n",
irq, int_usage_count);
Index: rtapi.h
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** rtapi.h 14 Aug 2003 04:08:26 -0000 1.20
--- rtapi.h 15 Aug 2003 20:45:13 -0000 1.21
***************
*** 47,52 ****
#define RTAPI_UNSUP -1 /* function not supported */
#define RTAPI_BADID -2 /* bad task, shmem, sem, or fifo ID */
- /* FIXME - remove BADH once everything is converted over to IDs */
- #define RTAPI_BADH -2 /* bad task, shmem, sem, or fifo handle */
#define RTAPI_INVAL -3 /* invalid argument */
#define RTAPI_NOMEM -4 /* not enough memory */
--- 47,50 ----
***************
*** 59,71 ****
/* NOTE: RTAPI assumes that ints are at least 32 bits long */
!
! /** Typedefs for object handles. The structs to which these handles *
! * refer are private, and may vary from one RTOS to another. *
! * In fact, don't even count on handles always being pointers. */
!
! /* SEE, it's happening... tasks are now referred to by int task id's */
! /* the others will change soon. update - only fifos are left */
! typedef struct rtapi_fifo *rtapi_fifo_handle;
!
/***********************************************************************
--- 57,62 ----
/* NOTE: RTAPI assumes that ints are at least 32 bits long */
! /* FIXME - need to review the API, and change everything that needs
! to be 32 bits to long int. */
/***********************************************************************
***************
*** 354,373 ****
/** 'rtapi_fifo_new()' creates a realtime fifo. 'key' identifies the *
* fifo, all modules wishing to access the same fifo must use the same *
! * key. 'size' is the depth of the fifo. On success, '*fifoptr' *
! * becomes a fifo handle, which points to internal data for the fifo *
! * and is used for subsequent calls dealing with it. Returns a status *
! * code. */
! /* NOTE - RTAI fifos require (stacksize - 256) to avoid oops messages *
! * on removal. (Does this apply to rtlinux as well ?) */
! extern int rtapi_fifo_new(int key, unsigned long int size,
! rtapi_fifo_handle * fifoptr);
/** 'rtapi_fifo_delete()' is the counterpart to 'rtapi_fifo_new()'. *
! * It destroys the fifo 'fifo'. Returns a status code. */
! extern int rtapi_fifo_delete(rtapi_fifo_handle fifo);
--- 345,364 ----
/** 'rtapi_fifo_new()' creates a realtime fifo. 'key' identifies the *
* fifo, all modules wishing to access the same fifo must use the same *
! * key. 'size' is the depth of the fifo. 'mode' is either 'R' or 'W', *
! * to request either read or write access to the fifo. On success, it *
! * returns a positive integer ID, which is used for subsequent calls *
! * dealing with the fifo. On failure, returns a negative error code. */
! /* NOTE - RTAI fifos require (stacksize >= fifosze + 256) to avoid *
! * oops messages on removal. (Does this apply to rtlinux as well ?) */
! extern int rtapi_fifo_new(int key, unsigned long int size, char mode);
/** 'rtapi_fifo_delete()' is the counterpart to 'rtapi_fifo_new()'. *
! * It closes the fifo associated with 'fifo_ID'. 'mode' is the mode *
! * that was specified when the fifo was created. Returns status code. */
! extern int rtapi_fifo_delete(int fifo_id, char mode);
***************
*** 384,405 ****
* replaced with something that works better. John Kasunich */
! /** 'rtapi_fifo_read()' reads data from 'fifo'. 'buf' is a buffer for *
! * the data, and 'size' is the maximum number of bytes to read. *
* 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(rtapi_fifo_handle fifo,
! char *buf, unsigned long int size);
! /** 'rtapi_fifo_write()' writes data to 'fifo'. Up to 'size' bytes are *
! * taken from the buffer at 'buf'. Returns the count of bytes actually *
! * written, or RTAPI_BADH. Does not block. If 'size' bytes of space *
! * are not available in the fifo, rtapi_fifo_write() will write as many *
! * 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);
--- 375,394 ----
* replaced with something that works better. John Kasunich */
! /** 'rtapi_fifo_read()' reads data from 'fifo_id'. 'buf' is a buffer *
! * for the data, and 'size' is the maximum number of bytes to read. *
* 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);
! /** 'rtapi_fifo_write()' writes data to 'fifo_id'. Up to 'size' bytes *
! * are taken from the buffer at 'buf'. Returns the number of bytes *
! * 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);
|