46 #define READING_BLOCK_SIZE 200
48 #define ERASE_MEMORY_AT_START 0
50 #define SIZE_OF_LOGGED_VALUES 4
52 #define SIZE_OF_VALUES_NAMES 10
58 #define SKIP_X_CALLS_BETWEEN_VALUES 0
61 #define NBR_VALUES_TO_LOG 9
107 #define MEMORY_READ_LATTENCY 5
109 #define TOTAL_MEMORY_SIZE 32
111 #define END_OF_MEMORY_THRESHOLD 10
356 for (i = 0; i < size; i++) {
464 static uint8_t ml_write_values_to_memory_status = 0;
465 static uint32_t previus_mem_addr = 0;
466 static uint8_t *previus_values = NULL;
467 static uint8_t previus_size = 0;
471 if ((ml_write_values_to_memory_status == 0) &&
472 ((previus_mem_addr != mem_addr) || (previus_values != values) || (previus_size != size))) {
474 ml_write_values_to_memory_status = 1;
475 previus_mem_addr = mem_addr;
476 previus_values = values;
480 switch (ml_write_values_to_memory_status) {
488 ml_write_values_to_memory_status = 2;
496 ml_write_values_to_memory_status = 3;
503 ml_write_values_to_memory_status = 3;
505 ml_write_values_to_memory_status = 0;
513 return ml_write_values_to_memory_status;
531 static uint8_t ml_erase_4k_on_memory_status = 0;
533 switch (ml_erase_4k_on_memory_status) {
537 ml_erase_4k_on_memory_status = 1;
542 ml_erase_4k_on_memory_status = 2;
549 ml_erase_4k_on_memory_status = 2;
551 ml_erase_4k_on_memory_status = 0;
559 return ml_erase_4k_on_memory_status;
576 static uint8_t ml_erase_memory_status = 0;
578 switch (ml_erase_memory_status) {
582 ml_erase_memory_status = 1;
587 ml_erase_memory_status = 2;
594 ml_erase_memory_status = 2;
596 ml_erase_memory_status = 0;
603 return ml_erase_memory_status;
646 static uint8_t append_to_memory_status = 0;
647 static uint8_t index_value_unwritten = 0;
649 uint8_t size_data_left_to_write;
652 uint32_t size_used_in_current_page, size_left_current_page, size_to_write;
654 while (!wait_for_SPI) {
656 switch (append_to_memory_status) {
662 append_to_memory_status = 1;
675 append_to_memory_status = 1;
686 size_left_current_page = 0x00000100 - size_used_in_current_page;
688 size_data_left_to_write = size - index_value_unwritten;
689 if (size_left_current_page > size_data_left_to_write) { size_to_write = size_data_left_to_write; }
690 else { size_to_write = size_left_current_page; }
692 if (size_to_write > 250) { size_to_write = 250; }
694 if (size_to_write > 0) {
698 index_value_unwritten += size_to_write;
701 if (index_value_unwritten == size) {
703 append_to_memory_status = 0;
704 index_value_unwritten = 0;
858 for (i = 0; i < size; i++) {
964 static uint8_t start_log_status = 0;
976 switch (start_log_status) {
986 start_log_status = 1;
990 start_log_status = 1;
998 start_log_status = 2;
1003 start_log_status = 3;
1008 start_log_status = 0;
1079 return return_value;
1150 if (uart_received ==
'A') {
1154 }
else if (uart_received ==
'B') {
1220 static uint8_t current_sequence_id = 0;
1224 if (
array[i] == sequence[current_sequence_id]) {
1225 current_sequence_id++;
1226 if (current_sequence_id >= sequence_size) {
1227 current_sequence_id = 0;
1231 current_sequence_id = 0;
Common code for AP and FBW telemetry.
enum SPIClockPolarity cpol
clock polarity control
enum SPIClockPhase cpha
clock phase control
enum SPISlaveSelect select
slave selection behavior
SPICallback after_cb
NULL or function called after the transaction.
enum SPIDataSizeSelect dss
data transfer word size
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
uint16_t input_length
number of data words to read
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
volatile uint8_t * input_buf
pointer to receive buffer for DMA
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
enum SPIBitOrder bitorder
MSB/LSB order.
uint16_t output_length
number of data words to write
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
@ SPICpolIdleHigh
CPOL = 1.
@ SPISelectUnselect
slave is selected before transaction and unselected after
SPI transaction structure.
void memory_write_values(uint32_t mem_addr, uint8_t *values, uint8_t size)
Function sending a request to write a buffer of values to the memory.
static void memory_read_values_cb(struct spi_transaction *trans)
Callback function decrypting the read values from the memory.
char ** name_of_the_values
list of the names of the messages you are logging
uint8_t start_new_log(void)
Function starting a new log.
#define READING_BLOCK_SIZE
size of the block that we read in the memory and send over UART. MAX = 250.
void ml_read_log_in_memory(void)
Function continuing the reading of the current log in memory.
uint8_t run_memory_management(void)
Function sending the buffer to the memory when possible.
static void memory_read_status_cb(struct spi_transaction *trans)
Callback function decrypting the status Byte of the memory.
void high_speed_logger_direct_memory_init(void)
Function initialisating the module.
uint8_t end_log(void)
Function ending the current log.
void memory_erase_4k(uint32_t mem_addr)
Function sending a request to erase 4KB of the memory.
uint32_t current_writting_addr
The address at wich we will write next time.
uint8_t sending_buffer_to_uart
Flag defining if we are sending values through the UART.
void add_array_to_buffer(uint8_t *array, uint8_t size)
Function adding an array to the local buffer.
#define TOTAL_MEMORY_SIZE
nbr of MB in the memory
void memory_read_values(uint32_t mem_addr, uint8_t size)
Function sending a request to read some values in memory.
uint8_t uart_read_buff[READING_BLOCK_SIZE+MEMORY_READ_LATTENCY]
Buffer used to fetch the values from the memory.
struct spi_transaction memory_send_value_transaction
Structure used for sending values to the memory.
uint8_t are_buffers_empty(void)
Function returning true if the two local buffers are empty.
#define SIZE_OF_VALUES_NAMES
size (in characters) of the nameof the logged values.
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
struct spi_transaction memory_transaction
Structure used for general comunication with the memory.
uint32_t nbr_lost_values
Number of Bytes we have lost due to overflows (reseted each time we can write agin in the buffer)
uint8_t start_lost_values_sequence[6]
Start sequence indicating we have lost some Bytes due to overflows.
#define SKIP_X_CALLS_BETWEEN_VALUES
Skip X values between write.
static volatile bool memory_ready
Flag stating if the memory is being used.
void memory_read_status_1(void)
Function sending a request to fetch the status Byte of the memory.
uint8_t nbr_values_in_buffer
Number of Bytes in the first buffer (buffer_values_logged)
void memory_completly_erase(void)
Function sending a request to erase the entire memory.
#define MEMORY_READ_LATTENCY
nbr of Bytes 0x00 received before the real values when reading the memory
uint8_t ml_erase_completely_memory(void)
Function erasing the entire memory.
void add_values_to_buffer(void)
Function adding the configured messages to the buffers of the values to be written in memory.
void memory_read_id(void)
Function sending a request for the ID of the memory chip.
#define NBR_VALUES_TO_LOG
nbr of messages you want to log
uint8_t start_values_sequence[3]
Start sequence written at the begining of the values of a log (after the header)
uint8_t ml_write_values_to_memory(uint32_t mem_addr, uint8_t *values, uint8_t size)
Function writting a buffer of values to the memory.
#define SIZE_OF_LOGGED_VALUES
size (in bytes) of the values we log.
static void memory_transaction_done_cb(struct spi_transaction *trans)
generic allback function for SPI transactions
uint8_t values_send_buffer[256]
Buffer used for sending value to the memory.
uint8_t buff[25]
Buffer used for general comunication over SPI (in buffer)
uint8_t stop_log_sequence[6]
Stop sequence written at the end of the log.
void high_speed_logger_direct_memory_periodic(void)
Main function of the module.
void memory_send_wren(void)
Function sending a request to set the writte enable flag in the memory.
uint8_t buffer_values_sending[256]
Second local buffer for the log.
uint32_t values_to_log[NBR_VALUES_TO_LOG]
list of the messages you want to log
void send_buffer_to_uart(void)
Function sending the read values from the memory to te UART.
uint8_t ml_erase_4k_on_memory(uint32_t mem_addr)
Function erasing 4KB of the memory.
uint8_t start_log_sequence[6]
Start sequence written at the begining of a log.
uint8_t send_buffer_to_memory(uint8_t *buffer, uint8_t *size)
Function sending a buffer ot the memory.
#define ERASE_MEMORY_AT_START
if we completly erase the memory at the start of the log.
uint8_t relaunch_reading_memory
Flag defining if we need to keep reading the memory (if the stop sequence is found we stop)
#define END_OF_MEMORY_THRESHOLD
the nbr of kilo Bytes left at the end of the memory before stoping the log automaticaly
void memory_send_wrdi(void)
Function sending a request to clear the writte enable flag in the memory.
uint8_t is_sequence_in_array(uint8_t *array, uint8_t array_size, uint8_t *sequence, uint8_t sequence_size)
Function testing if a sequence is in a buffer of values.
uint32_t current_unerased_addr
The address of the next block to erase.
uint8_t logging_status_gui
Status of the module.
uint8_t nbr_values_in_buffer_sending
Number of Bytes in the second buffer (nbr_values_in_buffer_sending)
uint8_t wait_answear_from_reading_memory
Flag defining if we are waiting for an answear from the memory when reading values from it.
uint8_t buffer_values_logged[256]
First local buffer for the log.
uint8_t buffer_used
Flag defining wich buffer is used.
uint8_t stop_lost_values_sequence[6]
Stop sequence indicating we have lost some Bytes due to overflows.
uint8_t memory_status_byte
Last status Byte read from the memory.
void run_logger(void)
Funcion called to add the values to log to the buffer with a frequency divider in order to not overfl...
void high_speed_logger_direct_memory_handler(uint8_t val)
Function managing the interface with the user.
void add_byte_to_buffer(uint8_t value)
Function adding a Byte to the local buffer.
uint32_t current_reading_addr
The address at wich we will read next time.
uint8_t append_values_to_memory(uint8_t *values, uint8_t size)
Function adding a buffer of values to the memory.
uint8_t continue_reading_memory
Flag defining if we need to keep reading the memory (if the PC asked for new values)
struct Imu imu
global IMU state
Inertial Measurement Unit interface.
void uart_put_byte(struct uart_periph *periph, long fd, uint8_t data)
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
void uart_periph_set_bits_stop_parity(struct uart_periph *periph, uint8_t bits, uint8_t stop, uint8_t parity)
uint8_t uart_getch(struct uart_periph *p)
Architecture independent SPI (Serial Peripheral Interface) API.
Periodic telemetry system header (includes downlink utility and generated code).
void uart_periph_init(struct uart_periph *p)
int WEAK uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.