diff --git a/Core/Inc/commands.h b/Core/Inc/commands.h index a5994a0..36bf227 100644 --- a/Core/Inc/commands.h +++ b/Core/Inc/commands.h @@ -23,6 +23,7 @@ extern RTC_HandleTypeDef hrtc; int do_help(char *args); int do_devid(char *args); int do_info(char *args); +int do_sinfo(char *args); int do_test(/*command_inst_t inst,*/ char *args); int do_time(char *args); diff --git a/Core/Inc/stm32_si5351.h b/Core/Inc/stm32_si5351.h index e4f2fe9..96dc5f5 100644 --- a/Core/Inc/stm32_si5351.h +++ b/Core/Inc/stm32_si5351.h @@ -155,6 +155,8 @@ char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize, int si5351_write_data(si5351_inst_t inst, void * data); int si5351_read_data(si5351_inst_t inst, void * data); +int si5351_get_instance(si5351_inst_t *inst); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/Core/Src/commands.c b/Core/Src/commands.c index b420ab5..11b1b81 100644 --- a/Core/Src/commands.c +++ b/Core/Src/commands.c @@ -16,6 +16,7 @@ #include //strchr #include //bsearch #include "helper.h" //ltrim +#include "stm32_si5351.h" #include "commands.h" @@ -55,7 +56,8 @@ static const cmd_table_t cmd_table[] = { {"help", 1, CMD_NO_FLAG, do_help }, {"hidden", 2, CMD_HIDDEN, do_test }, {"info", 1, CMD_NO_FLAG, do_info }, - {"secret", 1, CMD_SECRET, do_test }, + {"sinfo", 1, CMD_SECRET, do_sinfo }, + {"time", 1, CMD_NO_FLAG, do_time }, }; @@ -156,6 +158,20 @@ int do_info(char *args) { return 0; } +int do_sinfo(char *args) { + int rv = 0; + (void)args; + si5351_inst_t inst = NULL; + rv = si5351_get_instance(&inst); + printf("%d Si5351 instance%s found.\n", rv, (rv==1)?"":"s"); + while (rv > 0) { + printf("Si5351 Handle: 0x%08lx\n", (uint32_t)inst); + + rv = si5351_get_instance(&inst); + } + return rv; +} + int do_time(char *args) { HAL_StatusTypeDef status; diff --git a/Core/Src/stm32_si5351.c b/Core/Src/stm32_si5351.c index 3122056..ae4ff9d 100644 --- a/Core/Src/stm32_si5351.c +++ b/Core/Src/stm32_si5351.c @@ -112,7 +112,7 @@ typedef struct { /* Private variables ---------------------------------------------------------*/ si5351_HandleTypeDef * first_handle = NULL; /* pointer to the first instance */ -int si5351_errno = 0; /* error_number for functions whith return == NULL */ +int si5351_errno = 0; /* error_number for functions with return == NULL */ /* Private function prototypes -----------------------------------------------*/ #ifdef DEBUG @@ -932,3 +932,31 @@ char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize, return buf; } #endif //DEBUG + +/* some additional functions */ +/** @brief Function to get the handle of a si5351 device instance + * @param si5351_instance Given si5351 device handle or NULL for the first handle. + * @return si5351_inst_t handle + * @retval NULL when not found + */ +int si5351_get_instance(si5351_inst_t *inst) { + + si5351_inst_t tinst; + int rv = 0; + + if (!inst) + return -EINVAL; + + if (!(*inst)) + *inst = first_handle; + else + *inst = (*inst)->next; + + tinst = *inst; + while (tinst) { + rv++; + tinst = tinst->next; + } + return rv; +} +