si5351_get_instance, first sinfo command

This commit is contained in:
Thomas Kuschel 2022-07-16 05:09:05 +02:00
parent b50820b49e
commit 152ccf00e4
4 changed files with 49 additions and 2 deletions

View File

@ -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);

View File

@ -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

View File

@ -16,6 +16,7 @@
#include <string.h> //strchr
#include <stdlib.h> //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;

View File

@ -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;
}