diff --git a/firmware/app/structs/ttc_data.c b/firmware/app/structs/ttc_data.c index 6003f30b..add09c9a 100644 --- a/firmware/app/structs/ttc_data.c +++ b/firmware/app/structs/ttc_data.c @@ -26,9 +26,9 @@ * \author Gabriel Mariano Marcelino * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2021/04/14 + * \date 2024/04/22 * * \addtogroup ttc_data * \{ @@ -42,11 +42,11 @@ ttc_data_t ttc_data_buf; void downlink_add_packet(uint8_t *packet, uint16_t packet_size) { - uint16_t i = 0; + uint16_t i = 0U; ttc_data_buf.down_buf.packet_sizes[ttc_data_buf.down_buf.position_to_write] = packet_size; - for(i = 0; i = 5) + if (++ttc_data_buf.down_buf.position_to_write >= 5U) { - ttc_data_buf.down_buf.position_to_write = 0; + ttc_data_buf.down_buf.position_to_write = 0U; } } void downlink_pop_packet(uint8_t *packet, uint16_t *packet_size) { - uint16_t i = 0; + uint16_t i = 0U; - *packet_size = ttc_data_buf.down_buf.packet_sizes[ttc_data_buf.down_buf.position_to_read]; - - for(i = 0; i < ttc_data_buf.down_buf.packet_sizes[ttc_data_buf.down_buf.position_to_read]; i++) + if (ttc_data_buf.radio.tx_fifo_counter > 0U) { - packet[i] = ttc_data_buf.down_buf.packet_array[ttc_data_buf.down_buf.position_to_read][i]; - } + *packet_size = ttc_data_buf.down_buf.packet_sizes[ttc_data_buf.down_buf.position_to_read]; - ttc_data_buf.radio.tx_fifo_counter--; + for(i = 0U; i < ttc_data_buf.down_buf.packet_sizes[ttc_data_buf.down_buf.position_to_read]; i++) + { + packet[i] = ttc_data_buf.down_buf.packet_array[ttc_data_buf.down_buf.position_to_read][i]; + } - if (++ttc_data_buf.down_buf.position_to_read >= 5) - { - ttc_data_buf.down_buf.position_to_read = 0; + ttc_data_buf.radio.tx_fifo_counter--; + + if (++ttc_data_buf.down_buf.position_to_read >= 5U) + { + ttc_data_buf.down_buf.position_to_read = 0U; + } } } void uplink_add_packet(uint8_t *packet, uint16_t packet_size) { - uint16_t i = 0; + uint16_t i = 0U; ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_write] = packet_size; @@ -103,26 +106,25 @@ void uplink_pop_packet(uint8_t *packet, uint16_t *packet_size) { uint16_t i = 0; - *packet_size = ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read]; - - for(i = 0; i < ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read]; i++) + if (ttc_data_buf.radio.rx_fifo_counter > 0U) { - packet[i] = ttc_data_buf.up_buf.packet_array[ttc_data_buf.up_buf.position_to_read][i]; - ttc_data_buf.up_buf.packet_array[ttc_data_buf.up_buf.position_to_read][i] = 0xFF; /* Remove packet after a read */ - } - - ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read] = 0xFF; /* 0xFF means that there is no package in this position */ + *packet_size = ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read]; - ttc_data_buf.radio.rx_fifo_counter--; + for(i = 0; i < ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read]; i++) + { + packet[i] = ttc_data_buf.up_buf.packet_array[ttc_data_buf.up_buf.position_to_read][i]; + ttc_data_buf.up_buf.packet_array[ttc_data_buf.up_buf.position_to_read][i] = 0xFF; /* Remove packet after a read */ + } - if (++ttc_data_buf.up_buf.position_to_read >= 5) - { - ttc_data_buf.up_buf.position_to_read = 0; - } + ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read] = 0x00; /* 0x00 means that there is no package in this position */ - /* Update rx packet bytes */ - ttc_data_buf.radio.last_rx_packet_bytes = &(ttc_data_buf.up_buf.packet_sizes[ttc_data_buf.up_buf.position_to_read]); + ttc_data_buf.radio.rx_fifo_counter--; + if (++ttc_data_buf.up_buf.position_to_read >= 5) + { + ttc_data_buf.up_buf.position_to_read = 0; + } + } } /** \} End of ttc_data group */ diff --git a/firmware/app/tasks/eps_server.c b/firmware/app/tasks/eps_server.c index 7aa4a716..27712d84 100644 --- a/firmware/app/tasks/eps_server.c +++ b/firmware/app/tasks/eps_server.c @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.3 + * \version 0.5.1 * - * \date 2023/03/03 + * \date 2024/04/22 * * \addtogroup eps_server * \{ @@ -74,15 +74,7 @@ void vTaskEpsServer(void) sys_log_new_line(); sys_log_print_str("Packet: "); - - uint16_t i = 0; - - for(i = 0; i < eps_request.data.data_packet.len; i++) - { - sys_log_print_hex(eps_request.data.data_packet.packet[i]); - sys_log_print_str("|"); - } - + sys_log_dump_hex(eps_request.data.data_packet.packet, eps_request.data.data_packet.len); sys_log_new_line(); downlink_add_packet(eps_request.data.data_packet.packet, eps_request.data.data_packet.len); diff --git a/firmware/app/tasks/eps_server.h b/firmware/app/tasks/eps_server.h index a9fbf253..43c45e0b 100644 --- a/firmware/app/tasks/eps_server.h +++ b/firmware/app/tasks/eps_server.h @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.3.5 + * \version 0.5.1 * - * \date 2023/03/03 + * \date 2024/04/22 * * \defgroup eps EPS * \ingroup tasks @@ -41,9 +41,9 @@ #include #define TASK_EPS_SERVER_NAME "EPS Server" /**< Task name. */ -#define TASK_EPS_SERVER_STACK_SIZE 2000 /**< Stack size in bytes. */ -#define TASK_EPS_SERVER_PRIORITY 4 /**< Task priority. */ -#define TASK_EPS_SERVER_PERIOD_MS 250 /**< Task period in milliseconds. */ +#define TASK_EPS_SERVER_STACK_SIZE 1000 /**< Stack size in bytes. */ +#define TASK_EPS_SERVER_PRIORITY 3 /**< Task priority. */ +#define TASK_EPS_SERVER_PERIOD_MS 750 /**< Task period in milliseconds. */ #define TASK_EPS_SERVER_INITIAL_DELAY_MS 1000 /**< Delay, in milliseconds, before the first execution. */ #define TASK_EPS_SERVER_INIT_TIMEOUT_MS 10000 /**< Wait time to initialize the task in milliseconds. */ diff --git a/firmware/app/tasks/obdh_server.c b/firmware/app/tasks/obdh_server.c index 703b661e..92490b7b 100644 --- a/firmware/app/tasks/obdh_server.c +++ b/firmware/app/tasks/obdh_server.c @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2023/03/03 + * \date 2024/04/22 * * \addtogroup obdh_server * \{ @@ -62,13 +62,6 @@ void vTaskObdhServer(void) obdh_response_t obdh_response = {0}; obdh_request.command = 0x00U; /* No command */ - uint8_t buffer1[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t buffer2[7] = {0x22, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; - uint8_t buffer3[10] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}; - - uplink_add_packet(buffer2, 6); - uplink_add_packet(buffer3, 10); - while(1) { TickType_t last_cycle = xTaskGetTickCount(); @@ -91,19 +84,19 @@ void vTaskObdhServer(void) break; case CMDPR_CMD_WRITE_PARAM: - obdh_write_read_bytes(6); + obdh_write_read_bytes(7); sys_log_print_event_from_module(SYS_LOG_INFO, TASK_OBDH_SERVER_NAME, "TX is now "); switch(obdh_request.data.param_8) { case 0x00: - sys_log_print_msg("Turned on."); + sys_log_print_msg("Turned off."); ttc_data_buf.radio.tx_enable = obdh_request.data.param_8; break; case 0x01: - sys_log_print_msg("Turned off."); + sys_log_print_msg("Turned on."); ttc_data_buf.radio.tx_enable = obdh_request.data.param_8; break; @@ -117,9 +110,9 @@ void vTaskObdhServer(void) break; case CMDPR_CMD_TRANSMIT_PACKET: - obdh_write_read_bytes(6); + obdh_write_read_bytes(7); - downlink_add_packet(obdh_request.data.data_packet.packet, (obdh_request.data.data_packet.len)+3); + downlink_add_packet(obdh_request.data.data_packet.packet, obdh_request.data.data_packet.len); break; case CMDPR_CMD_READ_FIRST_PACKET: @@ -129,10 +122,13 @@ void vTaskObdhServer(void) obdh_send_response(&obdh_response); + obdh_write_read_bytes(7U); + break; case 0x00: /* Read mode */ - obdh_write_read_bytes(6); + obdh_write_read_bytes(7U); + break; default: break; diff --git a/firmware/app/tasks/obdh_server.h b/firmware/app/tasks/obdh_server.h index 8659e6ea..e8808d6c 100644 --- a/firmware/app/tasks/obdh_server.h +++ b/firmware/app/tasks/obdh_server.h @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2023/03/03 + * \date 2024/04/22 * * \defgroup obdh OBDH * \ingroup tasks @@ -41,7 +41,7 @@ #include #define TASK_OBDH_SERVER_NAME "OBDH Server" /**< Task name. */ -#define TASK_OBDH_SERVER_STACK_SIZE 4000 /**< Stack size in bytes. */ +#define TASK_OBDH_SERVER_STACK_SIZE 2000 /**< Stack size in bytes. */ #define TASK_OBDH_SERVER_PRIORITY 5 /**< Task priority. */ #define TASK_OBDH_SERVER_PERIOD_MS 100 /**< Task period in milliseconds. */ #define TASK_OBDH_SERVER_INITIAL_DELAY_MS 200 /**< Delay, in milliseconds, before the first execution. */ diff --git a/firmware/app/tasks/system_reset.c b/firmware/app/tasks/system_reset.c index c1e1c283..1c6ef984 100644 --- a/firmware/app/tasks/system_reset.c +++ b/firmware/app/tasks/system_reset.c @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.1.10 + * \version 0.5.1 * - * \date 2020/01/12 + * \date 2024/04/22 * * \addtogroup system_reset * \{ @@ -38,13 +38,15 @@ #include "system_reset.h" +#define pdMS_TO_TICKS_LONG( xTimeInMs ) ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInMs ) * ( uint64_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) ) + xTaskHandle xTaskSystemResetHandle; void vTaskSystemReset(void) { while(1) { - vTaskDelay(pdMS_TO_TICKS(TASK_SYSTEM_RESET_PERIOD_MS)); + vTaskDelay(pdMS_TO_TICKS_LONG(TASK_SYSTEM_RESET_PERIOD_MS)); sys_log_print_event_from_module(SYS_LOG_INFO, TASK_SYSTEM_RESET_NAME, "Restarting the system..."); sys_log_new_line(); diff --git a/firmware/app/tasks/uplink_manager.c b/firmware/app/tasks/uplink_manager.c index b0f0161f..31e9c87c 100644 --- a/firmware/app/tasks/uplink_manager.c +++ b/firmware/app/tasks/uplink_manager.c @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2023/04/03 + * \date 2024/04/22 * * \addtogroup uplink_manager * \{ @@ -36,7 +36,7 @@ #include #include #include - +#include #include "uplink_manager.h" #include "startup.h" @@ -53,22 +53,30 @@ void vTaskUplinkManager(void) sys_log_print_event_from_module(SYS_LOG_INFO, TASK_UPLINK_MANAGER_NAME, "Initializing the Uplink Manager..."); sys_log_new_line(); - ttc_data_buf.radio.rx_fifo_counter = 0; - ttc_data_buf.radio.rx_packet_counter = 0; - ttc_data_buf.radio.last_rx_packet_bytes = &(ttc_data_buf.up_buf.packet_sizes); + ttc_data_buf.radio.rx_fifo_counter = 0U; + ttc_data_buf.radio.rx_packet_counter = 0U; + ttc_data_buf.radio.last_rx_packet_bytes = 0U; - ttc_data_buf.up_buf.position_to_read = 0; - ttc_data_buf.up_buf.position_to_write = 0; + ttc_data_buf.up_buf.position_to_read = 0U; + ttc_data_buf.up_buf.position_to_write = 0U; - uint16_t rx_size = 230; - uint8_t rx_packet[230]; - uint8_t pop_rx_packet[230]; + uint8_t rx_packet[230] = {0}; while(1) { TickType_t last_cycle = xTaskGetTickCount(); - /* TODO */ + if (radio_available() == 0U) + { + radio_recv(rx_packet, 80U, 100U); + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_UPLINK_MANAGER_NAME, "Received a new package:"); + sys_log_dump_hex(rx_packet, 230U); + sys_log_new_line(); + + /*TODO ngham_decode(rx_packet);*/ + + uplink_add_packet(rx_packet, 220U); + } vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_UPLINK_MANAGER_PERIOD_MS)); } diff --git a/firmware/config/config.h b/firmware/config/config.h index 394c9540..5b387ef3 100644 --- a/firmware/config/config.h +++ b/firmware/config/config.h @@ -24,10 +24,11 @@ * \brief Configuration parameters definition. * * \author Gabriel Mariano Marcelino + * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2019/10/26 + * \date 2024/04/22 * * \defgroup config Configuration * \{ @@ -36,6 +37,9 @@ #ifndef CONFIG_H_ #define CONFIG_H_ +/* Targets the radio module, it can be '0' or '1'*/ +#define RADIO_MODULE 1 + /* Tasks */ #define CONFIG_TASK_STARTUP_ENABLED 1 #define CONFIG_TASK_WATCHDOG_RESET_ENABLED 1 diff --git a/firmware/config/radio_config_Si4463.h b/firmware/config/uhf_radio_config_Si4463.h similarity index 100% rename from firmware/config/radio_config_Si4463.h rename to firmware/config/uhf_radio_config_Si4463.h diff --git a/firmware/config/vhf_radio_config_Si4463.h b/firmware/config/vhf_radio_config_Si4463.h new file mode 100644 index 00000000..5021815d --- /dev/null +++ b/firmware/config/vhf_radio_config_Si4463.h @@ -0,0 +1,632 @@ +/*! @file radio_config.h + * @brief This file contains the automatically generated + * configurations. + * + * @n WDS GUI Version: 3.2.11.0 + * @n Device: Si4463 Rev.: B1 + * + * @b COPYRIGHT + * @n Silicon Laboratories Confidential + * @n Copyright 2017 Silicon Laboratories, Inc. + * @n http://www.silabs.com + */ + +#ifndef RADIO_CONFIG_H_ +#define RADIO_CONFIG_H_ + +// USER DEFINED PARAMETERS +// Define your own parameters here + +// INPUT DATA +/* +// Crys_freq(Hz): 30000000 Crys_tol(ppm): 10 IF_mode: 2 High_perf_Ch_Fil: 1 OSRtune: 0 Ch_Fil_Bw_AFC: 0 ANT_DIV: 0 PM_pattern: 0 +// MOD_type: 3 Rsymb(sps): 4800 Fdev(Hz): 1200 RXBW(Hz): 150000 Manchester: 0 AFC_en: 0 Rsymb_error: 0.0 Chip-Version: 2 +// RF Freq.(MHz): 145.9 API_TC: 29 fhst: 0 inputBW: 0 BERT: 0 RAW_dout: 0 D_source: 0 Hi_pfm_div: 1 +// +// # RX IF frequency is -468750 Hz +// # WB filter 1 (BW = 9.54 kHz); NB-filter 1 (BW = 9.54 kHz) +// +// Modulation index: 0.5 +*/ + + +// CONFIGURATION PARAMETERS +#define RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ 30000000L +#define RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER 0x00 +#define RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH 0x07 +#define RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP 0x03 +#define RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET 0xF000 + + +// CONFIGURATION COMMANDS + +/* +// Command: RF_POWER_UP +// Description: Command to power-up the device and select the operational mode and functionality. +*/ +#define RF_POWER_UP 0x02, 0x01, 0x00, 0x01, 0xC9, 0xC3, 0x80 + +/* +// Command: RF_GPIO_PIN_CFG +// Description: Configures the GPIO pins. +*/ +#define RF_GPIO_PIN_CFG 0x13, 0x00, 0x63, 0x61, 0x60, 0x67, 0x4B, 0x00 + +/* +// Set properties: RF_GLOBAL_XO_TUNE_2 +// Number of properties: 2 +// Group ID: 0x00 +// Start ID: 0x00 +// Default values: 0x40, 0x00, +// Descriptions: +// GLOBAL_XO_TUNE - Configure the internal capacitor frequency tuning bank for the crystal oscillator. +// GLOBAL_CLK_CFG - Clock configuration options. +*/ +#define RF_GLOBAL_XO_TUNE_2 0x11, 0x00, 0x02, 0x00, 0x52, 0x00 + +/* +// Set properties: RF_GLOBAL_CONFIG_1 +// Number of properties: 1 +// Group ID: 0x00 +// Start ID: 0x03 +// Default values: 0x20, +// Descriptions: +// GLOBAL_CONFIG - Global configuration settings. +*/ +#define RF_GLOBAL_CONFIG_1 0x11, 0x00, 0x01, 0x03, 0x60 + +/* +// Set properties: RF_INT_CTL_ENABLE_1 +// Number of properties: 1 +// Group ID: 0x01 +// Start ID: 0x00 +// Default values: 0x04, +// Descriptions: +// INT_CTL_ENABLE - This property provides for global enabling of the three interrupt groups (Chip, Modem and Packet Handler) in order to generate HW interrupts at the NIRQ pin. +*/ +#define RF_INT_CTL_ENABLE_1 0x11, 0x01, 0x01, 0x00, 0x00 + +/* +// Set properties: RF_FRR_CTL_A_MODE_4 +// Number of properties: 4 +// Group ID: 0x02 +// Start ID: 0x00 +// Default values: 0x01, 0x02, 0x09, 0x00, +// Descriptions: +// FRR_CTL_A_MODE - Fast Response Register A Configuration. +// FRR_CTL_B_MODE - Fast Response Register B Configuration. +// FRR_CTL_C_MODE - Fast Response Register C Configuration. +// FRR_CTL_D_MODE - Fast Response Register D Configuration. +*/ +#define RF_FRR_CTL_A_MODE_4 0x11, 0x02, 0x04, 0x00, 0x01, 0x02, 0x03, 0x07 + +/* +// Set properties: RF_PREAMBLE_TX_LENGTH_9 +// Number of properties: 9 +// Group ID: 0x10 +// Start ID: 0x00 +// Default values: 0x08, 0x14, 0x00, 0x0F, 0x21, 0x00, 0x00, 0x00, 0x00, +// Descriptions: +// PREAMBLE_TX_LENGTH - Configure length of TX Preamble. +// PREAMBLE_CONFIG_STD_1 - Configuration of reception of a packet with a Standard Preamble pattern. +// PREAMBLE_CONFIG_NSTD - Configuration of transmission/reception of a packet with a Non-Standard Preamble pattern. +// PREAMBLE_CONFIG_STD_2 - Configuration of timeout periods during reception of a packet with Standard Preamble pattern. +// PREAMBLE_CONFIG - General configuration bits for the Preamble field. +// PREAMBLE_PATTERN_31_24 - Configuration of the bit values describing a Non-Standard Preamble pattern. +// PREAMBLE_PATTERN_23_16 - Configuration of the bit values describing a Non-Standard Preamble pattern. +// PREAMBLE_PATTERN_15_8 - Configuration of the bit values describing a Non-Standard Preamble pattern. +// PREAMBLE_PATTERN_7_0 - Configuration of the bit values describing a Non-Standard Preamble pattern. +*/ +#define RF_PREAMBLE_TX_LENGTH_9 0x11, 0x10, 0x09, 0x00, 0x04, 0x14, 0x00, 0x0F, 0x31, 0x00, 0x00, 0x00, 0x00 + +/* +// Set properties: RF_SYNC_CONFIG_5 +// Number of properties: 5 +// Group ID: 0x11 +// Start ID: 0x00 +// Default values: 0x01, 0x2D, 0xD4, 0x2D, 0xD4, +// Descriptions: +// SYNC_CONFIG - Sync Word configuration bits. +// SYNC_BITS_31_24 - Sync word. +// SYNC_BITS_23_16 - Sync word. +// SYNC_BITS_15_8 - Sync word. +// SYNC_BITS_7_0 - Sync word. +*/ +#define RF_SYNC_CONFIG_5 0x11, 0x11, 0x05, 0x00, 0x03, 0xBA, 0x67, 0x54, 0x7E + +/* +// Set properties: RF_PKT_CRC_CONFIG_7 +// Number of properties: 7 +// Group ID: 0x12 +// Start ID: 0x00 +// Default values: 0x00, 0x01, 0x08, 0xFF, 0xFF, 0x00, 0x00, +// Descriptions: +// PKT_CRC_CONFIG - Select a CRC polynomial and seed. +// PKT_WHT_POLY_15_8 - 16-bit polynomial value for the PN Generator (e.g., for Data Whitening) +// PKT_WHT_POLY_7_0 - 16-bit polynomial value for the PN Generator (e.g., for Data Whitening) +// PKT_WHT_SEED_15_8 - 16-bit seed value for the PN Generator (e.g., for Data Whitening) +// PKT_WHT_SEED_7_0 - 16-bit seed value for the PN Generator (e.g., for Data Whitening) +// PKT_WHT_BIT_NUM - Selects which bit of the LFSR (used to generate the PN / data whitening sequence) is used as the output bit for data scrambling. +// PKT_CONFIG1 - General configuration bits for transmission or reception of a packet. +*/ +#define RF_PKT_CRC_CONFIG_7 0x11, 0x12, 0x07, 0x00, 0x80, 0x01, 0x08, 0xFF, 0xFF, 0x00, 0x02 + +/* +// Set properties: RF_PKT_LEN_12 +// Number of properties: 12 +// Group ID: 0x12 +// Start ID: 0x08 +// Default values: 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// Descriptions: +// PKT_LEN - Configuration bits for reception of a variable length packet. +// PKT_LEN_FIELD_SOURCE - Field number containing the received packet length byte(s). +// PKT_LEN_ADJUST - Provides for adjustment/offset of the received packet length value (in order to accommodate a variety of methods of defining total packet length). +// PKT_TX_THRESHOLD - TX FIFO almost empty threshold. +// PKT_RX_THRESHOLD - RX FIFO Almost Full threshold. +// PKT_FIELD_1_LENGTH_12_8 - Unsigned 13-bit Field 1 length value. +// PKT_FIELD_1_LENGTH_7_0 - Unsigned 13-bit Field 1 length value. +// PKT_FIELD_1_CONFIG - General data processing and packet configuration bits for Field 1. +// PKT_FIELD_1_CRC_CONFIG - Configuration of CRC control bits across Field 1. +// PKT_FIELD_2_LENGTH_12_8 - Unsigned 13-bit Field 2 length value. +// PKT_FIELD_2_LENGTH_7_0 - Unsigned 13-bit Field 2 length value. +// PKT_FIELD_2_CONFIG - General data processing and packet configuration bits for Field 2. +*/ +#define RF_PKT_LEN_12 0x11, 0x12, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x32, 0x04, 0x00, 0x00, 0x00, 0x00 + +/* +// Set properties: RF_PKT_FIELD_2_CRC_CONFIG_12 +// Number of properties: 12 +// Group ID: 0x12 +// Start ID: 0x14 +// Default values: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// Descriptions: +// PKT_FIELD_2_CRC_CONFIG - Configuration of CRC control bits across Field 2. +// PKT_FIELD_3_LENGTH_12_8 - Unsigned 13-bit Field 3 length value. +// PKT_FIELD_3_LENGTH_7_0 - Unsigned 13-bit Field 3 length value. +// PKT_FIELD_3_CONFIG - General data processing and packet configuration bits for Field 3. +// PKT_FIELD_3_CRC_CONFIG - Configuration of CRC control bits across Field 3. +// PKT_FIELD_4_LENGTH_12_8 - Unsigned 13-bit Field 4 length value. +// PKT_FIELD_4_LENGTH_7_0 - Unsigned 13-bit Field 4 length value. +// PKT_FIELD_4_CONFIG - General data processing and packet configuration bits for Field 4. +// PKT_FIELD_4_CRC_CONFIG - Configuration of CRC control bits across Field 4. +// PKT_FIELD_5_LENGTH_12_8 - Unsigned 13-bit Field 5 length value. +// PKT_FIELD_5_LENGTH_7_0 - Unsigned 13-bit Field 5 length value. +// PKT_FIELD_5_CONFIG - General data processing and packet configuration bits for Field 5. +*/ +#define RF_PKT_FIELD_2_CRC_CONFIG_12 0x11, 0x12, 0x0C, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + +/* +// Set properties: RF_PKT_FIELD_5_CRC_CONFIG_12 +// Number of properties: 12 +// Group ID: 0x12 +// Start ID: 0x20 +// Default values: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// Descriptions: +// PKT_FIELD_5_CRC_CONFIG - Configuration of CRC control bits across Field 5. +// PKT_RX_FIELD_1_LENGTH_12_8 - Unsigned 13-bit RX Field 1 length value. +// PKT_RX_FIELD_1_LENGTH_7_0 - Unsigned 13-bit RX Field 1 length value. +// PKT_RX_FIELD_1_CONFIG - General data processing and packet configuration bits for RX Field 1. +// PKT_RX_FIELD_1_CRC_CONFIG - Configuration of CRC control bits across RX Field 1. +// PKT_RX_FIELD_2_LENGTH_12_8 - Unsigned 13-bit RX Field 2 length value. +// PKT_RX_FIELD_2_LENGTH_7_0 - Unsigned 13-bit RX Field 2 length value. +// PKT_RX_FIELD_2_CONFIG - General data processing and packet configuration bits for RX Field 2. +// PKT_RX_FIELD_2_CRC_CONFIG - Configuration of CRC control bits across RX Field 2. +// PKT_RX_FIELD_3_LENGTH_12_8 - Unsigned 13-bit RX Field 3 length value. +// PKT_RX_FIELD_3_LENGTH_7_0 - Unsigned 13-bit RX Field 3 length value. +// PKT_RX_FIELD_3_CONFIG - General data processing and packet configuration bits for RX Field 3. +*/ +#define RF_PKT_FIELD_5_CRC_CONFIG_12 0x11, 0x12, 0x0C, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + +/* +// Set properties: RF_PKT_RX_FIELD_3_CRC_CONFIG_9 +// Number of properties: 9 +// Group ID: 0x12 +// Start ID: 0x2C +// Default values: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// Descriptions: +// PKT_RX_FIELD_3_CRC_CONFIG - Configuration of CRC control bits across RX Field 3. +// PKT_RX_FIELD_4_LENGTH_12_8 - Unsigned 13-bit RX Field 4 length value. +// PKT_RX_FIELD_4_LENGTH_7_0 - Unsigned 13-bit RX Field 4 length value. +// PKT_RX_FIELD_4_CONFIG - General data processing and packet configuration bits for RX Field 4. +// PKT_RX_FIELD_4_CRC_CONFIG - Configuration of CRC control bits across RX Field 4. +// PKT_RX_FIELD_5_LENGTH_12_8 - Unsigned 13-bit RX Field 5 length value. +// PKT_RX_FIELD_5_LENGTH_7_0 - Unsigned 13-bit RX Field 5 length value. +// PKT_RX_FIELD_5_CONFIG - General data processing and packet configuration bits for RX Field 5. +// PKT_RX_FIELD_5_CRC_CONFIG - Configuration of CRC control bits across RX Field 5. +*/ +#define RF_PKT_RX_FIELD_3_CRC_CONFIG_9 0x11, 0x12, 0x09, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + +/* +// Set properties: RF_MODEM_MOD_TYPE_12 +// Number of properties: 12 +// Group ID: 0x20 +// Start ID: 0x00 +// Default values: 0x02, 0x80, 0x07, 0x0F, 0x42, 0x40, 0x01, 0xC9, 0xC3, 0x80, 0x00, 0x06, +// Descriptions: +// MODEM_MOD_TYPE - Selects the type of modulation. In TX mode, additionally selects the source of the modulation. +// MODEM_MAP_CONTROL - Controls polarity and mapping of transmit and receive bits. +// MODEM_DSM_CTRL - Miscellaneous control bits for the Delta-Sigma Modulator (DSM) in the PLL Synthesizer. +// MODEM_DATA_RATE_2 - Unsigned 24-bit value used to determine the TX data rate +// MODEM_DATA_RATE_1 - Unsigned 24-bit value used to determine the TX data rate +// MODEM_DATA_RATE_0 - Unsigned 24-bit value used to determine the TX data rate +// MODEM_TX_NCO_MODE_3 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus. +// MODEM_TX_NCO_MODE_2 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus. +// MODEM_TX_NCO_MODE_1 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus. +// MODEM_TX_NCO_MODE_0 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus. +// MODEM_FREQ_DEV_2 - 17-bit unsigned TX frequency deviation word. +// MODEM_FREQ_DEV_1 - 17-bit unsigned TX frequency deviation word. +*/ +#define RF_MODEM_MOD_TYPE_12 0x11, 0x20, 0x0C, 0x00, 0x03, 0x00, 0x07, 0x02, 0xEE, 0x00, 0x05, 0xC9, 0xC3, 0x80, 0x00, 0x00 + +/* +// Set properties: RF_MODEM_FREQ_DEV_0_1 +// Number of properties: 1 +// Group ID: 0x20 +// Start ID: 0x0C +// Default values: 0xD3, +// Descriptions: +// MODEM_FREQ_DEV_0 - 17-bit unsigned TX frequency deviation word. +*/ +#define RF_MODEM_FREQ_DEV_0_1 0x11, 0x20, 0x01, 0x0C, 0xFC + +/* +// Set properties: RF_MODEM_TX_RAMP_DELAY_8 +// Number of properties: 8 +// Group ID: 0x20 +// Start ID: 0x18 +// Default values: 0x01, 0x00, 0x08, 0x03, 0xC0, 0x00, 0x10, 0x20, +// Descriptions: +// MODEM_TX_RAMP_DELAY - TX ramp-down delay setting. +// MODEM_MDM_CTRL - MDM control. +// MODEM_IF_CONTROL - Selects Fixed-IF, Scaled-IF, or Zero-IF mode of RX Modem operation. +// MODEM_IF_FREQ_2 - the IF frequency setting (an 18-bit signed number). +// MODEM_IF_FREQ_1 - the IF frequency setting (an 18-bit signed number). +// MODEM_IF_FREQ_0 - the IF frequency setting (an 18-bit signed number). +// MODEM_DECIMATION_CFG1 - Specifies three decimator ratios for the Cascaded Integrator Comb (CIC) filter. +// MODEM_DECIMATION_CFG0 - Specifies miscellaneous parameters and decimator ratios for the Cascaded Integrator Comb (CIC) filter. +*/ +#define RF_MODEM_TX_RAMP_DELAY_8 0x11, 0x20, 0x08, 0x18, 0x01, 0x00, 0x08, 0x02, 0x80, 0x00, 0xB0, 0x10 + +/* +// Set properties: RF_MODEM_BCR_OSR_1_9 +// Number of properties: 9 +// Group ID: 0x20 +// Start ID: 0x22 +// Default values: 0x00, 0x4B, 0x06, 0xD3, 0xA0, 0x06, 0xD3, 0x02, 0xC0, +// Descriptions: +// MODEM_BCR_OSR_1 - RX BCR/Slicer oversampling rate (12-bit unsigned number). +// MODEM_BCR_OSR_0 - RX BCR/Slicer oversampling rate (12-bit unsigned number). +// MODEM_BCR_NCO_OFFSET_2 - RX BCR NCO offset value (an unsigned 22-bit number). +// MODEM_BCR_NCO_OFFSET_1 - RX BCR NCO offset value (an unsigned 22-bit number). +// MODEM_BCR_NCO_OFFSET_0 - RX BCR NCO offset value (an unsigned 22-bit number). +// MODEM_BCR_GAIN_1 - The unsigned 11-bit RX BCR loop gain value. +// MODEM_BCR_GAIN_0 - The unsigned 11-bit RX BCR loop gain value. +// MODEM_BCR_GEAR - RX BCR loop gear control. +// MODEM_BCR_MISC1 - Miscellaneous control bits for the RX BCR loop. +*/ +#define RF_MODEM_BCR_OSR_1_9 0x11, 0x20, 0x09, 0x22, 0x00, 0x41, 0x07, 0xDD, 0x44, 0x07, 0xFF, 0x02, 0x00 + +/* +// Set properties: RF_MODEM_AFC_GEAR_7 +// Number of properties: 7 +// Group ID: 0x20 +// Start ID: 0x2C +// Default values: 0x00, 0x23, 0x83, 0x69, 0x00, 0x40, 0xA0, +// Descriptions: +// MODEM_AFC_GEAR - RX AFC loop gear control. +// MODEM_AFC_WAIT - RX AFC loop wait time control. +// MODEM_AFC_GAIN_1 - Sets the gain of the PLL-based AFC acquisition loop, and provides miscellaneous control bits for AFC functionality. +// MODEM_AFC_GAIN_0 - Sets the gain of the PLL-based AFC acquisition loop, and provides miscellaneous control bits for AFC functionality. +// MODEM_AFC_LIMITER_1 - Set the AFC limiter value. +// MODEM_AFC_LIMITER_0 - Set the AFC limiter value. +// MODEM_AFC_MISC - Specifies miscellaneous AFC control bits. +*/ +#define RF_MODEM_AFC_GEAR_7 0x11, 0x20, 0x07, 0x2C, 0x00, 0x12, 0x80, 0x7E, 0x01, 0xBF, 0xA0 + +/* +// Set properties: RF_MODEM_AGC_CONTROL_1 +// Number of properties: 1 +// Group ID: 0x20 +// Start ID: 0x35 +// Default values: 0xE0, +// Descriptions: +// MODEM_AGC_CONTROL - Miscellaneous control bits for the Automatic Gain Control (AGC) function in the RX Chain. +*/ +#define RF_MODEM_AGC_CONTROL_1 0x11, 0x20, 0x01, 0x35, 0xE2 + +/* +// Set properties: RF_MODEM_AGC_WINDOW_SIZE_9 +// Number of properties: 9 +// Group ID: 0x20 +// Start ID: 0x38 +// Default values: 0x11, 0x10, 0x10, 0x0B, 0x1C, 0x40, 0x00, 0x00, 0x2B, +// Descriptions: +// MODEM_AGC_WINDOW_SIZE - Specifies the size of the measurement and settling windows for the AGC algorithm. +// MODEM_AGC_RFPD_DECAY - Sets the decay time of the RF peak detectors. +// MODEM_AGC_IFPD_DECAY - Sets the decay time of the IF peak detectors. +// MODEM_FSK4_GAIN1 - Specifies the gain factor of the secondary branch in 4(G)FSK ISI-suppression. +// MODEM_FSK4_GAIN0 - Specifies the gain factor of the primary branch in 4(G)FSK ISI-suppression. +// MODEM_FSK4_TH1 - 16 bit 4(G)FSK slicer threshold. +// MODEM_FSK4_TH0 - 16 bit 4(G)FSK slicer threshold. +// MODEM_FSK4_MAP - 4(G)FSK symbol mapping code. +// MODEM_OOK_PDTC - Configures the attack and decay times of the OOK Peak Detector. +*/ +#define RF_MODEM_AGC_WINDOW_SIZE_9 0x11, 0x20, 0x09, 0x38, 0x11, 0x0E, 0x0E, 0x00, 0x1A, 0x20, 0x00, 0x00, 0x28 + +/* +// Set properties: RF_MODEM_OOK_CNT1_9 +// Number of properties: 9 +// Group ID: 0x20 +// Start ID: 0x42 +// Default values: 0xA4, 0x03, 0x56, 0x02, 0x00, 0xA3, 0x02, 0x80, 0xFF, +// Descriptions: +// MODEM_OOK_CNT1 - OOK control. +// MODEM_OOK_MISC - Selects the detector(s) used for demodulation of an OOK signal, or for demodulation of a (G)FSK signal when using the asynchronous demodulator. +// MODEM_RAW_SEARCH - Defines and controls the search period length for the Moving Average and Min-Max detectors. +// MODEM_RAW_CONTROL - Defines gain and enable controls for raw / nonstandard mode. +// MODEM_RAW_EYE_1 - 11 bit eye-open detector threshold. +// MODEM_RAW_EYE_0 - 11 bit eye-open detector threshold. +// MODEM_ANT_DIV_MODE - Antenna diversity mode settings. +// MODEM_ANT_DIV_CONTROL - Specifies controls for the Antenna Diversity algorithm. +// MODEM_RSSI_THRESH - Configures the RSSI threshold. +*/ +#define RF_MODEM_OOK_CNT1_9 0x11, 0x20, 0x09, 0x42, 0xA4, 0x03, 0xD6, 0x03, 0x00, 0x93, 0x01, 0x80, 0xFF + +/* +// Set properties: RF_MODEM_RSSI_CONTROL_1 +// Number of properties: 1 +// Group ID: 0x20 +// Start ID: 0x4C +// Default values: 0x01, +// Descriptions: +// MODEM_RSSI_CONTROL - Control of the averaging modes and latching time for reporting RSSI value(s). +*/ +#define RF_MODEM_RSSI_CONTROL_1 0x11, 0x20, 0x01, 0x4C, 0x00 + +/* +// Set properties: RF_MODEM_RSSI_COMP_1 +// Number of properties: 1 +// Group ID: 0x20 +// Start ID: 0x4E +// Default values: 0x32, +// Descriptions: +// MODEM_RSSI_COMP - RSSI compensation value. +*/ +#define RF_MODEM_RSSI_COMP_1 0x11, 0x20, 0x01, 0x4E, 0x40 + +/* +// Set properties: RF_MODEM_CLKGEN_BAND_1 +// Number of properties: 1 +// Group ID: 0x20 +// Start ID: 0x51 +// Default values: 0x08, +// Descriptions: +// MODEM_CLKGEN_BAND - Select PLL Synthesizer output divider ratio as a function of frequency band. +*/ +#define RF_MODEM_CLKGEN_BAND_1 0x11, 0x20, 0x01, 0x51, 0x0D + +/* +// Set properties: RF_MODEM_CHFLT_RX1_CHFLT_COE13_7_0_12 +// Number of properties: 12 +// Group ID: 0x21 +// Start ID: 0x00 +// Default values: 0xFF, 0xBA, 0x0F, 0x51, 0xCF, 0xA9, 0xC9, 0xFC, 0x1B, 0x1E, 0x0F, 0x01, +// Descriptions: +// MODEM_CHFLT_RX1_CHFLT_COE13_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE12_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE11_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE10_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE9_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE8_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE7_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE6_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE5_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE4_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE3_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE2_7_0 - Filter coefficients for the first set of RX filter coefficients. +*/ +#define RF_MODEM_CHFLT_RX1_CHFLT_COE13_7_0_12 0x11, 0x21, 0x0C, 0x00, 0xFF, 0xBA, 0x0F, 0x51, 0xCF, 0xA9, 0xC9, 0xFC, 0x1B, 0x1E, 0x0F, 0x01 + +/* +// Set properties: RF_MODEM_CHFLT_RX1_CHFLT_COE1_7_0_12 +// Number of properties: 12 +// Group ID: 0x21 +// Start ID: 0x0C +// Default values: 0xFC, 0xFD, 0x15, 0xFF, 0x00, 0x0F, 0xFF, 0xC4, 0x30, 0x7F, 0xF5, 0xB5, +// Descriptions: +// MODEM_CHFLT_RX1_CHFLT_COE1_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COE0_7_0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COEM0 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COEM1 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COEM2 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX1_CHFLT_COEM3 - Filter coefficients for the first set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE13_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE12_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE11_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE10_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE9_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE8_7_0 - Filter coefficients for the second set of RX filter coefficients. +*/ +#define RF_MODEM_CHFLT_RX1_CHFLT_COE1_7_0_12 0x11, 0x21, 0x0C, 0x0C, 0xFC, 0xFD, 0x15, 0xFF, 0x00, 0x0F, 0xFF, 0xBA, 0x0F, 0x51, 0xCF, 0xA9 + +/* +// Set properties: RF_MODEM_CHFLT_RX2_CHFLT_COE7_7_0_12 +// Number of properties: 12 +// Group ID: 0x21 +// Start ID: 0x18 +// Default values: 0xB8, 0xDE, 0x05, 0x17, 0x16, 0x0C, 0x03, 0x00, 0x15, 0xFF, 0x00, 0x00, +// Descriptions: +// MODEM_CHFLT_RX2_CHFLT_COE7_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE6_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE5_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE4_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE3_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE2_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE1_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COE0_7_0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COEM0 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COEM1 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COEM2 - Filter coefficients for the second set of RX filter coefficients. +// MODEM_CHFLT_RX2_CHFLT_COEM3 - Filter coefficients for the second set of RX filter coefficients. +*/ +#define RF_MODEM_CHFLT_RX2_CHFLT_COE7_7_0_12 0x11, 0x21, 0x0C, 0x18, 0xC9, 0xFC, 0x1B, 0x1E, 0x0F, 0x01, 0xFC, 0xFD, 0x15, 0xFF, 0x00, 0x0F + +/* +// Set properties: RF_PA_MODE_4 +// Number of properties: 4 +// Group ID: 0x22 +// Start ID: 0x00 +// Default values: 0x08, 0x7F, 0x00, 0x5D, +// Descriptions: +// PA_MODE - Selects the PA operating mode, and selects resolution of PA power adjustment (i.e., step size). +// PA_PWR_LVL - Configuration of PA output power level. +// PA_BIAS_CLKDUTY - Configuration of the PA Bias and duty cycle of the TX clock source. +// PA_TC - Configuration of PA ramping parameters. +*/ +#define RF_PA_MODE_4 0x11, 0x22, 0x04, 0x00, 0x08, 0x7F, 0x00, 0x3D + +/* +// Set properties: RF_SYNTH_PFDCP_CPFF_7 +// Number of properties: 7 +// Group ID: 0x23 +// Start ID: 0x00 +// Default values: 0x2C, 0x0E, 0x0B, 0x04, 0x0C, 0x73, 0x03, +// Descriptions: +// SYNTH_PFDCP_CPFF - Feed forward charge pump current selection. +// SYNTH_PFDCP_CPINT - Integration charge pump current selection. +// SYNTH_VCO_KV - Gain scaling factors (Kv) for the VCO tuning varactors on both the integrated-path and feed forward path. +// SYNTH_LPFILT3 - Value of resistor R2 in feed-forward path of loop filter. +// SYNTH_LPFILT2 - Value of capacitor C2 in feed-forward path of loop filter. +// SYNTH_LPFILT1 - Value of capacitors C1 and C3 in feed-forward path of loop filter. +// SYNTH_LPFILT0 - Bias current of the active amplifier in the feed-forward loop filter. +*/ +#define RF_SYNTH_PFDCP_CPFF_7 0x11, 0x23, 0x07, 0x00, 0x2C, 0x0E, 0x0B, 0x04, 0x0C, 0x73, 0x03 + +/* +// Set properties: RF_MATCH_VALUE_1_12 +// Number of properties: 12 +// Group ID: 0x30 +// Start ID: 0x00 +// Default values: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// Descriptions: +// MATCH_VALUE_1 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 1 value with the received Match 1 byte. +// MATCH_MASK_1 - Mask value to be logically AND-ed (bit-wise) with the Match 1 byte. +// MATCH_CTRL_1 - Enable for Packet Match functionality, and configuration of Match Byte 1. +// MATCH_VALUE_2 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 2 value with the received Match 2 byte. +// MATCH_MASK_2 - Mask value to be logically AND-ed (bit-wise) with the Match 2 byte. +// MATCH_CTRL_2 - Configuration of Match Byte 2. +// MATCH_VALUE_3 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 3 value with the received Match 3 byte. +// MATCH_MASK_3 - Mask value to be logically AND-ed (bit-wise) with the Match 3 byte. +// MATCH_CTRL_3 - Configuration of Match Byte 3. +// MATCH_VALUE_4 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 4 value with the received Match 4 byte. +// MATCH_MASK_4 - Mask value to be logically AND-ed (bit-wise) with the Match 4 byte. +// MATCH_CTRL_4 - Configuration of Match Byte 4. +*/ +#define RF_MATCH_VALUE_1_12 0x11, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + +/* +// Set properties: RF_FREQ_CONTROL_INTE_8 +// Number of properties: 8 +// Group ID: 0x40 +// Start ID: 0x00 +// Default values: 0x3C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, +// Descriptions: +// FREQ_CONTROL_INTE - Frac-N PLL Synthesizer integer divide number. +// FREQ_CONTROL_FRAC_2 - Frac-N PLL fraction number. +// FREQ_CONTROL_FRAC_1 - Frac-N PLL fraction number. +// FREQ_CONTROL_FRAC_0 - Frac-N PLL fraction number. +// FREQ_CONTROL_CHANNEL_STEP_SIZE_1 - EZ Frequency Programming channel step size. +// FREQ_CONTROL_CHANNEL_STEP_SIZE_0 - EZ Frequency Programming channel step size. +// FREQ_CONTROL_W_SIZE - Set window gating period (in number of crystal reference clock cycles) for counting VCO frequency during calibration. +// FREQ_CONTROL_VCOCNT_RX_ADJ - Adjust target count for VCO calibration in RX mode. +*/ +#define RF_FREQ_CONTROL_INTE_8 0x11, 0x40, 0x08, 0x00, 0x39, 0x0A, 0xE1, 0x47, 0x00, 0x00, 0x20, 0xFA + + +// AUTOMATICALLY GENERATED CODE! +// DO NOT EDIT/MODIFY BELOW THIS LINE! +// -------------------------------------------- + +#ifndef FIRMWARE_LOAD_COMPILE +#define RADIO_CONFIGURATION_DATA_ARRAY { \ + 0x07, RF_POWER_UP, \ + 0x08, RF_GPIO_PIN_CFG, \ + 0x06, RF_GLOBAL_XO_TUNE_2, \ + 0x05, RF_GLOBAL_CONFIG_1, \ + 0x05, RF_INT_CTL_ENABLE_1, \ + 0x08, RF_FRR_CTL_A_MODE_4, \ + 0x0D, RF_PREAMBLE_TX_LENGTH_9, \ + 0x09, RF_SYNC_CONFIG_5, \ + 0x0B, RF_PKT_CRC_CONFIG_7, \ + 0x10, RF_PKT_LEN_12, \ + 0x10, RF_PKT_FIELD_2_CRC_CONFIG_12, \ + 0x10, RF_PKT_FIELD_5_CRC_CONFIG_12, \ + 0x0D, RF_PKT_RX_FIELD_3_CRC_CONFIG_9, \ + 0x10, RF_MODEM_MOD_TYPE_12, \ + 0x05, RF_MODEM_FREQ_DEV_0_1, \ + 0x0C, RF_MODEM_TX_RAMP_DELAY_8, \ + 0x0D, RF_MODEM_BCR_OSR_1_9, \ + 0x0B, RF_MODEM_AFC_GEAR_7, \ + 0x05, RF_MODEM_AGC_CONTROL_1, \ + 0x0D, RF_MODEM_AGC_WINDOW_SIZE_9, \ + 0x0D, RF_MODEM_OOK_CNT1_9, \ + 0x05, RF_MODEM_RSSI_CONTROL_1, \ + 0x05, RF_MODEM_RSSI_COMP_1, \ + 0x05, RF_MODEM_CLKGEN_BAND_1, \ + 0x10, RF_MODEM_CHFLT_RX1_CHFLT_COE13_7_0_12, \ + 0x10, RF_MODEM_CHFLT_RX1_CHFLT_COE1_7_0_12, \ + 0x10, RF_MODEM_CHFLT_RX2_CHFLT_COE7_7_0_12, \ + 0x08, RF_PA_MODE_4, \ + 0x0B, RF_SYNTH_PFDCP_CPFF_7, \ + 0x10, RF_MATCH_VALUE_1_12, \ + 0x0C, RF_FREQ_CONTROL_INTE_8, \ + 0x00 \ + } +#else +#define RADIO_CONFIGURATION_DATA_ARRAY { 0 } +#endif + +// DEFAULT VALUES FOR CONFIGURATION PARAMETERS +#define RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ_DEFAULT 30000000L +#define RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER_DEFAULT 0x00 +#define RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH_DEFAULT 0x10 +#define RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP_DEFAULT 0x01 +#define RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET_DEFAULT 0x1000 + +#define RADIO_CONFIGURATION_DATA_RADIO_PATCH_INCLUDED 0x00 +#define RADIO_CONFIGURATION_DATA_RADIO_PATCH_SIZE 0x00 +#define RADIO_CONFIGURATION_DATA_RADIO_PATCH { } + +#ifndef RADIO_CONFIGURATION_DATA_ARRAY +#error "This property must be defined!" +#endif + +#ifndef RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ +#define RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ_DEFAULT +#endif + +#ifndef RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER +#define RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER_DEFAULT +#endif + +#ifndef RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH +#define RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH_DEFAULT +#endif + +#ifndef RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP +#define RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP_DEFAULT +#endif + +#ifndef RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET +#define RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET_DEFAULT +#endif + +#define RADIO_CONFIGURATION_DATA { \ + Radio_Configuration_Data_Array, \ + RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER, \ + RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH, \ + RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP, \ + RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET \ + } + +#endif /* RADIO_CONFIG_H_ */ diff --git a/firmware/devices/obdh/obdh.c b/firmware/devices/obdh/obdh.c index ed7aa374..eaa2c417 100644 --- a/firmware/devices/obdh/obdh.c +++ b/firmware/devices/obdh/obdh.c @@ -25,14 +25,16 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2023/02/12 + * \date 2024/04/22 * * \addtogroup obdh * \{ */ +#include + #include #include @@ -74,7 +76,7 @@ int obdh_read_request(obdh_request_t *obdh_request) uint8_t request[7] = {0}; spi_slave_dma_read(request, 7); - + /*TODO: Check here for preamble!*/ obdh_request->command = request[1]; if ((obdh_request->command != 0xFF) && (obdh_request->command != 0x00)) /* Received a request */ @@ -114,20 +116,26 @@ int obdh_read_request(obdh_request_t *obdh_request) obdh_request->data.data_packet.len = request[2]; - obdh_write_read_bytes(request[2]+2U); + spi_slave_dma_change_transfer_size((request[2] + 3U)); + + obdh_write_read_bytes((request[2] + 3U)); - vTaskDelay(pdMS_TO_TICKS(100)); + vTaskDelay(pdMS_TO_TICKS(130)); - spi_slave_dma_read(obdh_request->data.data_packet.packet, (obdh_request->data.data_packet.len)+3); + spi_slave_dma_read(obdh_request->data.data_packet.packet, (obdh_request->data.data_packet.len + 3U)); + + /* Removing protocol bytes */ + for (uint16_t i = 0; i < (uint16_t)(request[2]); i++) + { + obdh_request->data.data_packet.packet[i] = obdh_request->data.data_packet.packet[i+3U]; + } sys_log_print_event_from_module(SYS_LOG_INFO, OBDH_MODULE_NAME, "Transmit packet command received:"); sys_log_print_uint(obdh_request->data.data_packet.len); sys_log_print_msg(" bytes."); sys_log_new_line(); - sys_log_print_str("Packet: "); - sys_log_dump_hex(&(obdh_request->data.data_packet.packet[3]), obdh_request->data.data_packet.len); - sys_log_new_line(); + spi_slave_dma_change_transfer_size(7U); break; case CMDPR_CMD_READ_FIRST_PACKET: @@ -282,7 +290,9 @@ int obdh_write_response_param(ttc_data_t *ttc_data_buf, obdh_response_t *obdh_re break; case CMDPR_PARAM_N_BYTES_FIRST_AV_RX: - obdh_response->data.param_16 = *(ttc_data_buf->radio.last_rx_packet_bytes); + /* Update rx packet bytes */ + ttc_data_buf->radio.last_rx_packet_bytes = ttc_data_buf->up_buf.packet_sizes[ttc_data_buf->up_buf.position_to_read]; + obdh_response->data.param_16 = ttc_data_buf->radio.last_rx_packet_bytes; break; default: @@ -307,27 +317,28 @@ int obdh_flush_request(obdh_request_t *obdh_request) static int obdh_write_parameter(obdh_response_t *obdh_response) { int err = 0; - uint8_t response[6] = {0}; + uint8_t response[7] = {0}; - response[0] = obdh_response->command; - response[1] = obdh_response->parameter; + response[0] = 0x7EU; + response[1] = obdh_response->command; + response[2] = obdh_response->parameter; switch(cmdpr_param_size(obdh_response->parameter)) { case 1: - response[2] = obdh_response->data.param_8; + response[3] = obdh_response->data.param_8; break; case 2: - response[2] = (uint8_t)((obdh_response->data.param_16 >> 8) & 0xFFU); - response[3] = (uint8_t)(obdh_response->data.param_16 & 0xFFU); + response[3] = (uint8_t)((obdh_response->data.param_16 >> 8) & 0xFFU); + response[4] = (uint8_t)(obdh_response->data.param_16 & 0xFFU); break; case 4: - response[2] = (uint8_t)((obdh_response->data.param_32 >> 24) & 0xFFU); - response[3] = (uint8_t)((obdh_response->data.param_32 >> 16) & 0xFFU); - response[4] = (uint8_t)((obdh_response->data.param_32 >> 8) & 0xFFU); - response[5] = (uint8_t)(obdh_response->data.param_32 & 0xFFU); + response[3] = (uint8_t)((obdh_response->data.param_32 >> 24) & 0xFFU); + response[4] = (uint8_t)((obdh_response->data.param_32 >> 16) & 0xFFU); + response[5] = (uint8_t)((obdh_response->data.param_32 >> 8) & 0xFFU); + response[6] = (uint8_t)(obdh_response->data.param_32 & 0xFFU); break; default: @@ -340,7 +351,7 @@ static int obdh_write_parameter(obdh_response_t *obdh_response) if (err == 0) { - spi_slave_dma_write(response, 6); + spi_slave_dma_write(response, 7); } else { @@ -355,7 +366,9 @@ void obdh_write_read_bytes(uint16_t number_of_bytes) // cppcheck-suppress misra- uint8_t buffer[230]; uint8_t i; - for (i = 0U; i < 230U; i++) + buffer[0] = 0x7EU; + + for (i = 1U; i < number_of_bytes; i++) { buffer[i] = 0x00U; } @@ -365,14 +378,33 @@ void obdh_write_read_bytes(uint16_t number_of_bytes) // cppcheck-suppress misra- static int obdh_write_packet(obdh_response_t *obdh_response) { - int err = 0; + int err = -1; - spi_slave_dma_write(obdh_response->data.data_packet.packet, obdh_response->data.data_packet.len); + uint8_t transmission_buffer[70U]; + uint8_t transmission_buffer_p; - sys_log_print_str("Packet:"); + if((obdh_response->data.data_packet.len + 2) < 70U) + { + spi_slave_dma_change_transfer_size((obdh_response->data.data_packet.len + 2)); + + transmission_buffer[0] = 0x7EU; + transmission_buffer[1] = 0x04U; + + for (transmission_buffer_p = 0U; transmission_buffer_p < obdh_response->data.data_packet.len; transmission_buffer_p++) + { + transmission_buffer[transmission_buffer_p + 2U] = obdh_response->data.data_packet.packet[transmission_buffer_p]; + } - sys_log_dump_hex(obdh_response->data.data_packet.packet, obdh_response->data.data_packet.len); - sys_log_new_line(); + spi_slave_dma_write(transmission_buffer, (obdh_response->data.data_packet.len + 2)); + + vTaskDelay(pdMS_TO_TICKS(130)); + + spi_slave_dma_read(NULL, (obdh_response->data.data_packet.len + 2)); + + spi_slave_dma_change_transfer_size(7U); + + err = 0; + } return err; } diff --git a/firmware/devices/radio/radio.c b/firmware/devices/radio/radio.c index c2d70ef3..d26d6e10 100644 --- a/firmware/devices/radio/radio.c +++ b/firmware/devices/radio/radio.c @@ -26,9 +26,9 @@ * \author Gabriel Mariano Marcelino * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2019/10/27 + * \date 2024/04/22 * * \addtogroup radio * \{ @@ -64,26 +64,36 @@ int radio_init(void) int radio_send(uint8_t *data, uint16_t len) { - sys_log_print_event_from_module(SYS_LOG_INFO, RADIO_MODULE_NAME, "Transmitting "); - sys_log_print_uint(len); - sys_log_print_msg(" byte(s)..."); - sys_log_new_line(); - int err = -1; - led_set(LED_DOWNLINK); - - if(si446x_tx_long_packet(data, len)) + if (si446x_mutex_take() == 0) { - led_clear(LED_DOWNLINK); + sys_log_print_event_from_module(SYS_LOG_INFO, RADIO_MODULE_NAME, "Transmitting "); + sys_log_print_uint(len); + sys_log_print_msg(" byte(s)..."); + sys_log_new_line(); - if(si446x_rx_init()) + led_set(LED_DOWNLINK); + + if(si446x_tx_long_packet(data, len)) { - err = 0; + led_clear(LED_DOWNLINK); + + if(si446x_rx_init()) + { + err = 0; + } } - } - led_clear(LED_DOWNLINK); + led_clear(LED_DOWNLINK); + + si446x_mutex_give(); + } + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, RADIO_MODULE_NAME, "Couldn't get mutex control."); + sys_log_new_line(); + } return err; } @@ -94,20 +104,30 @@ int radio_recv(uint8_t *data, uint16_t len, uint32_t timeout_ms) uint16_t i = 0; - for(i = 0; i < (timeout_ms/100); i++) + if (si446x_mutex_take() == 0) { - if (si446x_wait_nirq()) + for(i = 0; i < (timeout_ms/100); i++) { - res = (int)si446x_rx_packet(data, len); + if (si446x_wait_nirq()) + { + res = (int)si446x_rx_packet(data, len); - si446x_clear_interrupts(); + si446x_clear_interrupts(); - si446x_rx_init(); + si446x_rx_init(); - break; + break; + } + + vTaskDelay(pdMS_TO_TICKS(500)); } - vTaskDelay(pdMS_TO_TICKS(500)); + si446x_mutex_give(); + } + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, RADIO_MODULE_NAME, "Couldn't get mutex control."); + sys_log_new_line(); } return res; @@ -120,7 +140,21 @@ int radio_available(void) int radio_sleep(void) { - return (int)si446x_enter_standby_mode(); + int err = -1; + + if (si446x_mutex_take() == 0) + { + err = si446x_enter_standby_mode(); + + si446x_mutex_give(); + } + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, RADIO_MODULE_NAME, "Couldn't get mutex control."); + sys_log_new_line(); + } + + return err; } int radio_get_temperature(radio_temp_t *temp) diff --git a/firmware/devices/radio/radio.h b/firmware/devices/radio/radio.h index 83ce7c58..7306a3b6 100644 --- a/firmware/devices/radio/radio.h +++ b/firmware/devices/radio/radio.h @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.1.23 + * \version 0.5.1 * - * \date 2019/10/27 + * \date 2024/04/22 * * \defgroup radio Radio * \ingroup devices @@ -83,7 +83,7 @@ int radio_send(uint8_t *data, uint16_t len); int radio_recv(uint8_t *data, uint16_t len, uint32_t timeout_ms); /** - * \brief Verifies the number of availables bytes to receive. + * \brief Verifies if there are unread received bytes. * * \return The number of available bytes to receive (-1 on error). */ diff --git a/firmware/devices/radio/radio_data.h b/firmware/devices/radio/radio_data.h index 182ccbb8..a73836fa 100644 --- a/firmware/devices/radio/radio_data.h +++ b/firmware/devices/radio/radio_data.h @@ -55,7 +55,7 @@ typedef struct uint32_t tx_packet_counter; /**< Number of total packets sent */ uint8_t rx_fifo_counter; /**< Packets received in queue */ uint8_t tx_fifo_counter; /**< Packets in queue to be sent */ - uint16_t *last_rx_packet_bytes; /**< Number of available bytes in the last packet received */ + uint16_t last_rx_packet_bytes; /**< Number of available bytes in the last packet received */ } radio_data_t; #endif /* RADIO_DATA_H_ */ diff --git a/firmware/drivers/si446x/si446x.c b/firmware/drivers/si446x/si446x.c index 5d986693..0dfae83b 100644 --- a/firmware/drivers/si446x/si446x.c +++ b/firmware/drivers/si446x/si446x.c @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.2.10 + * \version 0.5.1 * - * \date 2017/06/01 + * \date 2024/04/22 * * \addtogroup si446x * \{ @@ -36,7 +36,18 @@ #include #include -#include + +#if defined(RADIO_MODULE) && (RADIO_MODULE == 0) +#include + +#elif defined(RADIO_MODULE) && (RADIO_MODULE == 1) +#include + +#else +sys_log_print_event_from_module(SYS_LOG_ERROR, "Radio Configuration", "Failed to determine target radio!"); +sys_log_new_line(); +#endif /* CONFIG_DEV_RADIO_ENABLED */ + #include #include "si446x.h" @@ -54,6 +65,9 @@ int si446x_init(void) sys_log_new_line(); #endif /* CONFIG_DRIVERS_DEBUG_ENABLED */ + /* Create si446x mutex */ + si446x_mutex_create(); + si446x_gpio_init(); si446x_spi_init(); @@ -108,12 +122,12 @@ void si446x_reg_config(void) /* Set RF parameter like frequency, data rate, etc. */ si446x_set_config(SI446X_CONFIGURATION_DATA, sizeof(SI446X_CONFIGURATION_DATA)); + uint8_t buf[2]; /* Frequency adjust (Tested manually) */ buf[0] = SI446X_XO_TUNE_REG_VALUE; si446x_set_properties(SI446X_PROPERTY_GLOBAL_XO_TUNE, buf, 1); - /* TX/RX shares 128 bytes FIFO */ buf[0] = 0x10; si446x_set_properties(SI446X_PROPERTY_GLOBAL_CONFIG, buf, 1); @@ -464,9 +478,10 @@ void si446x_set_config(const uint8_t *parameters, uint16_t para_len) cmd_len = parameters[pos++] - 1; /* Get command len */ cmd = parameters[pos++]; /* Get command */ memcpy(buffer, parameters + pos, cmd_len); /* Get parameters */ - + si446x_delay_ms(10); si446x_set_cmd(cmd, buffer, cmd_len); pos += cmd_len; + } } diff --git a/firmware/drivers/si446x/si446x.h b/firmware/drivers/si446x/si446x.h index a5c987a8..0524b000 100644 --- a/firmware/drivers/si446x/si446x.h +++ b/firmware/drivers/si446x/si446x.h @@ -39,6 +39,9 @@ #include #include +/* Mutex config. */ +#define SI446X_MUTEX_WAIT_TIME_MS 100 + /** * \brief Si446x modes. */ diff --git a/firmware/drivers/si446x/si446x_config.h b/firmware/drivers/si446x/si446x_config.h index 4e7933d9..495334c5 100644 --- a/firmware/drivers/si446x/si446x_config.h +++ b/firmware/drivers/si446x/si446x_config.h @@ -1,34 +1,34 @@ /* * si446x_config.h - * + * * Copyright The TTC 2.0 Contributors. - * + * * This file is part of TTC 2.0. - * + * * TTC 2.0 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * TTC 2.0 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with TTC 2.0. If not, see . - * + * */ /** * \brief Si446x configuration. - * + * * \author Gabriel Mariano Marcelino - * - * \version 0.1.23 - * - * \date 2017/06/16 - * + * + * \version 0.5.1 + * + * \date 2024/04/22 + * * \addtogroup si446x * \{ */ diff --git a/firmware/drivers/si446x/si446x_mutex.c b/firmware/drivers/si446x/si446x_mutex.c index b5d7363e..b136c2c6 100644 --- a/firmware/drivers/si446x/si446x_mutex.c +++ b/firmware/drivers/si446x/si446x_mutex.c @@ -24,50 +24,74 @@ * \brief Si446x mutex functions implementation. * * \author Gabriel Mariano Marcelino + * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2023/04/13 + * \date 2024/04/22 * * \addtogroup si446x * \{ */ +#include + #include #include +#include + #include "si446x.h" #include "si446x_config.h" -static SemaphoreHandle_t si446x_semaphore = NULL; - -#define SI446X_MUTEX_WAIT_TIME_MS 100; +static SemaphoreHandle_t si446x_mutex = NULL; int si446x_mutex_create(void) { - return 0; + int err = 0; + + si446x_mutex = xSemaphoreCreateMutex(); + + if (si446x_mutex == NULL) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, SI446X_MODULE_NAME, "Error creating a mutex!"); + sys_log_new_line(); + + err = -1; + } + + return err; } int si446x_mutex_take(void) { int err = -1; - //if (si446x_semaphore != NULL) - //{ + if (si446x_mutex != NULL) + { /* See if we can obtain the semaphore. If the semaphore is not */ - /* available wait SYS_LOG_MUTEX_WAIT_TIME_MS ms to see if it becomes free */ - // if (xSemaphoreTake(si446x_semaphore, pdMS_TO_TICKS(SI446X_MUTEX_WAIT_TIME_MS)) == pdTRUE) - //{ - // err = 0; - //} - //} + /* available wait SI446X_MUTEX_WAIT_TIME_MS ms to see if it becomes free */ + if (xSemaphoreTake(si446x_mutex, pdMS_TO_TICKS(SI446X_MUTEX_WAIT_TIME_MS)) == pdTRUE) + { + err = 0; + } + } return err; } int si446x_mutex_give(void) { - return 0; + int err = -1; + + if (si446x_mutex != NULL) + { + xSemaphoreGive(si446x_mutex); + + err = 0; + } + + return err; } /**< \} End of si446x group */ diff --git a/firmware/drivers/spi_slave/spi_slave.c b/firmware/drivers/spi_slave/spi_slave.c index 4bdfcc08..b0805179 100644 --- a/firmware/drivers/spi_slave/spi_slave.c +++ b/firmware/drivers/spi_slave/spi_slave.c @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2022/05/21 + * \date 2024/04/22 * * \addtogroup spi_slave * \{ @@ -81,11 +81,11 @@ static int spi_read_isr_rx_buffer(spi_port_t port, uint8_t *data, uint16_t len); static int spi_slave_setup_gpio(spi_port_t port); -static uint8_t spi_slave_dma_tx_data[228] = {0}; -static uint8_t spi_slave_dma_rx_data[228] = {0}; +#define DMA_TX_TRANSFER_SIZE 7 +#define DMA_RX_TRANSFER_SIZE 7 -static uint16_t spi_slave_dma_tx_position; -static uint16_t spi_slave_dma_rx_position; +static uint8_t spi_slave_dma_tx_data[230U] = {0}; +static uint8_t spi_slave_dma_rx_data[230U] = {0}; int spi_slave_init(spi_port_t port, spi_config_t config) { @@ -100,7 +100,7 @@ int spi_slave_init(spi_port_t port, spi_config_t config) static DMA_initParam spi_slave_dma_param_tx = { .channelSelect = DMA_CHANNEL_0, .transferModeSelect = DMA_TRANSFER_REPEATED_SINGLE, - .transferSize = 228, + .transferSize = DMA_TX_TRANSFER_SIZE, .triggerSourceSelect = DMA_TRIGGERSOURCE_13, .transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE, .triggerTypeSelect = DMA_TRIGGER_HIGH, @@ -109,7 +109,7 @@ int spi_slave_init(spi_port_t port, spi_config_t config) static DMA_initParam spi_slave_dma_param_rx = { .channelSelect = DMA_CHANNEL_1, .transferModeSelect = DMA_TRANSFER_REPEATED_SINGLE, - .transferSize = 228, + .transferSize = DMA_RX_TRANSFER_SIZE, .triggerSourceSelect = DMA_TRIGGERSOURCE_12, .transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE, .triggerTypeSelect = DMA_TRIGGER_HIGH, @@ -309,11 +309,13 @@ int spi_slave_init(spi_port_t port, spi_config_t config) DMA_enableTransfers(DMA_CHANNEL_0); - spi_slave_dma_rx_position = 0U; - - for(i = 0U; i < 228U; i++) + for(i = 0U; i < (uint8_t) DMA_RX_TRANSFER_SIZE; i++) { spi_slave_dma_rx_data[i] = 0xFFU; + } + + for(i = 0U; i < (uint8_t) DMA_TX_TRANSFER_SIZE; i++) + { spi_slave_dma_tx_data[i] = 0xFFU; } @@ -325,9 +327,6 @@ int spi_slave_init(spi_port_t port, spi_config_t config) spi_slave_dma_tx_data[5] = 0x00U; spi_slave_dma_tx_data[6] = 0x00U; - /* Next command preamble */ - spi_slave_dma_tx_data[7] = 0x7EU; - DMA_init(&spi_slave_dma_param_rx); DMA_setSrcAddress(DMA_CHANNEL_1, USCI_A_SPI_getReceiveBufferAddressForDMA(base_address), DMA_DIRECTION_UNCHANGED); @@ -340,8 +339,6 @@ int spi_slave_init(spi_port_t port, spi_config_t config) DMA_enableTransfers(DMA_CHANNEL_1); - spi_slave_dma_tx_position = 8U; - __bis_SR_register(LPM4_bits + GIE); if (err == 0) @@ -371,56 +368,41 @@ void spi_slave_dma_write(uint8_t *data, uint16_t len) for(i = 0U; i < len; i++) { - spi_slave_dma_tx_data[spi_slave_dma_tx_position] = data[i]; - - spi_slave_dma_tx_position++; - - if (spi_slave_dma_tx_position > 227U) /* Reset position after the end of the buffer */ - { - spi_slave_dma_tx_position = 0U; - } + spi_slave_dma_tx_data[i] = data[i]; } +} - spi_slave_dma_tx_data[spi_slave_dma_tx_position] = 0x7EU; - - spi_slave_dma_tx_position++; +void spi_slave_dma_read(uint8_t *data, uint16_t len) +{ + uint16_t i = 0U; - if (spi_slave_dma_tx_position > 227U) /* Reset position after the end of the buffer */ + for(i = 0U; i < len; i++) { - spi_slave_dma_tx_position = 0U; + data[i] = spi_slave_dma_rx_data[i]; + spi_slave_dma_rx_data[i] = 0xFFU; /* Clear after read */ } } -void spi_slave_dma_read(uint8_t *data, uint16_t len) +void spi_slave_dma_change_transfer_size(uint16_t transfer_size) { - uint16_t i = 0U; + DMA_disableTransfers(DMA_CHANNEL_0); + DMA_disableTransfers(DMA_CHANNEL_1); - if ((spi_slave_dma_rx_data[spi_slave_dma_rx_position] != 0xFFU)) - { - for(i = 0U; i < len; i++) - { - data[i] = spi_slave_dma_rx_data[spi_slave_dma_rx_position]; + USCI_A_SPI_disable(USCI_A2_BASE); + USCI_A_SPI_enable(USCI_A2_BASE); - spi_slave_dma_rx_data[spi_slave_dma_rx_position] = 0xFFU; /* Clear after read */ + DMA_setSrcAddress(DMA_CHANNEL_0, (uint32_t)(uintptr_t)spi_slave_dma_tx_data, DMA_DIRECTION_INCREMENT); // cppcheck-suppress misra-c2012-11.4 + DMA_setDstAddress(DMA_CHANNEL_1, (uint32_t)(uintptr_t)spi_slave_dma_rx_data, DMA_DIRECTION_INCREMENT); // cppcheck-suppress misra-c2012-11.4 - spi_slave_dma_rx_position++; + DMA_setTransferSize(DMA_CHANNEL_0, transfer_size); + DMA_setTransferSize(DMA_CHANNEL_1, transfer_size); - if (spi_slave_dma_rx_position > 227U) - { - spi_slave_dma_rx_position = 0U; /* Reset position after the end of the buffer */ - } - } - } + DMA_enableTransfers(DMA_CHANNEL_0); + DMA_enableTransfers(DMA_CHANNEL_1); - else - { - for (i=0U; i < len; i++) - { - data[i] = 0xFFU; - } - } } + static int spi_slave_setup_gpio(spi_port_t port) { int err = 0; diff --git a/firmware/drivers/spi_slave/spi_slave.h b/firmware/drivers/spi_slave/spi_slave.h index cf84111e..c1a0613b 100644 --- a/firmware/drivers/spi_slave/spi_slave.h +++ b/firmware/drivers/spi_slave/spi_slave.h @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2022/05/21 + * \date 2024/04/22 * * \defgroup spi_slave SPI_SLAVE * \ingroup drivers @@ -84,6 +84,8 @@ void spi_slave_dma_write(uint8_t *data, uint16_t len); */ void spi_slave_dma_read(uint8_t *data, uint16_t len); +void spi_slave_dma_change_transfer_size(uint16_t transfer_size); + /** * \brief Enables SPI Slave port interruption. * diff --git a/firmware/tests/devices/Makefile b/firmware/tests/devices/Makefile index b3034f29..507ecc7b 100644 --- a/firmware/tests/devices/Makefile +++ b/firmware/tests/devices/Makefile @@ -22,7 +22,7 @@ TEMP_SENSOR_TEST_FLAGS=$(FLAGS),--wrap=adc_init,--wrap=adc_read,--wrap=adc_temp_ ANTENNA_TEST_FLAGS=$(FLAGS),--wrap=isis_antenna_init,--wrap=isis_antenna_get_data,--wrap=isis_antenna_arm,--wrap=isis_antenna_disarm,--wrap=isis_antenna_start_sequential_deploy,--wrap=isis_antenna_start_independent_deploy,--wrap=isis_antenna_read_deployment_status_code,--wrap=isis_antenna_read_deployment_status,--wrap=isis_antenna_get_antenna_status,--wrap=isis_antenna_get_antenna_timeout,--wrap=isis_antenna_get_burning,--wrap=isis_antenna_get_arming_status,--wrap=isis_antenna_get_raw_temperature,--wrap=isis_antenna_raw_to_temp_c,--wrap=isis_antenna_get_temperature_c,--wrap=isis_antenna_delay_s,--wrap=isis_antenna_delay_ms -RADIO_TEST_FLAGS=$(FLAGS),--wrap=si446x_init,--wrap=si446x_reg_config,--wrap=si446x_power_on_reset,--wrap=si446x_tx_packet,--wrap=si446x_tx_long_packet,--wrap=si446x_rx_packet,--wrap=si446x_rx_init,--wrap=si446x_check_device,--wrap=si446x_check_cts,--wrap=si446x_set_tx_power,--wrap=si446x_set_properties,--wrap=si446x_get_properties,--wrap=si446x_set_config,--wrap=si446x_set_preamble_len,--wrap=si446x_set_sync_word,--wrap=si446x_set_gpio_mode,--wrap=si446x_set_cmd,--wrap=si446x_get_cmd,--wrap=si446x_set_tx_interrupt,--wrap=si446x_set_rx_interrupt,--wrap=si446x_clear_interrupts,--wrap=si446x_write_tx_fifo,--wrap=si446x_read_rx_fifo,--wrap=si446x_fifo_reset,--wrap=si446x_enter_tx_mode,--wrap=si446x_enter_rx_mode,--wrap=si446x_enter_standby_mode,--wrap=si446x_wait_nirq,--wrap=si446x_wait_packet_sent,--wrap=si446x_wait_gpio1,--wrap=si446x_spi_init,--wrap=si446x_spi_enable,--wrap=si446x_spi_disable,--wrap=si446x_spi_write,--wrap=si446x_spi_read,--wrap=si446x_spi_transfer,--wrap=si446x_gpio_init,--wrap=si446x_gpio_set_pin,--wrap=si446x_gpio_clear_pin,--wrap=si446x_gpio_get_pin,--wrap=si446x_delay_s,--wrap=si446x_delay_ms,--wrap=si446x_delay_us,--wrap=led_set,--wrap=led_clear +RADIO_TEST_FLAGS=$(FLAGS),--wrap=si446x_init,--wrap=si446x_reg_config,--wrap=si446x_power_on_reset,--wrap=si446x_tx_packet,--wrap=si446x_tx_long_packet,--wrap=si446x_rx_packet,--wrap=si446x_rx_init,--wrap=si446x_check_device,--wrap=si446x_check_cts,--wrap=si446x_set_tx_power,--wrap=si446x_set_properties,--wrap=si446x_get_properties,--wrap=si446x_set_config,--wrap=si446x_set_preamble_len,--wrap=si446x_set_sync_word,--wrap=si446x_set_gpio_mode,--wrap=si446x_set_cmd,--wrap=si446x_get_cmd,--wrap=si446x_set_tx_interrupt,--wrap=si446x_set_rx_interrupt,--wrap=si446x_clear_interrupts,--wrap=si446x_write_tx_fifo,--wrap=si446x_read_rx_fifo,--wrap=si446x_fifo_reset,--wrap=si446x_enter_tx_mode,--wrap=si446x_enter_rx_mode,--wrap=si446x_enter_standby_mode,--wrap=si446x_wait_nirq,--wrap=si446x_wait_packet_sent,--wrap=si446x_wait_gpio1,--wrap=si446x_spi_init,--wrap=si446x_spi_enable,--wrap=si446x_spi_disable,--wrap=si446x_spi_write,--wrap=si446x_spi_read,--wrap=si446x_spi_transfer,--wrap=si446x_gpio_init,--wrap=si446x_gpio_set_pin,--wrap=si446x_gpio_clear_pin,--wrap=si446x_gpio_get_pin,--wrap=si446x_delay_s,--wrap=si446x_delay_ms,--wrap=si446x_delay_us,--wrap=led_set,--wrap=led_clear,--wrap=si446x_mutex_take,--wrap=si446x_mutex_give POWER_SENSOR_TEST_FLAGS=$(FLAGS),--wrap=ina22x_init,--wrap=ina22x_configuration,--wrap=ina22x_calibration,--wrap=ina22x_write_reg,--wrap=ina22x_read_reg,--wrap=ina22x_get_current_A,--wrap=ina22x_get_voltage_V,--wrap=ina22x_get_power_W,--wrap=ina22x_get_manufacturer_id,--wrap=ina22x_get_die_id @@ -30,7 +30,7 @@ LEDS_TEST_FLAGS=$(FLAGS),--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_ MEDIA_TEST_FLAGS=$(FLAGS),--wrap=flash_init,--wrap=flash_write,--wrap=flash_write_single,--wrap=flash_read_single,--wrap=flash_write_long,--wrap=flash_read_long,--wrap=flash_erase -OBDH_TEST_FLAGS=$(FLAGS),--wrap=spi_slave_init,--wrap=spi_slave_dma_write,--wrap=spi_slave_dma_read,--wrap=spi_slave_enable_isr,--wrap=spi_slave_disable_isr,--wrap=spi_slave_read_available,--wrap=spi_slave_read,--wrap=spi_slave_write,--wrap=spi_slave_flush,--wrap=spi_slave_bytes_not_sent +OBDH_TEST_FLAGS=$(FLAGS),--wrap=spi_slave_init,--wrap=spi_slave_dma_write,--wrap=spi_slave_dma_read,--wrap=spi_slave_enable_isr,--wrap=spi_slave_disable_isr,--wrap=spi_slave_read_available,--wrap=spi_slave_read,--wrap=spi_slave_write,--wrap=spi_slave_flush,--wrap=spi_slave_bytes_not_sent,--wrap=spi_slave_dma_change_transfer_size EPS_TEST_FLAGS=$(FLAGS),--wrap=uart_init,--wrap=uart_write,--wrap=uart_read,--wrap=uart_rx_enable,--wrap=uart_rx_disable,--wrap=uart_read_available,--wrap=uart_flush diff --git a/firmware/tests/devices/obdh_test.c b/firmware/tests/devices/obdh_test.c index c5f996cc..99ee335a 100644 --- a/firmware/tests/devices/obdh_test.c +++ b/firmware/tests/devices/obdh_test.c @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2023/02/17 + * \date 2024/04/22 * * \defgroup obdh_unit_test OBDH * \ingroup tests @@ -56,7 +56,7 @@ void generate_random_request(uint8_t *request); void generate_random_packet(uint8_t *packet, uint16_t len); -void generate_random_response(uint8_t *response); +void generate_random_response(obdh_response_t *response); /* OBDH Configuration */ spi_config_t spi_config = {0U, SPI_MODE_0}; @@ -83,6 +83,9 @@ static void obdh_read_request_test(void **state) uint8_t request[7] = {0}; uint16_t i = 0; + /* obdh_write_read_bytes */ + uint8_t buffer[230]; + generate_random_request(request); obdh_request.command = request[1]; @@ -119,15 +122,16 @@ static void obdh_read_request_test(void **state) obdh_request.data.data_packet.len = request[2]; - /* obdh_write_read_bytes */ - uint8_t buffer[230]; + buffer[0] = 0x7EU; - for(i = 0U; i < 230; i++) + for(i = 1U; i < 230; i++) { buffer[i] = 0x00U; } - dummy = request[2] + 2U; + expect_value(__wrap_spi_slave_dma_change_transfer_size, transfer_size, request[2] + 3); + + dummy = request[2] + 3U; expect_memory(__wrap_spi_slave_dma_write, data, buffer, (int)dummy); expect_value(__wrap_spi_slave_dma_write, len, dummy); @@ -143,6 +147,8 @@ static void obdh_read_request_test(void **state) will_return(__wrap_spi_slave_dma_read, obdh_request.data.data_packet.packet[i]); } + expect_value(__wrap_spi_slave_dma_change_transfer_size, transfer_size, 7U); + break; case CMDPR_CMD_READ_FIRST_PACKET: obdh_request.data.data_packet.len = request[2]; @@ -168,22 +174,26 @@ static void obdh_send_response_test(void **state) obdh_response_t obdh_response; uint8_t response[7]; - generate_random_response(response); + uint8_t transmission_buffer[70U]; + uint8_t transmission_buffer_p; - response[1] = CMDPR_CMD_READ_PARAM; - response[2] = CMDPR_PARAM_FW_VER; + generate_random_response(&(obdh_response)); - obdh_response.command = response[1]; + printf("obdh_command: %d\n", obdh_response.command); + printf("obdh_param:%d\n", obdh_response.parameter); + + response[0] = 0x7EU; + response[1] = obdh_response.command; switch(obdh_response.command) { case CMDPR_CMD_READ_PARAM: - obdh_response.parameter = response[2]; + response[2] = obdh_response.parameter; switch(cmdpr_param_size(obdh_response.parameter)) { case 1: - obdh_response.data.param_8 = response[3]; + response[3] = obdh_response.data.param_8; for(i = 4; i < 7; i++) { @@ -213,12 +223,37 @@ static void obdh_send_response_test(void **state) if (err == 0) { - expect_memory(__wrap_spi_slave_dma_write, data, &response[1], 6); - expect_value(__wrap_spi_slave_dma_write, len, 6); + expect_memory(__wrap_spi_slave_dma_write, data, response, 7U); + expect_value(__wrap_spi_slave_dma_write, len, (uint16_t) 7); } break; case CMDPR_CMD_READ_FIRST_PACKET: + err = -1; + + if ((obdh_response.data.data_packet.len + 2) < 70U) + { + + expect_value(__wrap_spi_slave_dma_change_transfer_size, transfer_size, (obdh_response.data.data_packet.len + 2)); + + transmission_buffer[0] = 0x7EU; + transmission_buffer[1] = 0x04U; + + for (transmission_buffer_p = 0U; transmission_buffer_p < obdh_response.data.data_packet.len; transmission_buffer_p++) + { + transmission_buffer[transmission_buffer_p + 2U] = obdh_response.data.data_packet.packet[transmission_buffer_p]; + } + + expect_memory(__wrap_spi_slave_dma_write, data, transmission_buffer, (obdh_response.data.data_packet.len + 2)); + expect_value(__wrap_spi_slave_dma_write, len, obdh_response.data.data_packet.len + 2); + + expect_value(__wrap_spi_slave_dma_read, len, (obdh_response.data.data_packet.len + 2)); + + expect_value(__wrap_spi_slave_dma_change_transfer_size, transfer_size, 7U); + + err = 0; + } + break; default: err = -1; @@ -226,7 +261,7 @@ static void obdh_send_response_test(void **state) break; } - assert_int_equal(obdh_send_response(&(obdh_response)), err); + assert_int_equal((int) obdh_send_response(&(obdh_response)), err); } int main(void) @@ -271,27 +306,35 @@ void generate_random_packet(uint8_t *packet, uint16_t len) } } -void generate_random_response(uint8_t *response) +void generate_random_response(obdh_response_t *response) { - uint8_t i; - response[0] = 0xE7; uint8_t answer_commands[] = {CMDPR_CMD_READ_PARAM, CMDPR_CMD_READ_FIRST_PACKET}; - response[1] = answer_commands[rand()%2]; + response->command = answer_commands[rand()%2]; - if (response[1] == CMDPR_CMD_READ_PARAM) + if (response->command == CMDPR_CMD_READ_PARAM) { - response[2] = (uint8_t)(rand()%24); - /* Random values */ - for(i = 3; i < 7; i ++) + response->parameter = (uint8_t)(rand()%24); + + switch(cmdpr_param_size(response->parameter)) { - /* From 0x00 to 0xFF */ - response[i] = (uint8_t)(rand() % 0x100); + case 1: + response->data.param_8 = (uint8_t)(rand() % 0x100); + + break; + case 2: + response->data.param_16 = (uint16_t)(rand() % 0x10000); + + break; + case 4: + response->data.param_32 = (uint32_t)(rand() % 0x100000000); + + break; } } - else if(response[1] == CMDPR_CMD_READ_FIRST_PACKET) + else if(response->command == CMDPR_CMD_READ_FIRST_PACKET) { - response[2] = (uint8_t)(rand() % max_packet_size + 1); + response->data.data_packet.len = (uint8_t)(rand() % max_packet_size + 1); } } diff --git a/firmware/tests/devices/radio_test.c b/firmware/tests/devices/radio_test.c index f90d61c0..bd614bd9 100644 --- a/firmware/tests/devices/radio_test.c +++ b/firmware/tests/devices/radio_test.c @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.2.12 + * \version 0.5.1 * - * \date 2021/02/21 + * \date 2024/04/25 * * \defgroup radio_unit_test Radio * \ingroup tests @@ -63,6 +63,8 @@ static void radio_send_test(void **state) uint8_t data[50] = {0}; uint16_t len = 50; + will_return(__wrap_si446x_mutex_take, 0); + expect_value(__wrap_led_set, l, LED_DOWNLINK); will_return(__wrap_led_set, 0); @@ -79,6 +81,8 @@ static void radio_send_test(void **state) expect_value(__wrap_led_clear, l, LED_DOWNLINK); will_return(__wrap_led_clear, 0); + will_return(__wrap_si446x_mutex_give, 0); + assert_return_code(radio_send(data, len), 0); } @@ -89,6 +93,8 @@ static void radio_recv_test(void **state) uint32_t timeout_ms = 100; uint16_t i; + will_return(__wrap_si446x_mutex_take, 0); + will_return(__wrap_si446x_wait_nirq, true); expect_value(__wrap_si446x_rx_packet, rx_buf, data); @@ -104,13 +110,19 @@ static void radio_recv_test(void **state) will_return(__wrap_si446x_rx_init, true); + will_return(__wrap_si446x_mutex_give, 0); + assert_return_code(radio_recv(data, len, timeout_ms), len); } static void radio_sleep_test(void **state) { + will_return(__wrap_si446x_mutex_take, 0); + will_return(__wrap_si446x_enter_standby_mode, 0); + will_return(__wrap_si446x_mutex_give, 0); + assert_return_code(radio_sleep(), 0); } diff --git a/firmware/tests/drivers/Makefile b/firmware/tests/drivers/Makefile index 28e9206e..2b6fd073 100644 --- a/firmware/tests/drivers/Makefile +++ b/firmware/tests/drivers/Makefile @@ -34,8 +34,8 @@ isis_antenna_test: $(BUILD_DIR)/isis_antenna.o $(BUILD_DIR)/isis_antenna_delay.o $(CC) $(ISIS_ANTENNA_TEST_FLAGS) $(BUILD_DIR)/isis_antenna.o $(BUILD_DIR)/isis_antenna_delay.o $(BUILD_DIR)/isis_antenna_i2c.o $(BUILD_DIR)/isis_antenna_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/tca4311a_wrap.o $(BUILD_DIR)/task.o -o $(BUILD_DIR)/$(TARGET_ISIS_ANTENNA) -lm -lcmocka .PHONY: si446x_test -si446x_test: $(BUILD_DIR)/si446x.o $(BUILD_DIR)/si446x_delay.o $(BUILD_DIR)/si446x_gpio.o $(BUILD_DIR)/si446x_spi.o $(BUILD_DIR)/si446x_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o - $(CC) $(SI446X_TEST_FLAGS) $(BUILD_DIR)/si446x.o $(BUILD_DIR)/si446x_delay.o $(BUILD_DIR)/si446x_gpio.o $(BUILD_DIR)/si446x_spi.o $(BUILD_DIR)/si446x_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o -o $(BUILD_DIR)/$(TARGET_SI446X) -lm -lcmocka +si446x_test: $(BUILD_DIR)/si446x.o $(BUILD_DIR)/si446x_delay.o $(BUILD_DIR)/si446x_gpio.o $(BUILD_DIR)/si446x_spi.o $(BUILD_DIR)/si446x_mutex.o $(BUILD_DIR)/si446x_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o $(BUILD_DIR)/semphr.o + $(CC) $(SI446X_TEST_FLAGS) $(BUILD_DIR)/si446x.o $(BUILD_DIR)/si446x_delay.o $(BUILD_DIR)/si446x_gpio.o $(BUILD_DIR)/si446x_spi.o $(BUILD_DIR)/si446x_mutex.o $(BUILD_DIR)/si446x_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/spi_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/task.o $(BUILD_DIR)/semphr.o -o $(BUILD_DIR)/$(TARGET_SI446X) -lm -lcmocka .PHONY: ina22x_test ina22x_test: $(BUILD_DIR)/ina22x.o $(BUILD_DIR)/ina22x_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/i2c_wrap.o @@ -67,6 +67,9 @@ $(BUILD_DIR)/si446x_delay.o: ../../drivers/si446x/si446x_delay.c $(BUILD_DIR)/si446x_gpio.o: ../../drivers/si446x/si446x_gpio.c $(CC) $(SI446X_TEST_FLAGS) -c $< -o $@ +$(BUILD_DIR)/si446x_mutex.o: ../../drivers/si446x/si446x_mutex.c + $(CC) $(SI446X_TEST_FLAGS) -c $< -o $@ + $(BUILD_DIR)/si446x_spi.o: ../../drivers/si446x/si446x_spi.c $(CC) $(SI446X_TEST_FLAGS) -c $< -o $@ @@ -120,6 +123,9 @@ $(BUILD_DIR)/tca4311a_wrap.o: ../mockups/drivers/tca4311a_wrap.c $(BUILD_DIR)/task.o: ../freertos_sim/task.c $(CC) $(FLAGS) -c $< -o $@ +$(BUILD_DIR)/semphr.o: ../freertos_sim/semphr.c + $(CC) $(FLAGS) -c $< -o $@ + .PHONY: clean clean: rm $(BUILD_DIR)/$(TARGET_TCA4311A) $(BUILD_DIR)/$(TARGET_ISIS_ANTENNA) $(BUILD_DIR)/$(TARGET_SI446X) $(BUILD_DIR)/$(TARGET_INA22X) $(BUILD_DIR)/$(TARGET_TPS382X) $(BUILD_DIR)/*.o diff --git a/firmware/tests/drivers/si446x_test.c b/firmware/tests/drivers/si446x_test.c index 591a3e39..9c21e3f4 100644 --- a/firmware/tests/drivers/si446x_test.c +++ b/firmware/tests/drivers/si446x_test.c @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.1.23 + * \version 0.5.1 * - * \date 2021/09/04 + * \date 2024/04/22 * * \defgroup si446x_unit_test Si446x * \ingroup tests @@ -44,7 +44,15 @@ #include #include -#include +#include + +#if defined(RADIO_MODULE) && (RADIO_MODULE == 0) +#include + +#elif defined(RADIO_MODULE) && (RADIO_MODULE == 1) +#include +#endif + #include #include #include diff --git a/firmware/tests/freertos_sim/semphr.c b/firmware/tests/freertos_sim/semphr.c new file mode 100644 index 00000000..d3c34872 --- /dev/null +++ b/firmware/tests/freertos_sim/semphr.c @@ -0,0 +1,50 @@ +/* + * semphr.c + * + * Copyright (C) 2021, SpaceLab. + * + * This file is part of TTC 2.0. + * + * TTC 2.0 it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TTC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with TTC 2.0. If not, see . + * + */ + +/** + * \brief FreeRTOS semphr simulation implementation. + * + * \author Miguel Boing + * + * \version 0.5.1 + * + * \date 2024/04/25 + * + * \addtogroup semphr_sim + * \{ + */ +#include "semphr.h" + +SemaphoreHandle_t xSemaphoreCreateMutex(void) +{ + return (SemaphoreHandle_t) 0x01; +} +BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xBlockTime) +{ + return pdTRUE; +} + +BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) +{ + return pdTRUE; +} + +/** \} End of semphr_sim group */ \ No newline at end of file diff --git a/firmware/tests/freertos_sim/semphr.h b/firmware/tests/freertos_sim/semphr.h new file mode 100644 index 00000000..18336f7b --- /dev/null +++ b/firmware/tests/freertos_sim/semphr.h @@ -0,0 +1,59 @@ +/* + * semphr.h + * + * Copyright (C) 2021, SpaceLab. + * + * This file is part of TTC 2.0. + * + * TTC 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TTC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with TTC 2.0. If not, see . + * + */ + +/** + * \brief FreeRTOS semphr simulation definition. + * + * \author Miguel Boing + * + * \version 5.1.0 + * + * \date 2024/04/25 + * + * \defgroup semphr_sim FreeRTOS semphr + * \ingroup tests + * \{ + */ + +#ifndef SEMPHR_SIM_H_ +#define SEMPHR_SIM_H_ + +#include +#include "FreeRTOS.h" + +typedef enum +{ + pdFALSE=0x00, + pdTRUE=0x01, +}BaseType_t; + +typedef int* SemaphoreHandle_t; + +SemaphoreHandle_t xSemaphoreCreateMutex(void); + +BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xBlockTime); + +BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore); + +#endif /* SEMPHR_SIM_H_ */ + +/** \} End of semphr_sim group */ \ No newline at end of file diff --git a/firmware/tests/mockups/drivers/si446x_wrap.c b/firmware/tests/mockups/drivers/si446x_wrap.c index 60edb272..9951d503 100644 --- a/firmware/tests/mockups/drivers/si446x_wrap.c +++ b/firmware/tests/mockups/drivers/si446x_wrap.c @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.1.23 + * \version 0.5.1 * - * \date 2021/04/27 + * \date 2024/04/22 * * \addtogroup si446x_wrap * \{ @@ -349,4 +349,14 @@ void __wrap_si446x_delay_us(uint32_t us) check_expected(us); } +int __wrap_si446x_mutex_take(void) +{ + return mock_type(int); +} + +int __wrap_si446x_mutex_give(void) +{ + return mock_type(int); +} + /** \} End of si446x_wrap group */ diff --git a/firmware/tests/mockups/drivers/si446x_wrap.h b/firmware/tests/mockups/drivers/si446x_wrap.h index 7f61f918..59ed4a0f 100644 --- a/firmware/tests/mockups/drivers/si446x_wrap.h +++ b/firmware/tests/mockups/drivers/si446x_wrap.h @@ -25,9 +25,9 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.1.23 + * \version 0.5.1 * - * \date 2021/04/27 + * \date 2024/04/22 * * \defgroup si446x_wrap Si446x Wrap * \ingroup tests @@ -128,6 +128,10 @@ void __wrap_si446x_delay_ms(uint16_t ms); void __wrap_si446x_delay_us(uint32_t us); +int __wrap_si446x_mutex_give(void); + +int __wrap_si446x_mutex_take(void); + #endif /* SI446X_WRAP_H_ */ /** \} End of si446x_wrap group */ diff --git a/firmware/tests/mockups/drivers/spi_slave_wrap.c b/firmware/tests/mockups/drivers/spi_slave_wrap.c index d5cc260a..258163c2 100644 --- a/firmware/tests/mockups/drivers/spi_slave_wrap.c +++ b/firmware/tests/mockups/drivers/spi_slave_wrap.c @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2022/05/22 + * \date 2024/04/22 * * \addtogroup spi_slave_wrap * \{ @@ -127,11 +127,16 @@ int __wrap_spi_slave_flush(spi_port_t port) return mock_type(int); } -uint16_t spi_slave_bytes_not_sent(spi_port_t port) +uint16_t __wrap_spi_slave_bytes_not_sent(spi_port_t port) { check_expected(port); return mock_type(uint16_t); } +void __wrap_spi_slave_dma_change_transfer_size(uint16_t transfer_size) +{ + check_expected(transfer_size); +} + /** \} End of spi_slave_wrap group */ diff --git a/firmware/tests/mockups/drivers/spi_slave_wrap.h b/firmware/tests/mockups/drivers/spi_slave_wrap.h index bc53b60d..cd1ef8cb 100644 --- a/firmware/tests/mockups/drivers/spi_slave_wrap.h +++ b/firmware/tests/mockups/drivers/spi_slave_wrap.h @@ -25,9 +25,9 @@ * * \author Miguel Boing * - * \version 0.4.5 + * \version 0.5.1 * - * \date 2021/08/25 + * \date 2024/04/22 * * \defgroup spi_slave_wrap SPI Slave Wrap * \ingroup tests @@ -58,7 +58,9 @@ int __wrap_spi_slave_write(spi_port_t port, uint8_t *data, uint16_t len); int __wrap_spi_slave_flush(spi_port_t port); -uint16_t spi_slave_bytes_not_sent(spi_port_t port); +uint16_t __wrap_spi_slave_bytes_not_sent(spi_port_t port); + +void __wrap_spi_slave_dma_change_transfer_size(uint16_t transfer_size); #endif /* SPI_WRAP_H_ */