Skip to content

Commit 408cd94

Browse files
author
Dilraj Gill
committed
Initial commit
0 parents  commit 408cd94

16 files changed

Lines changed: 1090 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.out

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": []
7+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"makefile.launchConfigurations": [
3+
{
4+
"cwd": "/home/dilgill/school/clubs/SSS/misc/loggers/build",
5+
"binaryPath": "/home/dilgill/school/clubs/SSS/misc/loggers/build/flash.out",
6+
"binaryArgs": []
7+
}
8+
]
9+
}

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "echo",
8+
"type": "shell",
9+
"command": "echo Hello"
10+
}
11+
]
12+
}

TestLoggers.c.bak

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "mockup_flash/flash.h"
2+
3+
int main() {
4+
// Check that all regions are on start of 256 byte boundaries
5+
assert(default_flash_header.events_header.start_addr % 256 == 0);
6+
assert(default_flash_header.exp1_header.start_addr % 256 == 0);
7+
assert(default_flash_header.exp2_header.start_addr % 256 == 0);
8+
assert(default_flash_header.exp3_header.start_addr % 256 == 0);
9+
assert(default_flash_header.exp4_header.start_addr % 256 == 0);
10+
assert(default_flash_header.exp5_header.start_addr % 256 == 0);
11+
12+
init_flash_header();
13+
fetch_flash_header();
14+
15+
// Checking that flash header was properly initialized to default
16+
assert(memcmp(&flash_header, &default_flash_header, sizeof(default_flash_header)) == 0);
17+
18+
uint64_t page_buff[ECC_BLOCK_SIZE/8];
19+
uint32_t block_addr;
20+
21+
// Should return the events in the correct sequence
22+
assert(get_oldest_page(page_buff, &block_addr) == EVENT);
23+
assert(get_oldest_page(page_buff, &block_addr) == EXP1);
24+
assert(get_oldest_page(page_buff, &block_addr) == EXP2);
25+
assert(get_oldest_page(page_buff, &block_addr) == EXP3);
26+
assert(get_oldest_page(page_buff, &block_addr) == EXP4);
27+
assert(get_oldest_page(page_buff, &block_addr) == EXP5);
28+
// Should start over again from
29+
assert(get_oldest_page(page_buff, &block_addr) == EVENT);
30+
31+
// The mock buffer should match the flash header:
32+
assert(memcmp(&flash_header, mock_flash_buff, sizeof(flash_header)) == 0);
33+
34+
// After calling get_oldest_page, the flash header should be different from the default
35+
assert(memcmp(&flash_header, &default_flash_header, sizeof(default_flash_header)) != 0);
36+
37+
// The only change should be the oldest_block_addrs for each set of logs
38+
struct FlashHeader new_header = default_flash_header;
39+
// events header should have rolled back to start
40+
// new_header.events_header.oldest_block_addr;
41+
new_header.exp1_header.oldest_block_addr += ECC_BLOCK_SIZE;
42+
new_header.exp2_header.oldest_block_addr += ECC_BLOCK_SIZE;
43+
new_header.exp3_header.oldest_block_addr += ECC_BLOCK_SIZE;
44+
new_header.exp4_header.oldest_block_addr += ECC_BLOCK_SIZE;
45+
new_header.exp5_header.oldest_block_addr += ECC_BLOCK_SIZE;
46+
47+
// Check that the new header matches the
48+
assert(memcmp(&flash_header, &new_header, sizeof(flash_header)) == 0);
49+
assert(memcmp(&new_header, mock_flash_buff, sizeof(new_header)) == 0);
50+
}

event_logger.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "event_logger.h"
2+
#include "mockup_flash/flash.h"
3+
#include "fits_in_bits.h"
4+
5+
#include <stdio.h>
6+
#include <stdint.h>
7+
#include <assert.h>
8+
#include <string.h>
9+
10+
11+
struct LocalEventLogs local_event_logs = {
12+
.buffer_size = LOCAL_EVENT_LOG_BUFF_SIZE,
13+
.tail = 0,
14+
.buffer = {0}
15+
};
16+
17+
// TODO: log overflows
18+
void handle_event_overflow() {
19+
push_event_logs_to_flash(&local_event_logs);
20+
}
21+
22+
uint8_t add_event_log(
23+
uint64_t event_log
24+
) {
25+
uint64_t current_log_index = local_event_logs.tail;
26+
27+
local_event_logs.buffer[current_log_index] = event_log;
28+
29+
current_log_index++;
30+
31+
if (current_log_index >= local_event_logs.buffer_size) {
32+
printf("overflow\n");
33+
local_event_logs.tail = 0;
34+
handle_event_overflow();
35+
} else {
36+
local_event_logs.tail = current_log_index;
37+
}
38+
39+
return 0;
40+
}
41+
42+
uint8_t build_and_add_event_log(
43+
unsigned int rtc_datetime, // Date+Hr+Min+Sec
44+
unsigned int current_mode,
45+
unsigned int action,
46+
unsigned int details,
47+
unsigned int extra
48+
) {
49+
50+
if ( !fits_in_bits(rtc_datetime, 22)
51+
|| !fits_in_bits(current_mode, 4)
52+
|| !fits_in_bits(action, 3)
53+
|| !fits_in_bits(details, 24)
54+
|| !fits_in_bits(extra, 11)
55+
) {
56+
// Gave too large a value somewhere :(
57+
printf("Improper value\n");
58+
return 1;
59+
}
60+
61+
union EventLog event_log = {.as_struct = {
62+
.rtc_datetime = rtc_datetime,
63+
.current_mode = current_mode,
64+
.action = action,
65+
.details = details,
66+
.extra = extra
67+
}};
68+
69+
add_event_log(event_log.as_uint64);
70+
return 0;
71+
}
72+
73+
/*
74+
int main() {
75+
76+
init_flash_header();
77+
fetch_flash_header();
78+
79+
for (int i = 0; i < 128; ++i) {
80+
build_and_add_event_log(i, 0, 0, 0, i);
81+
}
82+
83+
printf("Local Logs:\n");
84+
union EventLog ev_log;
85+
for(uint32_t i = 0; i < local_event_logs.buffer_size; ++i) {
86+
ev_log = (union EventLog)local_event_logs.buffer[i];
87+
printf("Local ev Log #%u - rtc_time: %u, extra: %u\n", i, ev_log.as_struct.rtc_datetime, ev_log.as_struct.extra );
88+
}
89+
puts("A");
90+
91+
uint64_t block_buff[32];
92+
uint32_t block_addr;
93+
94+
enum LogType log_type = get_oldest_page(block_buff, &block_addr);
95+
assert(log_type == EVENT);
96+
97+
union EventLog ev_logs[sizeof(block_buff)/sizeof(union EventLog)];
98+
99+
static_assert(sizeof(ev_logs) >= sizeof(block_buff), "Hmm");
100+
101+
memcpy(ev_logs, block_buff, sizeof(ev_logs));
102+
}
103+
*/

event_logger.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#ifndef LOGGERS_EVENT_LOGGER_H_
2+
#define LOGGERS_EVENT_LOGGER_H_
3+
4+
// #includes here... FLASH, Scheduler, RTC
5+
#include <stdint.h>
6+
/*
7+
* Each log is a 64 bit word with the following breakdown:
8+
* - RTC Date-Time - 22 bits (Date,Hr,Min,Sec in binary)
9+
* - Current Mode - 4 bits
10+
* - Action-Detail Pair - 27 bits (Action-3, Details - 24)
11+
* - Extra - 11 bits (potential redundancy)
12+
*
13+
* Details on Action-Detail pairs can be found in the Intellisat Loggers document
14+
* There is 1 event buffer, which can hold [INSERT NUMBER HERE] logs.
15+
*/
16+
17+
// enum Actions {
18+
// // actions here
19+
// };
20+
21+
22+
/**
23+
* Indicates whether the events buffer overflowed
24+
*
25+
* @returns Boolean (0 or 1)
26+
*/
27+
int detect_event_overflow();
28+
29+
/**
30+
* Responsible for handling an event overflow
31+
*
32+
* This function handles an overflow by overwriting from the start
33+
* of the buffer. Also logs the overflow
34+
*
35+
* @returns None
36+
*/
37+
void handle_event_overflow();
38+
39+
40+
// NOT PROPERLY DEFINED YET.. They should take in Details as inputs
41+
void log_system_oddity();
42+
void log_intercom();
43+
void log_mode_change();
44+
void log_exp_buffer_overflow();
45+
void log_exp_overflow();
46+
void log_event_overflow();
47+
48+
union EventLog {
49+
struct __attribute__((packed))
50+
{
51+
unsigned int rtc_datetime: 22;
52+
unsigned int current_mode: 4;
53+
unsigned int action: 3;
54+
unsigned int details: 24;
55+
unsigned int extra: 11;
56+
} as_struct;
57+
uint64_t as_uint64;
58+
};
59+
60+
#define LOCAL_EVENT_LOG_COUNT 32
61+
#define LOCAL_EVENT_LOG_BUFF_SIZE (LOCAL_EVENT_LOG_COUNT)
62+
63+
struct LocalEventLogs {
64+
uint32_t buffer_size;
65+
uint32_t tail;
66+
uint64_t buffer[LOCAL_EVENT_LOG_BUFF_SIZE];
67+
};
68+
69+
uint8_t get_local_event_log(uint64_t idx, struct LocalEventLogs * local_event_logs, union EventLog * const retrieved_log);
70+
71+
uint8_t get_latest_event_log(struct LocalEventLogs * local_event_logs, union EventLog * const retrieved_log);
72+
73+
uint8_t add_event_log( uint64_t event_log);
74+
75+
/**
76+
* Pass in event info to log. Stores event log locally.
77+
* Calls
78+
*/
79+
uint8_t build_and_add_event_log(
80+
unsigned int rtc_datetime, // Date+Hr+Min+Sec
81+
unsigned int current_mode,
82+
unsigned int action,
83+
unsigned int details,
84+
unsigned int extra
85+
);
86+
87+
#endif

0 commit comments

Comments
 (0)