|
From: <jmk...@us...> - 2003-08-04 06:00:28
|
Update of /cvsroot/emc/rtapi/src/rtapi
In directory sc8-pr-cvs1:/tmp/cvs-serv30223/src/rtapi
Modified Files:
rtai_rtapi.c rtapi.h rtl_rtapi.c rtl_ulapi.c sim_rtapi.c
Log Message:
RTLinux version now uses new API, everything builds, only timertask is tested
Index: rtai_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_rtapi.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** rtai_rtapi.c 3 Aug 2003 02:41:44 -0000 1.11
--- rtai_rtapi.c 4 Aug 2003 06:00:25 -0000 1.12
***************
*** 291,294 ****
--- 291,298 ----
}
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: start_task %p\n", task );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 311,314 ****
--- 315,322 ----
return RTAPI_FAIL;
}
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: stop_task %p\n", task );
+ }
+
return RTAPI_SUCCESS;
}
Index: rtapi.h
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** rtapi.h 3 Aug 2003 02:41:44 -0000 1.10
--- rtapi.h 4 Aug 2003 06:00:25 -0000 1.11
***************
*** 1,3 ****
! #ifndef RTAPI_H
#define RTAPI_H
--- 1,3 ----
! #ifndef RTAPI__H
#define RTAPI_H
***************
*** 73,77 ****
* returns either 0, or if the RTOS supports it, the actual timer *
* period in nanoseconds, (which may not be exactly what was requested *
! * due to hardware limitations). */
/* FIXME - the request is an unsigned long int, but the return value is
--- 73,78 ----
* returns either 0, or if the RTOS supports it, the actual timer *
* period in nanoseconds, (which may not be exactly what was requested *
! * due to hardware limitations). The upper limit for the timer period *
! * may be as low as 0.01 seconds, so be sure to check for errors. */
/* FIXME - the request is an unsigned long int, but the return value is
Index: rtl_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtl_rtapi.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** rtl_rtapi.c 8 Jul 2003 15:54:38 -0000 1.1.1.1
--- rtl_rtapi.c 4 Aug 2003 06:00:25 -0000 1.2
***************
*** 2,12 ****
rtl_rtapi.c
! Implementations of RT API functions declared in rtapi.h, for RTL
*/
#include <stdarg.h> /* va_* */
#include <linux/module.h>
! #include <linux/kernel.h> /* vsprintf() */
! #include <linux/malloc.h> /* kmalloc(), kfree(), GFP_USER */
#include <rtl.h> /* top level config */
[...1274 lines suppressed...]
!
! 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) {
! return RTAPI_INVAL;
! }
! return retval;
}
Index: rtl_ulapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtl_ulapi.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** rtl_ulapi.c 8 Jul 2003 15:54:38 -0000 1.1.1.1
--- rtl_ulapi.c 4 Aug 2003 06:00:25 -0000 1.2
***************
*** 1,29 ****
/*
! rtl_ulapi.c
Implementation of user-level API to RTL modules
*/
-
#include <stdio.h> /* sprintf() */
#include <stddef.h> /* size_t, needed by mbuff.h */
#include <fcntl.h> /* O_RDWR */
#include <unistd.h> /* open(), close() */
#include "mbuff.h"
#include "ulapi.h"
int ulapi_init(void)
{
! return 0;
}
int ulapi_exit(void)
{
! return 0;
}
/*
genstr() generates a string 'str' unique for unsigned integers 'i',
as the reverse, e.g., 120 -> "012", -1 -> "5927694924"
*/
static void genstr(unsigned int i, char *str)
{
--- 1,66 ----
/*
! rtai_ulapi.c
Implementation of user-level API to RTL modules
*/
#include <stdio.h> /* sprintf() */
#include <stddef.h> /* size_t, needed by mbuff.h */
#include <fcntl.h> /* O_RDWR */
#include <unistd.h> /* open(), close() */
+ #include <malloc.h> /* malloc(), free() */
#include "mbuff.h"
#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;
}
+
int ulapi_exit(void)
{
! /* does nothing, for now */
! return ULAPI_SUCCESS;
}
/*
+ RTAPI uses integers as keys, since these can be mapped onto either
+ integers or strings easily, whereas the reverse is not true: you can't
+ map an arbitrary string to an integer uniquely. Since mbuff takes
+ string keys, we need to convert them to some unique string using genstr().
+ */
+
+ /*
genstr() generates a string 'str' unique for unsigned integers 'i',
as the reverse, e.g., 120 -> "012", -1 -> "5927694924"
*/
+
+ #define KEYSTR_LEN 16 /* larger than number of digits in MAX_INT */
+
static void genstr(unsigned int i, char *str)
{
***************
*** 48,110 ****
}
! #define KEYSTR_LEN 16 /* larger than number of digits in MAX_INT */
!
! /*
! RTAPI uses integers as keys, since these can be mapped onto either
! integers or strings easily, whereas the reverse is not true: you can't
! map an arbitrary string to an integer uniquely. Since mbuff takes
! string keys, we need to convert them to some unique string using genstr().
! */
!
! int ulapi_alloc_shmem(int key, unsigned int size, int *id, void **ptr)
{
char keystr[KEYSTR_LEN];
genstr((unsigned int) key, keystr);
! *ptr = mbuff_alloc(keystr, size);
! /* leave id alone; we don't use it */
! if (0 != *ptr) {
! return 0;
}
- return -1;
}
! int ulapi_free_shmem(int key, unsigned int size, int id, const void *ptr)
{
char keystr[KEYSTR_LEN];
! genstr((unsigned int) key, keystr);
! mbuff_free(keystr, (void *) ptr);
! return 0;
}
! int ulapi_fifo_new(int key, int *fd, unsigned long int size)
{
enum { DEVSTR_LEN = 256 };
char devstr[DEVSTR_LEN];
sprintf(devstr, "/dev/rtf%d", key);
- *fd = open(devstr, O_RDONLY);
! return *fd;
}
! int ulapi_fifo_delete(int key, int fd, unsigned long int size)
{
! return close(fd);
}
! int ulapi_fifo_write(int fd, char *buf, unsigned long int size)
{
! return write(fd, buf, size);
}
! int ulapi_fifo_read(int fd, char *buf, unsigned long int size)
{
! return read(fd, buf, size);
}
--- 85,282 ----
}
! int ulapi_shmem_new(int key, unsigned int size, ulapi_shmem_handle * shmemptr)
{
+ ulapi_shmem_handle shmem;
char keystr[KEYSTR_LEN];
+ /* 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;
+ }
+
+ /* convert key to a string */
genstr((unsigned int) key, keystr);
+ /* now get shared memory block from OS */
+ shmem->mem = mbuff_alloc(keystr, 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)
{
char keystr[KEYSTR_LEN];
! /* validate shmem handle */
! if (shmem == NULL) {
! return ULAPI_BADH;
! }
! if (shmem->magic != SHMEM_MAGIC) {
! return ULAPI_BADH;
! }
! /* convert key to a string */
! genstr((unsigned int) shmem->key, keystr);
! /* free the shared memory */
! mbuff_free(keystr, (void *) 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;
! }
! return retval;
!
}
! 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;
! }
!
! /* get whatever data is available */
! retval = write(fifo->fd, buf, size);
! if (retval < 0) {
! return ULAPI_FAIL;
! }
! return retval;
}
Index: sim_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/sim_rtapi.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** sim_rtapi.c 22 Jul 2003 17:20:22 -0000 1.4
--- sim_rtapi.c 4 Aug 2003 06:00:25 -0000 1.5
***************
*** 200,203 ****
--- 200,205 ----
/* 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 )
|