优化中断

This commit is contained in:
2026-05-28 21:55:38 +08:00
parent a91d6db680
commit 81b62a148d
8 changed files with 150 additions and 200 deletions
+1
View File
@@ -4,4 +4,5 @@
<option name="pythonIntegrationState" value="YES" /> <option name="pythonIntegrationState" value="YES" />
</component> </component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="WestSettings"><![CDATA[{}]]></component>
</project> </project>
+100
View File
@@ -0,0 +1,100 @@
#include "LetterShell.h"
#include "shell.h"
/* 板级BSP头文件 */
#include "Bsp.h"
#define WR_BUFFER_SIZE 512
/* 1. 创建shell对象,开辟shell缓冲区 */
Shell Host; //Shell实例化
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
const COM_MAP_T *HostCom = TTY_COM;
/**
* @brief Shell写函数
* @param ComId 串口号,ch 数据
* @retval void
* @note void
* @example void
*/
signed short ShellWrite(char* ch, unsigned short Len)
{
ComSendStr(HostCom, (uint8_t* )ch,Len);
return Len;
}
/**
* @brief Shell读函数 - 中断回调实现
* @param Vector 中断向量号
* @retval void
* @note void
* @example void
*/
void LetterShellIrqFunc(void *Param)
{
uint8_t ch = 0x00;
ch = ComReceiveChar(Param);
shellHandler(&Host, ch);
}
/**
* @brief 初始化Shell
* @note void
* @param ComX 串口号,baud 波特率
* @retval void
*/
void LetterShellInit(const COM_MAP_T *ComX, uint32_t Baud)
{
//初始化串口
ComStdConfig(ComX, Baud);
//设置串口回调函数
IrqRegister(ComX->Periph.Irqn, LetterShellIrqFunc);
//设置中断等级
IrqEnable(ComX->Periph.Irqn,1,1);
//注册写函数
Host.write = ShellWrite;
//初始化LetterShell
shellInit(&Host, HostBuffer, WR_BUFFER_SIZE);
}
// /**
// * @brief 打印版本号
// * @param void
// * @retval void
// * @note void
// * @example void
// */
// void version(void)
// {
// printf("%s,%s\r\n",HARDWARE_VERSION,SOFTWARE_VERSION);
// }
//
// /**
// * @brief 重启单片机
// * @param void
// * @retval void
// * @note void
// * @example void
// */
// void reboot(void)
// {
// SystemReboot();
// }
//
// /**
// * @brief 串口测试程序
// * @param void
// * @retval void
// * @note void
// * @example void
// */
//
// void comTest(uint8_t ComId)
// {
// }
//
// //打印版本号
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), version, version, version);
// //软重启单片机
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), reboot, reboot, reboot);
// //串口测试
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), comTest, comTest, comTest);
+8
View File
@@ -0,0 +1,8 @@
#ifndef __LETTER_SHELL_H__
#define __LETTER_SHELL_H__
#include "Bsp.h"
void LetterShellInit(const COM_MAP_T *ComX, uint32_t Baud);
#endif
-159
View File
@@ -1,159 +0,0 @@
//
// Created by anonymous on 2026/5/24.
//
#include "Voilet.h"
// LED灯数组
#if (LED_NUM != 0)
const GPIO_CONFIG LED_PERIPH[] = {
{.GpioX = GPIO21, .Mode = GPIO_Mode_Out_PP, .Speed = GPIO_Speed_10MHz},
{.GpioX = GPIO69, .Mode = GPIO_Mode_Out_PP, .Speed = GPIO_Speed_10MHz},
};
#endif
//数字输入数组
#if (DI_NUM != 0)
const GPIO_CONFIG DI_PERIPH[] = {
{},
};
#endif
//数字输出数组
#if (DO_NUM != 0)
const GPIO_CONFIG DO_PERIPH[] = {
{},
};
#endif
//串口配置表
const COM_CONFIG COM_PERIPH[] = {
{COM0,.TxPort = GPIO9, .RxPort =GPIO10, .Speed = GPIO_Speed_50MHz},
{COM1,.TxPort = GPIO2, .RxPort = GPIO3, .Speed = GPIO_Speed_50MHz},
};
void BspExtraInit(void);
/**
* @brief Voilet BSP的初始化函数
* @note void
* @param void
* @retval void
*/
void VoiletBspInit(void) {
unsigned char i = 0;
INTERRUPT_DISABLE
//初始化中断系统
IrqInit();
//初始化延时库
DelayConfig();
//LED灯配置
#if (LED_NUM != 0)
for (i = 0;i < ARRAY_LEN(LED_PERIPH);i++) {
//配置GPIO口
GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
}
#endif
//DI采集配置
#if (DI_NUM != 0)
// for (i = 0;i < DI_NUM;i++) {
// //打开外设时钟
// GpioClockEnable(&LED_PERIPH[i].GpioX);
// //配置GPIO口
// GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
// }
#endif
//DO输出配置
#if (DO_NUM != 0)
// for (i = 0;i < DO_NUM;i++) {
// //打开外设时钟
// GpioClockEnable(&LED_PERIPH[i].GpioX);
// //配置GPIO口
// GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
// }
#endif
//串口配置
for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) {
GpioConfig(&COM_PERIPH[i].TxPort, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed);
GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, COM_PERIPH[i].Speed);
}
INTERRUPT_ENABLE
BspExtraInit();
}
/**
* @brief 扩展库初始化
* @note 理论上扩展库要在BSP的最后加载
* @param void
* @retval void
*/
void BspExtraInit(void)
{
//LetterShell初始化
#ifdef USE_SHELL
LetterShellInit(TTY_COM,TTY_BAUD);
#endif
}
/**
* @brief 打开LED灯
* @note void
* @param Chnl 通道
* @retval void
*/
void LedOn(uint8_t Chnl)
{
if (Chnl >= LED_NUM)
return;
GpioSet(&LED_PERIPH[Chnl].GpioX, RESET);
}
/**
* @brief 关闭LED灯
* @note void
* @param Chnl 通道
* @retval void
*/
void LedOff(uint8_t Chnl)
{
if (Chnl >= LED_NUM)
return;
GpioSet(&LED_PERIPH[Chnl].GpioX, SET);
}
void LedSet(uint8_t Chnl,uint8_t Value)
{
if (Chnl >= LED_NUM)
return;
if (Value == LED_ON) {
GpioSet(&LED_PERIPH[Chnl].GpioX, RESET);
}
else {
GpioSet(&LED_PERIPH[Chnl].GpioX, SET);
}
}
/**
* @brief 切换LED灯状态
* @note void
* @param Chnl 通道 Status 状态
* @retval void
*/
void LedToggle(uint8_t Chnl)
{
if (Chnl >= LED_NUM)
return;
if (GpioGet(&LED_PERIPH[Chnl].GpioX) == LED_ON)
{
GpioSet(&LED_PERIPH[Chnl].GpioX,LED_OFF);
}
else
{
GpioSet(&LED_PERIPH[Chnl].GpioX,LED_ON);
}
}
-39
View File
@@ -1,39 +0,0 @@
//
// Created by anonymous on 2026/5/24.
//
#ifndef VOILET_H
#define VOILET_H
#include "Bsp.h"
#define LED_NUM 2 //LED灯数量
#if (LED_NUM != 0)
#define LED0 0
#define LED1 1
#endif
#define DI_NUM 0
#if (DI_NUM != 0)
#endif
#define DO_NUM 0
#if (DO_NUM != 0)
#endif
#define TTY_BAUD 115200
typedef struct {
GPIO_MAP_T GpioX;
GPIOMode_TypeDef Mode;
GPIOSpeed_TypeDef Speed;
}GPIO_CONFIG;
typedef struct {
COM_MAP_T *ComX;
GPIO_MAP_T TxPort;
GPIO_MAP_T RxPort;
GPIOSpeed_TypeDef Speed;
}COM_CONFIG;
#endif //VOILET_H
+2 -2
View File
@@ -6,11 +6,11 @@
#include <stdint.h> #include <stdint.h>
/* BSP文件 */ /* BSP文件 */
#include "main.h" #include "main.h"
#include "Voilet.h" #include "Bsp.h"
int main(void) { int main(void) {
VoiletBspInit(); BspInit();
while (1) { while (1) {
LedToggle(LED0); LedToggle(LED0);
+38
View File
@@ -0,0 +1,38 @@
//
// Created by anonymous on 2026/5/28.
//
#ifndef _BOARD_H
#define _BOARD_H
/* Chip Library Enable */
/* Extra Library Enable */
#define TTY_COM COM1
#define TTY_BAUD 115200
//GPIO
//数组信号输入/出开关
#define DI_ON 1
#define DI_OFF 0
#define DO_ON 1
#define DO_OFF 0
//LED灯开关
#define LED_ON 0
#define LED_OFF 1
#define LED_NUM 2 //LED灯数量
#if (LED_NUM != 0)
#define LED0 0
#define LED1 1
#endif
#define DI_NUM 0
#if (DI_NUM != 0)
#endif
#define DO_NUM 0
#if (DO_NUM != 0)
#endif
#endif //_BOARD_H
+1
View File
@@ -76,6 +76,7 @@ add_compile_definitions(
# [我加的] 添加头文件搜索路径 - 根据你的项目结构调整 # [我加的] 添加头文件搜索路径 - 根据你的项目结构调整
include_directories( include_directories(
App App
Board
VoiletBspStm32F10x/Bsp/Inc VoiletBspStm32F10x/Bsp/Inc
VoiletBspStm32F10x/StdLib/Inc VoiletBspStm32F10x/StdLib/Inc
VoiletBspStm32F10x/System VoiletBspStm32F10x/System