📄 rtai_functions.c
字号:
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <time.h>#include <assert.h>#include <unistd.h>#include <curses.h>#include <sys/types.h>#include <sys/mman.h>#include <sys/stat.h>#include <fcntl.h>#include <signal.h>#include "../include/port.h"#include "../include/ogr_defines.h"#include "../include/ogr_structs.h"#define KEEP_STATIC_INLINE //for nam2num macros#include <rtai_shm.h>#include "defines.h"#include "globals.h"#include "rtai_functions.h"// TASK *Task;//------------------------------------------------------------------------------// cleanup// // De-allocates memory//void cleanup( void) { if ( Chn_RBuf) rtai_free( nam2num( SHM_CHN_RBUF), (void*) Chn_RBuf);#if 0 if ( corr) rtai_free( SHM_CHANNEL, (void*) corr); if ( param) rtai_free( SHM_CTRLPARMS, (void*) param); if ( chanBuf) rtai_free( SHM_BUF, (void*) chanBuf); if ( Task) rtai_free( SHM_TASK, (void*) Task);#endif return;}#if 0//------------------------------------------------------------------------------// numTasks//// Returns the number of tasks stored in the Task[] struct.//int numTasks(void) { int i; for (i=0; i < MAX_TASKS; i++) { if (strcmp("",Task[i].name)==0) /* empty spot */ return i; } /* Not found */ return FALSE;}#endif//------------------------------------------------------------------------------// chanBufRead // // Returns the CHANNEL data at index (given ch) //// index: 0 (newest data)// index: CHAN_RING_BUF_SIZE-1 (oldest data)//CHN_INFO chanBufRead( INT16 chHeadNow, INT16 index) {// do a few sanity checks if ((chHeadNow < 0) || (chHeadNow >= CHN_RBUF_LEN)) { printf( "Error, chanHeadNow [%d] out of bounds\n", chHeadNow); exit( 0); } if ((index < 0) || (index >= CHN_RBUF_LEN)) { printf( "Error, index [%d] out of bounds\n", index); exit( 0); }/* Calculate correct index (ring buffer * wraps at 0 and CHN_RBUF_LEN */ if ((chHeadNow-index) < 0) index = CHN_RBUF_LEN + (chHeadNow-index); else index = chHeadNow-index;// printf("rtai_fun: index = %d\n",index); index = max( 0, min( CHN_RBUF_LEN-1, index));// return chanBuf[index].chan[ch];// printf( "Chn_RBuf->chan[%d].ch = %d \n", index, Chn_RBuf->chan[index].ch);#if 0 { int i; for (i=0;i<100;i++) printf( "Chn_RBuf->chan[%d].ch = %d \n", i, Chn_RBuf->chan[i].ch); } #endif return Chn_RBuf->chan[index];}//------------------------------------------------------------------------------// chanBufReadRev // // Returns the CHANNEL data at index (given ch) //// index: 0 (newest data)// index: CHAN_RING_BUF_SIZE-1 (oldest data)//CHN_INFO chanBufReadRev( INT16 chHeadNow, INT16 index) {// do a few sanity checks if ((chHeadNow < 0) || (chHeadNow >= CHN_RBUF_LEN)) { printf( "Error, chanHeadNow [%d] out of bounds\n", chHeadNow); exit( 0); } if ((index < 0) || (index >= CHN_RBUF_LEN)) { printf( "Error, index [%d] out of bounds\n", index); exit( 0); } index = max( 0, min( CHN_RBUF_LEN-1, index)); return Chn_RBuf->chan[index];}/*******************************************************************************FUNCTION init_user()RETURNS None.PARAMETERS None.PURPOSE user land initializationWRITTEN BY G. Beyerle, S. Esterhuizen*******************************************************************************/void init_user( void) {#if 0// init shared memory corr = (CHANNEL_RBUF*) rtai_malloc( SHM_CHANNEL, sizeof( CHANNEL_RBUF)); if ( !corr) { printf( "rtai_malloc() failed in init_user().\n"); exit(-1); }#endif// init ring buffer Chn_RBuf = (CHN_RBUF*) rtai_malloc( nam2num( SHM_CHN_RBUF), sizeof( CHN_RBUF)); if ( !Chn_RBuf) { printf( "rtai_malloc(SHM_CHN_RBUF,%d) failed in init_user().\n", sizeof( CHN_RBUF)); exit(-1); }#if 0 param = (CTRLPARMS*) rtai_malloc( SHM_CTRLPARMS, sizeof( CTRLPARMS)); if ( !param) { printf( "rtai_malloc() failed in main().\n"); exit(-1); }#endif#if 0 Task = (TASK*) rtai_malloc( SHM_TASK, sizeof( TASK)*MAX_TASKS); if ( !Task) { printf( "rtai_malloc() failed in main().\n"); exit(-1); }#endif return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -