rtai-core/include/rtai_scb.h

Go to the documentation of this file.
00001 
00039 #ifndef _RTAI_SCB_H
00040 #define _RTAI_SCB_H
00041 
00042 #include <rtai_shm.h>
00043 #include <asm/rtai_atomic.h>
00044 
00045 #define SCB     ((void *)(scb))
00046 #define SIZE    ((volatile int *)scb)[-3]
00047 #define FBYTE   ((volatile int *)scb)[-2]
00048 #define LBYTE   ((volatile int *)scb)[-1]
00049 #define HDRSIZ  (3*sizeof(int))
00050 
00051 struct task_struct;
00052 
00088 RTAI_PROTO(void *, rt_scb_init, (unsigned long name, int size, int suprt))
00089 {       
00090         void *scb;
00091         if ((scb = rt_shm_alloc(name, size + HDRSIZ + 1, suprt)) && !atomic_cmpxchg((int *)scb, 0, name)) {
00092                 ((int *)scb)[1] = ((int *)scb)[2] = 0;
00093                 ((int *)scb)[0] = size + 1;
00094         } else {
00095                 while (!((int *)scb)[0]);
00096         }                       
00097         return scb ? scb + HDRSIZ : 0;
00098 }
00099 
00120 RTAI_PROTO(int, rt_scb_delete, (unsigned long name))
00121 { 
00122         return rt_shm_free(name);
00123 }
00124 
00139 RTAI_PROTO (int, rt_scb_bytes, (void *scb))
00140 { 
00141         int size = SIZE, fbyte = FBYTE, lbyte = LBYTE;
00142         return (lbyte >= fbyte ? lbyte - fbyte : size + lbyte - fbyte);
00143 }
00144 
00157 RTAI_PROTO(int, rt_scb_get, (void *scb, void *msg, int msg_size))
00158 { 
00159         int size = SIZE, fbyte = FBYTE, lbyte = LBYTE;
00160         if (msg_size > 0 && (lbyte >= fbyte ? lbyte - fbyte : size + lbyte - fbyte) >= msg_size) {
00161                 int tocpy;
00162                 if ((tocpy = size - fbyte) > msg_size) {
00163                         memcpy(msg, SCB + fbyte, msg_size);
00164                         FBYTE = fbyte + msg_size;
00165                 } else {
00166                         memcpy(msg, SCB + fbyte, tocpy);
00167                         if ((msg_size -= tocpy)) {
00168                                 memcpy(msg + tocpy, SCB, msg_size);
00169                         }
00170                         FBYTE = msg_size;
00171                 }
00172                 return 0;
00173         }
00174         return msg_size;
00175 }
00176 
00189 RTAI_PROTO(int, rt_scb_evdrp, (void *scb, void *msg, int msg_size))
00190 { 
00191         int size = SIZE, fbyte = FBYTE, lbyte = LBYTE;
00192         if (msg_size > 0 && (lbyte >= fbyte ? lbyte - fbyte : size + lbyte - fbyte) >= msg_size) {
00193                 int tocpy;
00194                 if ((tocpy = size - fbyte) > msg_size) {
00195                         memcpy(msg, SCB + fbyte, msg_size);
00196                 } else {
00197                         memcpy(msg, SCB + fbyte, tocpy);
00198                         if ((msg_size -= tocpy)) {
00199                                 memcpy(msg + tocpy, SCB, msg_size);
00200                         }
00201                 }
00202                 return 0;
00203         }
00204         return msg_size;
00205 }
00206 
00219 RTAI_PROTO(int, rt_scb_put, (void *scb, void *msg, int msg_size))
00220 { 
00221         int size = SIZE, fbyte = FBYTE, lbyte = LBYTE;
00222         if (msg_size > 0 && (lbyte >= fbyte ? size - (lbyte - fbyte) : lbyte - fbyte) > msg_size) {
00223                 int tocpy;
00224                 if ((tocpy = size - lbyte) > msg_size) {
00225                         memcpy(SCB + lbyte, msg, msg_size);
00226                         LBYTE = lbyte + msg_size;
00227                 } else {
00228                         memcpy(SCB + lbyte, msg, tocpy);
00229                         if ((msg_size -= tocpy)) {
00230                                 memcpy(SCB, msg + tocpy, msg_size);
00231                         }
00232                         LBYTE = msg_size;
00233                 }
00234                 return 0;
00235         }
00236         return msg_size;
00237 }
00238 
00239 #endif /* _RTAI_SCB_H */

Generated on Sat Jul 24 19:36:04 2004 for RTAI API by doxygen 1.3.4