QP/C++  7.3.3
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qs_fp.cpp
Go to the documentation of this file.
1//$file${src::qs::qs_fp.cpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpcpp.qm
4// File: ${src::qs::qs_fp.cpp}
5//
6// This code has been generated by QM 6.1.1 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// This code is covered by the following QP license:
10// License # : LicenseRef-QL-dual
11// Issued to : Any user of the QP/C++ real-time embedded framework
12// Framework(s) : qpcpp
13// Support ends : 2024-12-31
14// License scope:
15//
16// Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
17//
18// Q u a n t u m L e a P s
19// ------------------------
20// Modern Embedded Software
21//
22// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
23//
24// This software is dual-licensed under the terms of the open source GNU
25// General Public License version 3 (or any later version), or alternatively,
26// under the terms of one of the closed source Quantum Leaps commercial
27// licenses.
28//
29// The terms of the open source GNU General Public License version 3
30// can be found at: <www.gnu.org/licenses/gpl-3.0>
31//
32// The terms of the closed source Quantum Leaps commercial licenses
33// can be found at: <www.state-machine.com/licensing>
34//
35// Redistributions in source code must retain this top-level comment block.
36// Plagiarizing this software to sidestep the license obligations is illegal.
37//
38// Contact information:
39// <www.state-machine.com/licensing>
40// <info@state-machine.com>
41//
42//$endhead${src::qs::qs_fp.cpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43#define QP_IMPL // this is QF/QK implementation
44#include "qs_port.hpp" // QS port
45#include "qs_pkg.hpp" // QS package-scope internal interface
46
47//============================================================================
48//! @cond INTERNAL
49
50namespace QP {
51namespace QS {
52
53//${QS::QS-tx-fp::f32_fmt_} ..................................................
54void f32_fmt_(
55 std::uint8_t format,
56 float32_t f) noexcept
57{
58 union F32Rep {
59 float32_t f;
60 std::uint32_t u;
61 } fu32; // the internal binary representation
62 std::uint8_t chksum = priv_.chksum; // put in a temporary (register)
63 std::uint8_t * const buf = priv_.buf; // put in a temporary (register)
64 QSCtr head = priv_.head; // put in a temporary (register)
65 QSCtr const end = priv_.end; // put in a temporary (register)
66
67 fu32.f = f; // assign the binary representation
68
69 priv_.used = (priv_.used + 5U); // 5 bytes about to be added
70 QS_INSERT_ESC_BYTE_(format) // insert the format byte
71
72 for (std::uint_fast8_t i = 4U; i != 0U; --i) {
73 format = static_cast<std::uint8_t>(fu32.u);
74 QS_INSERT_ESC_BYTE_(format)
75 fu32.u >>= 8U;
76 }
77
78 priv_.head = head; // save the head
79 priv_.chksum = chksum; // save the checksum
80}
81
82//${QS::QS-tx-fp::f64_fmt_} ..................................................
83void f64_fmt_(
84 std::uint8_t format,
85 float64_t d) noexcept
86{
87 union F64Rep {
88 float64_t d;
89 std::uint32_t u[2];
90 } fu64; // the internal binary representation
91 std::uint8_t chksum = priv_.chksum;
92 std::uint8_t * const buf = priv_.buf;
93 QSCtr head = priv_.head;
94 QSCtr const end = priv_.end;
95 std::uint32_t i;
96 // static constant untion to detect endianness of the machine
97 static union U32Rep {
98 std::uint32_t u32;
99 std::uint8_t u8;
100 } const endian = { 1U };
101
102 fu64.d = d; // assign the binary representation
103
104 // is this a big-endian machine?
105 if (endian.u8 == 0U) {
106 // swap fu64.u[0] <-> fu64.u[1]...
107 i = fu64.u[0];
108 fu64.u[0] = fu64.u[1];
109 fu64.u[1] = i;
110 }
111
112 priv_.used = (priv_.used + 9U); // 9 bytes about to be added
113 QS_INSERT_ESC_BYTE_(format) // insert the format byte
114
115 // output 4 bytes from fu64.u[0]...
116 for (i = 4U; i != 0U; --i) {
117 QS_INSERT_ESC_BYTE_(static_cast<std::uint8_t>(fu64.u[0]))
118 fu64.u[0] >>= 8U;
119 }
120
121 // output 4 bytes from fu64.u[1]...
122 for (i = 4U; i != 0U; --i) {
123 QS_INSERT_ESC_BYTE_(static_cast<std::uint8_t>(fu64.u[1]))
124 fu64.u[1] >>= 8U;
125 }
126
127 priv_.head = head; // update the head
128 priv_.chksum = chksum; // update the checksum
129}
130
131} // namespace QS
132} // namespace QP
133
134//! @endcond
QF::Attr priv_
Definition qf_act.cpp:78
QP/C++ framework.
Definition qequeue.hpp:50
float float32_t
Definition qp.hpp:111
double float64_t
Definition qp.hpp:114
QS/C++ package-scope interface.
QS/C++ port to a 32-bit CPU, generic C++ compiler.