#include #include #include #include #include "rtpr.h" #define SERV_PORT 7775 #define MSG_SIZE 1500 int sock; struct sockaddr_in servaddr; struct sockaddr fromaddr; hrtime_t *times; char buffer[MSG_SIZE+1]; int pCount = 0; int tpCount = 0; int *c0, *c1; char *buff; /* the contents of shared memory may change at any time, thus volatile */ volatile char *shmData, *shmControl; int echo_rcv(int s,void *arg) { int ret = 0; int fromlen = 0; buff = buffer; times[pCount] = gethrtime(); c0[0] = pCount; pCount++; if (pCount == MAX_COUNT) pCount = 0; tpCount ++; if ( (c1[0] == pCount) && (c1[0] != INIT_MSG) ) { rtl_printf("Warning: BUFFER OVERFLOW - writing process too slow\n"); } ret = rt_recvfrom(sock, buff, MSG_SIZE,0 ,&fromaddr, &fromlen); //rtl_printf("%i %i %x %x %x %x \n",ret, fromlen,fromaddr.sa_data[1],fromaddr.sa_data[2],fromaddr.sa_data[3], fromaddr.sa_data[4]); return 0; } /* Module initialization - INSMOD */ int init_module(void) { int ret; // shared memory allocation shmData = (volatile char*) mbuff_alloc("recData",MAX_COUNT*sizeof(hrtime_t)); if( shmData == NULL ) { rtl_printf("mbuff_alloc failed\n"); return -1; } shmControl = (volatile char*) mbuff_alloc("recControl",1024); if( shmControl == NULL) { rtl_printf("mbuff_alloc failed\n"); mbuff_free("recData",(void*)shmData); return -1; } // received pointer c0 = (int*)&shmControl[0]; c0[0] = INIT_MSG; // write to file pointer c1 = (int*)&shmControl[8]; c1[0] = 0; times = (hrtime_t*)shmData; // message contents setup - fill with 'A' for(ret = 0; ret