|
From: <jmk...@us...> - 2003-07-23 01:22:53
|
Update of /cvsroot/emc/rtapi/examples/shmem
In directory sc8-pr-cvs1:/tmp/cvs-serv23441/examples/shmem
Modified Files:
shmemtask.c shmemusr.c
Log Message:
changed examples to use new api - fifo not working yet
Index: shmemtask.c
===================================================================
RCS file: /cvsroot/emc/rtapi/examples/shmem/shmemtask.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** shmemtask.c 8 Jul 2003 15:54:39 -0000 1.1.1.1
--- shmemtask.c 23 Jul 2003 01:22:49 -0000 1.2
***************
*** 9,22 ****
#include "common.h" /* shmem structure, SHMEM_KEY */
! static void *shmem_task = 0; /* the task structure */
enum { SHMEM_PERIOD_NSEC = 1000000 }; /* timer period, in nanoseconds */
enum { SHMEM_STACKSIZE = 1024 }; /* how big the stack is */
static int key = SHMEM_KEY;
- static int id = 0;
static SHMEM_STRUCT *shmem_struct = 0;
/* task code, executed each timer interrupt */
! void shmem_code(void)
{
while (1) {
--- 9,22 ----
#include "common.h" /* shmem structure, SHMEM_KEY */
! static rtapi_task_handle shmem_task; /* the task */
! static rtapi_shmem_handle shmem_mem; /* the shared memory area */
enum { SHMEM_PERIOD_NSEC = 1000000 }; /* timer period, in nanoseconds */
enum { SHMEM_STACKSIZE = 1024 }; /* how big the stack is */
static int key = SHMEM_KEY;
static SHMEM_STRUCT *shmem_struct = 0;
/* task code, executed each timer interrupt */
! void shmem_code ( int arg )
{
while (1) {
***************
*** 33,70 ****
int rtapi_app_main(void)
{
int shmem_prio;
- int t;
if (0 != rtapi_init()) {
return -1;
}
/* allocate and initialize the shared memory structure */
! if (0 != rtapi_alloc_shmem(key, sizeof(SHMEM_STRUCT), &id,
! (void **) &shmem_struct)) {
! rtapi_print("shmemtask: can't allocate shared memory\n");
return -1;
}
shmem_struct->heartbeat = 0;
/* set the base timer period */
! rtapi_clock_set_period(SHMEM_PERIOD_NSEC);
/* set the task priority to lowest, since we only have one task */
shmem_prio = rtapi_prio_lowest();
! /* launch the shmem task */
! shmem_task = rtapi_task_new();
! if (0 == shmem_task) {
! rtapi_print("shmemtask: can't create shmem task\n");
return -1;
}
! if (0 != rtapi_task_start(shmem_task, shmem_code, shmem_prio, SHMEM_STACKSIZE, SHMEM_PERIOD_NSEC, 0)) { /* 0 = no floating point */
! rtapi_print("shmemtask: can't start shmem task\n");
return -1;
}
! rtapi_print("shmemtask: started shmem task\n");
return 0;
--- 33,87 ----
int rtapi_app_main(void)
{
+ int retval;
int shmem_prio;
+ /*
if (0 != rtapi_init()) {
return -1;
}
+ */
/* allocate and initialize the shared memory structure */
! retval = rtapi_shmem_new( key, sizeof(SHMEM_STRUCT), &shmem_mem );
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print( "shmemtask init: rtapi_shmem_new returned %d\n", retval );
return -1;
}
+ retval = rtapi_shmem_getptr( shmem_mem, (void **)&shmem_struct );
+ if ( retval != RTAPI_SUCCESS ) {
+ rtapi_print( "shmemtask init: rtapi_shmem_getptr returned %d\n", retval );
+ return -1;
+ }
+
shmem_struct->heartbeat = 0;
/* set the base timer period */
! retval = rtapi_clock_set_period(SHMEM_PERIOD_NSEC);
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print( "shmemtask init: rtapi_clock_set_period returned %d\n", retval );
! return -1;
! }
/* set the task priority to lowest, since we only have one task */
shmem_prio = rtapi_prio_lowest();
! /* create the shmem task */
! retval = rtapi_task_new( &shmem_task );
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print( "shmemtask init: rtapi_task_new returned %d\n", retval );
return -1;
}
! /* start the shmem task */
! retval = rtapi_task_start( shmem_task, shmem_code,
! 0, shmem_prio,
! SHMEM_STACKSIZE,
! SHMEM_PERIOD_NSEC, RTAPI_NO_FP );
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print("shmemtask init: rtapi_task_start returned %d\n", retval );
return -1;
}
! rtapi_print("shmemtask init: started shmem task\n");
return 0;
***************
*** 74,97 ****
void rtapi_app_exit(void)
{
if (0 != shmem_struct) {
! rtapi_print("shmemtask: heartbeat is %u\n", shmem_struct->heartbeat);
}
! if (0 != shmem_task) {
! if (0 != rtapi_task_stop(shmem_task)) {
! rtapi_print("shmemtask: can't stop shmem task\n");
! }
! if (0 != rtapi_task_delete(shmem_task)) {
! rtapi_print("shmemtask: can't delete shmem task\n");
! }
! shmem_task = 0;
}
! if (0 != shmem_struct) {
! if (0 != rtapi_free_shmem(key, sizeof(SHMEM_STRUCT),
! id, (void *) shmem_struct)) {
! rtapi_print("shmemtask: can't free shared memory\n");
! }
! shmem_struct = 0;
}
--- 91,115 ----
void rtapi_app_exit(void)
{
+ int retval;
+
if (0 != shmem_struct) {
! rtapi_print("shmemtask exit: heartbeat is %u\n", shmem_struct->heartbeat);
}
! retval = rtapi_task_stop( shmem_task );
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print("shmemtask exit: rtapi_task_stop returned %d\n", retval );
! return;
! }
! retval = rtapi_task_delete( shmem_task );
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print("shmemtask exit: rtapi_task_delete returned %d\n", retval );
! return;
}
! retval = rtapi_shmem_delete( shmem_mem );
! if ( retval != RTAPI_SUCCESS ) {
! rtapi_print("shmemtask exit: rtapi_shmem_delete returned %d\n", retval );
! return;
}
Index: shmemusr.c
===================================================================
RCS file: /cvsroot/emc/rtapi/examples/shmem/shmemusr.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** shmemusr.c 8 Jul 2003 15:54:39 -0000 1.1.1.1
--- shmemusr.c 23 Jul 2003 01:22:49 -0000 1.2
***************
*** 6,10 ****
static int key = SHMEM_KEY;
! static int id = 0;
static SHMEM_STRUCT *shmem_struct;
--- 6,10 ----
static int key = SHMEM_KEY;
! static ulapi_shmem_handle shmem_mem;
static SHMEM_STRUCT *shmem_struct;
***************
*** 17,29 ****
int main()
{
! if (0 != ulapi_init()) {
! fprintf(stderr, "can't initialize user-level interface\n");
return -1;
}
! if (0 != ulapi_alloc_shmem(key, sizeof(SHMEM_STRUCT), &id,
! (void **) &shmem_struct) || 0 == shmem_struct) {
! fprintf(stderr, "can't allocate shared memory\n");
return -1;
}
--- 17,37 ----
int main()
{
+ int retval;
! retval = ulapi_init();
! if ( retval != ULAPI_SUCCESS ) {
! printf("shmemusr main: ulapi_init returned %d\n", retval );
return -1;
}
! /* allocate the shared memory structure */
! retval = ulapi_shmem_new( key, sizeof(SHMEM_STRUCT), &shmem_mem );
! if ( retval != ULAPI_SUCCESS ) {
! printf( "shmemusr main: ulapi_shmem_new returned %d\n", retval );
! return -1;
! }
! retval = ulapi_shmem_getptr( shmem_mem, (void **)&shmem_struct );
! if ( retval != ULAPI_SUCCESS ) {
! printf( "shmemusr main: ulapi_shmem_getptr returned %d\n", retval );
return -1;
}
***************
*** 31,41 ****
signal(SIGINT, quit);
while (!done) {
! printf("%u\n", shmem_struct->heartbeat);
sleep(1);
}
! if (0 != shmem_struct) {
! ulapi_free_shmem(key, sizeof(shmem_struct), id, shmem_struct);
! shmem_struct = 0;
}
--- 39,50 ----
signal(SIGINT, quit);
while (!done) {
! printf("%lu\n", shmem_struct->heartbeat);
sleep(1);
}
! retval = ulapi_shmem_delete( shmem_mem );
! if ( retval != ULAPI_SUCCESS ) {
! printf("shmemusr main: ulapi_free_shmem returned %d\n", retval );
! return -1;
}
|