UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
buffer_fram.c
Go to the documentation of this file.
1 
9 #include "../firmware.h"
10 
11 /*** Read ***/
12 
13 bool Buffer_FRAM_cache_read(buffer_cache_t *buffer)
14 {
15  FRAM_read(0x00000000, (uint8_t *)buffer, sizeof(buffer_cache_t));
16 
17  if(buffer->crc == Util_crc16((uint8_t *)&buffer, sizeof(buffer_cache_t) - sizeof(uint16_t)))
18  {
19  return true;
20  }
21  return false;
22 }
23 
24 void Buffer_FRAM_read_data(uint16_t slot, uint8_t *data)
25 {
26  FRAM_read((uint32_t)(BUFFER_FRAM_ADDRESS_SLOTS + (slot * BUFFER_SLOT_SIZE)), data, BUFFER_SLOT_SIZE);
27 }
28 
29 /*** Write ***/
30 
31 static inline void Buffer_FRAM_update_crc(buffer_cache_t *buffer)
32 {
33  buffer->crc = Util_crc16((uint8_t *)&buffer, sizeof(buffer_cache_t) - sizeof(uint16_t));
34  FRAM_write(BUFFER_FRAM_ADDRESS_CRC, (uint8_t *)&(buffer->crc), BUFFER_FRAM_SIZE_CRC);
35 }
36 
37 void Buffer_FRAM_write_last_index_stored(buffer_cache_t *buffer)
38 {
39  FRAM_write(BUFFER_FRAM_ADDRESS_LAST_INDEX, (uint8_t *)&(buffer->last_index_stored), sizeof(buffer->last_index_stored));
40  Buffer_FRAM_update_crc(buffer);
41 }
42 
43 void Buffer_FRAM_write_last_slot_transmitted(buffer_cache_t *buffer)
44 {
45  FRAM_write(BUFFER_FRAM_ADDRESS_LAST_SLOT, (uint8_t *)&(buffer->last_slot_transmitted), sizeof(buffer->last_slot_transmitted));
46  Buffer_FRAM_update_crc(buffer);
47 }
48 
49 void Buffer_FRAM_write_occupancy(buffer_cache_t *buffer)
50 {
51  FRAM_write(BUFFER_FRAM_ADDRESS_OCCUPANCY, (uint8_t *)&(buffer->occupancy), sizeof(buffer->occupancy));
52  Buffer_FRAM_update_crc(buffer);
53 }
54 
55 void Buffer_FRAM_write_indexes(buffer_cache_t *buffer)
56 {
57  FRAM_write(BUFFER_FRAM_ADDRESS_INDEXES, (uint8_t *)&(buffer->indexes), sizeof(buffer->indexes));
58  Buffer_FRAM_update_crc(buffer);
59 }
60 
61 void Buffer_FRAM_write_data(uint16_t slot, uint8_t *data)
62 {
63  FRAM_write((uint32_t)(BUFFER_FRAM_ADDRESS_SLOTS + (slot * BUFFER_SLOT_SIZE)), data, BUFFER_SLOT_SIZE);
64 }
65 
void FRAM_read(uint32_t address, uint8_t *data, uint32_t length)
Definition: fram.c:36
void FRAM_write(uint32_t address, uint8_t *data, uint32_t length)
Definition: fram.c:25
uint16_t Util_crc16(const uint8_t *buf, uint32_t size)
Definition: crc.c:100