Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.adass.org/adass/proceedings/adass00/P2-50/
Дата изменения: Tue May 29 20:08:53 2001 Дата индексирования: Tue Oct 2 05:54:10 2012 Кодировка: Поисковые слова: http astrokuban.info astrokuban |
int err = 0; if ( (err=rtf_create(0,1024)) < 0 ) return -EINVAL;
A periodic real-time task might then write data in the handler to the fifo using a code segment such as:
unsigned int sent = 0; while ( 1 ) { #ifdef RTL // RTLinux 2.2 re-scheduling point (void) pthread_wait_np(); #else // RTAI 1.3 re-scheduling point (void) rt_task_wait_period(); #endif (void) rtf_put(0,&sent,sizeof(sent)); sent++; }
The application then reads the fifo:
unsigned int recv = 0; if ( (fd=open("/dev/rtf0",O_RDONLY)) < 0 ) return (fd); while ( read(fd,&recv,sizeof(recv)) ) { (void) printf("%s: received %d\n",__FILE__,recv); } (void) close(fd);
It is easy to reverse this process to put data into the core and/or make the operation pass structured data. This fifo is destroyed in the cleanup_module using:
(void) rtf_destroy(0);
static int *mptr = (int *) NULL; mptr = (int *) mbuff_alloc("myints",1024*1024); #ifdef __KERNEL__ // code was called by init_module if ( mptr == (int *) NULL ) return -ENOMEM; #else // code was called by user application if ( mptr == (int *) NULL ) return (EXIT_FAILURE); #endif
The memory can then be accessed using straightforward de-referencing and pointer arithmetic to traverse the array. The memory is released using:
mbuff_free("myints",(void *)mptr);
Note that the name of the memory section must be common between the real-time core and application. Several applications may also references the same memory segment. The only restriction on the size of a memory section is the amount of system memory available. In the WIYN Top-Tilt Module project (Daly 2000), for example, 128Mb are mapped using a single call to mbuff_alloc.
This package provides a shared library (/usr/lib/liblvrtl.so) and 78 VIs that furnish access to fundamental data types. It also includes extensive test code for either hard real-time Linux variant. The following VIs are implemented in this release where dtype is one of the set {int8, int16, int32, uint8, uint16, uint32, float32, float64, string}:
Note that rtf_put_string and mbuff_put_string are the only two routines that add a NULL byte to the data before transfer. The real-time core must be set up to accept this extra byte. If the number of elements to put is 0, the code will size the data array and transfer the whole structure (rather than return an error).
The `get' and `put' VIs both accept a number of elements of the given data type to read/write. On error, is returned. On success, the number of bytes read or written is returned and not the requested number of elements. Since the mbuff_get_dtype and mbuff_put_dtype VIs also require an offset from the start of the memory array, poor G-code programming could result in a request that exceeds the bounds of the memory segment. Such an error is not trapped by this version of the code and the result will likely be an illegal pointer operation in the kernel resulting in a system crash. The programmer is urged to make sure that all inputs to these VIs are valid.
The fifo may be accessed using a blocking read, non-blocking read, read-write or write-only operation.
As an example, Figures 1 and 2 show the front panel and G-code diagram for a rtf_read_float32 operation. This example reads five floating point numbers from /dev/rtf0. Note how any output error from the embedded rtf_get_float32.vi is trapped within the G-code environment and terminates the loop. The data from each read appears in the `output' array.
Daly, P. N. 2000, in ASP Conf. Ser., Vol. 216, Astronomical Data Analysis Software and Systems IX, ed. N. Manset, C. Veillet, & D. Crabtree (San Francisco: ASP), 388