int rtapi_app_main(void) { int n, numchan, max_depth, retval; fifo_t tmp_fifo[MAX_STREAMERS]; /* validate config info */ for ( n = 0 ; n < MAX_STREAMERS ; n++ ) { if (( cfg[n] == NULL ) || ( *cfg == '\0' ) || ( depth[n] <= 0 )) { break; } tmp_fifo[n].num_pins = parse_types(&(tmp_fifo[n]), cfg[n]); if ( tmp_fifo[n].num_pins == 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: bad config string '%s'\n", cfg[n]); return -EINVAL; } max_depth = MAX_SHMEM / (sizeof(shmem_data_t) * tmp_fifo[n].num_pins); if ( depth[n] > max_depth ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: depth too large, max is %d\n", max_depth); return -ENOMEM; } tmp_fifo[n].depth = depth[n]; } if ( n == 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: no channels specified\n"); return -EINVAL; } numchan = n; /* clear shmem IDs */ for ( n = 0 ; n < MAX_STREAMERS ; n++ ) { shmem_id[n] = -1; } /* have good config info, connect to the HAL */ comp_id = hal_init("streamer"); if (comp_id < 0) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: hal_init() failed\n"); return -EINVAL; } /* create the streamers - allocate memory, export pins, etc. */ for (n = 0; n < numchan; n++) { retval = init_streamer(n, &(tmp_fifo[n])); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: streamer %d init failed\n", n); hal_exit(comp_id); return retval; } } rtapi_print_msg(RTAPI_MSG_INFO, "STREAMER: installed %d data streamers\n", numchan); hal_ready(comp_id); return 0; }
int rtapi_app_main(void) { int n, retval; comp_id = hal_init("streamer"); if (comp_id < 0) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: hal_init() failed\n"); return -EINVAL; } streams = hal_malloc(MAX_STREAMERS * sizeof(streamer_t)); /* validate config info */ for ( n = 0 ; n < MAX_STREAMERS ; n++ ) { if (( cfg[n] == NULL ) || ( *cfg == '\0' ) || ( depth[n] <= 0 )) { break; } retval = hal_stream_create(&streams[n].fifo, comp_id, STREAMER_SHMEM_KEY+n, depth[n], cfg[n]); if(retval < 0) { goto fail; } nstreamers++; retval = init_streamer(n, &streams[n]); } if ( n == 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: no channels specified\n"); retval = -EINVAL; goto fail; } hal_ready(comp_id); return 0; fail: for(n=0; n<nstreamers; n++) hal_stream_destroy(&streams[n].fifo); hal_exit(comp_id); return retval; }