QP/C  7.0.0
Real-Time Embedded Framework
qs_fp.c
Go to the documentation of this file.
1/*============================================================================
2*
3* Q u a n t u m L e a P s
4* ------------------------
5* Modern Embedded Software
6*
7* Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
8*
9* SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
10*
11* This software is dual-licensed under the terms of open-source GPL 3.0
12* (or any later version), or alternatively, under the terms of one of the
13* closed-source Quantum Leaps commercial licenses.
14*
15* The terms of the open source GPL 3.0 license can be found at:
16* <www.gnu.org/licenses/gpl-3.0.txt>
17*
18* The terms of the closed-source Quantum Leaps commercial licenses
19* can be found at:
20* <www.state-machine.com/licensing>
21*
22* NOTE: Please do NOT plagiarize this software to sidestep the license
23* obligations. This is both unfair and illegal.
24*
25* Contact information:
26* <www.state-machine.com>
27* <info@state-machine.com>
28============================================================================*/
36#define QP_IMPL /* this is QP implementation */
37#include "qs_port.h" /* QS port */
38#include "qs_pkg.h" /* QS package-scope internal interface */
39
40/*==========================================================================*/
41
47void QS_f32_fmt_(uint8_t format, float32_t f) {
48 union F32Rep {
49 float32_t f;
50 uint32_t u;
51 } fu32; /* the internal binary representation */
52 uint8_t chksum = QS_priv_.chksum; /* put in a temporary (register) */
53 uint8_t * const buf = QS_priv_.buf;
54 QSCtr head = QS_priv_.head;
55 QSCtr const end = QS_priv_.end;
56 uint_fast8_t i;
57
58 fu32.f = f; /* assign the binary representation */
59
60 QS_priv_.used += 5U; /* 5 bytes about to be added */
61 QS_INSERT_ESC_BYTE_(format) /* insert the format byte */
62
63 /* insert 4 bytes... */
64 for (i = 4U; i != 0U; --i) {
65 QS_INSERT_ESC_BYTE_((uint8_t)fu32.u)
66 fu32.u >>= 8U;
67 }
68
69 QS_priv_.head = head; /* save the head */
70 QS_priv_.chksum = chksum; /* save the checksum */
71}
72
73/*==========================================================================*/
74
81void QS_f64_fmt_(uint8_t format, float64_t d) {
82 union F64Rep {
83 float64_t d;
84 uint32_t u[2];
85 } fu64; /* the internal binary representation */
86 uint8_t chksum = QS_priv_.chksum;
87 uint8_t * const buf = QS_priv_.buf;
88 QSCtr head = QS_priv_.head;
89 QSCtr const end = QS_priv_.end;
90 uint32_t i;
91
92 /* static constant untion to detect endianness of the machine */
93 static union U32Rep {
94 uint32_t u32;
95 uint8_t u8;
96 } const endian = { 1U };
97
98 fu64.d = d; /* assign the binary representation */
99
100 /* is this a big-endian machine? */
101 if (endian.u8 == 0U) {
102 /* swap fu64.u[0] <-> fu64.u[1]... */
103 i = fu64.u[0];
104 fu64.u[0] = fu64.u[1];
105 fu64.u[1] = i;
106 }
107
108 QS_priv_.used += 9U; /* 9 bytes about to be added */
109 QS_INSERT_ESC_BYTE_(format) /* insert the format byte */
110
111 /* output 4 bytes from fu64.u[0]... */
112 for (i = 4U; i != 0U; --i) {
113 QS_INSERT_ESC_BYTE_((uint8_t)fu64.u[0])
114 fu64.u[0] >>= 8U;
115 }
116
117 /* output 4 bytes from fu64.u[1]... */
118 for (i = 4U; i != 0U; --i) {
119 QS_INSERT_ESC_BYTE_((uint8_t)fu64.u[1])
120 fu64.u[1] >>= 8U;
121 }
122
123 QS_priv_.head = head; /* save the head */
124 QS_priv_.chksum = chksum; /* save the checksum */
125}
float float32_t
Definition: qep.h:68
double float64_t
Definition: qep.h:76
QSPrivAttr QS_priv_
Definition: qs.c:41
uint8_t volatile chksum
Definition: qs.h:920
uint8_t * buf
Definition: qs.h:914
QSCtr volatile used
Definition: qs.h:918
uint_fast16_t QSCtr
Definition: qs.h:892
QSCtr end
Definition: qs.h:915
QSCtr volatile head
Definition: qs.h:916
Internal (package scope) QS/C interface.
#define QS_INSERT_ESC_BYTE_(b_)
Definition: qs_pkg.h:281
void QS_f32_fmt_(uint8_t format, float32_t f)
Definition: qs_fp.c:47
void QS_f64_fmt_(uint8_t format, float64_t d)
Definition: qs_fp.c:81