|
QP/C++
|
00001 00002 // Product: QS/C++ 00003 // Last Updated for Version: 4.4.00 00004 // Date of the Last Update: Mar 28, 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 program is open source software: you can redistribute it and/or 00013 // modify it under the terms of the GNU General Public License as published 00014 // by the Free Software Foundation, either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // Alternatively, this program may be distributed and modified under the 00018 // terms of Quantum Leaps commercial licenses, which expressly supersede 00019 // the GNU General Public License and are specifically designed for 00020 // licensees interested in retaining the proprietary status of their code. 00021 // 00022 // This program is distributed in the hope that it will be useful, 00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 // GNU General Public License for more details. 00026 // 00027 // You should have received a copy of the GNU General Public License 00028 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00029 // 00030 // Contact information: 00031 // Quantum Leaps Web sites: http://www.quantum-leaps.com 00032 // http://www.state-machine.com 00033 // e-mail: info@quantum-leaps.com 00035 #include "qs_pkg.h" 00036 00040 00041 QP_BEGIN_ 00042 00043 //............................................................................ 00044 // get up to *pn bytes of contiguous memory 00045 uint8_t const *QS::getBlock(uint16_t * const pNbytes) { 00046 uint8_t *block; 00047 if (QS_used_ == static_cast<QSCtr>(0)) { 00048 *pNbytes = static_cast<uint16_t>(0); 00049 block = static_cast<uint8_t *>(0); // no bytes to return right now 00050 } 00051 else { 00052 QSCtr n = static_cast<QSCtr>(QS_end_ - QS_tail_); 00053 if (n > QS_used_) { 00054 n = QS_used_; 00055 } 00056 if (n > static_cast<QSCtr>(*pNbytes)) { 00057 n = static_cast<QSCtr>(*pNbytes); 00058 } 00059 *pNbytes = static_cast<uint16_t>(n); 00060 QS_used_ = static_cast<QSCtr>(QS_used_ - n); 00061 QSCtr t = QS_tail_; 00062 QS_tail_ = static_cast<QSCtr>(QS_tail_ + n); 00063 if (QS_tail_ == QS_end_) { 00064 QS_tail_ = static_cast<QSCtr>(0); 00065 } 00066 block = &QS_PTR_AT_(t); 00067 } 00068 return block; 00069 } 00070 00071 QP_END_
1.7.6.1