Skip to content

Refactor logic analyzer #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 7, 2025
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE external/cmake-microchip/toolchain.cmake)
set(MICROCHIP_MCU PIC24EP256GP204)
set(CMAKE_SYSTEM_NAME Generic)

project(PSLAB_FIRMWARE LANGUAGES C ASM)

Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ add_subdirectory(bus)
add_subdirectory(helpers)
add_subdirectory(instruments)
add_subdirectory(registers)
add_subdirectory(registers_ng)
add_subdirectory(sdcard)
add_subdirectory(transport)

target_sources(pslab-firmware.elf PRIVATE
commands.c
main.c
states.c)

target_include_directories(pslab-firmware.elf PRIVATE
$(CMAKE_CURRENT_SOURCE_DIR)
$(CMAKE_CURRENT_SOURCE_DIR)/registers_ng
$(CMAKE_CURRENT_SOURCE_DIR)/helpers
)
2 changes: 2 additions & 0 deletions src/bus/i2c/i2c.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "types.h"

#include "i2c.h"
#include "../../helpers/delay.h"
#include "../../registers/system/pin_manager.h"
Expand Down
2 changes: 2 additions & 0 deletions src/bus/i2c/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <stddef.h>
#include <xc.h>

#include "types.h"

#include "../../commands.h"

#define SLAVE_I2C_GENERIC_RETRY_MAX 100
Expand Down
2 changes: 2 additions & 0 deletions src/bus/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <stdlib.h>
#include <xc.h>

#include "types.h"

#include "../../commands.h"
#include "../../transport/packet_handler.h"

Expand Down
2 changes: 2 additions & 0 deletions src/bus/spi/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <stdint.h>
#include <xc.h>

#include "types.h"

#include "../../commands.h"

/// @brief SPI chip select multiplexer.
Expand Down
2 changes: 2 additions & 0 deletions src/bus/uart/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <xc.h>

#include "types.h"

#include "uart.h"
#include "../../helpers/delay.h"
#include "../../commands.h"
Expand Down
2 changes: 2 additions & 0 deletions src/bus/uart/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stdbool.h>
#include <stdint.h>

#include "types.h"

#include "../../commands.h"

/**
Expand Down
42 changes: 18 additions & 24 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@
#include "bus/uart/uart.h"
#include "bus/spi/spi.h"
#include "helpers/device.h"
#include "helpers/interval.h"
#include "helpers/light.h"
#include "helpers/rtc.h"
#include "instruments/logicanalyzer.h"
#include "instruments/multimeter.h"
#include "instruments/oscilloscope.h"
#include "instruments/logic_analyzer.h"
#include "instruments/powersource.h"
#include "instruments/sensors.h"
#include "instruments/wavegenerator.h"
#include "registers/system/pin_manager.h"
#include "instruments/sensors.h"
#include "registers/converters/ctmu.h"
#include "transport/uart2.h"

Expand Down Expand Up @@ -109,17 +103,17 @@ CmdFunc const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1] = {
},
{ // 2 ADC
// 0 1 CAPTURE_ONE 2 CAPTURE_TWO 3 CAPTURE_DMASPEED
Undefined, OSCILLOSCOPE_capture_one, OSCILLOSCOPE_capture_two, OSCILLOSCOPE_capture_dma,
Undefined, Removed, Removed, Removed,
// 4 CAPTURE_FOUR 5 CONFIGURE_TRIGGER 6 GET_CAPTURE_STATUS 7 FETCH_SAMPLES
OSCILLOSCOPE_capture_four, OSCILLOSCOPE_configure_trigger, OSCILLOSCOPE_get_capture_status, OSCILLOSCOPE_fetch_samples,
Removed, Removed, Removed, Removed,
// 8 SET_PGA_GAIN 9 GET_VOLTAGE 10 GET_VOLTAGE_SUMMED 11 START_ADC_STREAMING
OSCILLOSCOPE_set_pga_gain, MULTIMETER_get_voltage, MULTIMETER_get_voltage_summed, Removed,
Removed, Removed, Removed, Removed,
// 12 SELECT_PGA_CHANNEL 13 CAPTURE_12BIT 14 CAPTURE_MULTIPLE 15 SET_HI_CAPTURE
Unimplemented, Unimplemented, Removed, Removed,
// 16 SET_LO_CAPTURE 17 SET_HI_CAPTURE12 18 SET_LO_CAPTURE12 19 CAPTURE_DMASPEED12
Removed, Removed, Removed, Removed,
// 20 MULTIPOINT_CAPACITANCE 21 SET_CAP 22 PULSE_TRAIN 23 CAPTURE_THREE
Removed, MULTIMETER_charge_capacitor, Removed, OSCILLOSCOPE_capture_three,
Removed, Removed, Removed, Removed,
// 24 25 26 27
Undefined, Undefined, Undefined, Undefined,
},
Expand Down Expand Up @@ -189,15 +183,15 @@ CmdFunc const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1] = {
},
{ // 7 WAVEGEN
// 0 1 SET_WG 2 3 SET_SQR1
Undefined, Unimplemented, Undefined, WAVEGENERATOR_set_square_1,
Undefined, Unimplemented, Undefined, Removed,
// 4 SET_SQR2 5 SET_SQRS 6 7 SQR4
WAVEGENERATOR_set_square_2, Removed, Undefined, WAVEGENERATOR_set_square_all,
Removed, Removed, Undefined, Removed,
// 8 MAP_REFERENCE 9 SET_WG_PHASE 10 SET_WAVEFORM_TYPE 11 SELECT_FREQ_REGISTER
WAVEGENERATOR_map_reference, WAVEGENERATOR_set_sine_dual, Unimplemented, Unimplemented,
Removed, Removed, Unimplemented, Unimplemented,
// 12 DELAY_GENERATOR 13 SET_SINE1 14 SET_SINE2 15 LOAD_WAVEFORM1
Unimplemented, WAVEGENERATOR_set_sine_1, WAVEGENERATOR_set_sine_2, WAVEGENERATOR_load_wave_1,
Unimplemented, Removed, Removed, Removed,
// 16 LOAD_WAVEFORM2 17 SQR1_PATTERN 18 READ_WAVEFORM1 19 READ_WAVEFORM2
WAVEGENERATOR_load_wave_2, Removed, WAVEGENERATOR_read_wave_1, WAVEGENERATOR_read_wave_2,
Removed, Removed, Removed, Removed,
// 20 21 22 23
Undefined, Undefined, Undefined, Undefined,
// 24 25 26 27
Expand Down Expand Up @@ -239,33 +233,33 @@ CmdFunc const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1] = {
// 0 1 GET_TIMING 2 3
Undefined, Unimplemented, Undefined, Undefined,
// 4 START_ONE_CHAN_LA 5 START_TWO_CHAN_LA 6 START_FOUR_CHAN_LA 7 FETCH_DMA_DATA
LOGICANALYZER_one_channel, LOGICANALYZER_two_channel, LOGICANALYZER_four_channel, Removed,
LA_cmd_capture, Removed, Removed, LA_cmd_fetch,
// 8 FETCH_INT_DMA_DATA 9 FETCH_LONG_DMA_DATA 10 COMPARATOR_TO_LA 11 GET_INITIAL_STATES
Removed, Removed, Unimplemented, INTERVAL_get_state,
Removed, Removed, Unimplemented, LA_cmd_get_initial_states,
// 12 TIMING_MEASUREMENTS 13 INTERVAL_MEASUREMENTS 14 CONFIGURE_COMPARATOR 15 START_ALTERNATE_ONE_CHAN_LA
Unimplemented, Unimplemented, Removed, LOGICANALYZER_one_channel_alt,
// 16 START_THREE_CHAN_LA 17 STOP_LA 18 INTERVAL_FETCH_BUFFER 19
LOGICANALYZER_three_channel, LOGICANALYZER_stop, INTERVAL_fetch_buffer, Undefined,
Unimplemented, Unimplemented, Removed, Removed,
// 16 START_THREE_CHAN_LA 17 STOP_LA 18 19
Removed, LA_cmd_stop, Undefined, Undefined,
// 20 21 22 23
Undefined, Undefined, Undefined, Undefined,
// 24 25 26 27
Undefined, Undefined, Undefined, Undefined,
},
{ // 11 COMMON
// 0 1 GET_CTMU_VOLTAGE 2 GET_CAPACITANCE 3 GET_FREQUENCY
Undefined, MULTIMETER_get_ctmu_volts, MULTIMETER_get_capacitance, Unimplemented,
Undefined, Removed, Removed, Unimplemented,
// 4 GET_INDUCTANCE 5 GET_VERSION 6 GET_FW_VERSION 7 DEBUG_IS_ENABLED
Unimplemented, DEVICE_get_hw_version, DEVICE_get_fw_version, Removed,
// 8 RETRIEVE_BUFFER 9 GET_HIGH_FREQUENCY 10 CLEAR_BUFFER 11 SET_RGB1
Removed, Unimplemented, Removed, Removed,
// 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS
Removed, Removed, DEVICE_read_register, DEVICE_write_register,
// 16 GET_CAP_RANGE 17 SET_RGB2 18 READ_LOG 19 RESTORE_STANDALONE
MULTIMETER_get_cap_range, Removed, Removed, DEVICE_reset,
Removed, Removed, Removed, DEVICE_reset,
// 20 GET_ALTERNATE_HIGH_FREQUENCY 21 SET_RGB_COMMON 22 SET_RGB3 23 START_CTMU
Unimplemented, LIGHT_rgb_pin, Removed, CTMU_start,
// 24 STOP_CTMU 25 START_COUNTING 26 FETCH_COUNT 27 FILL_BUFFER
CTMU_stop, SENSORS_start_counter, SENSORS_get_counter, Removed,
CTMU_stop, Removed, Removed, Removed,
},
{ // 12 PASSTHROUGH
// 0 1 2 3
Expand Down
27 changes: 0 additions & 27 deletions src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,6 @@ extern "C" {
#define NUM_SDCARD_CMDS 3
#define NUM_SECONDARY_CMDS_MAX NUM_COMMON_CMDS // Change if necessary.

/** Function return codes. */
enum Status {
// No error.
E_OK,
// General error.
E_FAILED,
E_NOT_IMPLEMENTED,
// Errors related to resource acquisition.
E_RESOURCE_NOT_INITIALIZED,
E_RESOURCE_BUSY,
// Errors related to memory.
E_MEMORY_INSUFFICIENT,
// Errors related to user input.
E_BAD_COMMAND,
E_BAD_SIZE,
E_BAD_ARGSIZE,
E_BAD_ARGUMENT,
// Communication errors specific to UART bus.
E_UART_RX_FRAMING,
E_UART_RX_OVERRUN,
E_UART_RX_PARITY,
E_UART_RX_TIMEOUT,
E_UART_TX_TIMEOUT,
// Number of status codes.
STATUS_NUMEL
};

/**
* @brief Command functions provide the remote API available to connected hosts.
*
Expand Down
1 change: 0 additions & 1 deletion src/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
target_sources(pslab-firmware.elf PRIVATE
delay.c
device.c
interval.c
light.c
rtc.c
)
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/delay.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "types.h"
#include "delay.h"

// This include needs to be last, otherwise the linker can't find the
// __delay_ms and __delay_us functions.
#include <libpic30.h>

void DELAY_ms(unsigned long d) {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* FCY and import <libpic30.h>.
*/

#include "types.h"
#include "../registers/system/clock.h"

#define FCY (_XTAL_FREQ / 2)
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <stdlib.h>
#include <string.h>

#include "types.h"

#include "../bus/uart/uart.h"
#include "../commands.h"
#include "../registers/system/pin_manager.h"
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern "C" {
#endif

#include "types.h"

/**
* @brief Get hardware version.
* @return Hardware version string
Expand Down
Loading