CHG adding additional compiler warnings in Debug mode, corrections
This commit is contained in:
@ -143,18 +143,16 @@ int main(void)
|
||||
}
|
||||
|
||||
puts("Registers of Device No. 1");
|
||||
char buf[33]; //using uint8_t
|
||||
//char buf[42]; //using uint16_t
|
||||
//char buf[60]; //using uint32_t
|
||||
//for (int i=0; i <= SI5351_FANOUT_ENABLE; i++) {
|
||||
for (int i=0; i <= 255; i++) {
|
||||
char buf[33];
|
||||
|
||||
for (uint8_t i=0; i <= SI5351_FANOUT_ENABLE; i++) {
|
||||
puts(si5351_read_register_debug(instance_si5351[1], buf, sizeof(buf), i));
|
||||
}
|
||||
/*
|
||||
|
||||
status = si5351_program(instance_si5351[1]);
|
||||
printf("Device #1 gets status %d\n", status);
|
||||
printf("Debug:\n%s", si5351_read_debug_msg(instance_si5351[1]));
|
||||
*/
|
||||
|
||||
for (int i=2; i>=0; i--) {
|
||||
si5351_deinit(instance_si5351[i]);
|
||||
}
|
||||
@ -561,17 +559,17 @@ PUTCHAR_PROTOTYPE
|
||||
/* USER CODE END Header_StartDefaultTask */
|
||||
void StartDefaultTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
(void) argument; //unused argument
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
// HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
|
||||
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
|
||||
osDelay(1);
|
||||
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
|
||||
osDelay(1999);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_start_terminal_task */
|
||||
@ -583,13 +581,13 @@ void StartDefaultTask(void *argument)
|
||||
/* USER CODE END Header_start_terminal_task */
|
||||
void start_terminal_task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN start_terminal_task */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osDelay(1);
|
||||
}
|
||||
/* USER CODE END start_terminal_task */
|
||||
/* USER CODE BEGIN start_terminal_task */
|
||||
(void)argument;
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
osDelay(1);
|
||||
}
|
||||
/* USER CODE END start_terminal_task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_start_id_task */
|
||||
@ -601,24 +599,24 @@ void start_terminal_task(void *argument)
|
||||
/* USER CODE END Header_start_id_task */
|
||||
void start_id_task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN start_id_task */
|
||||
//uint8_t tx_buf[80];
|
||||
//int tx_buf_len;
|
||||
/* USER CODE BEGIN start_id_task */
|
||||
(void)argument; //unused argument
|
||||
//uint8_t tx_buf[80];
|
||||
//int tx_buf_len;
|
||||
/* check if the SI5351 is present */
|
||||
int status = HAL_I2C_IsDeviceReady(&hi2c1, SI5351_I2C_ADDR, 3, 10 /*HAL_MAX_DELAY*/ ); // HAL_MAX_DELAY is blocking, use 10 ms
|
||||
int status = HAL_I2C_IsDeviceReady(&hi2c1, SI5351_I2C_ADDR, 3, 10 /*HAL_MAX_DELAY*/ ); // HAL_MAX_DELAY is blocking, use 10 ms
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
printf("\n" PROGRAM_ID "\n");
|
||||
printf(AUTHOR_STRING "\n");
|
||||
if (status == HAL_OK) {
|
||||
printf("Si5351 device found.\n");
|
||||
} else {
|
||||
printf("Error: Could not detect Si5351 device.\n");
|
||||
}
|
||||
osDelay(30*60);
|
||||
}
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
printf("\n" PROGRAM_ID "\n");
|
||||
printf(AUTHOR_STRING "\n");
|
||||
if (status == HAL_OK)
|
||||
printf("Si5351 device found.\n");
|
||||
else
|
||||
printf("Error: Could not detect Si5351 device.\n");
|
||||
|
||||
osDelay(30*60);
|
||||
}
|
||||
/* USER CODE END start_id_task */
|
||||
}
|
||||
|
||||
|
@ -11,13 +11,12 @@
|
||||
******************************************************************************/
|
||||
|
||||
/* Defines for compilation ---------------------------------------------------*/
|
||||
#define DEBUG 1
|
||||
#define OPTIMIZED 1
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
// @TODO try to get rid off including the HAL here, using pointer to the specified functions
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
@ -70,6 +69,7 @@ static int si5351_error_status_i2c(HAL_StatusTypeDef status) {
|
||||
case HAL_TIMEOUT: return -ETIMEDOUT; break;
|
||||
case HAL_ERROR: return -EIO; break;
|
||||
case HAL_BUSY: return -EBUSY; break;
|
||||
case HAL_OK:
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@ -250,35 +250,34 @@ int si5351_program(si5351_inst_t inst) {
|
||||
break;
|
||||
|
||||
/* for debugging purpose, read out fanout enable register */
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
status = si5351_read(inst, SI5351_FANOUT_ENABLE, &data, 1);
|
||||
if (status)
|
||||
break;
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - cx, "(%d) FANOUT_ENABLE 0x%x\n", cx, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - cx, "(%d) FANOUT_ENABLE %d\n", cx, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - (size_t)cx, "(%d) FANOUT_ENABLE 0x%x\n", cx, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - (size_t)cx, "(%d) FANOUT_ENABLE %d\n", cx, data);
|
||||
#endif
|
||||
data = SI5351_CLKIN_FANOUT_EN | SI5351_XO_FANOUT_EN | SI5351_MS_FANOUT_EN; // set them to 1b
|
||||
status = si5351_write(inst, SI5351_FANOUT_ENABLE, &data, 1);
|
||||
if (status)
|
||||
break;
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
status = si5351_read(inst, SI5351_FANOUT_ENABLE, &data, 1);
|
||||
if (status)
|
||||
break;
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - cx, "(%d) FANOUT_ENABLE 0x%x\n", cx, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - cx, "(%d) FANOUT_ENABLE %d\n", cx, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - (size_t)cx, "(%d) FANOUT_ENABLE 0x%x\n", cx, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - (size_t)cx, "(%d) FANOUT_ENABLE %d\n", cx, data);
|
||||
#endif
|
||||
|
||||
/* Crystal Internal Load Capacitance */
|
||||
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
status = si5351_read(inst, SI5351_CRYSTAL_INTERNAL_LOAD_CAPACITANCE, &data, 1);
|
||||
if (status)
|
||||
break;
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - cx, "(%d) XTAL int. Load Cap: 0x%x (%dd)\n", cx, data, data);
|
||||
cx += snprintf(inst->debug_msg + cx, sizeof(inst->debug_msg) - (size_t)cx, "(%d) XTAL int. Load Cap: 0x%x (%dd)\n", cx, data, data);
|
||||
#endif
|
||||
|
||||
|
||||
} while(0);
|
||||
|
||||
|
||||
@ -302,7 +301,7 @@ char * si5351_read_debug_msg(si5351_inst_t inst) {
|
||||
* @param n amount of characters to output to
|
||||
* @param value Value to output in binary representation
|
||||
* @param size
|
||||
* @return bytes written
|
||||
* @return bytes written (int)
|
||||
*/
|
||||
int __snprintb(char *buf, size_t n, void *value, size_t size)
|
||||
{
|
||||
@ -312,24 +311,24 @@ int __snprintb(char *buf, size_t n, void *value, size_t size)
|
||||
int cx = 0;
|
||||
|
||||
bits[blen] = '\0';
|
||||
for_endian(size) {
|
||||
for_endian((int)size) {
|
||||
byte = ((uint8_t *) value)[i];
|
||||
memset(bits, '0', blen);
|
||||
for (int j = 0; byte && j < blen; ++j) {
|
||||
for (int j = 0; byte && j < (int)blen; ++j) {
|
||||
if (byte & 0x80)
|
||||
bits[j] = '1';
|
||||
byte <<= 1;
|
||||
}
|
||||
cx += snprintf(buf+cx, n-cx, "%s%s", bits, (last_loop_endian)? "":" ");
|
||||
cx += snprintf(buf + cx, n - (size_t)cx, "%s%s", bits, (last_loop_endian)? "":" ");
|
||||
}
|
||||
return cx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize, uint8_t regaddr) {
|
||||
|
||||
uint8_t data;
|
||||
// uint16_t data16;
|
||||
// uint32_t data32;
|
||||
int status;
|
||||
int cx;
|
||||
|
||||
@ -339,12 +338,10 @@ char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize,
|
||||
status = si5351_read(inst, regaddr, &data, 1);
|
||||
if (status)
|
||||
return NULL;
|
||||
// data16 = data;
|
||||
// data32 = data;
|
||||
|
||||
cx = snprintf(buf, bufsize, "R%03u[0x%02x]=%3u[0x%02x][0b", regaddr, regaddr, data, data);
|
||||
cx += snprintb(buf + cx, bufsize - cx, data);
|
||||
// cx += snprintb(buf + cx, bufsize - cx, data32);
|
||||
cx += snprintf(buf + cx, bufsize - cx, "]");
|
||||
cx += snprintb(buf + cx, bufsize - (size_t)cx, data);
|
||||
cx += snprintf(buf + cx, bufsize - (size_t)cx, "]");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user