QP/C++  7.0.1
Real-Time Embedded Framework
qs_fp.cpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Embedded Framework (RTEF)
3// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
4//
5// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
6//
7// This software is dual-licensed under the terms of the open source GNU
8// General Public License version 3 (or any later version), or alternatively,
9// under the terms of one of the closed source Quantum Leaps commercial
10// licenses.
11//
12// The terms of the open source GNU General Public License version 3
13// can be found at: <www.gnu.org/licenses/gpl-3.0>
14//
15// The terms of the closed source Quantum Leaps commercial licenses
16// can be found at: <www.state-machine.com/licensing>
17//
18// Redistributions in source code must retain this top-level comment block.
19// Plagiarizing this software to sidestep the license obligations is illegal.
20//
21// Contact information:
22// <www.state-machine.com>
23// <info@state-machine.com>
24//============================================================================
30
31#define QP_IMPL // this is QF/QK implementation
32#include "qs_port.hpp" // QS port
33#include "qs_pkg.hpp" // QS package-scope internal interface
34
35namespace QP {
36
37//============================================================================
41void QS::f32_fmt_(std::uint8_t format, float32_t const d) noexcept {
42 union F32Rep {
43 float32_t f;
44 std::uint32_t u;
45 } fu32; // the internal binary representation
46 std::uint8_t chksum_ = priv_.chksum; // put in a temporary (register)
47 std::uint8_t * const buf_ = priv_.buf; // put in a temporary (register)
48 QSCtr head_ = priv_.head; // put in a temporary (register)
49 QSCtr const end_ = priv_.end; // put in a temporary (register)
50
51 fu32.f = d; // assign the binary representation
52
53 priv_.used = (priv_.used + 5U); // 5 bytes about to be added
54 QS_INSERT_ESC_BYTE_(format) // insert the format byte
55
56 for (std::uint_fast8_t i = 4U; i != 0U; --i) {
57 format = static_cast<std::uint8_t>(fu32.u);
59 fu32.u >>= 8U;
60 }
61
62 priv_.head = head_; // save the head
63 priv_.chksum = chksum_; // save the checksum
64}
65
66//============================================================================
70void QS::f64_fmt_(std::uint8_t format, float64_t const d) noexcept {
71 union F64Rep {
72 float64_t d;
73 std::uint32_t u[2];
74 } fu64; // the internal binary representation
75 std::uint8_t chksum_ = priv_.chksum;
76 std::uint8_t * const buf_ = priv_.buf;
77 QSCtr head_ = priv_.head;
78 QSCtr const end_ = priv_.end;
79 std::uint32_t i;
80 // static constant untion to detect endianness of the machine
81 static union U32Rep {
82 std::uint32_t u32;
83 std::uint8_t u8;
84 } const endian = { 1U };
85
86 fu64.d = d; // assign the binary representation
87
88 // is this a big-endian machine?
89 if (endian.u8 == 0U) {
90 // swap fu64.u[0] <-> fu64.u[1]...
91 i = fu64.u[0];
92 fu64.u[0] = fu64.u[1];
93 fu64.u[1] = i;
94 }
95
96 priv_.used = (priv_.used + 9U); // 9 bytes about to be added
97 QS_INSERT_ESC_BYTE_(format) // insert the format byte
98
99 // output 4 bytes from fu64.u[0]...
100 for (i = 4U; i != 0U; --i) {
101 QS_INSERT_ESC_BYTE_(static_cast<std::uint8_t>(fu64.u[0]))
102 fu64.u[0] >>= 8U;
103 }
104
105 // output 4 bytes from fu64.u[1]...
106 for (i = 4U; i != 0U; --i) {
107 QS_INSERT_ESC_BYTE_(static_cast<std::uint8_t>(fu64.u[1]))
108 fu64.u[1] >>= 8U;
109 }
110
111 priv_.head = head_; // update the head
112 priv_.chksum = chksum_; // update the checksum
113}
114
115} // namespace QP
static void f64_fmt_(std::uint8_t format, float64_t const d) noexcept
Output 64-bit floating point data element with format information.
Definition: qs_fp.cpp:70
static void f32_fmt_(std::uint8_t format, float32_t const d) noexcept
Output 32-bit floating point data element with format information.
Definition: qs_fp.cpp:41
namespace associated with the QP/C++ framework
Definition: exa_native.dox:1
std::uint_fast16_t QSCtr
QS ring buffer counter and offset type.
Definition: qs.hpp:250
float float32_t
alias for 32-bit IEEE 754 floating point numbers
Definition: qep.hpp:75
double float64_t
alias for 64-bit IEEE 754 floating point numbers
Definition: qep.hpp:84
Internal (package scope) QS/C++ interface.
#define QS_INSERT_ESC_BYTE_(b_)
Internal QS macro to insert an escaped byte into the QS buffer.
Definition: qs_pkg.hpp:92