QP/C
qs.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Product: QS/C
00003 * Last Updated for Version: 4.4.00
00004 * Date of the Last Update:  Jan 05, 2012
00005 *
00006 *                    Q u a n t u m     L e a P s
00007 *                    ---------------------------
00008 *                    innovating embedded systems
00009 *
00010 * Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
00011 *
00012 * This software may be distributed and modified under the terms of the GNU
00013 * General Public License version 2 (GPL) as published by the Free Software
00014 * Foundation and appearing in the file GPL.TXT included in the packaging of
00015 * this file. Please note that GPL Section 2[b] requires that all works based
00016 * on this software must also be made publicly available under the terms of
00017 * the GPL ("Copyleft").
00018 *
00019 * Alternatively, this software may be distributed and modified under the
00020 * terms of Quantum Leaps commercial licenses, which expressly supersede
00021 * the GPL and are specifically designed for licensees interested in
00022 * retaining the proprietary status of their code.
00023 *
00024 * Contact information:
00025 * Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 * e-mail:                  info@quantum-leaps.com
00027 *****************************************************************************/
00028 #include "qs_pkg.h"
00029 
00037 /*..........................................................................*/
00038 uint8_t QS_glbFilter_[32];                              /* global QS filter */
00039 
00040 /*..........................................................................*/
00041 uint8_t *QS_ring_;               /* pointer to the start of the ring buffer */
00042 QSCtr QS_end_;                      /* offset of the end of the ring buffer */
00043 QSCtr QS_head_;               /* offset to where next byte will be inserted */
00044 QSCtr QS_tail_;              /* offset of where next byte will be extracted */
00045 QSCtr QS_used_;             /* number of bytes currently in the ring buffer */
00046 uint8_t QS_seq_;                              /* the record sequence number */
00047 uint8_t QS_chksum_;                   /* the checksum of the current record */
00048 uint8_t QS_full_;                    /* the ring buffer is temporarily full */
00049 
00050 /*..........................................................................*/
00051 char_t const Q_ROM * Q_ROM_VAR QS_getVersion(void) {
00052     static char_t const Q_ROM Q_ROM_VAR version[] = {
00053         (char_t)((uint8_t)((QP_VERSION >> 12) & 0xFU) + (uint8_t)'0'),
00054         (char_t)'.',
00055         (char_t)((uint8_t)((QP_VERSION >>  8) & 0xFU) + (uint8_t)'0'),
00056         (char_t)'.',
00057         (char_t)((uint8_t)((QP_VERSION >>  4) & 0xFU) + (uint8_t)'0'),
00058         (char_t)((uint8_t)(QP_VERSION         & 0xFU) + (uint8_t)'0'),
00059         (char_t)'\0'
00060     };
00061     return version;
00062 }
00063 /*..........................................................................*/
00064 void QS_initBuf(uint8_t sto[], uint32_t stoSize) {
00065     QS_ring_ = &sto[0];
00066     QS_end_  = (QSCtr)stoSize;
00067 }
00068 /*..........................................................................*/
00069 void QS_filterOn(uint8_t rec) {
00070     if (rec == QS_ALL_RECORDS) {
00071         uint8_t i;
00072         for (i = (uint8_t)0; i < (uint8_t)sizeof(QS_glbFilter_); ++i) {
00073             QS_glbFilter_[i] = (uint8_t)0xFF;
00074         }
00075     }
00076     else {
00077         QS_glbFilter_[rec >> 3] |= (uint8_t)(1U << (rec & (uint8_t)0x07));
00078     }
00079 }
00080 /*..........................................................................*/
00081 void QS_filterOff(uint8_t rec) {
00082     if (rec == QS_ALL_RECORDS) {
00083         uint8_t i;
00084         for (i = (uint8_t)0; i < (uint8_t)sizeof(QS_glbFilter_); ++i) {
00085             QS_glbFilter_[i] = (uint8_t)0;
00086         }
00087     }
00088     else {
00089         QS_glbFilter_[rec >> 3] &=
00090             (uint8_t)(~(uint8_t)(1U << (rec & (uint8_t)0x07)));
00091     }
00092 }
00093 /*..........................................................................*/
00094 void QS_begin(uint8_t rec) {
00095     QS_chksum_ = (uint8_t)0;                          /* clear the checksum */
00096     ++QS_seq_;                      /* always increment the sequence number */
00097     QS_INSERT_ESC_BYTE(QS_seq_)                /* store the sequence number */
00098     QS_INSERT_ESC_BYTE(rec)                          /* store the record ID */
00099 }
00100 /*..........................................................................*/
00101 void QS_end(void) {
00102     QS_INSERT_CHKSUM_BYTE()
00103     QS_INSERT_BYTE(QS_FRAME)
00104     if (QS_used_ > QS_end_) {                 /* overrun over the old data? */
00105         QS_tail_ = QS_head_;              /* shift the tail to the old data */
00106         QS_used_ = QS_end_;                     /* the whole buffer is used */
00107     }
00108 }
00109 /*..........................................................................*/
00110 void QS_u8(uint8_t format, uint8_t d) {
00111     QS_INSERT_ESC_BYTE(format)
00112     QS_INSERT_ESC_BYTE(d)
00113 }
00114 /*..........................................................................*/
00115 void QS_u16(uint8_t format, uint16_t d) {
00116     QS_INSERT_ESC_BYTE(format)
00117     QS_INSERT_ESC_BYTE((uint8_t)d)
00118     d >>= 8;
00119     QS_INSERT_ESC_BYTE((uint8_t)d)
00120 }
00121 /*..........................................................................*/
00122 void QS_u32(uint8_t format, uint32_t d) {
00123     QS_INSERT_ESC_BYTE(format)
00124     QS_INSERT_ESC_BYTE((uint8_t)d)
00125     d >>= 8;
00126     QS_INSERT_ESC_BYTE((uint8_t)d)
00127     d >>= 8;
00128     QS_INSERT_ESC_BYTE((uint8_t)d)
00129     d >>= 8;
00130     QS_INSERT_ESC_BYTE((uint8_t)d)
00131 }
00132 
00133