QP/C
qs_pkg.h
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 26, 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 #ifndef qs_pkg_h
00029 #define qs_pkg_h
00030 
00037 #include "qs_port.h"                                             /* QS port */
00038 
00040 typedef uint16_t QSCtr;
00041 
00042 /*..........................................................................*/
00046 #define QS_INSERT_BYTE(b_) \
00047     QS_PTR_AT_(QS_head_) = (b_); \
00048     ++QS_head_; \
00049     if (QS_head_ == QS_end_) { \
00050         QS_head_ = (QSCtr)0; \
00051     } \
00052     ++QS_used_;
00053 
00055 #define QS_INSERT_ESC_BYTE(b_) \
00056     QS_chksum_ = (uint8_t)(QS_chksum_ + (b_)); \
00057     if (((b_) == QS_FRAME) || ((b_) == QS_ESC)) { \
00058         QS_INSERT_BYTE(QS_ESC) \
00059         QS_INSERT_BYTE((uint8_t)((b_) ^ QS_ESC_XOR)) \
00060     } \
00061     else { \
00062         QS_INSERT_BYTE(b_) \
00063     }
00064 
00068 #define QS_INSERT_CHKSUM_BYTE() \
00069     QS_chksum_ = (uint8_t)~QS_chksum_; \
00070     if ((QS_chksum_ == QS_FRAME) || (QS_chksum_ == QS_ESC)) { \
00071         QS_INSERT_BYTE(QS_ESC) \
00072         QS_INSERT_BYTE((uint8_t)(QS_chksum_ ^ QS_ESC_XOR)) \
00073     } \
00074     else { \
00075         QS_INSERT_BYTE(QS_chksum_) \
00076     }
00077 
00085 #define QS_PTR_AT_(i_) (QS_ring_[i_])
00086 
00093 #define QS_PTR_INC_(ptr_) (++(ptr_))
00094 
00096 #define QS_FRAME    ((uint8_t)0x7E)
00097 
00099 #define QS_ESC      ((uint8_t)0x7D)
00100 
00106 #define QS_ESC_XOR  ((uint8_t)0x20)
00107 
00108 #ifndef Q_ROM_BYTE
00109 
00123     #define Q_ROM_BYTE(rom_var_)   (rom_var_)
00124 #endif
00125 
00126 /*..........................................................................*/
00127 extern uint8_t *QS_ring_;      
00128 extern QSCtr QS_end_;             
00129 extern QSCtr QS_head_;      
00130 extern QSCtr QS_tail_;    
00131 extern QSCtr QS_used_;    
00132 extern uint8_t QS_seq_;                     
00133 extern uint8_t QS_chksum_;          
00134 extern uint8_t QS_full_;           
00136 #endif                                                          /* qs_pkg_h */
00137