127 lines
3.7 KiB
C
127 lines
3.7 KiB
C
/**
|
|
* Copyright (c) 2024 Wei-Lun Hsu. All Rights Reserved.
|
|
*/
|
|
/** @file syslog.c
|
|
*
|
|
* @author Wei-Lun Hsu
|
|
* @version 0.1
|
|
* @date 2024/08/29
|
|
* @license
|
|
* @description
|
|
*/
|
|
|
|
|
|
#include "hal_device.h"
|
|
#include "syslog.h"
|
|
//=============================================================================
|
|
// Constant Definition
|
|
//=============================================================================
|
|
#define CONFIG_LOG_MSG_DEVICE UART0
|
|
#define CONFIG_LOG_DEVICE_TX_IO_PORTx GPIOA
|
|
#define CONFIG_LOG_DEVICE_TX_IO_PINx GPIO_Pin_15
|
|
#define CONFIG_LOG_DEVICE_TX_IO_AF GPIO_AF_1
|
|
#define CONFIG_LOG_DEVICE_RESET() __HAL_SYSCFG_RESET_UART0()
|
|
//=============================================================================
|
|
// Macro Definition
|
|
//=============================================================================
|
|
|
|
//=============================================================================
|
|
// Structure Definition
|
|
//=============================================================================
|
|
|
|
//=============================================================================
|
|
// Global Data Definition
|
|
//=============================================================================
|
|
|
|
//=============================================================================
|
|
// Private Function Definition
|
|
//=============================================================================
|
|
void _putchar(char character)
|
|
{
|
|
UART_SendData(CONFIG_LOG_MSG_DEVICE, character);
|
|
UART_WaitTxFifoEmpty(CONFIG_LOG_MSG_DEVICE);
|
|
return;
|
|
}
|
|
|
|
//=============================================================================
|
|
// Public Function Definition
|
|
//=============================================================================
|
|
void syslog_init(void)
|
|
{
|
|
GPIO_InitTypeDef gpio_init = {0};
|
|
UART_InitTypeDef uart_init = {0};
|
|
|
|
/* configure GPIO Pin mux of UART Tx */
|
|
gpio_init.GPIO_Pin = CONFIG_LOG_DEVICE_TX_IO_PINx;
|
|
gpio_init.GPIO_AF_Mode = CONFIG_LOG_DEVICE_TX_IO_AF;
|
|
gpio_init.GPIO_Mode = GPIO_Mode_AF;
|
|
GPIO_Init(CONFIG_LOG_DEVICE_TX_IO_PORTx, &gpio_init);
|
|
|
|
uart_init.BaudRate = SLOG_SERIAL_BPS;
|
|
uart_init.WordLength = UART_WordLength_8b;
|
|
uart_init.StopBits = UART_StopBits_1;
|
|
uart_init.Parity = UART_Parity_No;
|
|
uart_init.Mode = UART_Mode_TxRx;
|
|
UART_Init(CONFIG_LOG_MSG_DEVICE, &uart_init);
|
|
|
|
UART_Start(CONFIG_LOG_MSG_DEVICE);
|
|
return;
|
|
}
|
|
|
|
void syslog_deinit(void)
|
|
{
|
|
GPIO_DeInit(CONFIG_LOG_DEVICE_TX_IO_PORTx, CONFIG_LOG_DEVICE_TX_IO_PINx);
|
|
CONFIG_LOG_DEVICE_RESET();
|
|
return;
|
|
}
|
|
|
|
void
|
|
syslog_dump_mem(
|
|
char *prefix,
|
|
uint32_t *pAddr,
|
|
int bytes,
|
|
int has_out_u32le)
|
|
{
|
|
if( has_out_u32le )
|
|
{
|
|
uintptr_t addr = (uintptr_t)pAddr;
|
|
uint32_t cnt = (bytes + 0x3) >> 2;
|
|
uint32_t *pCur = (uint32_t*)pAddr;
|
|
|
|
for(int i = 0; i < cnt; i++)
|
|
{
|
|
if( (i & 0x3) == 2 )
|
|
printf(" -");
|
|
else if( !(i & 0x3) )
|
|
{
|
|
printf("\n%s%08X |", prefix, addr);
|
|
addr += 16;
|
|
}
|
|
|
|
printf(" %08X", pCur[i]);
|
|
}
|
|
printf("\n\n");
|
|
}
|
|
else
|
|
{
|
|
uintptr_t addr = (uintptr_t)pAddr;
|
|
uint8_t *pCur = (uint8_t*)pAddr;
|
|
|
|
for(int i = 0; i < bytes; i++)
|
|
{
|
|
if( (i & 0xF) == 8 )
|
|
printf(" -");
|
|
else if( !(i & 0xF) )
|
|
{
|
|
printf("\n%s%08X |", prefix, addr);
|
|
addr += 16;
|
|
}
|
|
|
|
printf(" %02X", pCur[i]);
|
|
}
|
|
printf("\n\n");
|
|
}
|
|
|
|
return;
|
|
}
|