add log.c

This commit is contained in:
NeoZng
2022-11-11 21:20:58 +08:00
parent a1509ee665
commit ebb33406bb
15 changed files with 3824 additions and 9 deletions

View File

@@ -4,7 +4,7 @@
#include "memory.h"
/* can instance ptrs storage, used for recv callback */
static can_instance *instance[MX_REGISTER_DEVICE_CNT]={NULL};
static can_instance *instance[MX_REGISTER_DEVICE_CNT] = {NULL};
/* ----------------two static function called by CANRegister()-------------------- */

View File

@@ -0,0 +1,31 @@
#include "bsp_log.h"
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#include <stdio.h>
#define BUFFER_INDEX 0
void BSP_Log_Init() { SEGGER_RTT_Init(); }
int printf_log(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int n = SEGGER_RTT_vprintf(BUFFER_INDEX, fmt, &args);
va_end(args);
return n;
}
void Float2Str(char *str, float va)
{
int flag = va < 0;
int head = (int)va;
int point = (int)((va - head) * 1000);
head = abs(head);
point = abs(point);
if (flag)
sprintf(str, "-%d.%d", head, point);
else
sprintf(str, "%d.%d", head, point);
}

View File

@@ -0,0 +1,8 @@
#ifndef _BSP_LOG_H
#define _BSP_LOG_H
void BSP_Log_Init();
int printf_log(const char *fmt, ...);
void Float2Str(char *str, float va);
#endif

5
bsp/bsp_log.md Normal file
View File

@@ -0,0 +1,5 @@
# bsp_log
<p align='right'>neozng1@hnu.edu.cn</p>
## 使用说明

View File

@@ -13,7 +13,7 @@
/* usart service instance, modules' info would be recoreded here using USARTRegister() */
/* usart服务实例,所有注册了usart的模块信息会被保存在这里 */
static usart_instance *instance[DEVICE_USART_CNT]={NULL};
static usart_instance *instance[DEVICE_USART_CNT] = {NULL};
/**
* @brief usart service will start automatically, after each module registered