/* $Id: rwio.c,v 1.6 2004/03/25 00:06:14 jmuelmen Exp $ */ /* This file contains the OS-independent r/w IO routines */ #include #include "surf_int.h" #include "surf_drv.h" /* this is also the place where the surflib mutex is kept */ #define SURF_LOCK pthread_mutex_lock(&_surf_mut) #define SURF_UNLOCK pthread_mutex_unlock(&_surf_mut) static pthread_mutex_t _surf_mut; int surf_init () { surflib_init(); surf_mod_init(); surf_board_init(); pthread_mutex_init(&_surf_mut, NULL); return 0; } int surf_write_board (const char *b_name, int ep, char *buf, int count) { int ret; struct surf_t *board; SURF_LOCK; /* first try to find the board */ if (!(board = surf_search(b_name))) /* if it's not there, try rescanning the bus */ if (surf_find_boards()) { /* something bad happened on the bus. errno is already set. */ SURF_UNLOCK; return -1; } if (!(board = surf_search(b_name))) { /* if it's still not there, give up */ surf_errno = ENOBOARD; SURF_UNLOCK; return -1; } ret = surf_write_ep(board, ep, buf, count); SURF_UNLOCK; if (ret < 0) SURF_LOG(LOGSURF_ERROR, "Error writing\n"); return ret; } int surf_read_board (const char *b_name, int ep, char *buf, int count) { int ret; struct surf_t *board; SURF_LOCK; /* first try to find the board */ if (!(board = surf_search(b_name))) /* if it's not there, try rescanning the bus */ if (surf_find_boards()) { /* something bad happened on the bus. errno is already set. */ SURF_UNLOCK; return -1; } if (!(board = surf_search(b_name))) { /* if it's still not there, give up */ surf_errno = ENOBOARD; SURF_UNLOCK; return -1; } ret = surf_read_ep(board, ep, buf, count); SURF_UNLOCK; if (ret < 0) SURF_LOG(LOGSURF_ERROR, "Error reading\n"); return ret; } int surf_print_boards () { int ret; SURF_LOCK; ret = surft_print_boards(); SURF_UNLOCK; return ret; }