Skip to content
Snippets Groups Projects
Commit 2bbd72d1 authored by Christos Gentsos's avatar Christos Gentsos
Browse files

Mitig: TMR more variables and some function calls

parent cc9d8c11
No related branches found
No related tags found
No related merge requests found
#include <atmel_start.h>
#include <COAST.h>
#include "checksums.h"
int sysv_checksum(uint8_t *start_addr, uint8_t *end_addr)
int __xMR_FN_CALL sysv_checksum(uint8_t *start_addr, uint8_t *end_addr)
{
uint32_t result = 0;
uint16_t result16 = 0;
......@@ -13,7 +14,7 @@ int sysv_checksum(uint8_t *start_addr, uint8_t *end_addr)
return (result16 & 0xffff) + (result16 >> 16);
}
uint8_t crc8_byte(uint8_t n)
uint8_t __xMR_FN_CALL crc8_byte(uint8_t n)
{
uint8_t poly = 0x07; /* x^8 + x^2 + x + 1 */
uint8_t crc = n;
......@@ -25,11 +26,23 @@ uint8_t crc8_byte(uint8_t n)
return crc;
}
uint8_t crc8_bytearray(uint8_t *na, uint8_t len)
static uint8_t crc8_byte_notmr(uint8_t n)
{
uint8_t poly = 0x07; /* x^8 + x^2 + x + 1 */
uint8_t crc = n;
for (uint8_t i = 0; i < 8; ++i)
if (crc & 0x80)
crc = ((crc << 1) ^ poly);
else
crc = (crc << 1);
return crc;
}
uint8_t __xMR_FN_CALL crc8_bytearray(uint8_t *na, uint8_t len)
{
uint8_t result = 0;
for (uint8_t i = 0; i < len; ++i) {
result = crc8_byte(result ^ na[i]);
result = crc8_byte_notmr(result ^ na[i]);
}
return result;
}
#include <atmel_start.h>
#include <math.h>
#include <COAST.h>
uint16_t float_to_linear(float val)
uint16_t __xMR_FN_CALL float_to_linear(float val)
{
// only works with positive numbers for now
int32_t exp = ceilf(log2f(val) - log2f(1023));
......@@ -20,7 +21,7 @@ uint16_t float_to_linear(float val)
}
float linear_to_float(uint16_t val)
float __xMR_FN_CALL linear_to_float(uint16_t val)
{
int16_t exp = ((val & 0x8000)?0xffe0:0) | ((val >> 11) & 0x1f);
int16_t man = ((val & 0x0400)?0xf800:0) | (val & 0x7ff);
......
......@@ -15,7 +15,7 @@
#define send_nack(descr) hri_sercomi2cs_set_CTRLB_ACKACT_bit(descr->device.hw)
#define set_cmd(descr, cmd) hri_sercomi2cs_write_CTRLB_CMD_bf(descr->device.hw, cmd);
static struct io_descriptor *io;
static struct io_descriptor *io __xMR;
static uint16_t rx_state __xMR = CMD;
static uint8_t std_cmd_addr;
......
#include <atmel_start.h>
#include <stdlib.h>
#include <COAST.h>
#include <i2c_slave.h>
#include <flash_utils.h>
#include <usb_debug.h>
......@@ -13,7 +14,7 @@ const char MFR_DAT[] = "190801";
const char MFR_SER[] = "123456789";
void page_chk();
uint8_t page;
uint16_t page __xMR;
void accvolt();
void acccurr();
......@@ -128,7 +129,7 @@ void boot_new_fw()
}
void page_chk()
void __xMR page_chk()
{
if (page > 2)
page = 2;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment