Skip to content
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

Add command to read firmware version #155

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
// 0 1 GET_CTMU_VOLTAGE 2 GET_CAPACITANCE 3 GET_FREQUENCY
Undefined, MULTIMETER_GetCTMUVolts, MULTIMETER_GetCapacitance, Unimplemented,
// 4 GET_INDUCTANCE 5 GET_VERSION 6 7
Unimplemented, DEVICE_GetVersion, Undefined, Undefined,
Unimplemented, DEVICE_GetVersion, DEVICE_get_fw_version, Undefined,
// 8 RETRIEVE_BUFFER 9 GET_HIGH_FREQUENCY 10 CLEAR_BUFFER 11 SET_RGB1
BUFFER_Retrieve, Unimplemented, BUFFER_Clear, Removed,
// 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/device.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
#include <stdint.h>
#include <stddef.h>

#include "../bus/uart/uart.h"
#include "../commands.h"
#include "../registers/system/pin_manager.h"
#include "../registers/system/watchdog.h"

#define SEMVERS 3

const uint8_t VERSION_HW[] = "PSLab V6"; /** Hardware version. **/
union {
struct {
uint8_t const major;
uint8_t const minor;
uint8_t const patch;
};
uint8_t const version[SEMVERS];
} VERSION_FW = {{
.major = 3,
.minor = 0,
.patch = 0
}};

response_t DEVICE_GetVersion(void) {
uint8_t i;
Expand All @@ -14,6 +29,13 @@ response_t DEVICE_GetVersion(void) {
return DO_NOT_BOTHER;
}

response_t DEVICE_get_fw_version(void) {
for (size_t i = 0; i < SEMVERS; ++i) {
UART1_Write(VERSION_FW.version[i]);
}
return DO_NOT_BOTHER;
}

response_t DEVICE_Reset(void) {
__asm__ volatile ("reset");
return DO_NOT_BOTHER;
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ extern "C" {
*/
response_t DEVICE_GetVersion(void);

/**
* @brief Get firmware version.
* @return MAJOR (uint8_t), MINOR (uint8_t), PATCH (uint8_t)
*/
response_t DEVICE_get_fw_version(void);

/**
* @brief Reset the device by moving program counter to 0x0000
* @return DO_NOT_BOTHER
Expand Down