Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TivaEEPROMBitSet.hxx
Go to the documentation of this file.
1
36#ifndef _FREERTOS_DRIVER_TI_TIVAEEPROMBITSET_HXX_
37#define _FREERTOS_DRIVER_TI_TIVAEEPROMBITSET_HXX_
38
39#include "driverlib/rom.h"
40#include "driverlib/rom_map.h"
41
42#include "driverlib/eeprom.h"
43#include "driverlib/sysctl.h"
44
46
47template <unsigned USER_BIT_COUNT, unsigned BITS_PER_CELL = 27>
49{
50protected:
53 TivaEEPROMHwDefs(uint8_t block_start, uint8_t block_count)
54 : blockStart_(block_start)
55 , blockCount_(block_count)
56 {
57 HASSERT((block_start % block_count) == 0);
58 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
59 do
60 {
61 auto r = MAP_EEPROMInit();
62 if (r == EEPROM_INIT_OK)
63 break;
64 MAP_SysCtlDelay(100000);
65 } while(true);
66 auto num_blocks = MAP_EEPROMBlockCountGet();
67 HASSERT(block_start + block_count < num_blocks);
68 uint32_t total_size = MAP_EEPROMSizeGet();
69 // The hardware for which this driver is written has 16 words per
70 // block.
71 HASSERT(total_size / num_blocks == 64);
72 }
73
75 static constexpr unsigned bits_per_cell()
76 {
77 return BITS_PER_CELL;
78 }
79
80 static constexpr unsigned virtual_cell_count()
81 {
82 return (USER_BIT_COUNT + bits_per_cell()) / bits_per_cell();
83 }
84
85 unsigned physical_cell_count()
86 {
87 return blockCount_ * 16; // Tiva has 16 cells per block (64 bytes)
88 }
89
90 void write_cell(unsigned cell_offset, eeprom_t value)
91 {
92 MAP_EEPROMProgram(&value, get_address(cell_offset), 4);
93 }
94
95 eeprom_t read_cell(unsigned cell_offset)
96 {
97 eeprom_t ret;
98 MAP_EEPROMRead(&ret, get_address(cell_offset), 4);
99 return ret;
100 }
101
102private:
105 uint32_t get_address(unsigned cell_offset)
106 {
107 uint32_t address = blockStart_;
108 address = EEPROMAddrFromBlock(address);
109 address += (cell_offset << 2);
110 return address;
111 }
112
114 uint8_t blockStart_;
116 uint8_t blockCount_;
117};
118
119#endif // _FREERTOS_DRIVER_TI_TIVAEEPROMBITSET_HXX_
Template of how the HW class should look like.
uint32_t get_address(unsigned cell_offset)
static constexpr unsigned bits_per_cell()
uint8_t blockStart_
Number of the first block for our data.
TivaEEPROMHwDefs(uint8_t block_start, uint8_t block_count)
For the Tiva 123 use block_count as multiple of 2, for Tiva 129 use multiple of 8.
uint8_t blockCount_
Number of the blocks of 16 words each to use for our data.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138