From 430e21aac48c9b83459c13bb5a399493c5117897 Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 9 Jul 2009 16:42:35 +0000 Subject: [PATCH] new handling of TERMINATIOn-Status-bits . --- libtrbnet/trberror.c | 96 +++++++++++++++++++++++--------------------- libtrbnet/trberror.h | 21 +++++++--- 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/libtrbnet/trberror.c b/libtrbnet/trberror.c index 9f26330..4d8a88b 100644 --- a/libtrbnet/trberror.c +++ b/libtrbnet/trberror.c @@ -7,7 +7,8 @@ /* Error Handling */ int trb_errno = TRB_NONE; -uint64_t trb_statusbits = 0; + +TRB_TERM trb_term = {0, 0, 0, 0}; void trb_error(const char *s) { @@ -18,8 +19,8 @@ void trb_error(const char *s) } /* Print Statusbits */ - if (trb_errno == TRB_TERM_ERRBIT) { - fprintf(stderr, "%s\n", trb_statusbits_str(trb_statusbits)); + if (trb_errno == TRB_STATUS_ERROR) { + fprintf(stderr, "%s\n", trb_strterm(trb_term)); } } @@ -40,55 +41,59 @@ const char* trb_strerror(int errno) "User-Buffer Overflow", "Invalid Channel", "Invalid number of Packages returned", - "TERMINATION ErrorBit(s) set", + "Termination Status Error", "Invalid TRB-Address", "Invalid Data-Buffer Length", "Endpoint not reached", "DMA not available (check whether module 'can_module.ko' is loaded)", "DMA-Timeout", - "ReadMem invalid size" + "ReadMem invalid size", + "Invalid data-length give by Header" }; - if (errno < 21) { + if (errno < 22) { return errorstring[errno]; } else { return "Unknown Errno"; } } -const char* trb_statusbits_str(uint64_t statusbits) +const char* trb_strterm(TRB_TERM term) { - static const char commonStatusBits[16][64] = { - "Endpoint not reached", - "Coll: collision detected", - "WordMiss: word missing", - "Checksum: checksum error", - "DontKnow: dont understand", - "BufferMatch: buffer mismatch", - "", "", "", "", "", "", "", "", "", "" + static const char commonStatusBits[16][64] = { + "Endpoint not reached", /* error */ + "Coll: collision detected", /* error */ + "WordMiss: word missing", /* error */ + "Checksum: checksum error", /* status, at the moment */ + "DontKnow: dont understand", /* error */ + "BufferMatch: buffer mismatch", /* error */ + "", "", "", "", "", "", "", "", "", "" }; - static const char ch0StatusBits[16][64] = { - "Ch0_TrigCtr: trigger counter mismatch", - "", - "", - "", - "Ch0_BufferHalfFull: data-buffers half full", - "Ch0_BuffersFull: data-buffers almost full" + static const char ch0StatusBits[16][64] = { + "Ch0_TrigCtr: trigger counter mismatch", /* status */ + "", + "", + "", + "Ch0_BufferHalfFull: data-buffers half full", /* status */ + "Ch0_BuffersFull: data-buffers almost full" /* status */ "", "", "", "", "", "", "", "", "", "" }; - static const char ch1StatusBits[16][64] = { - "Ch1_TrigNum: trigger number mismatch", - "Ch1_TrigCode: trigger code / random mismatch", - "Ch1_Length: wrong length", - "Ch1_NoAnswer: answer missing", - "", - "", - "", - "", - "Ch1_NotFound: not found" - "", "", "", "", "", "", "", "" + static const char ch1StatusBits[16][64] = { + "Ch1_TrigNum: trigger number mismatch", /* status */ + "Ch1_TrigCode: trigger code / random mismatch", /* status */ + "Ch1_Length: wrong length", /* status */ + "Ch1_NoAnswer: answer missing", /* status */ + "", + "", + "", + "", + "Ch1_NotFound: sent trigger number mismatch", /* status */ + "Ch1_DataMissing: parts of the data are missing",/* status */ + "Ch1_Sync: serious sync problem detected", /* status */ + "Ch1_EvtBroken: event data corrupted", /* status */ + "", "", "", "" }; static const char ch2StatusBits[16][64] = { @@ -96,10 +101,10 @@ const char* trb_statusbits_str(uint64_t statusbits) "", "", "", "", "", "", "", "" }; - static const char ch3StatusBits[16][64] = { - "Ch3_Address: unknown address", - "Ch3_TimeOut: timeout error", - "Ch3_NoData: no more data" + static const char ch3StatusBits[16][64] = { + "Ch3_Address: unknown address", /* error */ + "Ch3_TimeOut: timeout error", /* error */ + "Ch3_NoData: no more data" /* status */ "", "", "", "", "", "", "", "", "", "", "", "", "" }; @@ -112,29 +117,28 @@ const char* trb_statusbits_str(uint64_t statusbits) static char buffer[2048] = ""; unsigned int i; - uint8_t channel = (statusbits & 0x700000000LL) >> 32; - if (channel >= 4) { - snprintf(buffer, 2048, "INVALID ChannelId %d", channel); + if (term.channel >= 4) { + snprintf(buffer, 2048, "INVALID ChannelId %d", term.channel); return buffer; } snprintf(buffer, 2048, "CommonStatusBits: 0x%04x, Channel#%d StatusBits: 0x%04x\n", - (uint16_t)(statusbits & 0x0000ffffLL), - channel, - (uint16_t)((statusbits & 0xffff0000LL) >> 16)); + term.status_common, + term.channel, + term.status_channel); for (i = 0; i < 16; i++) { - if (((statusbits & 0xffffLL) & (0x01LL << i)) != (i != 0 ? 0 : 1)) { + if ((term.status_common & (0x01 << i)) != (i != 0 ? 0 : 1)) { strncat(buffer, " ", 2048); strncat(buffer, commonStatusBits[i], 2048); strncat(buffer, "\n", 2048); } } for (i = 0; i < 16; i++) { - if ((((statusbits & 0xffff0000LL) >> 16) & (0x01LL << i)) != 0) { + if ((term.status_channel & (0x01 << i)) != 0) { strncat(buffer, " ", 2048); - strncat(buffer, chStatusBits[channel] + 64 * i, 2048); + strncat(buffer, chStatusBits[term.channel] + 64 * i, 2048); strncat(buffer, "\n", 2048); } } diff --git a/libtrbnet/trberror.h b/libtrbnet/trberror.h index b70cac9..6ba7c40 100644 --- a/libtrbnet/trberror.h +++ b/libtrbnet/trberror.h @@ -18,23 +18,34 @@ typedef enum { TRB_USER_BUFFER_OVF = 11, TRB_INVALID_CHANNEL = 12, TRB_INVALID_PKG_NUMBER = 13, - TRB_TERM_ERRBIT = 14, + TRB_STATUS_ERROR = 14, TRB_INVALID_ADDRESS = 15, TRB_INVALID_LENGTH = 16, TRB_ENDPOINT_NOT_REACHED = 17, TRB_DMA_UNAVAILABLE = 18, TRB_DMA_TIMEOUT = 19, - TRB_READMEM_INVALID_SIZE = 20 + TRB_READMEM_INVALID_SIZE = 20, + TRB_HDR_DLEN = 21 } TRB_ERROR; extern int trb_errno; -extern uint64_t trb_statusbits; - void trb_error(const char *s); const char* trb_strerror(int errno); -const char* trb_statusbits_str(uint64_t statusbits); + +/* last TRBNet-TermPackage */ + +typedef struct { + uint16_t status_common; + uint16_t status_channel; + uint16_t sequenz; + uint8_t channel; +} TRB_TERM; + +extern TRB_TERM trb_term; + +const char* trb_strterm(TRB_TERM term); #endif -- 2.43.0