/*
Copyright 2017 - 2018 Danny Bokma danny@diebie.nl
Copyright 2019 - 2020 Kevin Dionne kevin.dionne@ennoid.me
This file is part of the DieBieMS/ENNOID-BMS firmware.
The DieBieMS/ENNOID-BMS firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The DieBieMS/ENNOID-BMS firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "driverHWSPI1.h"
#include "stdlib.h"
#include "math.h"
#include "mainDataTypes.h"
#include "modDelay.h"
//#include "driverSWLTC6804.h"
/*
Pre computed crc15 table used for the LTC6804 PEC calculation
The code used to generate the crc15 table is:
void generate_crc15_table()
{
int remainder;
for(int i = 0; i<256;i++)
{
remainder = i<< 7;
for (int bit = 8; bit > 0; --bit)
{
if ((remainder & 0x4000) > 0)//equivalent to remainder & 2^14 simply check for MSB
{
remainder = ((remainder << 1)) ;
remainder = (remainder ^ 0x4599);
}
else
{
remainder = ((remainder << 1));
}
}
crc15Table[i] = remainder&0xFFFF;
}
}
*/
static const unsigned int crc15Table[256] = {
0x0000, 0xc599, 0xceab, 0x0b32, 0xd8cf, 0x1d56, 0x1664, 0xd3fd, 0xf407, 0x319e, 0x3aac, //!