00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _RTAI_FIFOS_H
00027 #define _RTAI_FIFOS_H
00028
00029 #include <rtai_types.h>
00030
00031 #define MAX_FIFOS 64
00032
00033 #define RTAI_FIFOS_MAJOR 150
00034
00035 #define RESET 1
00036 #define RESIZE 2
00037 #define RTF_SUSPEND_TIMED 3
00038 #define OPEN_SIZED 4
00039 #define READ_ALL_AT_ONCE 5
00040 #define READ_TIMED 6
00041 #define WRITE_TIMED 7
00042 #define RTF_SEM_INIT 8
00043 #define RTF_SEM_WAIT 9
00044 #define RTF_SEM_TRYWAIT 10
00045 #define RTF_SEM_TIMED_WAIT 11
00046 #define RTF_SEM_POST 12
00047 #define RTF_SEM_DESTROY 13
00048 #define SET_ASYNC_SIG 14
00049 #define EAVESDROP 19
00050 #define OVRWRITE 20
00051 #define READ_IF 21
00052 #define WRITE_IF 22
00053 #define RTF_NAMED_CREATE 23
00054
00055 #define RTF_GET_N_FIFOS 15
00056 #define RTF_GET_FIFO_INFO 16
00057 #define RTF_CREATE_NAMED 17
00058 #define RTF_NAME_LOOKUP 18
00059
00060 #define RTF_NAMELEN 15
00061
00062 struct rt_fifo_info_struct{
00063 unsigned int fifo_number;
00064 unsigned int size;
00065 unsigned int opncnt;
00066 int avbs, frbs;
00067 char name[RTF_NAMELEN+1];
00068 };
00069
00070 struct rt_fifo_get_info_struct{
00071 unsigned int fifo;
00072 unsigned int n;
00073 struct rt_fifo_info_struct *ptr;
00074 };
00075
00076 #define FUN_FIFOS_LXRT_INDX 10
00077
00078 #define _CREATE 0
00079 #define _DESTROY 1
00080 #define _PUT 2
00081 #define _GET 3
00082 #define _RESET 4
00083 #define _RESIZE 5
00084 #define _SEM_INIT 6
00085 #define _SEM_DESTRY 7
00086 #define _SEM_POST 8
00087 #define _SEM_TRY 9
00088 #define _CREATE_NAMED 10
00089 #define _GETBY_NAME 11
00090 #define _OVERWRITE 12
00091 #define _PUT_IF 13
00092 #define _GET_IF 14
00093 #define _NAMED_CREATE 15
00094 #define _AVBS 16
00095 #define _FRBS 17
00096
00097 #ifdef __KERNEL__
00098
00099 #include <rtai.h>
00100
00101 #ifdef __cplusplus
00102 extern "C" {
00103 #endif
00104
00105 int __rtai_fifos_init(void);
00106
00107 void __rtai_fifos_exit(void);
00108
00109 int rtf_init(void);
00110
00111 typedef int (*rtf_handler_t)(unsigned int fifo, int rw);
00112
00113
00114
00115
00116
00117
00118
00119
00120 int rtf_create_handler(unsigned int fifo,
00121 void *handler );
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #define X_FIFO_HANDLER(handler) ((int (*)(unsigned int, int rw))(handler))
00137
00138
00139
00140
00141
00142
00143 #undef rtf_create
00144 RTAI_SYSCALL_MODE int rtf_create(unsigned int fifo, int size);
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 int rtf_named_create(const char *name, int size);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 RTAI_SYSCALL_MODE int rtf_create_named(const char *name);
00165
00166
00167
00168
00169
00170
00171
00172
00173 RTAI_SYSCALL_MODE int rtf_getfifobyname(const char *name);
00174
00175
00176
00177
00178
00179
00180
00181
00182 RTAI_SYSCALL_MODE int rtf_reset(unsigned int fifo);
00183
00184
00185
00186
00187
00188
00189 RTAI_SYSCALL_MODE int rtf_destroy(unsigned int fifo);
00190
00191
00192
00193
00194
00195
00196
00197
00198 RTAI_SYSCALL_MODE int rtf_resize(unsigned int minor, int size);
00199
00200
00201
00202
00203
00204
00205
00206 RTAI_SYSCALL_MODE int rtf_put(unsigned int fifo,
00207 void * buf,
00208 int count );
00209
00210
00211
00212
00213
00214
00215
00216
00217 RTAI_SYSCALL_MODE int rtf_ovrwr_put(unsigned int fifo,
00218 void * buf,
00219 int count );
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 extern RTAI_SYSCALL_MODE int rtf_put_if (unsigned int fifo,
00230 void * buf,
00231 int count );
00232
00233
00234
00235
00236
00237
00238 RTAI_SYSCALL_MODE int rtf_get(unsigned int fifo,
00239 void * buf,
00240 int count );
00241
00242
00243
00244
00245
00246
00247
00248 RTAI_SYSCALL_MODE int rtf_get_if(unsigned int fifo,
00249 void * buf,
00250 int count );
00251
00252
00253
00254
00255
00256
00257 int rtf_evdrp(unsigned int fifo,
00258 void * buf,
00259 int count );
00260
00261
00262
00263
00264
00265 RTAI_SYSCALL_MODE int rtf_sem_init(unsigned int fifo,
00266 int value );
00267
00268
00269
00270
00271
00272
00273 RTAI_SYSCALL_MODE int rtf_sem_post(unsigned int fifo );
00274
00275
00276
00277
00278
00279
00280 RTAI_SYSCALL_MODE int rtf_sem_trywait(unsigned int fifo );
00281
00282
00283
00284
00285
00286
00287 RTAI_SYSCALL_MODE int rtf_sem_destroy(unsigned int fifo );
00288
00289 #define rtf_sem_delete rtf_sem_destroy
00290
00291
00292
00293
00294
00295
00296 RTAI_SYSCALL_MODE int rtf_get_frbs(unsigned int fifo );
00297
00298
00299
00300
00301 #define rtf_create_using_bh(fifo, size, bh_list) rtf_create(fifo, size)
00302 #define rtf_create_using_bh_and_usr_buf(fifo, buf, size, bh_list) rtf_create(fifo, size)
00303 #define rtf_destroy_using_usr_buf(fifo) rtf_destroy(fifo)
00304
00305 #ifdef __cplusplus
00306 }
00307 #endif
00308
00309 #else
00310
00311 #include <sys/types.h>
00312 #include <sys/stat.h>
00313 #include <sys/ioctl.h>
00314 #include <fcntl.h>
00315 #include <unistd.h>
00316 #include <stdio.h>
00317 #include <string.h>
00318 #include <rtai_lxrt.h>
00319
00320 #ifdef __cplusplus
00321 extern "C" {
00322 #endif
00323
00324 RTAI_PROTO(int, rtf_create,(unsigned int fifo, int size))
00325 {
00326 struct { unsigned long fifo, size; } arg = { fifo, size };
00327 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _CREATE, &arg).i[LOW];
00328 }
00329
00330 RTAI_PROTO(int, rtf_destroy,(unsigned int fifo))
00331 {
00332 struct { unsigned long fifo; } arg = { fifo };
00333 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _DESTROY, &arg).i[LOW];
00334 }
00335
00336 RTAI_PROTO(int, rtf_put,(unsigned int fifo, const void *buf, int count))
00337 {
00338 char lbuf[count];
00339 struct { unsigned long fifo; void *buf; long count; } arg = { fifo, lbuf, count };
00340 memcpy(lbuf, buf, count);
00341 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _PUT, &arg).i[LOW];
00342 }
00343
00344 RTAI_PROTO(int, rtf_put_if,(unsigned int fifo, const void *buf, int count))
00345 {
00346 char lbuf[count];
00347 struct { unsigned long fifo; void *buf; long count; } arg = { fifo, lbuf, count };
00348 memcpy(lbuf, buf, count);
00349 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _PUT_IF, &arg).i[LOW];
00350 }
00351
00352 RTAI_PROTO(int, rtf_get,(unsigned int fifo, void *buf, int count))
00353 {
00354 int retval;
00355 char lbuf[count];
00356 struct { unsigned long fifo; void *buf; long count; } arg = { fifo, lbuf, count };
00357 retval = rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _GET, &arg).i[LOW];
00358 if (retval > 0) {
00359 memcpy(buf, lbuf, retval);
00360 }
00361 return retval;
00362 }
00363
00364 RTAI_PROTO(int, rtf_get_if,(unsigned int fifo, void *buf, int count))
00365 {
00366 int retval;
00367 char lbuf[count];
00368 struct { unsigned long fifo; void *buf; long count; } arg = { fifo, lbuf, count };
00369 retval = rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _GET_IF, &arg).i[LOW];
00370 if (retval > 0) {
00371 memcpy(buf, lbuf, retval);
00372 }
00373 return retval;
00374 }
00375
00376 RTAI_PROTO(int, rtf_get_avbs, (unsigned int fifo))
00377 {
00378 struct { unsigned long fifo; } arg = { fifo };
00379 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _AVBS, &arg).i[LOW];
00380 }
00381
00382 RTAI_PROTO(int, rtf_get_frbs, (unsigned int fifo))
00383 {
00384 struct { unsigned long fifo; } arg = { fifo };
00385 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _FRBS, &arg).i[LOW];
00386 }
00387
00388 RTAI_PROTO(int, rtf_reset_lxrt,(unsigned int fifo))
00389 {
00390 struct { unsigned long fifo; } arg = { fifo };
00391 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _RESET, &arg).i[LOW];
00392 }
00393
00394 RTAI_PROTO(int, rtf_resize_lxrt,(unsigned int fifo, int size))
00395 {
00396 struct { unsigned long fifo, size; } arg = { fifo, size };
00397 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _RESIZE, &arg).i[LOW];
00398 }
00399
00400 RTAI_PROTO(int, rtf_sem_init_lxrt,(unsigned int fifo, int value))
00401 {
00402 struct { unsigned long fifo, value; } arg = { fifo, value };
00403 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _SEM_INIT, &arg).i[LOW];
00404 }
00405
00406 RTAI_PROTO(int, rtf_sem_post_lxrt,(unsigned int fifo))
00407 {
00408 struct { unsigned long fifo; } arg = { fifo };
00409 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _SEM_POST, &arg).i[LOW];
00410 }
00411
00412 RTAI_PROTO(int, rtf_sem_trywait_lxrt,(unsigned int fifo))
00413 {
00414 struct { unsigned long fifo; } arg = { fifo };
00415 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _SEM_TRY, &arg).i[LOW];
00416 }
00417
00418 RTAI_PROTO(int, rtf_sem_destroy_lxrt,(unsigned int fifo))
00419 {
00420 struct { unsigned long fifo; } arg = { fifo };
00421 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _SEM_DESTRY, &arg).i[LOW];
00422 }
00423
00424 RTAI_PROTO(int, rtf_named_create_lxrt,(const char *name, int size))
00425 {
00426 int len;
00427 char lname[len = strlen(name)];
00428 struct { char * name; long size; } arg = { lname, size };
00429 strncpy(lname, name, len);
00430 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _NAMED_CREATE, &arg).i[LOW];
00431 }
00432
00433 RTAI_PROTO(int, rtf_create_named_lxrt,(const char *name))
00434 {
00435 int len;
00436 char lname[len = strlen(name)];
00437 struct { char * name; } arg = { lname };
00438 strncpy(lname, name, len);
00439 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _CREATE_NAMED, &arg).i[LOW];
00440 }
00441
00442 RTAI_PROTO(int, rtf_getfifobyname_lxrt,(const char *name))
00443 {
00444 int len;
00445 char lname[len = strlen(name)];
00446 struct { char * name; } arg = { lname };
00447 strncpy(lname, name, len);
00448 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _GETBY_NAME, &arg).i[LOW];
00449 }
00450
00451 RTAI_PROTO(int, rtf_ovrwr_put,(unsigned int fifo, const void *buf, int count))
00452 {
00453 char lbuf[count];
00454 struct { unsigned long fifo; void *buf; long count; } arg = { fifo, lbuf, count };
00455 memcpy(lbuf, buf, count);
00456 return rtai_lxrt(FUN_FIFOS_LXRT_INDX, SIZARG, _OVERWRITE, &arg).i[LOW];
00457 }
00458
00459 RTAI_PROTO(int, rtf_reset,(int fd))
00460 {
00461 int ret = ioctl(fd, RESET);
00462 return ret < 0 ? -errno : ret;
00463 }
00464
00465 RTAI_PROTO(int, rtf_resize,(int fd, int size))
00466 {
00467 int ret = ioctl(fd, RESIZE, size);
00468 return ret < 0 ? -errno : ret;
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 RTAI_PROTO(int, rtf_suspend_timed,(int fd, int ms_delay))
00486 {
00487 int ret = ioctl(fd, RTF_SUSPEND_TIMED, ms_delay);
00488 return ret < 0 ? -errno : ret;
00489 }
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 RTAI_PROTO(int, rtf_open_sized,(const char *dev, int perm, int size))
00526 {
00527 int fd;
00528
00529 if ((fd = open(dev, perm)) < 0) {
00530 return -errno;
00531 }
00532 if (ioctl(fd, RESIZE, size) < 0) {
00533 close(fd);
00534 return -errno;
00535 }
00536 return fd;
00537 }
00538
00539 RTAI_PROTO(int, rtf_evdrp,(int fd, void *buf, int count))
00540 {
00541 struct { void *buf; long count; } args = { buf, count };
00542 int ret = ioctl(fd, EAVESDROP, &args);
00543 return ret < 0 ? -errno : ret;
00544 }
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 RTAI_PROTO(int, rtf_read_all_at_once,(int fd, void *buf, int count))
00563 {
00564 struct { void *buf; long count; } args = { buf, count };
00565 int ret = ioctl(fd, READ_ALL_AT_ONCE, &args);
00566 return ret < 0 ? -errno : ret;
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590 RTAI_PROTO(int, rtf_read_timed,(int fd, void *buf, int count, int ms_delay))
00591 {
00592 struct { void *buf; long count, delay; } args = { buf, count, ms_delay };
00593 int ret = ioctl(fd, READ_TIMED, &args);
00594 return ret < 0 ? -errno : ret;
00595 }
00596
00597 RTAI_PROTO(int, rtf_read_if,(int fd, void *buf, int count))
00598 {
00599 struct { void *buf; long count; } args = { buf, count };
00600 int ret = ioctl(fd, READ_IF, &args);
00601 return ret < 0 ? -errno : ret;
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 RTAI_PROTO(int, rtf_write_timed,(int fd, void *buf, int count, int ms_delay))
00626 {
00627 struct { void *buf; long count, delay; } args = { buf, count, ms_delay };
00628 int ret = ioctl(fd, WRITE_TIMED, &args);
00629 return ret < 0 ? -errno : ret;
00630 }
00631
00632 RTAI_PROTO(int, rtf_overwrite,(int fd, void *buf, int count))
00633 {
00634 struct { void *buf; long count; } args = { buf, count };
00635 int ret = ioctl(fd, OVRWRITE, &args);
00636 return ret < 0 ? -errno : ret;
00637 }
00638
00639 RTAI_PROTO(int, rtf_write_if,(int fd, void *buf, int count))
00640 {
00641 struct { void *buf; long count; } args = { buf, count };
00642 int ret = ioctl(fd, WRITE_IF, &args);
00643 return ret < 0 ? -errno : ret;
00644 }
00645
00646 RTAI_PROTO(int, rtf_sem_init,(int fd, int value))
00647 {
00648 int ret = ioctl(fd, RTF_SEM_INIT, value);
00649 return ret < 0 ? -errno : ret;
00650 }
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674 RTAI_PROTO(int, rtf_sem_wait,(int fd))
00675 {
00676 int ret = ioctl(fd, RTF_SEM_WAIT);
00677 return ret < 0 ? -errno : ret;
00678 }
00679
00680 RTAI_PROTO(int, rtf_sem_trywait,(int fd))
00681 {
00682 int ret = ioctl(fd, RTF_SEM_TRYWAIT);
00683 return ret < 0 ? -errno : ret;
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712 RTAI_PROTO(int, rtf_sem_timed_wait,(int fd, int ms_delay))
00713 {
00714 int ret = ioctl(fd, RTF_SEM_TIMED_WAIT, ms_delay);
00715 return ret < 0 ? -errno : ret;
00716 }
00717
00718 RTAI_PROTO(int, rtf_sem_post,(int fd))
00719 {
00720 int ret = ioctl(fd, RTF_SEM_POST);
00721 return ret < 0 ? -errno : ret;
00722 }
00723
00724 RTAI_PROTO(int, rtf_sem_destroy,(int fd))
00725 {
00726 int ret = ioctl(fd, RTF_SEM_DESTROY);
00727 return ret < 0 ? -errno : ret;
00728 }
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741 RTAI_PROTO(int, rtf_set_async_sig,(int fd, int signum))
00742 {
00743 int ret = ioctl(fd, SET_ASYNC_SIG, signum);
00744 return ret < 0 ? -errno : ret;
00745 }
00746
00747
00748
00749
00750
00751
00752 RTAI_PROTO_ALWAYS_INLINE(char *, rtf_getfifobyminor,(int minor, char *buf, int len))
00753 {
00754 snprintf(buf,len,CONFIG_RTAI_FIFOS_TEMPLATE,minor);
00755 return buf;
00756 }
00757
00758 RTAI_PROTO(int, rtf_getfifobyname,(const char *name))
00759 {
00760 int fd, minor;
00761 char nm[RTF_NAMELEN+1];
00762
00763 if (strlen(name) > RTF_NAMELEN) {
00764 return -1;
00765 }
00766 if ((fd = open(rtf_getfifobyminor(0,nm,sizeof(nm)), O_RDONLY)) < 0) {
00767 return -errno;
00768 }
00769 strncpy(nm, name, RTF_NAMELEN+1);
00770 minor = ioctl(fd, RTF_NAME_LOOKUP, nm);
00771 close(fd);
00772 return minor < 0 ? -errno : minor;
00773 }
00774
00775 RTAI_PROTO(int, rtf_named_create,(const char *name, int size))
00776 {
00777 int fd, minor;
00778 char nm[RTF_NAMELEN+1];
00779
00780 if (strlen(name) > RTF_NAMELEN) {
00781 return -1;
00782 }
00783 if ((fd = open(rtf_getfifobyminor(0,nm,sizeof(nm)), O_RDONLY)) < 0) {
00784 return -errno;
00785 }
00786 strncpy(nm, name, RTF_NAMELEN+1);
00787 minor = ioctl(fd, RTF_NAMED_CREATE, nm, size);
00788 close(fd);
00789 return minor < 0 ? -errno : minor;
00790 }
00791
00792 RTAI_PROTO(int, rtf_create_named,(const char *name))
00793 {
00794 int fd, minor;
00795 char nm[RTF_NAMELEN+1];
00796
00797 if (strlen(name) > RTF_NAMELEN) {
00798 return -1;
00799 }
00800 if ((fd = open(rtf_getfifobyminor(0,nm,sizeof(nm)), O_RDONLY)) < 0) {
00801 return -errno;
00802 }
00803 strncpy(nm, name, RTF_NAMELEN+1);
00804 minor = ioctl(fd, RTF_CREATE_NAMED, nm);
00805 close(fd);
00806 return minor < 0 ? -errno : minor;
00807 }
00808
00809 #ifdef __cplusplus
00810 }
00811 #endif
00812
00813 #endif
00814
00815 #endif