feat: 换用更简单的通信帧格式
This commit is contained in:
90
app/by_frame.c
Normal file
90
app/by_frame.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "by_frame.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "zf_common_headfile.h"
|
||||||
|
#include "lwrb.h"
|
||||||
|
#include "crc16.h"
|
||||||
|
|
||||||
|
lwrb_t lwrb_struct;
|
||||||
|
uint8_t lwrb_buffer[50];
|
||||||
|
uint8_t frame_buffer[100];
|
||||||
|
|
||||||
|
void by_frame_init(void)
|
||||||
|
{
|
||||||
|
uart_init(BY_FRAME_UART_INDEX, BY_FRAME_UART_BAUDRATE, BY_FRAME_UART_TX_PIN, BY_FRAME_UART_RX_PIN);
|
||||||
|
uart_rx_interrupt(BY_FRAME_UART_INDEX, ENABLE);
|
||||||
|
|
||||||
|
lwrb_init(&lwrb_struct, lwrb_buffer, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_frame_send(uint8_t data_num, uint32_t *data_array)
|
||||||
|
{
|
||||||
|
uint16_t crc_cal = 0;
|
||||||
|
frame_buffer[0] = BY_FRAME_HEAD_1;
|
||||||
|
frame_buffer[1] = BY_FRAME_HEAD_2;
|
||||||
|
|
||||||
|
memcpy(frame_buffer + 2, data_array, data_num * sizeof(uint32_t));
|
||||||
|
crc_cal = crc16_check(frame_buffer, 2 + data_num * sizeof(uint32_t));
|
||||||
|
|
||||||
|
frame_buffer[2 + data_num * sizeof(uint32_t)] = (uint8_t)(crc_cal >> 8);
|
||||||
|
frame_buffer[3 + data_num * sizeof(uint32_t)] = (uint8_t)(crc_cal);
|
||||||
|
|
||||||
|
uart_write_buffer(BY_FRAME_UART_INDEX, frame_buffer, 4 + data_num * sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_frame_parse(uint8_t data_num, uint32_t *data_array)
|
||||||
|
{
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
uint8_t cnt_crc = 2;
|
||||||
|
uint8_t data = 0;
|
||||||
|
uint8_t data_array_temp[100] = {0};
|
||||||
|
uint16_t crc_cal = 0;
|
||||||
|
|
||||||
|
if (lwrb_get_full(&lwrb_struct) >= (4 + data_num * sizeof(uint32_t))) {
|
||||||
|
while (lwrb_read(&lwrb_struct, &data, 1)) {
|
||||||
|
// printf("char : %0.2X\r\n", data);
|
||||||
|
if ((0 == cnt) && (BY_FRAME_HEAD_1 == data)) {
|
||||||
|
cnt = 1;
|
||||||
|
data_array_temp[0] = data;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((1 == cnt) && (BY_FRAME_HEAD_2 == data)) {
|
||||||
|
cnt = 2;
|
||||||
|
data_array_temp[1] = data;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((2 <= cnt) && (cnt < 2 + data_num * sizeof(uint32_t))) {
|
||||||
|
data_array_temp[cnt] = data;
|
||||||
|
cnt++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnt_crc) {
|
||||||
|
crc_cal |= ((uint16_t)data << (--cnt_crc * 8));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("GET CRC %0.4X\r\n", crc_cal);
|
||||||
|
// printf("CAL CRC %0.4X\r\n", crc16_check((uint8_t *)data_array_temp, 2 + data_num * sizeof(uint32_t)));
|
||||||
|
|
||||||
|
if (!cnt_crc) {
|
||||||
|
if (crc_cal == crc16_check((uint8_t *)data_array_temp, 2 + data_num * sizeof(uint32_t))) {
|
||||||
|
memcpy(data_array, data_array_temp + 2, data_num * sizeof(uint32_t));
|
||||||
|
lwrb_reset(&lwrb_struct); // 处理完直接清空缓冲区,避免堆积产生处理阻塞
|
||||||
|
// printf("parsed done!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_frame_parse_uart_handle(uint8_t data)
|
||||||
|
{
|
||||||
|
lwrb_write(&lwrb_struct, &data, 1);
|
||||||
|
}
|
||||||
24
app/by_frame.h
Normal file
24
app/by_frame.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef _BY_FRAME_H__
|
||||||
|
#define _BY_FRAME_H__
|
||||||
|
|
||||||
|
/* BY_TINY_FRAME 的超级减配版本(好吧基本上完全没有关系)
|
||||||
|
* 主要是等应答还是挺慢的,写数据场景只需要下位机校验数据合理性即可,读数据等应答即可
|
||||||
|
* 并且需要同步的参数并不多,所以考虑直接使用定长的特定结构的帧,一帧全部下发
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define BY_FRAME_HEAD_1 (0XEB)
|
||||||
|
#define BY_FRAME_HEAD_2 (0x90)
|
||||||
|
|
||||||
|
#define BY_FRAME_UART_TX_PIN (UART4_MAP1_TX_B0)
|
||||||
|
#define BY_FRAME_UART_RX_PIN (UART4_MAP1_RX_B1)
|
||||||
|
#define BY_FRAME_UART_INDEX (UART_4)
|
||||||
|
#define BY_FRAME_UART_BAUDRATE (115200)
|
||||||
|
|
||||||
|
extern void by_frame_init(void);
|
||||||
|
extern void by_frame_send(uint8_t data_num, uint32_t *data_array);
|
||||||
|
extern void by_frame_parse(uint8_t data_num, uint32_t *data_array);
|
||||||
|
extern void by_frame_parse_uart_handle(uint8_t data);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
#include "by_buzzer.h"
|
#include "by_buzzer.h"
|
||||||
#include "by_rt_button.h"
|
#include "by_rt_button.h"
|
||||||
#include "by_tiny_frame_parse.h"
|
#include "by_frame.h"
|
||||||
|
|
||||||
#include "jj_motion.h"
|
#include "jj_motion.h"
|
||||||
#include "jj_blueteeth.h"
|
#include "jj_blueteeth.h"
|
||||||
@@ -112,7 +112,7 @@ void UART4_IRQHandler(void)
|
|||||||
if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) {
|
if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) {
|
||||||
uint8_t data_s = 0;
|
uint8_t data_s = 0;
|
||||||
uart_query_byte(UART_4, &data_s);
|
uart_query_byte(UART_4, &data_s);
|
||||||
by_tiny_frame_parse_uart_handle(data_s);
|
by_frame_parse_uart_handle(data_s);
|
||||||
USART_ClearITPendingBit(UART4, USART_IT_RXNE);
|
USART_ClearITPendingBit(UART4, USART_IT_RXNE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ void TIM5_IRQHandler(void)
|
|||||||
void TIM6_IRQHandler(void)
|
void TIM6_IRQHandler(void)
|
||||||
{
|
{
|
||||||
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) {
|
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) {
|
||||||
//ICM_getEulerianAngles();
|
// ICM_getEulerianAngles();
|
||||||
imu660ra_get_gyro();
|
imu660ra_get_gyro();
|
||||||
TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
|
TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,11 +38,8 @@ float in_speed;
|
|||||||
float out_speed;
|
float out_speed;
|
||||||
float set_speed = 0.0f;
|
float set_speed = 0.0f;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int cnt1 = 0;
|
int cnt1 = 0;
|
||||||
|
|
||||||
void sport_motion(void)
|
void sport_motion(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -50,7 +47,7 @@ void sport_motion(void)
|
|||||||
in_gyro = imu660ra_gyro_z; // 陀螺仪输入
|
in_gyro = imu660ra_gyro_z; // 陀螺仪输入
|
||||||
in_angle = 0; // 图像远端输入
|
in_angle = 0; // 图像远端输入
|
||||||
in_pos = 0; // 图像近端输入
|
in_pos = 0; // 图像近端输入
|
||||||
in_speed = encoder_get_count(TIM5_ENCOEDER) / 1024 / 0.01 * 0.25; // 速度输入,m/s
|
in_speed = encoder_get_count(TIM5_ENCOEDER) / 1024 / 0.01 * 0.25; // 速度输入,m/s
|
||||||
encoder_clear_count(TIM5_ENCOEDER); // 清除计数
|
encoder_clear_count(TIM5_ENCOEDER); // 清除计数
|
||||||
PID_Compute(&far_gyro_pid);
|
PID_Compute(&far_gyro_pid);
|
||||||
|
|
||||||
|
|||||||
22
app/main.c
22
app/main.c
@@ -31,12 +31,14 @@
|
|||||||
|
|
||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
#include "by_buzzer.h"
|
#include "by_buzzer.h"
|
||||||
#include "by_tiny_frame.h"
|
#include "by_frame.h"
|
||||||
#include "by_rt_button.h"
|
#include "by_rt_button.h"
|
||||||
#include "by_fan_control.h"
|
#include "by_fan_control.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
TYPE_UNION test_data;
|
||||||
|
TYPE_UNION test_data_last;
|
||||||
clock_init(SYSTEM_CLOCK_120M);
|
clock_init(SYSTEM_CLOCK_120M);
|
||||||
system_delay_init();
|
system_delay_init();
|
||||||
debug_init();
|
debug_init();
|
||||||
@@ -50,8 +52,8 @@ int main(void)
|
|||||||
by_rb_init();
|
by_rb_init();
|
||||||
by_pwm_init();
|
by_pwm_init();
|
||||||
// by_buzzer_init();
|
// by_buzzer_init();
|
||||||
|
by_frame_init();
|
||||||
|
|
||||||
by_tiny_frame_init();
|
|
||||||
Page_Init();
|
Page_Init();
|
||||||
sport_pid_init();
|
sport_pid_init();
|
||||||
|
|
||||||
@@ -61,9 +63,17 @@ int main(void)
|
|||||||
printf("ok\r\n");
|
printf("ok\r\n");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
Page_Run();
|
// Page_Run();
|
||||||
//by_buzzer_run();
|
by_frame_parse(1, &test_data.u32);
|
||||||
jj_bt_run();
|
|
||||||
by_tiny_frame_run();
|
if (test_data.u32 != test_data_last.u32) {
|
||||||
|
ips200_show_float(0, 50, test_data.f32, 4, 2);
|
||||||
|
// printf("- %ld\r\n", (uint32_t)(test_data.f32 * 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
test_data_last.u32 = test_data.u32;
|
||||||
|
|
||||||
|
// by_buzzer_run();
|
||||||
|
// jj_bt_run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "by_tiny_frame.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "crc16.h"
|
|
||||||
#include "zf_common_headfile.h"
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
#include "by_tiny_frame_master_read.h"
|
|
||||||
#include "by_tiny_frame_master_write.h"
|
|
||||||
#include "by_tiny_frame_slave_read_write.h"
|
|
||||||
|
|
||||||
void by_tiny_frame_init(void)
|
|
||||||
{
|
|
||||||
/*** 初始化相关外设 ***/
|
|
||||||
uart_init(BY_TF_UART_INDEX, BY_TF_UART_BAUDRATE, BY_TF_UART_TX_PIN, BY_TF_UART_RX_PIN);
|
|
||||||
uart_rx_interrupt(BY_TF_UART_INDEX, ENABLE);
|
|
||||||
|
|
||||||
by_tiny_frame_parse_init();
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
by_tiny_frame_parse_handle_register(by_tiny_frame_read_write_handle);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_run(void)
|
|
||||||
{
|
|
||||||
by_tiny_frame_parse_run();
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
by_tiny_frame_read_run();
|
|
||||||
by_tiny_frame_write_run();
|
|
||||||
#elif defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
by_tiny_frame_read_write_run();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_H__
|
|
||||||
#define _BY_TINY_FRAME_H__
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
#include "by_tiny_frame_master_read.h"
|
|
||||||
#include "by_tiny_frame_master_write.h"
|
|
||||||
#elif defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
#include "by_tiny_frame_slave_read_write.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void by_tiny_frame_init(void);
|
|
||||||
void by_tiny_frame_run(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_CONFIG_H__
|
|
||||||
#define _BY_TINY_FRAME_CONFIG_H__
|
|
||||||
|
|
||||||
#define BY_TF_DEBUG (1)
|
|
||||||
|
|
||||||
#define BY_TF_UART_TX_PIN (UART4_MAP1_TX_B0)
|
|
||||||
#define BY_TF_UART_RX_PIN (UART4_MAP1_RX_B1)
|
|
||||||
#define BY_TF_UART_INDEX (UART_4)
|
|
||||||
#define BY_TF_UART_BAUDRATE (115200)
|
|
||||||
|
|
||||||
#define BY_TF_PARSE_BUFFER_SIZE (50)
|
|
||||||
|
|
||||||
// 注释此项则为主机,否则为从机
|
|
||||||
#define BY_TF_DEVICE_SLAVE
|
|
||||||
|
|
||||||
/********** 从机模式配置选项 **********/
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
// 从机地址 (多从机通信时注意修改地址,避免冲突)
|
|
||||||
#define BY_TF_DEVICE_SLAVE_ADDRESS (0x0D)
|
|
||||||
/********** 主机模式配置选项 **********/
|
|
||||||
#else
|
|
||||||
#define BY_TF_DEVICE_MASTER
|
|
||||||
// 监听/解析 超时时间 单位毫秒
|
|
||||||
#define BY_TF_PARSE_TIMEOUT (200)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#include "by_tiny_frame_master_read.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
|
|
||||||
uint8_t read_processing_flag;
|
|
||||||
uint32_t *data_p;
|
|
||||||
|
|
||||||
void by_tiny_frame_read_run(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data)
|
|
||||||
{
|
|
||||||
// 填充数据
|
|
||||||
by_tf_pack_frame_t frame_s;
|
|
||||||
frame_s.slave_id = slave_id;
|
|
||||||
frame_s.cmd = BY_TINY_FRAME_READ_CMD_CODE;
|
|
||||||
frame_s.reg_addr = reg_addr;
|
|
||||||
frame_s.data = 0;
|
|
||||||
|
|
||||||
// 发送写请求
|
|
||||||
by_tiny_frame_pack_send(&frame_s);
|
|
||||||
// 设置响应监听 id
|
|
||||||
by_tiny_frame_parse_set_listen_slave_id(slave_id);
|
|
||||||
// 注册响应监听回调
|
|
||||||
by_tiny_frame_parse_handle_register(by_tiny_frame_read_handle);
|
|
||||||
// 开启响应监听
|
|
||||||
by_tiny_frame_parse_start_listen();
|
|
||||||
|
|
||||||
read_processing_flag = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
|
||||||
{
|
|
||||||
|
|
||||||
read_processing_flag = 0;
|
|
||||||
if (!status) {
|
|
||||||
*data_p = frame_s.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("****** READ REGISTER DONE ******\r\n");
|
|
||||||
printf("SLAVE ID: 0x%0.2X\r\n", frame_s.frame[0]);
|
|
||||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
|
||||||
if (status) {
|
|
||||||
printf("read operation failed!!!\r\n");
|
|
||||||
} else {
|
|
||||||
printf("read operation successful!!!\r\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_MASTER_READ_H__
|
|
||||||
#define _BY_TINY_FRAME_MASTER_READ_H__
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
|
|
||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
#include "by_tiny_frame_pack.h"
|
|
||||||
|
|
||||||
#define BY_TINY_FRAME_READ_CMD_CODE (0x03)
|
|
||||||
|
|
||||||
extern void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data);
|
|
||||||
extern void by_tiny_frame_read_run(void);
|
|
||||||
extern void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
#include "by_tiny_frame_master_write.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
|
|
||||||
#include "by_tiny_frame_pack.h"
|
|
||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
|
|
||||||
uint8_t write_processing_flag;
|
|
||||||
|
|
||||||
void by_tiny_frame_write_run(void)
|
|
||||||
{
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data)
|
|
||||||
{
|
|
||||||
// 填充数据
|
|
||||||
by_tf_pack_frame_t frame_s;
|
|
||||||
frame_s.slave_id = slave_id;
|
|
||||||
frame_s.cmd = BY_TINY_FRAME_WRITE_CMD_CODE;
|
|
||||||
frame_s.reg_addr = reg_addr;
|
|
||||||
frame_s.data = data;
|
|
||||||
|
|
||||||
// 发送写请求
|
|
||||||
by_tiny_frame_pack_send(&frame_s);
|
|
||||||
// 设置响应监听 id
|
|
||||||
by_tiny_frame_parse_set_listen_slave_id(slave_id);
|
|
||||||
// 注册响应监听回调
|
|
||||||
by_tiny_frame_parse_handle_register(by_tiny_frame_write_handle);
|
|
||||||
// 开启响应监听
|
|
||||||
by_tiny_frame_parse_start_listen();
|
|
||||||
|
|
||||||
write_processing_flag = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
|
||||||
{
|
|
||||||
write_processing_flag = 0;
|
|
||||||
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("****** WRITE REGISTER DONE ******\r\n");
|
|
||||||
printf("SLAVE ID: 0x%0.2X\r\n", frame_s.frame[0]);
|
|
||||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
|
||||||
if (status) {
|
|
||||||
printf("write operation failed!!!\r\n");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
printf("write operation successful!!!\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_MASTER_WRITE_H__
|
|
||||||
#define _BY_TINY_FRAME_MASTER_WRITE_H__
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
|
|
||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
#include "by_tiny_frame_pack.h"
|
|
||||||
|
|
||||||
#define BY_TINY_FRAME_WRITE_CMD_CODE (0x06)
|
|
||||||
|
|
||||||
extern void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data);
|
|
||||||
extern void by_tiny_frame_write_run(void);
|
|
||||||
extern void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#include "by_tiny_frame_pack.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "zf_common_headfile.h"
|
|
||||||
#include "crc16.h"
|
|
||||||
|
|
||||||
void by_tiny_frame_pack_init(void)
|
|
||||||
{
|
|
||||||
/** nothing to init **/
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_pack_send(by_tf_pack_frame_t *frame_s)
|
|
||||||
{
|
|
||||||
uint16_t calc_crc_val = 0;
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
frame_s->frame[0] = ((frame_s->slave_id << 1) + 1);
|
|
||||||
#else
|
|
||||||
frame_s->frame[0] = (frame_s->slave_id << 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 填充指令段
|
|
||||||
frame_s->frame[1] = frame_s->cmd;
|
|
||||||
// 填充寄存器地址段
|
|
||||||
frame_s->frame[2] = (uint8_t)((frame_s->reg_addr >> 8) & 0xFF);
|
|
||||||
frame_s->frame[3] = (uint8_t)(frame_s->reg_addr & 0xFF);
|
|
||||||
// 填充数据段
|
|
||||||
frame_s->frame[4] = (uint8_t)((frame_s->data >> 24) & 0xFF);
|
|
||||||
frame_s->frame[5] = (uint8_t)((frame_s->data >> 16) & 0xFF);
|
|
||||||
frame_s->frame[6] = (uint8_t)((frame_s->data >> 8) & 0xFF);
|
|
||||||
frame_s->frame[7] = (uint8_t)(frame_s->data & 0xFF);
|
|
||||||
// 填充 CRC 段
|
|
||||||
calc_crc_val = crc16_check(frame_s->frame, (sizeof(frame_s->frame) - 2));
|
|
||||||
frame_s->frame[8] = (uint8_t)((calc_crc_val >> 8) & 0xFF);
|
|
||||||
frame_s->frame[9] = (uint8_t)(calc_crc_val & 0xFF);
|
|
||||||
|
|
||||||
/** 从串口发送 **/
|
|
||||||
uart_write_buffer(BY_TF_UART_INDEX, frame_s->frame, sizeof(frame_s->frame));
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_PACK_H__
|
|
||||||
#define _BY_TINY_FRAME_PACK_H__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
|
|
||||||
// 从机地址 (1b) - 功能码 (1b) - 寄存器地址 (2b) - 数据 (4b) - CRC(2b)
|
|
||||||
// 从机地址 (1b) 0-127, 最低位表示发送方,主机请求低位为 0,从机应答低位为 1
|
|
||||||
// 高字节在前
|
|
||||||
|
|
||||||
typedef struct by_tf_pack_frame_t {
|
|
||||||
uint8_t frame[10];
|
|
||||||
uint8_t slave_id;
|
|
||||||
uint8_t cmd;
|
|
||||||
uint16_t reg_addr;
|
|
||||||
uint32_t data;
|
|
||||||
} by_tf_pack_frame_t;
|
|
||||||
|
|
||||||
extern void by_tiny_frame_pack_init(void);
|
|
||||||
extern void by_tiny_frame_pack_send(by_tf_pack_frame_t *frame_s);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
|
|
||||||
#include "crc16.h"
|
|
||||||
#include "lwrb.h"
|
|
||||||
|
|
||||||
lwrb_t lwrb_struct;
|
|
||||||
uint8_t buffer_rb[BY_TF_PARSE_BUFFER_SIZE];
|
|
||||||
uint8_t buffer_out;
|
|
||||||
uint8_t listen_slave_id;
|
|
||||||
uint8_t listen_flag;
|
|
||||||
uint16_t listen_timeout;
|
|
||||||
uint16_t listen_timevia;
|
|
||||||
by_tf_parse_frame_t frame_now;
|
|
||||||
by_tf_parse_done_handle_func parse_done_handle;
|
|
||||||
|
|
||||||
void by_tiny_frame_parse_init(void)
|
|
||||||
{
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
listen_timeout = BY_TF_PARSE_TIMEOUT;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** 初始化环形缓冲区 **/
|
|
||||||
lwrb_init(&lwrb_struct, buffer_rb, 40);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t by_tiny_frame_parse_listening(by_tf_parse_frame_t *frame_s, const uint8_t slave_id, const uint8_t buff)
|
|
||||||
{
|
|
||||||
|
|
||||||
static uint8_t cnt_s = 0;
|
|
||||||
static uint8_t cnt_rest_s = 0;
|
|
||||||
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("%0.2X\r\n", buff);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
do {
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
if ((0 == cnt_s) && ((slave_id << 1) == buff)) {
|
|
||||||
#else
|
|
||||||
if ((0 == cnt_s) && (((slave_id << 1) + 1) == buff)) {
|
|
||||||
#endif
|
|
||||||
memset(frame_s, 0, sizeof(*frame_s));
|
|
||||||
cnt_s = 1;
|
|
||||||
cnt_rest_s = 9;
|
|
||||||
frame_s->frame[0] = buff;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (1 <= cnt_s) {
|
|
||||||
frame_s->frame[cnt_s] = buff;
|
|
||||||
cnt_s++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == --cnt_rest_s) {
|
|
||||||
cnt_s = 0;
|
|
||||||
|
|
||||||
frame_s->cmd = frame_s->frame[1];
|
|
||||||
frame_s->reg_addr |= ((uint16_t)frame_s->frame[2] << 8);
|
|
||||||
frame_s->reg_addr |= (uint16_t)frame_s->frame[3];
|
|
||||||
frame_s->data |= ((uint32_t)frame_s->frame[4] << 24);
|
|
||||||
frame_s->data |= ((uint32_t)frame_s->frame[5] << 16);
|
|
||||||
frame_s->data |= ((uint32_t)frame_s->frame[6] << 8);
|
|
||||||
frame_s->data |= (uint32_t)frame_s->frame[7];
|
|
||||||
frame_s->crc_val |= ((uint16_t)frame_s->frame[8] << 8);
|
|
||||||
frame_s->crc_val |= (uint16_t)frame_s->frame[9];
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief by_tf_parse 串口回调函数,在对应串口中断函数中调用
|
|
||||||
*
|
|
||||||
* @param buff
|
|
||||||
*/
|
|
||||||
void by_tiny_frame_parse_uart_handle(uint8_t buff)
|
|
||||||
{
|
|
||||||
lwrb_write(&lwrb_struct, &buff, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief by_tf_parse 定时回调函数,要求触发周期为 1ms
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void by_tiny_frame_parse_timer_handle(void)
|
|
||||||
{
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
if (listen_flag) {
|
|
||||||
listen_timevia++;
|
|
||||||
} else {
|
|
||||||
listen_timevia = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void by_tiny_frame_parse_run(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_MASTER)
|
|
||||||
if (0 == listen_flag) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (listen_timeout <= listen_timevia) {
|
|
||||||
// 接收超时,停止监听
|
|
||||||
parse_done_handle(frame_now, 1);
|
|
||||||
by_tiny_frame_parse_end_listen();
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("by_tf_listen timeout\r\n");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < lwrb_get_full(&lwrb_struct); i++) {
|
|
||||||
|
|
||||||
if (!lwrb_read(&lwrb_struct, &buffer_out, 1)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO 目前接收校验错误也会等待直至超时
|
|
||||||
// TODO 待结合 read&wirte 部分修改监听的从机地址
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
if (!by_tiny_frame_parse_listening(&frame_now, BY_TF_DEVICE_SLAVE_ADDRESS, buffer_out))
|
|
||||||
#else
|
|
||||||
if (!by_tiny_frame_parse_listening(&frame_now, listen_slave_id, buffer_out))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
if (!by_tiny_frame_parse_crc(&frame_now)) {
|
|
||||||
|
|
||||||
// 接收成功后停止监听
|
|
||||||
by_tiny_frame_parse_end_listen();
|
|
||||||
// 解析成功回调
|
|
||||||
parse_done_handle(frame_now, 0);
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("frame parsed!\r\n");
|
|
||||||
#endif
|
|
||||||
// 解析帧
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if (!mp_cmd_parse_modbus_handle(data)) {
|
|
||||||
// mp_cmd_mb_parse(&mp_cmd_mb_now, &mp_cmd_parsed_now);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s)
|
|
||||||
{
|
|
||||||
uint16_t calc_crc_val = 0;
|
|
||||||
|
|
||||||
calc_crc_val = crc16_check(frame_s->frame, (sizeof(frame_s->frame) - 2));
|
|
||||||
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("get: %0.2X", frame_s->crc_val);
|
|
||||||
printf("\r\n");
|
|
||||||
|
|
||||||
printf("cal: %0.2X", calc_crc_val);
|
|
||||||
printf("\r\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((frame_s->crc_val == calc_crc_val) || (frame_s->crc_val == 0xFFFF)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 校验错误则直接结束监听
|
|
||||||
by_tiny_frame_parse_end_listen();
|
|
||||||
parse_done_handle(frame_now, 1);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_parse_handle_register(by_tf_parse_done_handle_func func)
|
|
||||||
{
|
|
||||||
// FIXME 监听过程中应不允许更改
|
|
||||||
// FIXME 未校验是否传入非空值,另外假设未执行注册,也会产生非法访问
|
|
||||||
parse_done_handle = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_parse_start_listen(void)
|
|
||||||
{
|
|
||||||
listen_flag = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_parse_end_listen(void)
|
|
||||||
{
|
|
||||||
listen_flag = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_parse_set_listen_slave_id(uint8_t slave_id)
|
|
||||||
{
|
|
||||||
listen_slave_id = slave_id;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_PARSE_H__
|
|
||||||
#define _BY_TINY_FRAME_PARSE_H__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
|
|
||||||
// 从机地址 (1b) - 功能码 (1b) - 寄存器地址 (2b) - 数据 (4b) - CRC(2b)
|
|
||||||
// 从机地址 (1b) 0-127, 最低位表示发送方,主机请求低位为 0,从机应答低位为 1
|
|
||||||
// 高字节在前
|
|
||||||
|
|
||||||
typedef struct by_tf_parse_frame_t {
|
|
||||||
uint8_t frame[10];
|
|
||||||
uint8_t cmd;
|
|
||||||
uint16_t reg_addr;
|
|
||||||
uint16_t crc_val;
|
|
||||||
uint32_t data;
|
|
||||||
} by_tf_parse_frame_t;
|
|
||||||
|
|
||||||
typedef void (*by_tf_parse_done_handle_func)(by_tf_parse_frame_t, uint8_t);
|
|
||||||
|
|
||||||
extern void by_tiny_frame_parse_init(void);
|
|
||||||
extern void by_tiny_frame_parse_uart_handle(uint8_t buff);
|
|
||||||
extern void by_tiny_frame_parse_run(void);
|
|
||||||
extern uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s);
|
|
||||||
extern void by_tiny_frame_parse_handle_register(by_tf_parse_done_handle_func func);
|
|
||||||
extern void by_tiny_frame_parse_start_listen(void);
|
|
||||||
extern void by_tiny_frame_parse_end_listen(void);
|
|
||||||
extern void by_tiny_frame_parse_set_listen_slave_id(uint8_t slave_id);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
#include "by_tiny_frame_slave_read_write.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
#include "by_tiny_frame_pack.h"
|
|
||||||
|
|
||||||
#include "jj_motion.h"
|
|
||||||
|
|
||||||
void by_tiny_frame_read_write_run(void)
|
|
||||||
{
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void by_tiny_frame_read_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
|
||||||
{
|
|
||||||
by_tf_pack_frame_t frame_pack_s;
|
|
||||||
|
|
||||||
frame_pack_s.slave_id = BY_TF_DEVICE_SLAVE_ADDRESS;
|
|
||||||
frame_pack_s.cmd = frame_s.cmd;
|
|
||||||
frame_pack_s.reg_addr = frame_s.reg_addr;
|
|
||||||
|
|
||||||
if (status) {
|
|
||||||
// 接收出错,一般为 CRC 校验错误
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (frame_s.cmd) {
|
|
||||||
case 0x03:
|
|
||||||
// 添加查询接口,操作完成后应答,主机读取,这个是从机
|
|
||||||
frame_pack_s.data = 0XFFFFFFFF; //it's useless just now
|
|
||||||
by_tiny_frame_pack_send(&frame_pack_s);
|
|
||||||
break;
|
|
||||||
case 0x06:
|
|
||||||
// 添加写入接口,操作完成后应答
|
|
||||||
switch (frame_pack_s.reg_addr) {
|
|
||||||
case 0x00:
|
|
||||||
in_angle = (float)frame_s.data;
|
|
||||||
break;
|
|
||||||
case 0x01:
|
|
||||||
in_pos = (float)frame_s.data;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
by_tiny_frame_pack_send(&frame_pack_s);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (BY_TF_DEBUG)
|
|
||||||
printf("****** EXECUTE CMD SUCCESSFUL ******\r\n");
|
|
||||||
printf("Device ID: 0x%0.2X\r\n", BY_TF_DEVICE_SLAVE_ADDRESS);
|
|
||||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#ifndef _BY_TINY_FRAME_SLAVE_READ_WRITE_H__
|
|
||||||
#define _BY_TINY_FRAME_SLAVE_READ_WRITE_H__
|
|
||||||
|
|
||||||
#include "by_tiny_frame_config.h"
|
|
||||||
|
|
||||||
#if defined(BY_TF_DEVICE_SLAVE)
|
|
||||||
|
|
||||||
#include "by_tiny_frame_parse.h"
|
|
||||||
|
|
||||||
#define BY_TINY_FRAME_READ_CMD_CODE (0x03)
|
|
||||||
#define BY_TINY_FRAME_WRITE_CMD_CODE (0x06)
|
|
||||||
|
|
||||||
extern void by_tiny_frame_read_write_run(void);
|
|
||||||
extern void by_tiny_frame_read_write_handle(by_tf_parse_frame_t frame_s, uint8_t status);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -110,7 +110,7 @@
|
|||||||
// 例:C5-C12 IPS200_DATAPORT 设置为 GPIOC DATA_START_NUM 设置为 5
|
// 例:C5-C12 IPS200_DATAPORT 设置为 GPIOC DATA_START_NUM 设置为 5
|
||||||
// --------------------双排 SPI 接口两寸屏幕引脚定义--------------------//
|
// --------------------双排 SPI 接口两寸屏幕引脚定义--------------------//
|
||||||
|
|
||||||
#define IPS200_DEFAULT_DISPLAY_DIR (IPS200_PORTAIT) // 默认的显示方向
|
#define IPS200_DEFAULT_DISPLAY_DIR (IPS200_CROSSWISE) // 默认的显示方向
|
||||||
#define IPS200_DEFAULT_PENCOLOR (RGB565_YELLOW) // 默认的画笔颜色
|
#define IPS200_DEFAULT_PENCOLOR (RGB565_YELLOW) // 默认的画笔颜色
|
||||||
#define IPS200_DEFAULT_BGCOLOR (RGB565_BLACK) // 默认的背景颜色
|
#define IPS200_DEFAULT_BGCOLOR (RGB565_BLACK) // 默认的背景颜色
|
||||||
#define IPS200_DEFAULT_DISPLAY_FONT (IPS200_8X16_FONT) // 默认的字体模式
|
#define IPS200_DEFAULT_DISPLAY_FONT (IPS200_8X16_FONT) // 默认的字体模式
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
* CH32V307VCT6 Opensourec Library <20><><EFBFBD><EFBFBD>CH32V307VCT6 <20><>Դ<EFBFBD>⣩<EFBFBD><E2A3A9>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڹٷ<DAB9> SDK <20>ӿڵĵ<DAB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
|
* CH32V307VCT6 Opensourec Library <20><><EFBFBD><EFBFBD>CH32V307VCT6 <20><>Դ<EFBFBD>⣩<EFBFBD><E2A3A9>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڹٷ<DAB9> SDK <20>ӿڵĵ<DAB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
|
||||||
* Copyright (c) 2022 SEEKFREE <20><><EFBFBD>ɿƼ<C9BF>
|
* Copyright (c) 2022 SEEKFREE <20><><EFBFBD>ɿƼ<C9BF>
|
||||||
*
|
*
|
||||||
* <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>CH32V307VCT6 <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
* <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD> CH32V307VCT6 <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||||
*
|
*
|
||||||
* CH32V307VCT6 <20><>Դ<EFBFBD><D4B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* CH32V307VCT6 <20><>Դ<EFBFBD><D4B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
* <20><><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᷢ<EFBFBD><E1B7A2><EFBFBD><EFBFBD> GPL<50><4C>GNU General Public License<73><65><EFBFBD><EFBFBD> GNUͨ<55>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* <20><><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᷢ<EFBFBD><E1B7A2><EFBFBD><EFBFBD> GPL<50><4C>GNU General Public License<73><65><EFBFBD><EFBFBD> GNU ͨ<EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
* <20><> GPL <20>ĵ<EFBFBD>3<EFBFBD>棨<EFBFBD><EFBFBD> GPL3.0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>κκ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><DEB8><EFBFBD>
|
* <20><> GPL <20>ĵ<EFBFBD> 3 <EFBFBD>棨<EFBFBD><EFBFBD> GPL3.0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>κκ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><DEB8><EFBFBD>
|
||||||
*
|
*
|
||||||
* <20><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κεı<CEB5>֤
|
* <20><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κεı<CEB5>֤
|
||||||
* <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB>ʺ<EFBFBD><CABA>ض<EFBFBD><D8B6><EFBFBD>;<EFBFBD>ı<EFBFBD>֤
|
* <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB>ʺ<EFBFBD><CABA>ض<EFBFBD><D8B6><EFBFBD>;<EFBFBD>ı<EFBFBD>֤
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* <20>ļ<DEB8>¼
|
* <20>ļ<DEB8>¼
|
||||||
* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ע
|
* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ע
|
||||||
* 2022-09-15 <20><>W first version
|
* 2022-09-15 <20><> W first version
|
||||||
********************************************************************************************************************/
|
********************************************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@@ -95,9 +95,9 @@ void pit_disable (pit_index_enum pit_n)
|
|||||||
//-------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> timer_ch <20><>ʱ<EFBFBD><CAB1>ͨ<EFBFBD><CDA8>
|
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> timer_ch <20><>ʱ<EFBFBD><CAB1>ͨ<EFBFBD><CDA8>
|
||||||
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> us <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>(1-65535)
|
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> us <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> (1-65535)
|
||||||
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD> void
|
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD> void
|
||||||
// <20><>ע<EFBFBD><D7A2>Ϣ pit_init(TIMER_1, 5); ʹ<>ö<EFBFBD>ʱ<EFBFBD><CAB1>1<EFBFBD><EFBFBD>Ϊ5msһ<EFBFBD>ε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
// <20><>ע<EFBFBD><D7A2>Ϣ pit_init(TIMER_1, 5); ʹ<>ö<EFBFBD>ʱ<EFBFBD><CAB1> 1 <EFBFBD><EFBFBD>Ϊ 5ms һ<EFBFBD>ε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
//-------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
void pit_init (pit_index_enum pit_n, uint32 period)
|
void pit_init (pit_index_enum pit_n, uint32 period)
|
||||||
{
|
{
|
||||||
@@ -136,10 +136,10 @@ void pit_init (pit_index_enum pit_n, uint32 period)
|
|||||||
TIM_TimeBaseStructure.TIM_Period = period_temp;
|
TIM_TimeBaseStructure.TIM_Period = period_temp;
|
||||||
TIM_TimeBaseStructure.TIM_Prescaler = freq_div; // <20><>Ƶֵ
|
TIM_TimeBaseStructure.TIM_Prescaler = freq_div; // <20><>Ƶֵ
|
||||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ӷָ<D3B7>:TDTS = Tck_tim
|
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ӷָ<D3B7>:TDTS = Tck_tim
|
||||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // TIM<49><4D><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>ģʽ
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // TIM <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||||
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; // <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0
|
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; // <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 0
|
||||||
TIM_TimeBaseInit(tim_index, &TIM_TimeBaseStructure); // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>TIMx<4D><78>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
|
TIM_TimeBaseInit(tim_index, &TIM_TimeBaseStructure); // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> TIMx <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
|
||||||
TIM_ITConfig(tim_index,TIM_IT_Update,ENABLE ); // ʹ<><CAB9>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>TIM<49>ж<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
TIM_ITConfig(tim_index,TIM_IT_Update,ENABLE ); // ʹ<><CAB9>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD> TIM <EFBFBD>жϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
TIM_ClearITPendingBit(tim_index, TIM_IT_Update);
|
TIM_ClearITPendingBit(tim_index, TIM_IT_Update);
|
||||||
|
|
||||||
const uint32 irq_index[10] =
|
const uint32 irq_index[10] =
|
||||||
@@ -156,7 +156,7 @@ void pit_init (pit_index_enum pit_n, uint32 period)
|
|||||||
TIM10_UP_IRQn
|
TIM10_UP_IRQn
|
||||||
};
|
};
|
||||||
|
|
||||||
interrupt_set_priority((IRQn_Type)irq_index[(uint8)pit_n], 0x03); // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
interrupt_set_priority((IRQn_Type)irq_index[(uint8)pit_n], (1<<5) | 3); // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||||
interrupt_enable((IRQn_Type)irq_index[pit_n]); // ʹ<><CAB9><EFBFBD>ж<EFBFBD>
|
interrupt_enable((IRQn_Type)irq_index[pit_n]); // ʹ<><CAB9><EFBFBD>ж<EFBFBD>
|
||||||
|
|
||||||
TIM_Cmd(tim_index, ENABLE); // ʹ<>ܶ<EFBFBD>ʱ<EFBFBD><CAB1>
|
TIM_Cmd(tim_index, ENABLE); // ʹ<>ܶ<EFBFBD>ʱ<EFBFBD><CAB1>
|
||||||
|
|||||||
Reference in New Issue
Block a user