kopia lustrzana https://github.com/espressif/esp-idf
feat(ulp-riscv): Add convenience print function that supports different widths
This commit adds a convenience function to print hex numbers of different widths on the ULP RISC-V core. Closes https://github.com/espressif/esp-idf/pull/13180pull/13431/head
rodzic
5e47ed70c2
commit
08dead4b31
|
@ -35,6 +35,14 @@ void ulp_riscv_print_str(const char *str);
|
||||||
*/
|
*/
|
||||||
void ulp_riscv_print_hex(int h);
|
void ulp_riscv_print_hex(int h);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prints a hex number with the specified number of digits. Does not print 0x, only the digits
|
||||||
|
*
|
||||||
|
* @param Hex number to print
|
||||||
|
* @param number_of_digits Number of digits to print.
|
||||||
|
*/
|
||||||
|
void ulp_riscv_print_hex_with_number_of_digits(int h, int number_of_digits);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,3 +60,38 @@ void ulp_riscv_print_hex(int h)
|
||||||
|
|
||||||
ULP_RISCV_EXIT_CRITICAL();
|
ULP_RISCV_EXIT_CRITICAL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ulp_riscv_print_hex_with_number_of_digits(int h, int number_of_digits)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
if (!s_print_ctx.putc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number_of_digits < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number_of_digits >= 8) {
|
||||||
|
ulp_riscv_print_hex(h);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Perform the bit-banged UART operation in a critical section */
|
||||||
|
ULP_RISCV_ENTER_CRITICAL();
|
||||||
|
|
||||||
|
// Does not print '0x', only the digits specified by the number_of_digits argument
|
||||||
|
for (x = 0; x < number_of_digits; x++) {
|
||||||
|
c = (h >> ((number_of_digits - 1) * 4)) & 0xf; // extract the leftmost byte
|
||||||
|
if (c < 10) {
|
||||||
|
s_print_ctx.putc(s_print_ctx.putc_ctx, '0' + c);
|
||||||
|
} else {
|
||||||
|
s_print_ctx.putc(s_print_ctx.putc_ctx, 'a' + c - 10);
|
||||||
|
}
|
||||||
|
h <<= 4; // move the 2nd leftmost byte to the left, to be extracted next
|
||||||
|
}
|
||||||
|
|
||||||
|
ULP_RISCV_EXIT_CRITICAL();
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue