mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 08:46:42 +08:00
Add readme of slup and cant modules
This commit is contained in:
parent
74119f6c8a
commit
cc3d350ecf
11
README.en.md
11
README.en.md
@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](LICENSE)
|
||||
[](Lamdonn@163.com)
|
||||

|
||||
@ -11,14 +11,14 @@
|
||||
|
||||
[中文版](README.md)
|
||||
|
||||
varch (we architecture, meaning our framework library) is a commonly used code module library for embedded C language, including algorithm libraries, data structure (container) libraries, parser libraries, independent C language std libraries, tool libraries, and more.
|
||||
varch (we architecture, meaning our framework library) is a commonly used code module library for embedded C language, including the commonly used embedded algorithm library (search, check, filter, hash, sort, etc.), data structure/container library (general queue, stack, heap, list, dynamic array, string, set, dictionary, map, graph, etc.), parser library (csv, ini, json, xml, etc.), mathematical library (large number operation, mathematical operation), independent C language st d library, utility library, etc.
|
||||
It has the characteristics of **simplicity, universality, and efficiency**, with the aim of **learning** and **using it immediately** in development, improving development efficiency and code reliability and stability.
|
||||
|
||||
## Content
|
||||
|
||||
| module | version | usage | path | describe |
|
||||
|:-------------|:---------|:-----------------------------|:------------------------------------------|:--------------------------------------|
|
||||
| overall | 00.03.02 | [link](README.en.md) | [path](./) | Overall
|
||||
| overall | 00.03.03 | [link](README.en.md) | [path](./) | Overall
|
||||
| init | 01.00.00 | [link](/doc/init.en.md) | [path](./source/00_application) | Initialize export module
|
||||
| console | 01.00.01 | [link](/doc/console.en.md) | [path](./source/00_application/console) | Console command input, combined with the 'command' module, parsing commands entered in the console
|
||||
| arg | 01.00.00 | [link](/doc/arg.en.md) | [path](./source/01_general) | Indefinite parameters, obtain the number of indefinite parameters and specified parameters
|
||||
@ -34,7 +34,6 @@ It has the characteristics of **simplicity, universality, and efficiency**, with
|
||||
| tool | 01.01.00 | [link](/doc/tool.en.md) | [path](./source/01_general) | General tools code
|
||||
| valloc | 01.00.00 | [link](/doc/valloc.en.md) | [path](./source/01_general) | Dynamic memory usage testing tool
|
||||
| vlog | 01.01.00 | [link](/doc/vlog.en.md) | [path](./source/01_general) | Log output module
|
||||
| intl | 01.00.00 | [link](/doc/intl.en.md) | [path](./source/01_general) | Large integer arithmetic module
|
||||
| date | 01.00.00 | [link](/doc/date.en.md) | [path](./source/01_general) | Date calculation module, calculating date differences, printing calendars, etc
|
||||
| vctype | 01.00.00 | [link](/doc/vctype.en.md) | [path](./source/02_vstd) | Similar to the C standard library ctype
|
||||
| vmath | 01.00.00 | [link](/doc/vmath.en.md) | [path](./source/02_vstd) | Similar to the C standard library math
|
||||
@ -70,10 +69,12 @@ It has the characteristics of **simplicity, universality, and efficiency**, with
|
||||
| xml | 01.00.00 | [link](/doc/xml.en.md) | [path](./source/05_parser) | XML file parsing generator
|
||||
| ramt | 01.00.00 | [link](/doc/ramt.en.md) | [path](./source/06_performance) | RAM test module
|
||||
| romt | 01.00.00 | [link](/doc/romt.en.md) | [path](./source/06_performance) | ROM test module
|
||||
| cant | 00.01.00 | [link](/doc/cant.en.md) | [path](./source/06_performance) | CAN test module
|
||||
| slup | 00.01.00 | [link](/doc/slup.en.md) | [path](./source/06_performance) | serial link universal protocol
|
||||
| cpul | 01.00.00 | [link](/doc/cpul.en.md) | [path](./source/06_performance) | CPU load test module, including obtaining and increasing load
|
||||
| unitt | 01.00.00 | [link](/doc/unitt.en.md) | [path](./source/06_performance) | Simple unit test module
|
||||
| intl | 01.01.00 | [link](/doc/intl.en.md) | [path](./source/07_math) | Large integer arithmetic module
|
||||
| floatl | 01.01.00 | [link](/doc/floatl.en.md) | [path](./source/07_math) | Large floating-point arithmetic module
|
||||
| floatl | 01.01.01 | [link](/doc/floatl.en.md) | [path](./source/07_math) | Large floating-point arithmetic module
|
||||
| flmath | 01.00.00 | [link](/doc/flmath.en.md) | [path](./source/07_math) | Large floating-point arithmetic math module
|
||||
|
||||
## Usage
|
||||
|
||||
11
README.md
11
README.md
@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](LICENSE)
|
||||
[](Lamdonn@163.com)
|
||||

|
||||
@ -11,14 +11,14 @@
|
||||
|
||||
[English version](README.en.md)
|
||||
|
||||
varch(we-architecture,意为我们的框架库)是嵌入式C语言常用代码模块库,包含了嵌入式中常用的算法库, 数据结构(容器)库, 解析器库, 独立C语言std库, 工具库等等。
|
||||
varch(we-architecture,意为我们的框架库)是嵌入式C语言常用代码模块库,包含了嵌入式中常用的算法库(查找、校验、过滤、哈希、排序等)、数据结构/容器库(通用队列、栈、堆、列表、动态数组、字符串、集合、字典、映射、图等)、解析器库(csv、ini、json、xml等)、数学库(大数运算、数学运算)、独立C语言std库、工具库等等。
|
||||
具有**简单, 通用, 高效**的特点,目的为了**学习**以及在开发中**拿来就用**,提高开发效率以及代码可靠稳定性。
|
||||
|
||||
## 内容
|
||||
|
||||
| module | version | usage | path | describe |
|
||||
|:-------------|:---------|:-----------------------------|:------------------------------------------|:--------------------------------------|
|
||||
| overall | 00.03.02 | [link](README.md) | [path](./) | 整体
|
||||
| overall | 00.03.03 | [link](README.md) | [path](./) | 整体
|
||||
| init | 01.00.00 | [link](/doc/init.md) | [path](./source/00_application) | 初始化导出模块
|
||||
| console | 01.00.01 | [link](/doc/console.md) | [path](./source/00_application/console) | 控制台命令输入,结合 `command` 模块,解析在控制台中输入的命令
|
||||
| arg | 01.00.00 | [link](/doc/arg.md) | [path](./source/01_general) | 不定参数,获取不定参数和指定参数的个数
|
||||
@ -34,7 +34,6 @@ varch(we-architecture,意为我们的框架库)是嵌入式C语言常用
|
||||
| tool | 01.01.00 | [link](/doc/tool.md) | [path](./source/01_general) | 通用工具代码
|
||||
| valloc | 01.00.00 | [link](/doc/valloc.md) | [path](./source/01_general) | 动态内存使用测试工具
|
||||
| vlog | 01.01.00 | [link](/doc/vlog.md) | [path](./source/01_general) | 日志输出模块
|
||||
| intl | 01.00.00 | [link](/doc/intl.md) | [path](./source/01_general) | 大型整数运算模块
|
||||
| date | 01.00.00 | [link](/doc/date.md) | [path](./source/01_general) | 日期计算模块,计算日期差、打印日历等
|
||||
| vctype | 01.00.00 | [link](/doc/vctype.md) | [path](./source/02_vstd) | 类似于C标准库ctype
|
||||
| vmath | 01.00.00 | [link](/doc/vmath.md) | [path](./source/02_vstd) | 类似于C标准库math
|
||||
@ -70,10 +69,12 @@ varch(we-architecture,意为我们的框架库)是嵌入式C语言常用
|
||||
| xml | 01.00.00 | [link](/doc/xml.md) | [path](./source/05_parser) | XML文件解析生成器
|
||||
| ramt | 01.00.00 | [link](/doc/ramt.md) | [path](./source/06_performance) | RAM测试模块
|
||||
| romt | 01.00.00 | [link](/doc/romt.md) | [path](./source/06_performance) | ROM测试模块
|
||||
| cant | 00.01.00 | [link](/doc/cant.md) | [path](./source/06_performance) | CAN测试模块
|
||||
| slup | 00.01.00 | [link](/doc/slup.md) | [path](./source/06_performance) | 串口连接通用协议模块(serial link universal protocol)
|
||||
| cpul | 01.00.00 | [link](/doc/cpul.md) | [path](./source/06_performance) | CPU负载测试模块,包含获取和增加负载
|
||||
| unitt | 01.00.00 | [link](/doc/unitt.md) | [path](./source/06_performance) | 简易的单元测试模块
|
||||
| intl | 01.01.00 | [link](/doc/intl.md) | [path](./source/07_math) | 大型整数运算模块
|
||||
| floatl | 01.01.00 | [link](/doc/floatl.md) | [path](./source/07_math) | 大型浮点数运算模块
|
||||
| floatl | 01.01.01 | [link](/doc/floatl.md) | [path](./source/07_math) | 大型浮点数运算模块
|
||||
| flmath | 01.00.00 | [link](/doc/flmath.md) | [path](./source/07_math) | 大型浮点数数学运算模块
|
||||
|
||||
## 使用说明
|
||||
|
||||
192
doc/cant.en.md
Normal file
192
doc/cant.en.md
Normal file
@ -0,0 +1,192 @@
|
||||
## Introduction
|
||||
|
||||
`cant` is a simple CAN (Controller Area Network) device testing module for the C language. It conducts tests on the CAN bus from the application layer perspective, enabling the monitoring of data error frames and frame losses. Additionally, it can simulate the CAN bus load to ensure stability under high - voltage bus conditions.
|
||||
|
||||
## Interfaces
|
||||
|
||||
### Type Definitions
|
||||
|
||||
#### `cant_transfer_t` Function Pointer Type
|
||||
```c
|
||||
typedef int (*cant_transfer_t)(uint32_t canid, uint8_t *data, uint16_t length);
|
||||
```
|
||||
**Type Description**: This is a function pointer type related to CAN transmission, which can be used for CAN data sending or receiving functions.
|
||||
**Parameter Introduction**:
|
||||
- `canid`: The identifier of the CAN message.
|
||||
- `data`: A pointer to the data to be sent or received.
|
||||
- `length`: The length of the data.
|
||||
**Return Value**: The function returns an `int` value, and its specific meaning is determined by the actual function used.
|
||||
|
||||
### Structure Definitions
|
||||
|
||||
#### `CANT` Structure
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t channel;
|
||||
uint8_t baundrate;
|
||||
uint16_t period; // `cant_task()` call period
|
||||
cant_transfer_t transmit; // can transmit the drive function
|
||||
cant_transfer_t receive; // can receive hook functions
|
||||
} config;
|
||||
|
||||
uint16_t busload;
|
||||
uint32_t periodbits;
|
||||
uint32_t timestamp;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t canid;
|
||||
float compression;
|
||||
float rate;
|
||||
uint16_t tarload;
|
||||
uint32_t gapbase;
|
||||
uint32_t gapcount;
|
||||
uint32_t curcount;
|
||||
uint8_t data[64];
|
||||
} dummy;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t canid;
|
||||
uint32_t errcount;
|
||||
uint32_t curcount;
|
||||
uint32_t vercount;
|
||||
uint32_t lstcount;
|
||||
} verify;
|
||||
} CANT;
|
||||
```
|
||||
**Structure Description**: This structure is used to represent a CAN device, including the configuration information, bus load, timestamp, dummy data, and verification data of the CAN device.
|
||||
**Sub - structure and Member Introduction**:
|
||||
- **`config` Sub - structure**: Contains the configuration information of the CAN device.
|
||||
- `channel`: The channel number of the CAN bus.
|
||||
- `baundrate`: The baud rate of the CAN bus.
|
||||
- `period`: The call period of the `cant_task()` function.
|
||||
- `transmit`: A pointer to the CAN data sending function.
|
||||
- `receive`: A pointer to the CAN data receiving function.
|
||||
- **`busload`**: The load value of the CAN bus.
|
||||
- **`periodbits`**: Bit information related to the period.
|
||||
- **`timestamp`**: The timestamp.
|
||||
- **`dummy` Sub - structure**: Contains the dummy data of the CAN device.
|
||||
- `canid`: The identifier of the CAN message.
|
||||
- `compression`: The compression factor, of type `float`.
|
||||
- `rate`: The rate, of type `float`.
|
||||
- `tarload`: The target load.
|
||||
- `gapbase`: The gap base value.
|
||||
- `gapcount`: The gap count.
|
||||
- `curcount`: The current count.
|
||||
- `data`: The data array, with a size of 64 bytes.
|
||||
- **`verify` Sub - structure**: Contains the verification data of the CAN device.
|
||||
- `canid`: The identifier of the CAN message.
|
||||
- `errcount`: The error count.
|
||||
- `curcount`: The current count.
|
||||
- `vercount`: The verification count.
|
||||
- `lstcount`: The last count.
|
||||
|
||||
### Functions
|
||||
|
||||
#### `cant_set_dummy_canid` Function
|
||||
```c
|
||||
int cant_set_dummy_canid(CANT *cant, uint32_t canid);
|
||||
```
|
||||
**Function Description**: Sets the CAN identifier of the dummy data of the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be operated on.
|
||||
- `canid`: The CAN identifier to be set.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The setting is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
- `CANT_E_ECANID`: The passed `canid` is 0.
|
||||
|
||||
#### `cant_set_verify_canid` Function
|
||||
```c
|
||||
int cant_set_verify_canid(CANT *cant, uint32_t canid);
|
||||
```
|
||||
**Function Description**: Sets the CAN identifier of the verification data of the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be operated on.
|
||||
- `canid`: The CAN identifier to be set.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The setting is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
- `CANT_E_ECANID`: The passed `canid` is 0.
|
||||
|
||||
#### `cant_set_busload` Function
|
||||
```c
|
||||
int cant_set_busload(CANT *cant, uint16_t load);
|
||||
```
|
||||
**Function Description**: Sets the bus load of the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be operated on.
|
||||
- `load`: The bus load value to be set.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The setting is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
|
||||
#### `cant_get_busload` Function
|
||||
```c
|
||||
int cant_get_busload(CANT *cant, uint16_t *load);
|
||||
```
|
||||
**Function Description**: Obtains the bus load of the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be operated on.
|
||||
- `load`: A pointer to the variable used to store the bus load value.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The acquisition is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
- `CANT_E_LOAD`: The passed `load` pointer is `NULL`.
|
||||
|
||||
#### `cant_transmit` Function
|
||||
```c
|
||||
int cant_transmit(CANT *cant, uint32_t canid, uint8_t *data, uint16_t length);
|
||||
```
|
||||
**Function Description**: Sends data through the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be operated on.
|
||||
- `canid`: The CAN identifier of the data to be sent.
|
||||
- `data`: A pointer to the data to be sent.
|
||||
- `length`: The length of the data to be sent.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The sending is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
- `CANT_E_DATA`: The passed `data` pointer is `NULL`.
|
||||
- `CANT_E_TRANSMIT`: The `transmit` function pointer in the `cant` structure is `NULL`.
|
||||
- `CANT_E_TRANSFAIL`: The actual sending function returns a non - zero value, indicating a sending failure.
|
||||
|
||||
#### `cant_receive` Function
|
||||
```c
|
||||
int cant_receive(CANT *cant, uint32_t canid, uint8_t *data, uint16_t length);
|
||||
```
|
||||
**Function Description**: Receives data through the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be operated on.
|
||||
- `canid`: The CAN identifier of the data to be received.
|
||||
- `data`: A pointer to the buffer used to store the received data.
|
||||
- `length`: The length of the data to be received.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The reception is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
|
||||
#### `cant_init` Function
|
||||
```c
|
||||
int cant_init(CANT *cant);
|
||||
```
|
||||
**Function Description**: Initializes the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to be initialized.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The initialization is successful.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
|
||||
#### `cant_task` Function
|
||||
```c
|
||||
int cant_task(CANT *cant);
|
||||
```
|
||||
**Function Description**: The main task function of the CAN device, used to handle the periodic tasks of the CAN device.
|
||||
**Parameter Introduction**:
|
||||
- `cant`: A pointer to the `CANT` structure, representing the CAN device to execute the task.
|
||||
**Return Value**:
|
||||
- `CANT_E_OK`: The task is executed successfully.
|
||||
- `CANT_E_INVALID`: The passed `cant` pointer is `NULL`.
|
||||
192
doc/cant.md
Normal file
192
doc/cant.md
Normal file
@ -0,0 +1,192 @@
|
||||
## 介绍
|
||||
|
||||
`cant` 是一个用于 C 语言的简单 CAN(Controller Area Network)设备测试模块。从应用层角度对CAN总线进行测试,可以监控数据错误帧、丢帧,同时可以模拟CAN总线负载,确保在总线高压状态下的稳定性。
|
||||
|
||||
## 接口
|
||||
|
||||
### 类型定义
|
||||
|
||||
#### `cant_transfer_t` 函数指针类型
|
||||
```c
|
||||
typedef int (*cant_transfer_t)(uint32_t canid, uint8_t *data, uint16_t length);
|
||||
```
|
||||
**类型说明**:这是与 CAN 传输相关的函数指针类型,可用于 CAN 数据的发送或接收函数。
|
||||
**参数介绍**:
|
||||
- `canid`:CAN 消息的标识符。
|
||||
- `data`:指向要发送或接收的数据的指针。
|
||||
- `length`:数据的长度。
|
||||
**返回值**:函数返回一个 `int` 类型的值,具体含义由实际使用的函数决定。
|
||||
|
||||
### 结构体定义
|
||||
|
||||
#### `CANT` 结构体
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t channel;
|
||||
uint8_t baundrate;
|
||||
uint16_t period; // `cant_task()` call period
|
||||
cant_transfer_t transmit; // can transmit the drive function
|
||||
cant_transfer_t receive; // can receive hook functions
|
||||
} config;
|
||||
|
||||
uint16_t busload;
|
||||
uint32_t periodbits;
|
||||
uint32_t timestamp;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t canid;
|
||||
float compression;
|
||||
float rate;
|
||||
uint16_t tarload;
|
||||
uint32_t gapbase;
|
||||
uint32_t gapcount;
|
||||
uint32_t curcount;
|
||||
uint8_t data[64];
|
||||
} dummy;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t canid;
|
||||
uint32_t errcount;
|
||||
uint32_t curcount;
|
||||
uint32_t vercount;
|
||||
uint32_t lstcount;
|
||||
} verify;
|
||||
} CANT;
|
||||
```
|
||||
**结构体说明**:该结构体用于表示 CAN 设备,包含了 CAN 设备的配置信息、总线负载、时间戳、虚拟数据和验证数据等内容。
|
||||
**子结构体及成员介绍**:
|
||||
- **`config` 子结构体**:包含 CAN 设备的配置信息。
|
||||
- `channel`:CAN 总线的通道号。
|
||||
- `baundrate`:CAN 总线的波特率。
|
||||
- `period`:`cant_task()` 函数的调用周期。
|
||||
- `transmit`:指向 CAN 数据发送函数的指针。
|
||||
- `receive`:指向 CAN 数据接收函数的指针。
|
||||
- **`busload`**:CAN 总线的负载值。
|
||||
- **`periodbits`**:与周期相关的位信息。
|
||||
- **`timestamp`**:时间戳。
|
||||
- **`dummy` 子结构体**:包含 CAN 设备的虚拟数据。
|
||||
- `canid`:CAN 消息的标识符。
|
||||
- `compression`:压缩因子,类型为 `float`。
|
||||
- `rate`:速率,类型为 `float`。
|
||||
- `tarload`:目标负载。
|
||||
- `gapbase`:间隙基值。
|
||||
- `gapcount`:间隙计数。
|
||||
- `curcount`:当前计数。
|
||||
- `data`:数据数组,大小为 64 字节。
|
||||
- **`verify` 子结构体**:包含 CAN 设备的验证数据。
|
||||
- `canid`:CAN 消息的标识符。
|
||||
- `errcount`:错误计数。
|
||||
- `curcount`:当前计数。
|
||||
- `vercount`:验证计数。
|
||||
- `lstcount`:上一次计数。
|
||||
|
||||
### 函数
|
||||
|
||||
#### `cant_set_dummy_canid` 函数
|
||||
```c
|
||||
int cant_set_dummy_canid(CANT *cant, uint32_t canid);
|
||||
```
|
||||
**函数说明**:设置 CAN 设备虚拟数据的 CAN 标识符。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要操作的 CAN 设备。
|
||||
- `canid`:要设置的 CAN 标识符。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:设置成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
- `CANT_E_ECANID`:传入的 `canid` 为 0。
|
||||
|
||||
#### `cant_set_verify_canid` 函数
|
||||
```c
|
||||
int cant_set_verify_canid(CANT *cant, uint32_t canid);
|
||||
```
|
||||
**函数说明**:设置 CAN 设备验证数据的 CAN 标识符。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要操作的 CAN 设备。
|
||||
- `canid`:要设置的 CAN 标识符。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:设置成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
- `CANT_E_ECANID`:传入的 `canid` 为 0。
|
||||
|
||||
#### `cant_set_busload` 函数
|
||||
```c
|
||||
int cant_set_busload(CANT *cant, uint16_t load);
|
||||
```
|
||||
**函数说明**:设置 CAN 设备的总线负载。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要操作的 CAN 设备。
|
||||
- `load`:要设置的总线负载值。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:设置成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
|
||||
#### `cant_get_busload` 函数
|
||||
```c
|
||||
int cant_get_busload(CANT *cant, uint16_t *load);
|
||||
```
|
||||
**函数说明**:获取 CAN 设备的总线负载。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要操作的 CAN 设备。
|
||||
- `load`:指向用于存储总线负载值的变量的指针。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:获取成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
- `CANT_E_LOAD`:传入的 `load` 指针为 `NULL`。
|
||||
|
||||
#### `cant_transmit` 函数
|
||||
```c
|
||||
int cant_transmit(CANT *cant, uint32_t canid, uint8_t *data, uint16_t length);
|
||||
```
|
||||
**函数说明**:通过 CAN 设备发送数据。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要操作的 CAN 设备。
|
||||
- `canid`:要发送数据的 CAN 标识符。
|
||||
- `data`:指向要发送的数据的指针。
|
||||
- `length`:要发送的数据的长度。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:发送成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
- `CANT_E_DATA`:传入的 `data` 指针为 `NULL`。
|
||||
- `CANT_E_TRANSMIT`:`cant` 结构体中的 `transmit` 函数指针为 `NULL`。
|
||||
- `CANT_E_TRANSFAIL`:实际的发送函数返回非零值,表示发送失败。
|
||||
|
||||
#### `cant_receive` 函数
|
||||
```c
|
||||
int cant_receive(CANT *cant, uint32_t canid, uint8_t *data, uint16_t length);
|
||||
```
|
||||
**函数说明**:通过 CAN 设备接收数据。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要操作的 CAN 设备。
|
||||
- `canid`:要接收数据的 CAN 标识符。
|
||||
- `data`:指向用于存储接收数据的缓冲区的指针。
|
||||
- `length`:要接收的数据的长度。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:接收成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
|
||||
#### `cant_init` 函数
|
||||
```c
|
||||
int cant_init(CANT *cant);
|
||||
```
|
||||
**函数说明**:初始化 CAN 设备。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要初始化的 CAN 设备。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:初始化成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
|
||||
#### `cant_task` 函数
|
||||
```c
|
||||
int cant_task(CANT *cant);
|
||||
```
|
||||
**函数说明**:CAN 设备的主任务函数,用于处理 CAN 设备的周期性任务。
|
||||
**参数介绍**:
|
||||
- `cant`:指向 `CANT` 结构体的指针,代表要执行任务的 CAN 设备。
|
||||
**返回值**:
|
||||
- `CANT_E_OK`:任务执行成功。
|
||||
- `CANT_E_INVALID`:传入的 `cant` 指针为 `NULL`。
|
||||
255
doc/slup.en.md
Normal file
255
doc/slup.en.md
Normal file
@ -0,0 +1,255 @@
|
||||
## Introduction
|
||||
|
||||
`slup` is a simple serial link general protocol module for the C language. It defines protocol-related configuration structures, queue structures, parser structures, and dummy data structures, etc. At the same time, it provides a series of function interfaces for initializing the protocol module, sending data, obtaining link status and rate information, setting dummy data, and other operations, which facilitates developers to implement communication functions based on serial links in C language projects.
|
||||
|
||||
## Interfaces
|
||||
|
||||
### Function Pointer Types
|
||||
1. **`slup_putc_t` Function Pointer Type**:
|
||||
```c
|
||||
typedef int (*slup_putc_t)(char c);
|
||||
```
|
||||
- **Purpose**: Used to point to a function for writing a character.
|
||||
- **Parameter**: `c`, the character to be written.
|
||||
- **Return Value**: Of the `int` type, the specific meaning is determined by the actual function.
|
||||
2. **`slup_check_t` Function Pointer Type**:
|
||||
```c
|
||||
typedef uint32_t (*slup_check_t)(uint8_t *data, uint16_t length);
|
||||
```
|
||||
- **Purpose**: Used to point to a function for checking data.
|
||||
- **Parameters**:
|
||||
- `data`: A pointer to the data array to be checked.
|
||||
- `length`: The length of the data.
|
||||
- **Return Value**: Of the `uint32_t` type, returns the check result.
|
||||
3. **`slup_receive_t` Function Pointer Type**:
|
||||
```c
|
||||
typedef int (*slup_receive_t)(uint8_t *data, uint16_t length);
|
||||
```
|
||||
- **Purpose**: Used to point to a function for receiving data.
|
||||
- **Parameters**:
|
||||
- `data`: A pointer to the buffer for receiving data.
|
||||
- `length`: The length of the data to be received.
|
||||
- **Return Value**: Of the `int` type, the specific meaning is determined by the actual function.
|
||||
|
||||
### Structure Definitions
|
||||
1. **`SLUP_CFG` Structure**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
uint8_t head[SLUP_HEAD_MAX]; /**< head mask */
|
||||
uint8_t tail[SLUP_TAIL_MAX]; /**< tail mask */
|
||||
uint8_t hsize : 4; /**< head size */
|
||||
uint8_t tsize : 4; /**< tail size */
|
||||
uint8_t csize : 4; /**< check code size */
|
||||
uint8_t ssize : 4; /**< sn size */
|
||||
} SLUP_CFG;
|
||||
```
|
||||
- **Purpose**: Used to store the configuration information of the SLUP protocol, including the head mask, tail mask, head size, tail size, check code size, and sequence number size.
|
||||
- **Member Introduction**:
|
||||
- `head`: An array storing the head mask, with a maximum size of `SLUP_HEAD_MAX`.
|
||||
- `tail`: An array storing the tail mask, with a maximum size of `SLUP_TAIL_MAX`.
|
||||
- `hsize`: The head size, occupying 4 bits.
|
||||
- `tsize`: The tail size, occupying 4 bits.
|
||||
- `csize`: The check code size, occupying 4 bits.
|
||||
- `ssize`: The sequence number size, occupying 4 bits.
|
||||
2. **`SLUP_QUEUE` Structure**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
char base[SLUP_RXQUE_SIZE]; /* base address of data */
|
||||
uint32_t size; /* size of queue */
|
||||
uint32_t head; /* index of queue head */
|
||||
uint32_t tail; /* index of queue tail */
|
||||
} SLUP_QUEUE;
|
||||
```
|
||||
- **Purpose**: Used to define the SLUP queue for storing received data.
|
||||
- **Member Introduction**:
|
||||
- `base`: The base address array of the queue data, with a size of `SLUP_RXQUE_SIZE`.
|
||||
- `size`: The total size of the queue.
|
||||
- `head`: The index of the queue head.
|
||||
- `tail`: The index of the queue tail.
|
||||
3. **`SLUP_PARSER` Structure**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t hindex : 4;
|
||||
uint8_t tindex : 4;
|
||||
uint8_t cindex : 4;
|
||||
uint8_t sindex : 4;
|
||||
uint8_t lindex : 2;
|
||||
uint8_t frame;
|
||||
uint16_t length;
|
||||
uint16_t dindex;
|
||||
uint32_t check;
|
||||
uint32_t sn;
|
||||
} SLUP_PARSER;
|
||||
```
|
||||
- **Purpose**: A structure used to parse SLUP data, recording various states and information during the parsing process.
|
||||
- **Member Introduction**:
|
||||
- `state`: The current state of the parser.
|
||||
- `hindex`: The head index, occupying 4 bits.
|
||||
- `tindex`: The tail index, occupying 4 bits.
|
||||
- `cindex`: The check code index, occupying 4 bits.
|
||||
- `sindex`: The sequence number index, occupying 4 bits.
|
||||
- `lindex`: The length index, occupying 2 bits.
|
||||
- `frame`: The frame status flag.
|
||||
- `length`: The length of the data being processed.
|
||||
- `dindex`: The index within the data.
|
||||
- `check`: The check value of the data.
|
||||
- `sn`: The sequence number.
|
||||
4. **`SLUP_DUMMY` Structure**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
float compression;
|
||||
float rate;
|
||||
uint32_t target;
|
||||
uint32_t gapbase;
|
||||
uint32_t gapcount;
|
||||
uint8_t data[64];
|
||||
} SLUP_DUMMY;
|
||||
```
|
||||
- **Purpose**: A structure used to store SLUP dummy data.
|
||||
- **Member Introduction**:
|
||||
- `compression`: The compression factor, of the floating-point type.
|
||||
- `rate`: The rate value, of the floating-point type.
|
||||
- `target`: The target value.
|
||||
- `gapbase`: The gap base value.
|
||||
- `gapcount`: The gap count.
|
||||
- `data`: An array for storing data, with a size of 64 bytes.
|
||||
5. **`SLUP` Structure**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
SLUP_CFG cfg;
|
||||
SLUP_QUEUE queue;
|
||||
SLUP_PARSER parser;
|
||||
SLUP_DUMMY dummy;
|
||||
uint8_t buffer[SLUP_FRAME_MAX];
|
||||
uint32_t bsize;
|
||||
uint32_t sn;
|
||||
uint8_t link;
|
||||
uint8_t silent;
|
||||
uint16_t period;
|
||||
uint32_t timestamp;
|
||||
uint32_t upbits;
|
||||
uint32_t downbits;
|
||||
uint32_t uprate;
|
||||
uint32_t downrate;
|
||||
slup_putc_t putc;
|
||||
slup_check_t check;
|
||||
slup_receive_t receive;
|
||||
} SLUP;
|
||||
```
|
||||
- **Purpose**: The main structure of the SLUP protocol, integrating multiple parts such as configuration, queue, parser, and dummy data.
|
||||
- **Member Introduction**:
|
||||
- `cfg`: The `SLUP_CFG` structure, storing protocol configuration information.
|
||||
- `queue`: The `SLUP_QUEUE` structure, storing receive queue information.
|
||||
- `parser`: The `SLUP_PARSER` structure, storing parser information.
|
||||
- `dummy`: The `SLUP_DUMMY` structure, storing dummy data information.
|
||||
- `buffer`: The buffer for storing data, with a maximum size of `SLUP_FRAME_MAX`.
|
||||
- `bsize`: The size of the buffer.
|
||||
- `sn`: The sequence number.
|
||||
- `link`: The link status flag.
|
||||
- `silent`: The silent status flag.
|
||||
- `period`: The period value.
|
||||
- `timestamp`: The timestamp.
|
||||
- `upbits`: The number of bits in the upload direction.
|
||||
- `downbits`: The number of bits in the download direction.
|
||||
- `uprate`: The upload rate.
|
||||
- `downrate`: The download rate.
|
||||
- `putc`: A function pointer of the `slup_putc_t` type, used for writing characters.
|
||||
- `check`: A function pointer of the `slup_check_t` type, used for checking data.
|
||||
- `receive`: A function pointer of the `slup_receive_t` type, used for receiving data.
|
||||
|
||||
### Functions
|
||||
1. **`slup_init` Function**:
|
||||
```c
|
||||
int slup_init(SLUP *slup);
|
||||
```
|
||||
- **Function**: Initializes the `SLUP` structure.
|
||||
- **Parameter**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- **Return Value**:
|
||||
- `SLUP_E_OK`: Initialization is successful.
|
||||
- `SLUP_E_INVALID`: The passed `slup` pointer is `NULL`.
|
||||
- **Explanation**: This function initializes each field in the `SLUP` structure.
|
||||
2. **`slup_send` Function**:
|
||||
```c
|
||||
int slup_send(SLUP *slup, uint8_t *data, uint16_t length);
|
||||
```
|
||||
- **Function**: Sends SLUP protocol data with the frame type `0x01`.
|
||||
- **Parameters**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- `data`: A pointer to the buffer of the data to be sent.
|
||||
- `length`: The length of the data buffer.
|
||||
- **Return Value**:
|
||||
- `SLUP_E_OK`: The data is successfully sent.
|
||||
- Others: The corresponding error code.
|
||||
- **Explanation**: This function simply calls the `slup_send_package` function to send the provided data with the frame type `0x01`.
|
||||
3. **`slup_link_status` Function**:
|
||||
```c
|
||||
int slup_link_status(SLUP *slup, uint8_t *link);
|
||||
```
|
||||
- **Function**: Obtains the current link status from the `SLUP` structure.
|
||||
- **Parameters**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- `link`: A pointer to the variable used to store the link status.
|
||||
- **Return Value**:
|
||||
- `SLUP_E_OK`: The acquisition is successful.
|
||||
- Others: The corresponding error code.
|
||||
- **Explanation**: This function checks the validity of the passed pointer.
|
||||
4. **`slup_upload_rate` Function**:
|
||||
```c
|
||||
int slup_upload_rate(SLUP *slup, uint32_t *rate);
|
||||
```
|
||||
- **Function**: Obtains the upload rate from the `SLUP` structure.
|
||||
- **Parameters**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- `rate`: A pointer to the variable used to store the upload rate.
|
||||
- **Return Value**:
|
||||
- `SLUP_E_OK`: The acquisition is successful.
|
||||
- Others: The corresponding error code.
|
||||
- **Explanation**: This function checks the validity of the passed pointer.
|
||||
5. **`slup_download_rate` Function**:
|
||||
```c
|
||||
int slup_download_rate(SLUP *slup, uint32_t *rate);
|
||||
```
|
||||
- **Function**: Obtains the download rate from the `SLUP` structure.
|
||||
- **Parameters**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- `rate`: A pointer to the variable used to store the download rate.
|
||||
- **Return Value**:
|
||||
- `SLUP_E_OK`: The acquisition is successful.
|
||||
- Others: The corresponding error code.
|
||||
- **Explanation**: This function checks the validity of the passed pointer.
|
||||
6. **`slup_set_dummy` Function**:
|
||||
```c
|
||||
int slup_set_dummy(SLUP *slup, uint32_t rate);
|
||||
```
|
||||
- **Function**: Sets the target rate of the dummy data in the `SLUP` structure.
|
||||
- **Parameters**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- `rate`: The target rate value to be set.
|
||||
- **Return Value**:
|
||||
- `SLUP_E_OK`: The setting is successful.
|
||||
- `SLUP_E_INVALID`: The passed `slup` pointer is `NULL`.
|
||||
- **Explanation**: This function checks the validity of the passed pointer.
|
||||
7. **`slup_getc` Function**:
|
||||
```c
|
||||
void slup_getc(SLUP *slup, char c);
|
||||
```
|
||||
- **Function**: Handles the reception of a single character in the SLUP system.
|
||||
- **Parameters**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- `c`: The received character.
|
||||
- **Explanation**: This function updates the link status to the receive state (sets `SLUP_LINK_RX`), clears the silent flag, updates the download statistics, and pushes the received character into the queue.
|
||||
8. **`slup_task` Function**:
|
||||
```c
|
||||
void slup_task(SLUP *slup);
|
||||
```
|
||||
- **Function**: The main task function of the SLUP system.
|
||||
- **Parameter**:
|
||||
- `slup`: A pointer to the `SLUP` structure.
|
||||
- **Explanation**: This function updates the timestamp and performs various operations according to the timestamp value, such as sending heartbeat messages, calculating the rate, performing dummy data sending, and updating dummy data parameters, etc. It also calls the `slup_parse_task` function to parse the received data in the queue.
|
||||
255
doc/slup.md
Normal file
255
doc/slup.md
Normal file
@ -0,0 +1,255 @@
|
||||
## 介绍
|
||||
|
||||
`slup` 是一个用于 C 语言的简单串行链路通用协议模块。它定义了协议相关的配置结构体、队列结构体、解析器结构体以及虚拟数据结构体等,同时提供了一系列函数接口,用于初始化协议模块、发送数据、获取链路状态和速率信息、设置虚拟数据等操作,方便开发者在 C 语言项目中实现基于串行链路的通信功能。
|
||||
|
||||
## 接口
|
||||
|
||||
### 函数指针类型
|
||||
1. **`slup_putc_t` 函数指针类型**:
|
||||
```c
|
||||
typedef int (*slup_putc_t)(char c);
|
||||
```
|
||||
- **用途**:用于指向一个写字符的函数。
|
||||
- **参数**:`c`,要写入的字符。
|
||||
- **返回值**:`int` 类型,具体含义由实际函数决定。
|
||||
2. **`slup_check_t` 函数指针类型**:
|
||||
```c
|
||||
typedef uint32_t (*slup_check_t)(uint8_t *data, uint16_t length);
|
||||
```
|
||||
- **用途**:用于指向一个检查数据的函数。
|
||||
- **参数**:
|
||||
- `data`:指向要检查的数据数组的指针。
|
||||
- `length`:数据的长度。
|
||||
- **返回值**:`uint32_t` 类型,返回检查结果。
|
||||
3. **`slup_receive_t` 函数指针类型**:
|
||||
```c
|
||||
typedef int (*slup_receive_t)(uint8_t *data, uint16_t length);
|
||||
```
|
||||
- **用途**:用于指向一个接收数据的函数。
|
||||
- **参数**:
|
||||
- `data`:指向接收数据缓冲区的指针。
|
||||
- `length`:接收数据的长度。
|
||||
- **返回值**:`int` 类型,具体含义由实际函数决定。
|
||||
|
||||
### 结构体定义
|
||||
1. **`SLUP_CFG` 结构体**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
uint8_t head[SLUP_HEAD_MAX]; /**< head mask */
|
||||
uint8_t tail[SLUP_TAIL_MAX]; /**< tail mask */
|
||||
uint8_t hsize : 4; /**< head size */
|
||||
uint8_t tsize : 4; /**< tail size */
|
||||
uint8_t csize : 4; /**< check code size */
|
||||
uint8_t ssize : 4; /**< sn size */
|
||||
} SLUP_CFG;
|
||||
```
|
||||
- **用途**:用于存储 SLUP 协议的配置信息,包括头部掩码、尾部掩码、头部大小、尾部大小、校验码大小和序列号大小。
|
||||
- **成员介绍**:
|
||||
- `head`:存储头部掩码的数组,最大尺寸为 `SLUP_HEAD_MAX`。
|
||||
- `tail`:存储尾部掩码的数组,最大尺寸为 `SLUP_TAIL_MAX`。
|
||||
- `hsize`:头部大小,占用 `4` 位。
|
||||
- `tsize`:尾部大小,占用 `4` 位。
|
||||
- `csize`:校验码大小,占用 `4` 位。
|
||||
- `ssize`:序列号大小,占用 `4` 位。
|
||||
2. **`SLUP_QUEUE` 结构体**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
char base[SLUP_RXQUE_SIZE]; /* base address of data */
|
||||
uint32_t size; /* size of queue */
|
||||
uint32_t head; /* index of queue head */
|
||||
uint32_t tail; /* index of queue tail */
|
||||
} SLUP_QUEUE;
|
||||
```
|
||||
- **用途**:用于定义 SLUP 队列,存储接收的数据。
|
||||
- **成员介绍**:
|
||||
- `base`:队列数据的基地址数组,大小为 `SLUP_RXQUE_SIZE`。
|
||||
- `size`:队列的总大小。
|
||||
- `head`:队列头部的索引。
|
||||
- `tail`:队列尾部的索引。
|
||||
3. **`SLUP_PARSER` 结构体**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t hindex : 4;
|
||||
uint8_t tindex : 4;
|
||||
uint8_t cindex : 4;
|
||||
uint8_t sindex : 4;
|
||||
uint8_t lindex : 2;
|
||||
uint8_t frame;
|
||||
uint16_t length;
|
||||
uint16_t dindex;
|
||||
uint32_t check;
|
||||
uint32_t sn;
|
||||
} SLUP_PARSER;
|
||||
```
|
||||
- **用途**:用于解析 SLUP 数据的结构体,记录解析过程中的各种状态和信息。
|
||||
- **成员介绍**:
|
||||
- `state`:解析器的当前状态。
|
||||
- `hindex`:头部索引,占用 `4` 位。
|
||||
- `tindex`:尾部索引,占用 `4` 位。
|
||||
- `cindex`:校验码索引,占用 `4` 位。
|
||||
- `sindex`:序列号索引,占用 `4` 位。
|
||||
- `lindex`:长度索引,占用 `2` 位。
|
||||
- `frame`:帧状态标志。
|
||||
- `length`:正在处理的数据长度。
|
||||
- `dindex`:数据内的索引。
|
||||
- `check`:数据的校验值。
|
||||
- `sn`:序列号。
|
||||
4. **`SLUP_DUMMY` 结构体**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
float compression;
|
||||
float rate;
|
||||
uint32_t target;
|
||||
uint32_t gapbase;
|
||||
uint32_t gapcount;
|
||||
uint8_t data[64];
|
||||
} SLUP_DUMMY;
|
||||
```
|
||||
- **用途**:用于存储 SLUP 虚拟数据的结构体。
|
||||
- **成员介绍**:
|
||||
- `compression`:压缩因子,浮点数类型。
|
||||
- `rate`:速率值,浮点数类型。
|
||||
- `target`:目标值。
|
||||
- `gapbase`:间隙基值。
|
||||
- `gapcount`:间隙计数。
|
||||
- `data`:存储数据的数组,大小为 `64` 字节。
|
||||
5. **`SLUP` 结构体**:
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
SLUP_CFG cfg;
|
||||
SLUP_QUEUE queue;
|
||||
SLUP_PARSER parser;
|
||||
SLUP_DUMMY dummy;
|
||||
uint8_t buffer[SLUP_FRAME_MAX];
|
||||
uint32_t bsize;
|
||||
uint32_t sn;
|
||||
uint8_t link;
|
||||
uint8_t silent;
|
||||
uint16_t period;
|
||||
uint32_t timestamp;
|
||||
uint32_t upbits;
|
||||
uint32_t downbits;
|
||||
uint32_t uprate;
|
||||
uint32_t downrate;
|
||||
slup_putc_t putc;
|
||||
slup_check_t check;
|
||||
slup_receive_t receive;
|
||||
} SLUP;
|
||||
```
|
||||
- **用途**:SLUP 协议的主要结构体,整合了配置、队列、解析器、虚拟数据等多个部分。
|
||||
- **成员介绍**:
|
||||
- `cfg`:`SLUP_CFG` 结构体,存储协议配置信息。
|
||||
- `queue`:`SLUP_QUEUE` 结构体,存储接收队列信息。
|
||||
- `parser`:`SLUP_PARSER` 结构体,存储解析器信息。
|
||||
- `dummy`:`SLUP_DUMMY` 结构体,存储虚拟数据信息。
|
||||
- `buffer`:存储数据的缓冲区,最大尺寸为 `SLUP_FRAME_MAX`。
|
||||
- `bsize`:缓冲区的大小。
|
||||
- `sn`:序列号。
|
||||
- `link`:链路状态标志。
|
||||
- `silent`:静音状态标志。
|
||||
- `period`:周期值。
|
||||
- `timestamp`:时间戳。
|
||||
- `upbits`:上传方向的位数。
|
||||
- `downbits`:下载方向的位数。
|
||||
- `uprate`:上传速率。
|
||||
- `downrate`:下载速率。
|
||||
- `putc`:`slup_putc_t` 类型的函数指针,用于写字符。
|
||||
- `check`:`slup_check_t` 类型的函数指针,用于检查数据。
|
||||
- `receive`:`slup_receive_t` 类型的函数指针,用于接收数据。
|
||||
|
||||
### 函数
|
||||
1. **`slup_init` 函数**:
|
||||
```c
|
||||
int slup_init(SLUP *slup);
|
||||
```
|
||||
- **功能**:初始化 SLUP 结构体。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- **返回值**:
|
||||
- `SLUP_E_OK`:初始化成功。
|
||||
- `SLUP_E_INVALID`:传入的 `slup` 指针为 `NULL`。
|
||||
- **说明**:该函数初始化 `SLUP` 结构体中的各个字段。
|
||||
2. **`slup_send` 函数**:
|
||||
```c
|
||||
int slup_send(SLUP *slup, uint8_t *data, uint16_t length);
|
||||
```
|
||||
- **功能**:以帧类型 `0x01` 发送 SLUP 协议数据。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- `data`:指向要发送的数据缓冲区的指针。
|
||||
- `length`:数据缓冲区的长度。
|
||||
- **返回值**:
|
||||
- `SLUP_E_OK`:数据成功发送。
|
||||
- 其他:相应的错误码。
|
||||
- **说明**:该函数简单调用 `slup_send_package` 函数,以帧类型 `0x01` 发送提供的数据。
|
||||
3. **`slup_link_status` 函数**:
|
||||
```c
|
||||
int slup_link_status(SLUP *slup, uint8_t *link);
|
||||
```
|
||||
- **功能**:从 SLUP 结构体中获取当前链路状态。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- `link`:指向用于存储链路状态的变量的指针。
|
||||
- **返回值**:
|
||||
- `SLUP_E_OK`:获取成功。
|
||||
- 其他:相应的错误码。
|
||||
- **说明**:该函数检查传入指针的有效性。
|
||||
4. **`slup_upload_rate` 函数**:
|
||||
```c
|
||||
int slup_upload_rate(SLUP *slup, uint32_t *rate);
|
||||
```
|
||||
- **功能**:从 SLUP 结构体中获取上传速率。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- `rate`:指向用于存储上传速率的变量的指针。
|
||||
- **返回值**:
|
||||
- `SLUP_E_OK`:获取成功。
|
||||
- 其他:相应的错误码。
|
||||
- **说明**:该函数检查传入指针的有效性。
|
||||
5. **`slup_download_rate` 函数**:
|
||||
```c
|
||||
int slup_download_rate(SLUP *slup, uint32_t *rate);
|
||||
```
|
||||
- **功能**:从 SLUP 结构体中获取下载速率。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- `rate`:指向用于存储下载速率的变量的指针。
|
||||
- **返回值**:
|
||||
- `SLUP_E_OK`:获取成功。
|
||||
- 其他:相应的错误码。
|
||||
- **说明**:该函数检查传入指针的有效性。
|
||||
6. **`slup_set_dummy` 函数**:
|
||||
```c
|
||||
int slup_set_dummy(SLUP *slup, uint32_t rate);
|
||||
```
|
||||
- **功能**:设置 SLUP 结构体中虚拟数据的目标速率。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- `rate`:要设置的目标速率值。
|
||||
- **返回值**:
|
||||
- `SLUP_E_OK`:设置成功。
|
||||
- `SLUP_E_INVALID`:传入的 `slup` 指针为 `NULL`。
|
||||
- **说明**:该函数检查传入指针的有效性。
|
||||
7. **`slup_getc` 函数**:
|
||||
```c
|
||||
void slup_getc(SLUP *slup, char c);
|
||||
```
|
||||
- **功能**:处理 SLUP 系统中单个字符的接收。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- `c`:接收到的字符。
|
||||
- **说明**:该函数更新链路状态为接收状态(设置 `SLUP_LINK_RX`),清除静音标志,更新下载统计信息,并将接收到的字符推入队列。
|
||||
8. **`slup_task` 函数**:
|
||||
```c
|
||||
void slup_task(SLUP *slup);
|
||||
```
|
||||
- **功能**:SLUP 系统的主任务函数。
|
||||
- **参数**:
|
||||
- `slup`:指向 `SLUP` 结构体的指针。
|
||||
- **说明**:该函数更新时间戳,并根据时间戳值执行各种操作,如发送心跳消息、计算速率、执行虚拟数据发送和更新虚拟数据参数等。它还调用 `slup_parse_task` 函数来解析队列中接收到的数据。
|
||||
@ -1,3 +1,12 @@
|
||||
version 0.3.3
|
||||
date 2025.03.18
|
||||
changes
|
||||
1. Add the initial version slup and cant
|
||||
2. Add floatl_to_d() function
|
||||
|
||||
---------------------------------------------------------------------------------------------
|
||||
---------------------------------------------------------------------------------------------
|
||||
|
||||
version 0.3.2
|
||||
date 2025.03.13
|
||||
changes
|
||||
|
||||
@ -111,16 +111,94 @@ typedef struct
|
||||
} verify;
|
||||
} CANT;
|
||||
|
||||
/**
|
||||
* \brief Sets the CAN ID for the CAN device's dummy data.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \param canid: The CAN ID value to be set.
|
||||
* \return CANT_E_OK if the setting is successful, CANT_E_INVALID if the pointer is NULL,
|
||||
* CANT_E_ECANID if the provided CAN ID is 0.
|
||||
*
|
||||
* This function checks if the provided pointer is valid.
|
||||
*/
|
||||
int cant_set_dummy_canid(CANT *cant, uint32_t canid);
|
||||
|
||||
/**
|
||||
* \brief Sets the CAN ID for the verification settings in the CAN device.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \param canid: The CAN ID value to be set.
|
||||
* \return CANT_E_OK if the setting is successful, CANT_E_INVALID if the pointer is NULL,
|
||||
* CANT_E_ECANID if the provided CAN ID is 0.
|
||||
*
|
||||
* This function checks if the provided pointer is valid.
|
||||
*/
|
||||
int cant_set_verify_canid(CANT *cant, uint32_t canid);
|
||||
|
||||
/**
|
||||
* \brief Sets the target bus load for the CAN device's dummy data.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \param load: The target bus load value to be set.
|
||||
* \return CANT_E_OK if the setting is successful, CANT_E_INVALID if the pointer is NULL.
|
||||
*
|
||||
* This function checks if the provided pointer is valid.
|
||||
*/
|
||||
int cant_set_busload(CANT *cant, uint16_t load);
|
||||
|
||||
/**
|
||||
* \brief Retrieves the target bus load for the CAN device's dummy data.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \param load: Pointer to a variable where the target bus load will be stored.
|
||||
* \return CANT_E_OK if the retrieval is successful, CANT_E_INVALID if the pointer is NULL,
|
||||
* CANT_E_LOAD if the provided load pointer is NULL.
|
||||
*
|
||||
* This function checks if the provided pointers are valid.
|
||||
*/
|
||||
int cant_get_busload(CANT *cant, uint16_t *load);
|
||||
|
||||
/**
|
||||
* \brief Transmits data over the CAN bus using the provided CAN device configuration.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \param canid: The CAN ID to which the data will be transmitted.
|
||||
* \param data: Pointer to the data buffer to be transmitted.
|
||||
* \param length: The length of the data buffer.
|
||||
* \return CANT_E_OK if the transmission is successful, appropriate error codes otherwise.
|
||||
* CANT_E_INVALID if the pointer to the CANT structure is NULL.
|
||||
* CANT_E_DATA if the data pointer is NULL.
|
||||
* CANT_E_TRANSMIT if the transmission function pointer in the configuration is NULL.
|
||||
* CANT_E_TRANSFAIL if the actual transmission function returns a non-zero value.
|
||||
*
|
||||
* This function first checks the validity of the input parameters.
|
||||
*/
|
||||
int cant_transmit(CANT *cant, uint32_t canid, uint8_t *data, uint16_t length);
|
||||
|
||||
/**
|
||||
* \brief Receives data over the CAN bus and performs related operations.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \param canid: The CAN ID from which the data is received.
|
||||
* \param data: Pointer to the buffer where the received data will be stored.
|
||||
* \param length: The length of the received data.
|
||||
* \return CANT_E_OK if the operation is successful, CANT_E_INVALID if the pointer to the CANT structure is NULL.
|
||||
*
|
||||
* This function first checks the validity of the input pointer.
|
||||
*/
|
||||
int cant_receive(CANT *cant, uint32_t canid, uint8_t *data, uint16_t length);
|
||||
|
||||
/**
|
||||
* \brief Initializes the CANT structure representing the CAN device.
|
||||
* \param cant: Pointer to the CANT structure to be initialized.
|
||||
* \return CANT_E_OK if the initialization is successful, CANT_E_INVALID if the pointer is NULL.
|
||||
*
|
||||
* This function initializes various fields in the CANT structure.
|
||||
*/
|
||||
int cant_init(CANT *cant);
|
||||
|
||||
/**
|
||||
* \brief The main task function for the CAN device.
|
||||
* \param cant: Pointer to the CANT structure representing the CAN device.
|
||||
* \return CANT_E_OK if the task is executed successfully, CANT_E_INVALID if the pointer is NULL.
|
||||
*
|
||||
* This function is the main task handler for the CAN device. It updates the timestamp of the
|
||||
* CAN device. Based on the timestamp value, it performs different operations at specific intervals.
|
||||
*/
|
||||
int cant_task(CANT *cant);
|
||||
|
||||
#endif
|
||||
|
||||
@ -193,13 +193,87 @@ typedef struct
|
||||
slup_receive_t receive;
|
||||
} SLUP;
|
||||
|
||||
/**
|
||||
* \brief Initializes the SLUP structure.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \return SLUP_E_OK if the initialization is successful, SLUP_E_INVALID if the pointer is NULL.
|
||||
*
|
||||
* This function initializes various fields in the SLUP structure.
|
||||
*/
|
||||
int slup_init(SLUP *slup);
|
||||
|
||||
/**
|
||||
* \brief Sends data in the SLUP protocol with a frame type of 0x01.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \param data: Pointer to the data buffer to be sent.
|
||||
* \param length: The length of the data buffer.
|
||||
* \return SLUP_E_OK if the data is successfully sent, appropriate error code otherwise.
|
||||
*
|
||||
* This function simply calls the slup_send_package function with a frame type of 0x01
|
||||
* to send the provided data.
|
||||
*/
|
||||
int slup_send(SLUP *slup, uint8_t *data, uint16_t length);
|
||||
|
||||
/**
|
||||
* \brief Retrieves the current link status from the SLUP structure.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \param link: Pointer to a variable where the link status will be stored.
|
||||
* \return SLUP_E_OK if the retrieval is successful, appropriate error code otherwise.
|
||||
*
|
||||
* This function checks if the provided pointers are valid.
|
||||
*/
|
||||
int slup_link_status(SLUP *slup, uint8_t *link);
|
||||
|
||||
/**
|
||||
* \brief Retrieves the upload rate from the SLUP structure.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \param rate: Pointer to a variable where the upload rate will be stored.
|
||||
* \return SLUP_E_OK if the retrieval is successful, appropriate error code otherwise.
|
||||
*
|
||||
* This function checks if the provided pointers are valid.
|
||||
*/
|
||||
int slup_upload_rate(SLUP *slup, uint32_t *rate);
|
||||
|
||||
/**
|
||||
* \brief Retrieves the download rate from the SLUP structure.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \param rate: Pointer to a variable where the download rate will be stored.
|
||||
* \return SLUP_E_OK if the retrieval is successful, appropriate error code otherwise.
|
||||
*
|
||||
* This function checks if the provided pointers are valid.
|
||||
*/
|
||||
int slup_download_rate(SLUP *slup, uint32_t *rate);
|
||||
|
||||
/**
|
||||
* \brief Sets the target rate for the dummy data in the SLUP structure.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \param rate: The target rate value to be set.
|
||||
* \return SLUP_E_OK if the setting is successful, SLUP_E_INVALID if the pointer is NULL.
|
||||
*
|
||||
* This function checks if the provided pointer is valid.
|
||||
*/
|
||||
int slup_set_dummy(SLUP *slup, uint32_t rate);
|
||||
|
||||
/**
|
||||
* \brief Handles the reception of a single character in the SLUP system.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
* \param c: The received character.
|
||||
*
|
||||
* This function updates the link status to indicate a received character (sets SLUP_LINK_RX),
|
||||
* clears the silent flag, updates the download statistics, and pushes the received character
|
||||
* into the queue.
|
||||
*/
|
||||
void slup_getc(SLUP *slup, char c);
|
||||
|
||||
/**
|
||||
* \brief The main task function for the SLUP system.
|
||||
* \param slup: Pointer to the SLUP structure.
|
||||
*
|
||||
* This function is the main task handler for the SLUP system. It updates the timestamp,
|
||||
* and based on the timestamp value, performs various operations such as sending heartbeat
|
||||
* messages, calculating rates, executing dummy data sending, and updating dummy data parameters.
|
||||
* It also calls the slup_parse_task function to parse the received data in the queue.
|
||||
*/
|
||||
void slup_task(SLUP *slup);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user