46 #define READING_BLOCK_SIZE 200
47 #define ERASE_MEMORY_AT_START 0
49 #define SIZE_OF_LOGGED_VALUES 4
51 #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
108 #define TOTAL_MEMORY_SIZE 32
110 #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;
973 if (i != (NBR_VALUES_TO_LOG - 1)) { strcat(msg_names,
";"); }
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;
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.
static void memory_transaction_done_cb(struct spi_transaction *trans)
generic allback function for SPI transactions
void high_speed_logger_direct_memory_init(void)
Function initialisating the module.
uint8_t start_values_sequence[3]
Start sequence written at the begining of the values of a log (after the header)
enum SPIClockPolarity cpol
clock polarity control
uint8_t logging_status_gui
Status of the module.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t nbr_values_in_buffer
Number of Bytes in the first buffer (buffer_values_logged)
void high_speed_logger_direct_memory_handler(uint8_t val)
Function managing the interface with the user.
void memory_send_wren(void)
Function sending a request to set the writte enable flag in the memory.
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
uint8_t stop_log_sequence[6]
Stop sequence written at the end of the log.
uint16_t output_length
number of data words to write
uint8_t buffer_values_logged[256]
First local buffer for the log.
struct spi_transaction memory_transaction
Structure used for general comunication with the memory.
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t uart_getch(struct uart_periph *p)
uint8_t ml_erase_completely_memory(void)
Function erasing the entire memory.
uint8_t buffer_values_sending[256]
Second local buffer for the log.
#define ERASE_MEMORY_AT_START
if we completly erase the memory at the start of the log.
void send_buffer_to_uart(void)
Function sending the read values from the memory to te UART.
uint32_t nbr_lost_values
Number of Bytes we have lost due to overflows (reseted each time we can write agin in the buffer) ...
static volatile bool memory_ready
Flag stating if the memory is being used.
uint8_t buffer_used
Flag defining wich buffer is used.
#define SIZE_OF_VALUES_NAMES
size (in characters) of the nameof the logged values.
uint8_t continue_reading_memory
Flag defining if we need to keep reading the memory (if the PC asked for new values) ...
static void memory_read_status_cb(struct spi_transaction *trans)
Callback function decrypting the status Byte of the memory.
void memory_send_wrdi(void)
Function sending a request to clear the writte enable flag in the memory.
void memory_erase_4k(uint32_t mem_addr)
Function sending a request to erase 4KB of the memory.
SPI transaction structure.
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
enum SPIBitOrder bitorder
MSB/LSB order.
struct spi_transaction memory_send_value_transaction
Structure used for sending values to the memory.
uint8_t start_log_sequence[6]
Start sequence written at the begining of a log.
struct Imu imu
global IMU state
#define SIZE_OF_LOGGED_VALUES
size (in bytes) of the values we log.
uint8_t start_lost_values_sequence[6]
Start sequence indicating we have lost some Bytes due to overflows.
char ** name_of_the_values
list of the names of the messages you are logging
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
uint32_t current_writting_addr
The address at wich we will write next time.
uint8_t send_buffer_to_memory(uint8_t *buffer, uint8_t *size)
Function sending a buffer ot the memory.
void add_array_to_buffer(uint8_t *array, uint8_t size)
Function adding an array to the local buffer.
uint8_t are_buffers_empty(void)
Function returning true if the two local buffers are empty.
void memory_read_id(void)
Function sending a request for the ID of the memory chip.
enum SPISlaveSelect select
slave selection behavior
#define TOTAL_MEMORY_SIZE
nbr of MB in the memory
void high_speed_logger_direct_memory_periodic(void)
Main function of the module.
uint8_t stop_lost_values_sequence[6]
Stop sequence indicating we have lost some Bytes due to overflows.
uint32_t current_reading_addr
The address at wich we will read next time.
Architecture independent SPI (Serial Peripheral Interface) API.
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
enum SPIClockPhase cpha
clock phase control
int32_t r
in rad/s with INT32_RATE_FRAC
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
#define READING_BLOCK_SIZE
size of the block that we read in the memory and send over UART. MAX = 250.
uint8_t run_memory_management(void)
Function sending the buffer to the memory when possible.
uint8_t nbr_values_in_buffer_sending
Number of Bytes in the second buffer (nbr_values_in_buffer_sending)
#define NBR_VALUES_TO_LOG
nbr of messages you want to log
uint8_t relaunch_reading_memory
Flag defining if we need to keep reading the memory (if the stop sequence is found we stop) ...
uint8_t ml_erase_4k_on_memory(uint32_t mem_addr)
Function erasing 4KB of the memory.
uint8_t sending_buffer_to_uart
Flag defining if we are sending values through the UART.
static void memory_read_values_cb(struct spi_transaction *trans)
Callback function decrypting the read values 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...
SPICallback after_cb
NULL or function called after the transaction.
uint8_t uart_read_buff[READING_BLOCK_SIZE+MEMORY_READ_LATTENCY]
Buffer used to fetch the values from the memory.
void uart_periph_init(struct uart_periph *p)
void ml_read_log_in_memory(void)
Function continuing the reading of the current log in memory.
uint8_t append_values_to_memory(uint8_t *values, uint8_t size)
Function adding a buffer of values to the memory.
uint8_t end_log(void)
Function ending the current log.
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.
Inertial Measurement Unit interface.
uint16_t input_length
number of data words to read
int uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len)
void uart_put_byte(struct uart_periph *p, long fd, uint8_t data)
Uart transmit implementation.
void memory_completly_erase(void)
Function sending a request to erase the entire memory.
uint8_t values_send_buffer[256]
Buffer used for sending value to the memory.
uint8_t memory_status_byte
Last status Byte read from the memory.
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity)
Set parity and stop bits.
uint8_t wait_answear_from_reading_memory
Flag defining if we are waiting for an answear from the memory when reading values from it...
#define END_OF_MEMORY_THRESHOLD
the nbr of kilo Bytes left at the end of the memory before stoping the log automaticaly ...
slave is selected before transaction and unselected after
#define SKIP_X_CALLS_BETWEEN_VALUES
Skip X values between write.
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.
uint32_t values_to_log[NBR_VALUES_TO_LOG]
list of the messages you want to log
void memory_read_values(uint32_t mem_addr, uint8_t size)
Function sending a request to read some values in memory.
Common code for AP and FBW telemetry.
enum SPIDataSizeSelect dss
data transfer word size
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
int32_t p
in rad/s with INT32_RATE_FRAC
volatile uint8_t * input_buf
pointer to receive buffer for DMA
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
void add_byte_to_buffer(uint8_t value)
Function adding a Byte to the local buffer.
uint8_t start_new_log(void)
Function starting a new log.
#define MEMORY_READ_LATTENCY
nbr of Bytes 0x00 received before the real values when reading the memory
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
void add_values_to_buffer(void)
Function adding the configured messages to the buffers of the values to be written in memory...
int32_t q
in rad/s with INT32_RATE_FRAC
uint8_t buff[25]
Buffer used for general comunication over SPI (in buffer)
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
void memory_read_status_1(void)
Function sending a request to fetch the status Byte of the memory.
uint32_t current_unerased_addr
The address of the next block to erase.