ARPDAS_QNX6 1.0
Defines | Functions | Variables
serusb.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <fcntl.h>
#include <ctype.h>
#include "serusb.h"
#include "nl_assert.h"
Include dependency graph for serusb.c:

Go to the source code of this file.

Defines

#define RESP_OK   0
#define RESP_UNREC   1
#define RESP_UNEXP   2
#define RESP_INV   3
#define RESP_INTR   4
#define RESP_ERR   5

Functions

static void dequeue_request (signed short status, int n_args, unsigned short arg0, unsigned short arg1, char *s)
static void set_timeout (int enable)
static void process_request (void)
static void enqueue_sbreq (int type, int rcvid, char *req, unsigned short n_reads)
static int sb_data_arm (void)
static int read_hex (char **sp, unsigned short *arg)
static void process_interrupt (unsigned int nb)
static void process_response (char *buf)
static void sb_read_usb (void)
static int sb_data_ready (message_context_t *ctp, int code, unsigned flags, void *handle)
static int sb_timeout (message_context_t *ctp, int code, unsigned flags, void *handle)
static void init_serusb (dispatch_t *dpp, int ionotify_pulse, int timeout_pulse)
static void ErrorReply (int rcvid, int rv)
void incoming_sbreq (int rcvid, subbusd_req_t *req)
void init_subbus (dispatch_t *dpp)
void shutdown_subbus (void)

Variables

static char sb_ibuf [SB_SERUSB_MAX_REQUEST]
static int sb_ibuf_idx = 0
static sbd_request_t sbdrq [SUBBUSD_MAX_REQUESTS]
static sbd_request_tcur_req
static unsigned int sbdrq_head = 0
static unsigned int sbdrq_tail = 0
static int sb_fd
static struct sigevent ionotify_event
static timer_t timeout_timer
static struct itimerspec
timeout_enable 
timeout_disable
static int n_timeouts = 0
static int n_writes = 0
static int n_reads = 0
static int n_part_reads = 0
static int n_compound_reads = 0

Define Documentation

#define RESP_ERR   5

Definition at line 344 of file serusb.c.

Referenced by process_response().

#define RESP_INTR   4

Definition at line 343 of file serusb.c.

Referenced by process_response().

#define RESP_INV   3

Definition at line 342 of file serusb.c.

Referenced by process_response().

#define RESP_OK   0

Definition at line 339 of file serusb.c.

Referenced by process_response().

#define RESP_UNEXP   2

Definition at line 341 of file serusb.c.

Referenced by process_response().

#define RESP_UNREC   1

Definition at line 340 of file serusb.c.

Referenced by process_response().


Function Documentation

static void dequeue_request ( signed short  status,
int  n_args,
unsigned short  arg0,
unsigned short  arg1,
char *  s 
) [static]

Sends the response to the client (if any) and removes it from the queue. Initiates processing of the next command if one is waiting. Current assumption: n_args maps 1:1 onto SBRT_ codes n_args == 3 is only for 'V' request/response n_args == 4 is only for 'M' request/response We need to parse the 'M' response here rather than in process_response() because we need direct access to the reply structure.

Definition at line 177 of file serusb.c.

References ascii_escape(), subbusd_rep_t::capabilities, subbusd_rep_t::data, subbusd_cap_t::features, subbusd_rep_t::hdr, subbusd_rep_t::mread, subbusd_mread_t::n_reads, n_reads, sbd_request_t::n_reads, subbusd_cap_t::name, nl_assert, nl_error, process_request(), sbd_request_t::rcvid, read_hex(), sbd_request_t::request, subbusd_rep_hdr_t::ret_type, subbusd_mread_t::rvals, SBDR_TYPE_CLIENT, SBDR_TYPE_INTERNAL, sbdrq_head, SBRT_CAP, SBRT_MREAD, SBRT_NONE, SBRT_US, SBS_NOACK, SBS_RESP_ERROR, SBS_RESP_SYNTAX, set_timeout(), subbusd_rep_hdr_t::status, SUBBUS_NAME_MAX, SUBBUSD_MAX_REQUESTS, subbusd_cap_t::subfunc, sbd_request_t::type, and subbusd_rep_t::value.

Referenced by process_request(), process_response(), and sb_timeout().

Here is the call graph for this function:

Here is the caller graph for this function:

static void enqueue_sbreq ( int  type,
int  rcvid,
char *  req,
unsigned short  n_reads 
) [static]

This is where we serialize the request.

Definition at line 103 of file serusb.c.

References n_reads, sbd_request_t::n_reads, nl_error, process_request(), sbd_request_t::rcvid, sbd_request_t::request, SB_SERUSB_MAX_REQUEST, SBDR_STATUS_QUEUED, sbdrq_head, sbdrq_tail, sbd_request_t::status, SUBBUSD_MAX_REQUESTS, and sbd_request_t::type.

Referenced by incoming_sbreq(), init_subbus(), and process_interrupt().

Here is the call graph for this function:

Here is the caller graph for this function:

static void ErrorReply ( int  rcvid,
int  rv 
) [static]

Definition at line 631 of file serusb.c.

References nl_assert, subbusd_rep_hdr_t::ret_type, SBRT_NONE, and subbusd_rep_hdr_t::status.

Referenced by incoming_sbreq().

Here is the caller graph for this function:

void incoming_sbreq ( int  rcvid,
subbusd_req_t req 
)

This is where we serialize the request The basic sanity of the incoming message has been checked by subbus_io_msg before it gets here, so we can at least assume that the message was big enough to include the specified message type, and that the message type is defined.

Definition at line 647 of file serusb.c.

References subbusd_req_data0::address, subbusd_req_hdr_t::command, subbusd_req_t::d0, subbusd_req_t::d1, subbusd_req_t::d4, subbusd_req_data0::data, subbusd_rep_t::data, subbusd_req_data1::data, subbusd_req_t::data, enqueue_sbreq(), ErrorReply(), subbusd_rep_t::hdr, int_attach(), int_detach(), subbus_mread_req::multread_cmd, subbus_mread_req::n_reads, nl_error, subbusd_rep_hdr_t::ret_type, sb_cache_read(), sb_cache_write(), SB_SERUSB_MAX_REQUEST, SBC_DISARM, SBC_GETCAPS, SBC_INTATT, SBC_INTDET, SBC_MREAD, SBC_QUIT, SBC_READACK, SBC_READCACHE, SBC_READFAIL, SBC_READSW, SBC_SETCMDENBL, SBC_SETCMDSTRB, SBC_SETFAIL, SBC_TICK, SBC_WRITEACK, SBC_WRITECACHE, SBDR_TYPE_CLIENT, subbusd_req_t::sbhdr, SBRT_NONE, SBRT_US, SBS_ACK, SBS_NOACK, SBS_OK, subbusd_rep_hdr_t::status, and subbusd_rep_t::value.

Referenced by subbus_io_msg().

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_serusb ( dispatch_t *  dpp,
int  ionotify_pulse,
int  timeout_pulse 
) [static]

Definition at line 576 of file serusb.c.

References ionotify_event, nl_error, sb_fd, sb_read_usb(), timeout_disable, and timeout_timer.

Referenced by init_subbus().

Here is the call graph for this function:

Here is the caller graph for this function:

void init_subbus ( dispatch_t *  dpp)

Definition at line 732 of file serusb.c.

References enqueue_sbreq(), init_serusb(), sb_data_ready(), sb_timeout(), and SBDR_TYPE_INTERNAL.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_interrupt ( unsigned int  nb) [static]

Definition at line 304 of file serusb.c.

References carddef::bitno, carddefs, carddef::cardID, enqueue_sbreq(), carddef::event, expint_detach(), carddef::next, nl_assert, nl_error, carddef::owner, and SBDR_TYPE_INTERNAL.

Referenced by process_response().

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_request ( void  ) [static]

Definition at line 44 of file serusb.c.

References dequeue_request(), n_writes, nl_assert, nl_error, sbd_request_t::request, sb_fd, SBDR_STATUS_QUEUED, SBDR_STATUS_SENT, SBDR_TYPE_CLIENT, SBDR_TYPE_INTERNAL, sbdrq_head, sbdrq_tail, SBS_OK, set_timeout(), sbd_request_t::status, SUBBUSD_MAX_REQUESTS, and sbd_request_t::type.

Referenced by dequeue_request(), and enqueue_sbreq().

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_response ( char *  buf) [static]

process_response() reviews the response in the buffer to determine if it is a suitable response to the current request. If so, it is returned to the requester. process_response() is not responsible for advancing to the next request, but it is responsible for dequeuing the current request if it has been completed.

The string in resp is guaranteed to have had a newline at the end, which was replaced with a NUL, so we are guaranteed to have a NUL- terminated string.

Definition at line 360 of file serusb.c.

References ascii_escape(), dequeue_request(), nl_error, process_interrupt(), read_hex(), sbd_request_t::request, RESP_ERR, RESP_INTR, RESP_INV, RESP_OK, RESP_UNEXP, RESP_UNREC, SBS_ACK, SBS_NOACK, and SBS_OK.

Referenced by sb_read_usb().

Here is the call graph for this function:

Here is the caller graph for this function:

static int read_hex ( char **  sp,
unsigned short *  arg 
) [static]

Parses the input string for a hexadecimal integer.

Returns:
zero on failure.

Definition at line 148 of file serusb.c.

Referenced by dequeue_request(), and process_response().

Here is the caller graph for this function:

static int sb_data_arm ( void  ) [static]

Definition at line 135 of file serusb.c.

References ionotify_event, nl_error, and sb_fd.

Referenced by sb_read_usb().

Here is the caller graph for this function:

static int sb_data_ready ( message_context_t *  ctp,
int  code,
unsigned  flags,
void *  handle 
) [static]

Definition at line 556 of file serusb.c.

References sb_read_usb().

Referenced by init_subbus().

Here is the call graph for this function:

Here is the caller graph for this function:

static void sb_read_usb ( void  ) [static]

Definition at line 516 of file serusb.c.

References n_compound_reads, n_part_reads, n_reads, nl_assert, nl_error, process_response(), sb_data_arm(), sb_fd, sb_ibuf, sb_ibuf_idx, and SB_SERUSB_MAX_REQUEST.

Referenced by init_serusb(), and sb_data_ready().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sb_timeout ( message_context_t *  ctp,
int  code,
unsigned  flags,
void *  handle 
) [static]

Definition at line 562 of file serusb.c.

References dequeue_request(), n_timeouts, nl_error, sbd_request_t::request, SBDR_TYPE_INTERNAL, and sbd_request_t::type.

Referenced by init_subbus().

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_timeout ( int  enable) [static]

Definition at line 33 of file serusb.c.

References nl_error, timeout_disable, and timeout_timer.

Referenced by dequeue_request(), and process_request().

Here is the caller graph for this function:

void shutdown_subbus ( void  )

Definition at line 748 of file serusb.c.

References n_compound_reads, n_part_reads, n_reads, n_writes, and nl_error.

Referenced by main().

Here is the caller graph for this function:


Variable Documentation

Definition at line 17 of file serusb.c.

struct sigevent ionotify_event [static]

Definition at line 20 of file serusb.c.

Referenced by init_serusb(), and sb_data_arm().

int n_compound_reads = 0 [static]

Definition at line 28 of file serusb.c.

Referenced by sb_read_usb(), and shutdown_subbus().

int n_part_reads = 0 [static]

Definition at line 27 of file serusb.c.

Referenced by sb_read_usb(), and shutdown_subbus().

int n_reads = 0 [static]
int n_timeouts = 0 [static]

Definition at line 23 of file serusb.c.

Referenced by sb_timeout().

int n_writes = 0 [static]

Definition at line 25 of file serusb.c.

Referenced by process_request(), and shutdown_subbus().

int sb_fd [static]

Definition at line 19 of file serusb.c.

Referenced by init_serusb(), process_request(), sb_data_arm(), and sb_read_usb().

char sb_ibuf[SB_SERUSB_MAX_REQUEST] [static]

Definition at line 14 of file serusb.c.

Referenced by sb_read_usb().

int sb_ibuf_idx = 0 [static]

Definition at line 15 of file serusb.c.

Referenced by sb_read_usb().

sbd_request_t sbdrq[SUBBUSD_MAX_REQUESTS] [static]

Definition at line 16 of file serusb.c.

unsigned int sbdrq_head = 0 [static]

Definition at line 18 of file serusb.c.

Referenced by dequeue_request(), enqueue_sbreq(), and process_request().

unsigned int sbdrq_tail = 0

Definition at line 18 of file serusb.c.

Referenced by enqueue_sbreq(), and process_request().

struct itimerspec timeout_enable timeout_disable [static]

Definition at line 22 of file serusb.c.

Referenced by init_serusb(), and set_timeout().

timer_t timeout_timer [static]

Definition at line 21 of file serusb.c.

Referenced by init_serusb(), and set_timeout().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines