Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add e2p access functions (not used in firmware currently) with workin…
…g unit test
- Loading branch information
Showing
11 changed files
with
192 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<Workspace name="shc"><Project path="shc_basestation\shc_basestation.pnproj"></Project><Project path="shc_tempsensor\shc_tempsensor.pnproj"></Project><Project path="shc_powerswitch\shc_powerswitch.pnproj"></Project><Project path="shc_dimmer\shc_dimmer.pnproj"></Project><Project path="rfm12\rfm12.pnproj"></Project><Project path="src_common\src_common.pnproj"></Project><Project path="makefile_common\makefile_common.pnproj"></Project></Workspace> | ||
<Workspace name="shc"><Project path="shc_basestation\shc_basestation.pnproj"></Project><Project path="shc_tempsensor\shc_tempsensor.pnproj"></Project><Project path="shc_powerswitch\shc_powerswitch.pnproj"></Project><Project path="shc_dimmer\shc_dimmer.pnproj"></Project><Project path="rfm12\rfm12.pnproj"></Project><Project path="src_common\src_common.pnproj"></Project><Project path="makefile_common\makefile_common.pnproj"></Project><Project path="unittest\unittest.pnproj"></Project></Workspace> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<Project name="shc_basestation"><File path="Makefile"></File><File path="shc_basestation.c"></File><File path="rfm12_config.h"></File><File path="request_buffer.c"></File><File path="request_buffer.h"></File><File path="fuses.c"></File><File path="e2p_layout_base_station.h"></File></Project> | ||
<Project name="shc_basestation"><File path="Makefile"></File><File path="shc_basestation.c"></File><File path="rfm12_config.h"></File><File path="request_buffer.c"></File><File path="request_buffer.h"></File><File path="fuses.c"></File><File path="e2p_layout.h"></File></Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<Project name="shc_dimmer"><File path="shc_dimmer.c"></File><File path="Makefile"></File><File path="rfm12_config.h"></File><File path="fuses.c"></File><File path="e2p_layout_dimmer.h"></File></Project> | ||
<Project name="shc_dimmer"><File path="shc_dimmer.c"></File><File path="Makefile"></File><File path="rfm12_config.h"></File><File path="fuses.c"></File><File path="e2p_layout.h"></File></Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<Project name="shc_tempsensor"><File path="Makefile"></File><File path="shc_tempsensor.c"></File><File path="rfm12_config.h"></File><File path="sht11.c"></File><File path="sht11.h"></File><File path="config.h"></File><File path="fuses.c"></File><File path="e2p_layout_temperature_sensor.h"></File></Project> | ||
<Project name="shc_tempsensor"><File path="Makefile"></File><File path="shc_tempsensor.c"></File><File path="rfm12_config.h"></File><File path="sht11.c"></File><File path="sht11.h"></File><File path="config.h"></File><File path="fuses.c"></File><File path="e2p_layout.h"></File></Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "e2p_access.h" | ||
|
||
#ifdef UNITTEST | ||
|
||
const uint8_t e2p[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255, 254, 253, 252, 251, 250, 249, 248 }; | ||
|
||
uint8_t eeprom_read_byte (const uint8_t *__p) | ||
{ | ||
uint32_t p = (uint32_t)__p; | ||
return e2p[p]; | ||
} | ||
|
||
void signal_error_state(void) | ||
{ | ||
//exit(1); | ||
} | ||
|
||
#endif | ||
|
||
// Read UIntValue from EEPROM and limit it to the given boundaries. | ||
// Go into error mode if bit length is not as assumed. | ||
uint32_t __eeprom_read_UIntValue32(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval, uint16_t max_bits_for_type) | ||
{ | ||
if (length_bits > max_bits_for_type) | ||
{ | ||
signal_error_state(); | ||
} | ||
|
||
uint32_t val = eeprom_read_byte((uint8_t*)(byte + 0)) << (24 + bit); | ||
|
||
if (length_bits + bit > 8) | ||
{ | ||
val += eeprom_read_byte((uint8_t*)(byte + 1)) << (16 + bit); | ||
} | ||
|
||
if (length_bits + bit > 16) | ||
{ | ||
val += eeprom_read_byte((uint8_t*)(byte + 2)) << (8 + bit); | ||
} | ||
|
||
if (length_bits + bit > 24) | ||
{ | ||
val += eeprom_read_byte((uint8_t*)(byte + 3)) << (0 + bit); | ||
} | ||
|
||
if (length_bits + bit > 32) | ||
{ | ||
val += eeprom_read_byte((uint8_t*)(byte + 4)) >> (8 - bit); | ||
} | ||
|
||
val = val >> (32 - length_bits); // move wanted bits to the lowest position | ||
|
||
if (length_bits < 32) | ||
{ | ||
val = val & ((1 << length_bits) - 1); // filter out only the wanted bits | ||
} | ||
|
||
if (val < minval) | ||
{ | ||
val = minval; | ||
} | ||
|
||
if (val > maxval) | ||
{ | ||
val = maxval; | ||
} | ||
|
||
return val; | ||
} | ||
|
||
// Wrapper function that casts to needed type and tells the internal function the max bit size of the type. | ||
uint8_t eeprom_read_UIntValue8(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval) | ||
{ | ||
return (uint8_t)__eeprom_read_UIntValue32(byte, bit, length_bits, minval, maxval, 8); | ||
} | ||
|
||
// Wrapper function that casts to needed type and tells the internal function the max bit size of the type. | ||
uint16_t eeprom_read_UIntValue16(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval) | ||
{ | ||
return (uint16_t)__eeprom_read_UIntValue32(byte, bit, length_bits, minval, maxval, 16); | ||
} | ||
|
||
// Wrapper function that casts to needed type and tells the internal function the max bit size of the type. | ||
uint32_t eeprom_read_UIntValue32(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval) | ||
{ | ||
return __eeprom_read_UIntValue32(byte, bit, length_bits, minval, maxval, 32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdint.h> | ||
|
||
#ifdef UNITTEST | ||
|
||
uint8_t eeprom_read_byte (const uint8_t *__p); | ||
void signal_error_state(void); | ||
|
||
#endif | ||
|
||
uint8_t eeprom_read_UIntValue8 (uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval); | ||
uint16_t eeprom_read_UIntValue16(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval); | ||
uint32_t eeprom_read_UIntValue32(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<Project name="src_common"><File path="uart.c"></File><File path="uart.h"></File><File path="util.c"></File><File path="util.h"></File><File path="aes256.c"></File><File path="aes256.h"></File></Project> | ||
<Project name="src_common"><File path="uart.c"></File><File path="uart.h"></File><File path="util.c"></File><File path="util.h"></File><File path="aes256.c"></File><File path="aes256.h"></File><File path="e2p_access.c"></File><File path="e2p_access.h"></File></Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,90 @@ | ||
/* | ||
* This file is part of smarthomatic, http://www.smarthomatic.org. | ||
* Copyright (c) 2013 Uwe Freese | ||
* | ||
* smarthomatic 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. | ||
* | ||
* smarthomatic 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 smarthomatic. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "../src_common/e2p_access.h" | ||
|
||
uint8_t res = 0; | ||
|
||
void compare(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval, uint32_t assumed_value, uint32_t val) | ||
{ | ||
printf("Test eeprom_read_UIntValueXX(%d, %d, %d, %u, %u)\n", byte, bit, length_bits, minval, maxval); | ||
printf(" Assumed value: %d, returned value: %u", assumed_value, val); | ||
|
||
if (val != assumed_value) | ||
{ | ||
res = 1; | ||
printf(" --> NOK\n"); | ||
} | ||
else | ||
{ | ||
printf(" --> OK\n"); | ||
} | ||
} | ||
|
||
// Test one of the e2p read functions. | ||
void test_eeprom_read_UIntValue8(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval, uint32_t assumed_value) | ||
{ | ||
uint32_t x = eeprom_read_UIntValue8(byte, bit, length_bits, minval, maxval); | ||
compare(byte, bit, length_bits, minval, maxval, assumed_value, x); | ||
} | ||
|
||
void test_eeprom_read_UIntValue16(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval, uint32_t assumed_value) | ||
{ | ||
uint32_t x = eeprom_read_UIntValue16(byte, bit, length_bits, minval, maxval); | ||
compare(byte, bit, length_bits, minval, maxval, assumed_value, x); | ||
} | ||
|
||
void test_eeprom_read_UIntValue32(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval, uint32_t assumed_value) | ||
{ | ||
uint32_t x = eeprom_read_UIntValue32(byte, bit, length_bits, minval, maxval); | ||
compare(byte, bit, length_bits, minval, maxval, assumed_value, x); | ||
} | ||
|
||
int main(int argc , char** argv){ | ||
printf("Hello World\n"); | ||
return EXIT_SUCCESS; | ||
printf("smarthomatic unit test\n"); | ||
|
||
// 8 Bit tests | ||
test_eeprom_read_UIntValue8(5, 0, 8, 0, 255, 5); // normal read | ||
test_eeprom_read_UIntValue8(5, 0, 8, 7, 255, 7); // min test | ||
test_eeprom_read_UIntValue8(5, 0, 8, 0, 3, 3); // max test | ||
test_eeprom_read_UIntValue8(5, 1, 7, 0, 255, 5); // offset test within a byte | ||
test_eeprom_read_UIntValue8(5, 2, 8, 0, 255, 5 << 2); // offset test over byte boundary | ||
test_eeprom_read_UIntValue8(5, 7, 1, 0, 255, 1); // bit masking test | ||
|
||
// 16 Bit tests | ||
test_eeprom_read_UIntValue16(5, 0, 16, 0, 65535, 1286); // normal read | ||
test_eeprom_read_UIntValue16(5, 0, 16, 1400, 65535, 1400); // min test | ||
test_eeprom_read_UIntValue16(5, 0, 16, 0, 3, 3); // max test | ||
test_eeprom_read_UIntValue16(5, 1, 15, 0, 65535, 1286); // offset test within a byte | ||
test_eeprom_read_UIntValue16(5, 2, 16, 0, 65535, 1286 << 2); // offset test over byte boundary | ||
test_eeprom_read_UIntValue16(5, 7, 1, 0, 65535, 1); // bit masking test | ||
|
||
// 32 Bit tests | ||
test_eeprom_read_UIntValue32(5, 0, 32, 0, 4294967295U, 84281096U); // normal read | ||
test_eeprom_read_UIntValue32(5, 0, 32, 90000000U, 4294967295U, 90000000U); // min test | ||
test_eeprom_read_UIntValue32(5, 0, 32, 0, 3, 3); // max test | ||
test_eeprom_read_UIntValue32(5, 1, 31, 0, 4294967295U, 84281096U); // offset test within a byte | ||
test_eeprom_read_UIntValue32(5, 2, 32, 0, 4294967295U, 84281096U << 2); // offset test over byte boundary | ||
test_eeprom_read_UIntValue32(5, 7, 1, 0, 4294967295U, 1); // bit masking test | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<Project name="unittest"><File path="main.c"></File><File path="Makefile"></File></Project> |