aboutsummaryrefslogtreecommitdiffstats
path: root/fw/types.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-10-24 16:55:59 -0400
committerSam Anthony <sam@samanthony.xyz>2025-10-24 16:55:59 -0400
commit01bd9cbc6fe64f236a1b467f011e56dcae0306e7 (patch)
treedc74cfa742d77befcbe58715e3ae7a2727c89781 /fw/types.c
parenta0c6bbb21c5e7d9e0090e66c316cf88ef7f0726b (diff)
downloadcan-gauge-interface-01bd9cbc6fe64f236a1b467f011e56dcae0306e7.zip
table module
Diffstat (limited to 'fw/types.c')
-rw-r--r--fw/types.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/fw/types.c b/fw/types.c
index d87c891..1064379 100644
--- a/fw/types.c
+++ b/fw/types.c
@@ -4,16 +4,50 @@
#include "types.h"
-void
-addU16(U16 *a, U8 b) {
- a->lo += b;
+U16
+addU16(U16 a, U16 b) {
+ a.hi += b.hi;
+ a.lo += b.lo;
if (STATUSbits.C) {
- a->hi++;
+ a.hi++;
}
+ return a;
}
-void
-lshiftU16(U16 *a, U8 b) {
- a->hi = (U8)(a->hi << b) | (a->lo >> (8u-b));
- a->lo <<= b;
+U16
+addU16U8(U16 a, U8 b) {
+ a.lo += b;
+ if (STATUSbits.C) {
+ a.hi++;
+ }
+ return a;
+}
+
+U16
+lshiftU16(U16 a, U8 b) {
+ a.hi = (U8)(a.hi << b) | (a.lo >> (8u-b));
+ a.lo <<= b;
+ return a;
+}
+
+U16
+rshiftU16(U16 a, U8 b) {
+ a.lo = (U8)((a.hi >> (8u-b)) << (8u-b)) | (U8)(a.lo >> b);
+ a.hi >>= b;
+ return a;
+}
+
+I8
+cmpU16(U16 a, U16 b) {
+ if (a.hi > b.hi) {
+ return 1;
+ } else if (a.hi < b.hi) {
+ return -1;
+ } else if (a.lo > b.lo) {
+ return 1;
+ } else if (a.lo < b.lo) {
+ return -1;
+ } else {
+ return 0;
+ }
}