blob: 5dd658ac14effd1ab22b5fbf43f8781669ecbf44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/*
* Checksum for the GNSS Receiver External Interface Specification (GREIS).
*
* This file is Copyright (c) 2017-2018 Virgin Orbit
* SPDX-License-Identifier: BSD-2-clause
*/
#include <limits.h>
#include "driver_greis.h"
static inline unsigned char greis_rotate_left(unsigned char val)
{
/* left circular rotation by two bits */
return (val << 2) | (val >> (CHAR_BIT - 2));
}
unsigned char greis_checksum(const unsigned char *src, int count)
{
unsigned char res = 0;
while (count--)
res = greis_rotate_left(res) ^ *src++;
return greis_rotate_left(res);
}
|