Compare commits
6 Commits
42ceefc5ad
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 249409457f | |||
| 9869835739 | |||
| cfad5acd82 | |||
| 0516210c95 | |||
| 9f38c6ea75 | |||
| 4f108bc26a |
@@ -0,0 +1,3 @@
|
||||
[submodule "ThirdParty/LetterShellV3"]
|
||||
path = ThirdParty/LetterShellV3
|
||||
url = https://git.linuxacme.com/iorebuild/LetterShellV3.git
|
||||
+14
-36
@@ -1,37 +1,22 @@
|
||||
#ifndef __BSP_H__
|
||||
#define __BSP_H__
|
||||
|
||||
#include "VoiletTypeDef.h"
|
||||
#include "Voilet.h"
|
||||
|
||||
#define ARRAY_LEN(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/* BOOL类型定义 */
|
||||
typedef enum {
|
||||
false = 0,
|
||||
true = 1,
|
||||
} bool_t;
|
||||
|
||||
//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
|
||||
|
||||
/* Voilet */
|
||||
void VoiletBspInit(void);
|
||||
/* Board */
|
||||
#include "Board.h"
|
||||
|
||||
/* BSP */
|
||||
void AllPeriphClockDisable(void);
|
||||
void BspInit(void);
|
||||
void LedOn(uint8_t Chnl);
|
||||
void LedOff(uint8_t Chnl);
|
||||
void LedSet(uint8_t Chnl,uint8_t Value);
|
||||
void LedToggle(uint8_t Chnl);
|
||||
|
||||
//Interrupt
|
||||
void IrqInit(void);
|
||||
void IrqRegister(unsigned char Irqn,void(*Func)(void *Param));
|
||||
void IrqEnable(uint32_t Irq, uint8_t NvicPrePriority, uint8_t NvicSubPriority);
|
||||
void IrqDisable(uint32_t Irq);
|
||||
|
||||
//System Delay
|
||||
void DelayConfig(void);
|
||||
unsigned int DwtCntGet(void);
|
||||
@@ -39,18 +24,16 @@ void DelayUs(unsigned int Us);
|
||||
void DelayMs(unsigned int Ms);
|
||||
|
||||
/* GPIO */
|
||||
void GpioClockEnable(const GPIO_MAP_T *GpioX);
|
||||
void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed);
|
||||
void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value);
|
||||
unsigned char GpioGet(const GPIO_MAP_T *GpioX);
|
||||
|
||||
/* UART */
|
||||
void UartClockEnable(const COM_MAP_T *ComX);
|
||||
// void UartSendChar(uint32_t ComId,uint8_t Data);
|
||||
// void UartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len);
|
||||
// void UartStdConfig(COM_MAP_T ComX, uint32_t baud);
|
||||
// void UartAdvConfig(const COM_MAP_T *ComX, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity);
|
||||
// #define UartStdConfig(ComX, baud) UartStdConfig((COM_MAP_T)ComX, baud)
|
||||
void ComSendChar(const COM_MAP_T *ComX,uint8_t Data);
|
||||
void ComSendStr(const COM_MAP_T *ComX,uint8_t* Data, uint64_t Len);
|
||||
uint8_t ComReceiveChar(const COM_MAP_T *ComX);
|
||||
void ComStdConfig(const COM_MAP_T *ComX, uint32_t Baud);
|
||||
void ComAdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity);
|
||||
|
||||
// /* 板级BSP头文件 */
|
||||
// #include "Board.h"
|
||||
@@ -86,11 +69,6 @@ void UartClockEnable(const COM_MAP_T *ComX);
|
||||
// void LedOn(uint8_t Chnl);
|
||||
//
|
||||
//
|
||||
// //Interrupt
|
||||
// void SystemInterruptInit(void);
|
||||
// void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t));
|
||||
// void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority);
|
||||
// void InterruptDisable(uint32_t Vector);
|
||||
//
|
||||
// //Usart
|
||||
// void SystemUsartInit(void);
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef __LETTER_SHELL_H__
|
||||
#define __LETTER_SHELL_H__
|
||||
|
||||
#include "Bsp.h"
|
||||
|
||||
void LetterShellInit(uint32_t ComId, uint32_t baud);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,236 @@
|
||||
//
|
||||
// Created by anonymous on 2026/5/24.
|
||||
//
|
||||
|
||||
#ifndef _VOILET_PORT_H
|
||||
#define _VOILET_PORT_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define INTERRUPT_ENABLE __set_PRIMASK(0); //开启中断
|
||||
#define INTERRUPT_DISABLE __set_PRIMASK(1); //关闭中断
|
||||
|
||||
#define ARRAY_LEN(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/* BOOL类型定义 */
|
||||
typedef enum {
|
||||
false = 0,
|
||||
true = 1,
|
||||
} BOOL_MAP_T;
|
||||
|
||||
/* DI数字信号采集枚举 */
|
||||
enum {
|
||||
DI_OFF = 0,
|
||||
DI_ON
|
||||
};
|
||||
/* DO数字信号输出枚举 */
|
||||
enum {
|
||||
DO_OFF = 0,
|
||||
DO_ON
|
||||
};
|
||||
/* LED灯输出枚举 */
|
||||
enum {
|
||||
LED_OFF = 0,
|
||||
LED_ON
|
||||
};
|
||||
|
||||
/* Interrupt Irq */
|
||||
typedef struct {
|
||||
unsigned char Irqn;
|
||||
void *Periph;
|
||||
void (*IrqCallback)(void *Param);
|
||||
}IRQ_MAP_T;
|
||||
|
||||
#define IRQ_NUM 67 //系统共有多少个中断
|
||||
#define NVIC_GROUP_LEVEL NVIC_PriorityGroup_2 //中断组
|
||||
|
||||
/* GPIO */
|
||||
typedef struct {
|
||||
GPIO_TypeDef *GpioPort;
|
||||
unsigned short GpioPin;
|
||||
// unsigned char Irqn;
|
||||
} GPIO_PERIPH_T;
|
||||
|
||||
typedef struct {
|
||||
void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State);
|
||||
unsigned int ClockTree;
|
||||
GPIO_PERIPH_T Periph;
|
||||
} GPIO_MAP_T;
|
||||
|
||||
typedef struct {
|
||||
GPIO_MAP_T GpioX;
|
||||
GPIOMode_TypeDef Mode;
|
||||
GPIOSpeed_TypeDef Speed;
|
||||
}GPIO_CONFIG;
|
||||
|
||||
// ==================== GPIOA 组 ====================
|
||||
#ifdef GPIOA
|
||||
#define GPIO0 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_0}}
|
||||
#define GPIO1 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_1}}
|
||||
#define GPIO2 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_2}}
|
||||
#define GPIO3 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_3}}
|
||||
#define GPIO4 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_4}}
|
||||
#define GPIO5 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_5}}
|
||||
#define GPIO6 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_6}}
|
||||
#define GPIO7 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_7}}
|
||||
#define GPIO8 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_8}}
|
||||
#define GPIO9 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_9}}
|
||||
#define GPIO10 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_10}}
|
||||
#define GPIO11 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_11}}
|
||||
#define GPIO12 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_12}}
|
||||
#define GPIO13 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_13}}
|
||||
#define GPIO14 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_14}}
|
||||
#define GPIO15 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_15}}
|
||||
#endif
|
||||
#ifdef GPIOB
|
||||
// ==================== GPIOB 组 ====================
|
||||
#define GPIO16 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_0}}
|
||||
#define GPIO17 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_1}}
|
||||
#define GPIO18 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_2}}
|
||||
#define GPIO19 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_3}}
|
||||
#define GPIO20 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_4}}
|
||||
#define GPIO21 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_5}}
|
||||
#define GPIO22 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_6}}
|
||||
#define GPIO23 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_7}}
|
||||
#define GPIO24 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_8}}
|
||||
#define GPIO25 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_9}}
|
||||
#define GPIO26 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_10}}
|
||||
#define GPIO27 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_11}}
|
||||
#define GPIO28 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_12}}
|
||||
#define GPIO29 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_13}}
|
||||
#define GPIO30 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_14}}
|
||||
#define GPIO31 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_15}}
|
||||
#endif
|
||||
#ifdef GPIOC
|
||||
// ==================== GPIOC 组 ====================
|
||||
#define GPIO32 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_0}}
|
||||
#define GPIO33 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_1}}
|
||||
#define GPIO34 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_2}}
|
||||
#define GPIO35 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_3}}
|
||||
#define GPIO36 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_4}}
|
||||
#define GPIO37 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_5}}
|
||||
#define GPIO38 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_6}}
|
||||
#define GPIO39 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_7}}
|
||||
#define GPIO40 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_8}}
|
||||
#define GPIO41 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_9}}
|
||||
#define GPIO42 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_10}}
|
||||
#define GPIO43 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_11}}
|
||||
#define GPIO44 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_12}}
|
||||
#define GPIO45 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_13}}
|
||||
#define GPIO46 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_14}}
|
||||
#define GPIO47 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_15}}
|
||||
#endif
|
||||
#ifdef GPIOD
|
||||
// ==================== GPIOD 组 ====================
|
||||
#define GPIO48 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_0}}
|
||||
#define GPIO49 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_1}}
|
||||
#define GPIO50 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_2}}
|
||||
#define GPIO51 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_3}}
|
||||
#define GPIO52 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_4}}
|
||||
#define GPIO53 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_5}}
|
||||
#define GPIO54 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_6}}
|
||||
#define GPIO55 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_7}}
|
||||
#define GPIO56 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_8}}
|
||||
#define GPIO57 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_9}}
|
||||
#define GPIO58 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_10}}
|
||||
#define GPIO59 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_11}}
|
||||
#define GPIO60 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_12}}
|
||||
#define GPIO61 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_13}}
|
||||
#define GPIO62 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_14}}
|
||||
#define GPIO63 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_15}}
|
||||
#endif
|
||||
#ifdef GPIOE
|
||||
// ==================== GPIOE 组 ====================
|
||||
#define GPIO64 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_0}}
|
||||
#define GPIO65 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_1}}
|
||||
#define GPIO66 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_2}}
|
||||
#define GPIO67 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_3}}
|
||||
#define GPIO68 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_4}}
|
||||
#define GPIO69 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_5}}
|
||||
#define GPIO70 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_6}}
|
||||
#define GPIO71 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_7}}
|
||||
#define GPIO72 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_8}}
|
||||
#define GPIO73 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_9}}
|
||||
#define GPIO74 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_10}}
|
||||
#define GPIO75 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_11}}
|
||||
#define GPIO76 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_12}}
|
||||
#define GPIO77 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_13}}
|
||||
#define GPIO78 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_14}}
|
||||
#define GPIO79 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_15}}
|
||||
#endif
|
||||
#ifdef GPIOF
|
||||
// ==================== GPIOF 组 ====================
|
||||
#define GPIO80 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_0}}
|
||||
#define GPIO81 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_1}}
|
||||
#define GPIO82 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_2}}
|
||||
#define GPIO83 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_3}}
|
||||
#define GPIO84 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_4}}
|
||||
#define GPIO85 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_5}}
|
||||
#define GPIO86 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_6}}
|
||||
#define GPIO87 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_7}}
|
||||
#define GPIO88 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_8}}
|
||||
#define GPIO89 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_9}}
|
||||
#define GPIO90 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_10}}
|
||||
#define GPIO91 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_11}}
|
||||
#define GPIO92 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_12}}
|
||||
#define GPIO93 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_13}}
|
||||
#define GPIO94 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_14}}
|
||||
#define GPIO95 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_15}}
|
||||
#endif
|
||||
#ifdef GPIOG
|
||||
// ==================== GPIOG 组 ====================
|
||||
#define GPIO96 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_0}}
|
||||
#define GPIO97 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_1}}
|
||||
#define GPIO98 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_2}}
|
||||
#define GPIO99 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_3}}
|
||||
#define GPIO100 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_4}}
|
||||
#define GPIO101 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_5}}
|
||||
#define GPIO102 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_6}}
|
||||
#define GPIO103 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_7}}
|
||||
#define GPIO104 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_8}}
|
||||
#define GPIO105 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_9}}
|
||||
#define GPIO106 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_10}}
|
||||
#define GPIO107 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_11}}
|
||||
#define GPIO108 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_12}}
|
||||
#define GPIO109 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_13}}
|
||||
#define GPIO110 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_14}}
|
||||
#define GPIO111 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_15}}
|
||||
#endif
|
||||
|
||||
#define GPIO_NULL {0, 0, {0, 0}}
|
||||
|
||||
/* COM */
|
||||
typedef struct {
|
||||
USART_TypeDef *UartId;
|
||||
unsigned char Irqn;
|
||||
} COM_PERIPH_T;
|
||||
|
||||
typedef struct {
|
||||
void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State);
|
||||
unsigned int ClockTree;
|
||||
COM_PERIPH_T Periph;
|
||||
} COM_MAP_T;
|
||||
|
||||
typedef struct {
|
||||
COM_MAP_T *ComX; //串口外设
|
||||
GPIO_MAP_T TxPort; //发送端口
|
||||
GPIO_MAP_T RxPort; //接收端口
|
||||
GPIO_MAP_T TxRxEn; //收发使能
|
||||
}COM_CONFIG;
|
||||
|
||||
#define COM_NUM 5
|
||||
#ifdef USART1
|
||||
#define COM0 (&(COM_MAP_T){RCC_APB2PeriphClockCmd, RCC_APB2Periph_USART1, {USART1,USART1_IRQn}})
|
||||
#endif
|
||||
#ifdef USART2
|
||||
#define COM1 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART2, {USART2,USART2_IRQn}})
|
||||
#endif
|
||||
#ifdef USART3
|
||||
#define COM2 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART3,{USART3,USART3_IRQn}})
|
||||
#endif
|
||||
#ifdef UART4
|
||||
#define COM3 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART4,{UART4,UART4_IRQn}})
|
||||
#endif
|
||||
#define COM4 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART5,{UART5,UART5_IRQn}})
|
||||
|
||||
#endif //_VOILET_PORT_H
|
||||
@@ -1,173 +0,0 @@
|
||||
//
|
||||
// Created by anonymous on 2026/5/24.
|
||||
//
|
||||
|
||||
#ifndef VOILETTYPEDEF_H
|
||||
#define VOILETTYPEDEF_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define INTERRUPT_ENABLE __set_PRIMASK(0); //开启中断
|
||||
#define INTERRUPT_DISABLE __set_PRIMASK(1); //关闭中断
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef *Periph;
|
||||
unsigned short GpioPin;
|
||||
} GPIO_MAP_T;
|
||||
|
||||
// ==================== GPIOA 组 ====================
|
||||
#ifdef GPIOA
|
||||
#define GPIO0 {GPIOA, GPIO_Pin_0}
|
||||
#define GPIO1 {GPIOA, GPIO_Pin_1}
|
||||
#define GPIO2 {GPIOA, GPIO_Pin_2}
|
||||
#define GPIO3 {GPIOA, GPIO_Pin_3}
|
||||
#define GPIO4 {GPIOA, GPIO_Pin_4}
|
||||
#define GPIO5 {GPIOA, GPIO_Pin_5}
|
||||
#define GPIO6 {GPIOA, GPIO_Pin_6}
|
||||
#define GPIO7 {GPIOA, GPIO_Pin_7}
|
||||
#define GPIO8 {GPIOA, GPIO_Pin_8}
|
||||
#define GPIO9 {GPIOA, GPIO_Pin_9}
|
||||
#define GPIO10 {GPIOA, GPIO_Pin_10}
|
||||
#define GPIO11 {GPIOA, GPIO_Pin_11}
|
||||
#define GPIO12 {GPIOA, GPIO_Pin_12}
|
||||
#define GPIO13 {GPIOA, GPIO_Pin_13}
|
||||
#define GPIO14 {GPIOA, GPIO_Pin_14}
|
||||
#define GPIO15 {GPIOA, GPIO_Pin_15}
|
||||
#endif
|
||||
#ifdef GPIOB
|
||||
// ==================== GPIOB 组 ====================
|
||||
#define GPIO16 {GPIOB, GPIO_Pin_0}
|
||||
#define GPIO17 {GPIOB, GPIO_Pin_1}
|
||||
#define GPIO18 {GPIOB, GPIO_Pin_2}
|
||||
#define GPIO19 {GPIOB, GPIO_Pin_3}
|
||||
#define GPIO20 {GPIOB, GPIO_Pin_4}
|
||||
#define GPIO21 {GPIOB, GPIO_Pin_5}
|
||||
#define GPIO22 {GPIOB, GPIO_Pin_6}
|
||||
#define GPIO23 {GPIOB, GPIO_Pin_7}
|
||||
#define GPIO24 {GPIOB, GPIO_Pin_8}
|
||||
#define GPIO25 {GPIOB, GPIO_Pin_9}
|
||||
#define GPIO26 {GPIOB, GPIO_Pin_10}
|
||||
#define GPIO27 {GPIOB, GPIO_Pin_11}
|
||||
#define GPIO28 {GPIOB, GPIO_Pin_12}
|
||||
#define GPIO29 {GPIOB, GPIO_Pin_13}
|
||||
#define GPIO30 {GPIOB, GPIO_Pin_14}
|
||||
#define GPIO31 {GPIOB, GPIO_Pin_15}
|
||||
#endif
|
||||
#ifdef GPIOC
|
||||
// ==================== GPIOC 组 ====================
|
||||
#define GPIO32 {GPIOC, GPIO_Pin_0}
|
||||
#define GPIO33 {GPIOC, GPIO_Pin_1}
|
||||
#define GPIO34 {GPIOC, GPIO_Pin_2}
|
||||
#define GPIO35 {GPIOC, GPIO_Pin_3}
|
||||
#define GPIO36 {GPIOC, GPIO_Pin_4}
|
||||
#define GPIO37 {GPIOC, GPIO_Pin_5}
|
||||
#define GPIO38 {GPIOC, GPIO_Pin_6}
|
||||
#define GPIO39 {GPIOC, GPIO_Pin_7}
|
||||
#define GPIO40 {GPIOC, GPIO_Pin_8}
|
||||
#define GPIO41 {GPIOC, GPIO_Pin_9}
|
||||
#define GPIO42 {GPIOC, GPIO_Pin_10}
|
||||
#define GPIO43 {GPIOC, GPIO_Pin_11}
|
||||
#define GPIO44 {GPIOC, GPIO_Pin_12}
|
||||
#define GPIO45 {GPIOC, GPIO_Pin_13}
|
||||
#define GPIO46 {GPIOC, GPIO_Pin_14}
|
||||
#define GPIO47 {GPIOC, GPIO_Pin_15}
|
||||
#endif
|
||||
#ifdef GPIOD
|
||||
// ==================== GPIOD 组 ====================
|
||||
#define GPIO48 {GPIOD, GPIO_Pin_0}
|
||||
#define GPIO49 {GPIOD, GPIO_Pin_1}
|
||||
#define GPIO50 {GPIOD, GPIO_Pin_2}
|
||||
#define GPIO51 {GPIOD, GPIO_Pin_3}
|
||||
#define GPIO52 {GPIOD, GPIO_Pin_4}
|
||||
#define GPIO53 {GPIOD, GPIO_Pin_5}
|
||||
#define GPIO54 {GPIOD, GPIO_Pin_6}
|
||||
#define GPIO55 {GPIOD, GPIO_Pin_7}
|
||||
#define GPIO56 {GPIOD, GPIO_Pin_8}
|
||||
#define GPIO57 {GPIOD, GPIO_Pin_9}
|
||||
#define GPIO58 {GPIOD, GPIO_Pin_10}
|
||||
#define GPIO59 {GPIOD, GPIO_Pin_11}
|
||||
#define GPIO60 {GPIOD, GPIO_Pin_12}
|
||||
#define GPIO61 {GPIOD, GPIO_Pin_13}
|
||||
#define GPIO62 {GPIOD, GPIO_Pin_14}
|
||||
#define GPIO63 {GPIOD, GPIO_Pin_15}
|
||||
#endif
|
||||
#ifdef GPIOE
|
||||
// ==================== GPIOE 组 ====================
|
||||
#define GPIO64 {GPIOE, GPIO_Pin_0}
|
||||
#define GPIO65 {GPIOE, GPIO_Pin_1}
|
||||
#define GPIO66 {GPIOE, GPIO_Pin_2}
|
||||
#define GPIO67 {GPIOE, GPIO_Pin_3}
|
||||
#define GPIO68 {GPIOE, GPIO_Pin_4}
|
||||
#define GPIO69 {GPIOE, GPIO_Pin_5}
|
||||
#define GPIO70 {GPIOE, GPIO_Pin_6}
|
||||
#define GPIO71 {GPIOE, GPIO_Pin_7}
|
||||
#define GPIO72 {GPIOE, GPIO_Pin_8}
|
||||
#define GPIO73 {GPIOE, GPIO_Pin_9}
|
||||
#define GPIO74 {GPIOE, GPIO_Pin_10}
|
||||
#define GPIO75 {GPIOE, GPIO_Pin_11}
|
||||
#define GPIO76 {GPIOE, GPIO_Pin_12}
|
||||
#define GPIO77 {GPIOE, GPIO_Pin_13}
|
||||
#define GPIO78 {GPIOE, GPIO_Pin_14}
|
||||
#define GPIO79 {GPIOE, GPIO_Pin_15}
|
||||
#endif
|
||||
#ifdef GPIOF
|
||||
// ==================== GPIOF 组 ====================
|
||||
#define GPIO80 {GPIOF, GPIO_Pin_0}
|
||||
#define GPIO81 {GPIOF, GPIO_Pin_1}
|
||||
#define GPIO82 {GPIOF, GPIO_Pin_2}
|
||||
#define GPIO83 {GPIOF, GPIO_Pin_3}
|
||||
#define GPIO84 {GPIOF, GPIO_Pin_4}
|
||||
#define GPIO85 {GPIOF, GPIO_Pin_5}
|
||||
#define GPIO86 {GPIOF, GPIO_Pin_6}
|
||||
#define GPIO87 {GPIOF, GPIO_Pin_7}
|
||||
#define GPIO88 {GPIOF, GPIO_Pin_8}
|
||||
#define GPIO89 {GPIOF, GPIO_Pin_9}
|
||||
#define GPIO90 {GPIOF, GPIO_Pin_10}
|
||||
#define GPIO91 {GPIOF, GPIO_Pin_11}
|
||||
#define GPIO92 {GPIOF, GPIO_Pin_12}
|
||||
#define GPIO93 {GPIOF, GPIO_Pin_13}
|
||||
#define GPIO94 {GPIOF, GPIO_Pin_14}
|
||||
#define GPIO95 {GPIOF, GPIO_Pin_15}
|
||||
#endif
|
||||
#ifdef GPIOG
|
||||
// ==================== GPIOG 组 ====================
|
||||
#define GPIO96 {GPIOG, GPIO_Pin_0}
|
||||
#define GPIO97 {GPIOG, GPIO_Pin_1}
|
||||
#define GPIO98 {GPIOG, GPIO_Pin_2}
|
||||
#define GPIO99 {GPIOG, GPIO_Pin_3}
|
||||
#define GPIO100 {GPIOG, GPIO_Pin_4}
|
||||
#define GPIO101 {GPIOG, GPIO_Pin_5}
|
||||
#define GPIO102 {GPIOG, GPIO_Pin_6}
|
||||
#define GPIO103 {GPIOG, GPIO_Pin_7}
|
||||
#define GPIO104 {GPIOG, GPIO_Pin_8}
|
||||
#define GPIO105 {GPIOG, GPIO_Pin_9}
|
||||
#define GPIO106 {GPIOG, GPIO_Pin_10}
|
||||
#define GPIO107 {GPIOG, GPIO_Pin_11}
|
||||
#define GPIO108 {GPIOG, GPIO_Pin_12}
|
||||
#define GPIO109 {GPIOG, GPIO_Pin_13}
|
||||
#define GPIO110 {GPIOG, GPIO_Pin_14}
|
||||
#define GPIO111 {GPIOG, GPIO_Pin_15}
|
||||
#endif
|
||||
|
||||
#define GPIOEND {(GPIO_TypeDef *)0xFFFFFFFF, 0xFFFF}
|
||||
|
||||
typedef struct {
|
||||
USART_TypeDef *Periph;
|
||||
unsigned int Irqn;
|
||||
} COM_MAP_T;
|
||||
|
||||
#ifdef USART1
|
||||
#define COM0 {USART1,USART1_IRQn}
|
||||
#endif
|
||||
#ifdef USART2
|
||||
#define COM1 {USART2,USART2_IRQn}
|
||||
#endif
|
||||
#ifdef USART3
|
||||
#define COM2 {USART3,USART3_IRQn}
|
||||
#endif
|
||||
#ifdef UART4
|
||||
#define COM3 {UART4,UART4_IRQn}
|
||||
#endif
|
||||
#define COM4 {UART5,UART5_IRQn}
|
||||
|
||||
#endif //VOILETTYPEDEF_H
|
||||
+163
-187
@@ -1,210 +1,186 @@
|
||||
#include "Bsp.h"
|
||||
|
||||
void AllPeriphClockDisable(void);
|
||||
#ifdef TTY_COM
|
||||
#include "LetterShell.h"
|
||||
#endif
|
||||
|
||||
// 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},
|
||||
{COM1,.TxPort = GPIO2, .RxPort = GPIO3,.TxRxEn = GPIO55},
|
||||
};
|
||||
|
||||
void BspExtraInit(void);
|
||||
|
||||
/**
|
||||
* @brief 关闭所有外设时钟
|
||||
* @brief Voilet BSP的初始化函数
|
||||
* @note void
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void AllPeriphClockDisable(void)
|
||||
{
|
||||
// ==================== GPIOA 组 ====================
|
||||
#ifdef GPIOA
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
|
||||
#endif
|
||||
#ifdef GPIOB
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, DISABLE);
|
||||
// ==================== GPIOB 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOC
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, DISABLE);
|
||||
// ==================== GPIOC 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOD
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, DISABLE);
|
||||
// ==================== GPIOD 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOE
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, DISABLE);
|
||||
// ==================== GPIOE 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOF
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, DISABLE);
|
||||
// ==================== GPIOF 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOG
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, DISABLE);
|
||||
// ==================== GPIOG 组 ====================
|
||||
#endif
|
||||
void BspInit(void) {
|
||||
unsigned char i = 0;
|
||||
|
||||
#ifdef USART1
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
#endif
|
||||
INTERRUPT_DISABLE
|
||||
|
||||
#ifdef USART2
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
|
||||
#endif
|
||||
//初始化中断系统
|
||||
IrqInit();
|
||||
|
||||
#ifdef USART3
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE);
|
||||
#endif
|
||||
//初始化延时库
|
||||
DelayConfig();
|
||||
|
||||
#ifdef UART4
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
#endif
|
||||
//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
|
||||
|
||||
#ifdef UART5
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
#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, GPIO_Speed_2MHz);
|
||||
GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, GPIO_Speed_2MHz);
|
||||
}
|
||||
|
||||
INTERRUPT_ENABLE
|
||||
|
||||
BspExtraInit();
|
||||
}
|
||||
//
|
||||
// #ifdef USE_DIGITAL_OUTPUT
|
||||
// GPIO_ST DigiTalOutPut[DO_NUM] =
|
||||
// {
|
||||
// GPIOB,GPIO_Pin_8,RESET,
|
||||
// };
|
||||
// #endif
|
||||
//
|
||||
// #ifdef USE_DIGITAL_INPUT
|
||||
// GPIO_ST DigiTalInPut[DI_NUM] =
|
||||
// {
|
||||
// GPIOF,GPIO_Pin_8,SET,
|
||||
// GPIOE,GPIO_Pin_4,SET,
|
||||
// GPIOE,GPIO_Pin_3,SET,
|
||||
// };
|
||||
// #endif
|
||||
//
|
||||
// //LED灯数组
|
||||
// #ifdef USE_LED
|
||||
// GPIO_ST DigiTalLed[LED_NUM] =
|
||||
// {
|
||||
// GPIOB,GPIO_Pin_5,SET,
|
||||
// GPIOE,GPIO_Pin_5,SET,
|
||||
// };
|
||||
// #endif
|
||||
//
|
||||
// /**
|
||||
// * @brief BSP的配置和初始化
|
||||
// * @param void
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void BspInit(void)
|
||||
// {
|
||||
// //关闭所有系统中断
|
||||
// INTERRUPT_DISABLE
|
||||
//
|
||||
// //System Delay
|
||||
// SystemDelayConfig();
|
||||
//
|
||||
// //Interrupt
|
||||
// SystemInterruptInit();
|
||||
//
|
||||
// //Gpio
|
||||
// SystemGpioInit();
|
||||
//
|
||||
// {
|
||||
// //DO
|
||||
// #ifdef USE_DIGITAL_OUTPUT
|
||||
// for (uint8_t i = 0; i < DO_NUM; i++) {
|
||||
// GpioConfig(DigiTalOutPut[i].GpioPort,DigiTalOutPut[i].GpioPin,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);
|
||||
// GpioSetSts(DigiTalOutPut[i].GpioPort,DigiTalOutPut[i].GpioPin,DigiTalOutPut[i].DefaultStatus);
|
||||
// }
|
||||
// #endif
|
||||
// //DI
|
||||
// #ifdef USE_DIGITAL_INPUT
|
||||
// for (uint8_t i = 0; i < DI_NUM; i++) {
|
||||
// GpioConfig(DigiTalInPut[i].GpioPort,DigiTalInPut[i].GpioPin,GPIO_Mode_IPU,GPIO_Speed_50MHz);
|
||||
// }
|
||||
// #endif
|
||||
// //LED
|
||||
// #ifdef USE_LED
|
||||
// for (uint8_t i = 0; i < LED_NUM; i++) {
|
||||
// GpioConfig(DigiTalLed[i].GpioPort,DigiTalLed[i].GpioPin,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);
|
||||
// GpioSetSts(DigiTalLed[i].GpioPort,DigiTalLed[i].GpioPin,DigiTalLed[i].DefaultStatus);
|
||||
// }
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// //Usart
|
||||
// SystemUsartInit();
|
||||
//
|
||||
// {
|
||||
// //串口的TX引脚需要复用推挽模式,RX引脚需要浮空输入模式
|
||||
// #ifdef USE_USART1
|
||||
// GpioConfig(COM0_TX_PORT,COM0_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// GpioConfig(COM0_RX_PORT,COM0_RX_PIN,GPIO_Mode_IPU,GPIO_Speed_50MHz);
|
||||
// #endif
|
||||
// #ifdef USE_USART2
|
||||
// GpioConfig(COM1_TX_PORT,COM1_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// GpioConfig(COM1_RX_PORT,COM1_RX_PIN,GPIO_Mode_IPU,GPIO_Speed_50MHz);
|
||||
// #endif
|
||||
// #ifdef USE_USART3
|
||||
// GpioConfig(COM2_TX_PORT,COM2_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// GpioConfig(COM2_RX_PORT,COM2_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// #endif
|
||||
// #ifdef USE_USART4
|
||||
// GpioConfig(COM3_TX_PORT,COM3_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// GpioConfig(COM3_RX_PORT,COM3_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// #endif
|
||||
// #ifdef USE_USART5
|
||||
// GpioConfig(COM4_TX_PORT,COM4_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// GpioConfig(COM4_RX_PORT,COM4_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// #ifdef EXTRA_BSP
|
||||
// BspExtraInit();
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// void SystemStart(void)
|
||||
// {
|
||||
// //开启系统中断
|
||||
// INTERRUPT_ENABLE
|
||||
//
|
||||
// #ifdef USE_RTOS
|
||||
// #ifdef USE_FREERTOS
|
||||
// #endif
|
||||
// #ifdef USE_UCOS
|
||||
// #endif
|
||||
// #ifdef USE_THREADX
|
||||
// #endif
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 扩展库初始化
|
||||
// * @param void
|
||||
// * @retval void
|
||||
// * @note 理论上扩展库要在BSP的最后加载
|
||||
// * @example void
|
||||
// */
|
||||
// void BspExtraInit(void)
|
||||
// {
|
||||
// //LetterShell初始化
|
||||
// #ifdef USE_SHELL
|
||||
// LetterShellInit(TTY_COM,TTY_BAUD);
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// //用户层接口
|
||||
// void BspSystemReboot(void)
|
||||
// {
|
||||
// INTERRUPT_DISABLE
|
||||
// NVIC_SystemReset(); // 执行软件复位
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 扩展库初始化
|
||||
* @note 理论上扩展库要在BSP的最后加载
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void BspExtraInit(void)
|
||||
{
|
||||
//LetterShell初始化
|
||||
#ifdef TTY_COM
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void Rs485StdConfig(const COM_MAP_T *ComX,unsigned int Baud)
|
||||
{
|
||||
for (unsigned char i = 0;i < ARRAY_LEN(COM_PERIPH);i++) {
|
||||
if (ComX == COM_PERIPH[i].ComX) {
|
||||
if (COM_PERIPH[i].TxRxEn.ClockTree) {
|
||||
GpioSet(&COM_PERIPH[i].TxRxEn,Baud);
|
||||
}
|
||||
ComStdConfig(COM_PERIPH[i].ComX,Baud);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rs485AdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 重写Printf函数
|
||||
* @note void
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
// ||
|
||||
// #include <SysCall.c>
|
||||
#if defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
|
||||
+8
-26
@@ -8,26 +8,7 @@
|
||||
*/
|
||||
void GpioClockEnable(const GPIO_MAP_T *GpioX)
|
||||
{
|
||||
if(GpioX->Periph == GPIOA)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOB)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOC)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOD)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOE)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOF)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOG)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
|
||||
GpioX->ClockCmd(GpioX->ClockTree,ENABLE);
|
||||
}
|
||||
/**
|
||||
* @brief 配置GPIO口
|
||||
@@ -39,11 +20,12 @@ void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_Ty
|
||||
{
|
||||
GPIO_InitTypeDef GpioInitSt;
|
||||
|
||||
GpioInitSt.GPIO_Pin = GpioX->GpioPin;
|
||||
GpioInitSt.GPIO_Pin = GpioX->Periph.GpioPin;
|
||||
GpioInitSt.GPIO_Mode = GpioMode;
|
||||
GpioInitSt.GPIO_Speed = GpioSpeed;
|
||||
|
||||
GPIO_Init(GpioX->Periph, &GpioInitSt);
|
||||
//打开外设时钟
|
||||
GpioClockEnable(GpioX);
|
||||
GPIO_Init(GpioX->Periph.GpioPort, &GpioInitSt);
|
||||
}
|
||||
/**
|
||||
* @brief 改变GPIO口状态
|
||||
@@ -55,11 +37,11 @@ void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
|
||||
{
|
||||
if (Value == (uint8_t)RESET)
|
||||
{
|
||||
GPIO_ResetBits(GpioX->Periph, GpioX->GpioPin);
|
||||
GPIO_ResetBits(GpioX->Periph.GpioPort, GpioX->Periph.GpioPin);
|
||||
}
|
||||
else if (Value == (uint8_t)SET)
|
||||
{
|
||||
GPIO_SetBits(GpioX->Periph, GpioX->GpioPin);
|
||||
GPIO_SetBits(GpioX->Periph.GpioPort, GpioX->Periph.GpioPin);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -70,6 +52,6 @@ void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
|
||||
*/
|
||||
unsigned char GpioGet(const GPIO_MAP_T *GpioX)
|
||||
{
|
||||
return (unsigned char)GPIO_ReadInputDataBit(GpioX->Periph, GpioX->GpioPin);
|
||||
return (unsigned char)GPIO_ReadInputDataBit(GpioX->Periph.GpioPort, GpioX->Periph.GpioPin);
|
||||
}
|
||||
|
||||
|
||||
+119
-114
@@ -1,114 +1,119 @@
|
||||
// #include "Bsp.h"
|
||||
//
|
||||
// INTERRUPT_ST Interrupt[INTERRUPT_NUM];
|
||||
//
|
||||
// /**
|
||||
// * @brief 中断回调函数初始化为空
|
||||
// * @param void
|
||||
// * @retval void
|
||||
// * @note 初始化系统中断
|
||||
// * @example void
|
||||
// */
|
||||
// void SystemInterruptInit(void)
|
||||
// {
|
||||
// //设定系统中断组
|
||||
// NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||
// //清空结构体
|
||||
// for (uint8_t i = 0;i < INTERRUPT_NUM;i++)
|
||||
// {
|
||||
// Interrupt[i].CallBack = NULL;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 中断回调函数注册
|
||||
// * @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||
// * @retval void
|
||||
// * @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||
// * @example void
|
||||
// */
|
||||
// void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t))
|
||||
// {
|
||||
// Interrupt[Irqn].CallBack = Func;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 中断NVIC配置
|
||||
// * @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||
// * @retval void
|
||||
// * @note 设定一个中断的优先级
|
||||
// * @example void
|
||||
// */
|
||||
// void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||
// {
|
||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
||||
//
|
||||
// NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
// NVIC_Init(&NVIC_InitStructure);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 关闭中断
|
||||
// * @param Vector:中断号
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void InterruptDisable(uint32_t Vector)
|
||||
// {
|
||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
||||
// NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
// NVIC_Init(&NVIC_InitStructure);
|
||||
// }
|
||||
//
|
||||
// void USART1_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(USART1, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[USART1_IRQn].CallBack)((uint32_t)USART1);
|
||||
// }
|
||||
//
|
||||
// void USART2_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(USART2, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[USART2_IRQn].CallBack)((uint32_t)USART2);
|
||||
// }
|
||||
//
|
||||
// void USART3_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(USART3, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(USART3, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[USART3_IRQn].CallBack)((uint32_t)USART3);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void USART4_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(UART4, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(UART4, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[UART4_IRQn].CallBack)((uint32_t)UART4);
|
||||
// }
|
||||
//
|
||||
// void USART5_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(UART5, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[UART5_IRQn].CallBack)((uint32_t)UART5);
|
||||
// }
|
||||
#include <stddef.h>
|
||||
|
||||
#include "Bsp.h"
|
||||
|
||||
IRQ_MAP_T IRQ_PERIPH[IRQ_NUM];
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数初始化为空
|
||||
* @note 初始化系统中断
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void IrqInit(void)
|
||||
{
|
||||
//设定系统中断组
|
||||
NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||
for (uint8_t i = 0; i < IRQ_NUM; i++) {
|
||||
IRQ_PERIPH[i].IrqCallback = NULL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief 中断回调函数注册
|
||||
* @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||
* @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||
* @retval void
|
||||
*/
|
||||
void IrqRegister(unsigned char Irqn,void(*Func)(void *Param)) {
|
||||
IRQ_PERIPH[Irqn].Irqn = Irqn;
|
||||
IRQ_PERIPH[Irqn].IrqCallback = Func;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断NVIC配置
|
||||
* @note 设定一个中断的优先级
|
||||
* @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||
* @retval void
|
||||
*/
|
||||
void IrqEnable(uint32_t Irq, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭中断
|
||||
* @note void
|
||||
* @param Vector:中断号
|
||||
* @retval void
|
||||
*/
|
||||
void IrqDisable(uint32_t Irq)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
if (IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback != NULL) {
|
||||
if (USART_GetFlagStatus(COM0->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM0->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback(COM0);
|
||||
}
|
||||
}
|
||||
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM1->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM1->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback != NULL) {
|
||||
IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback(COM1);
|
||||
}
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM2->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM2->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback != NULL) {
|
||||
IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback(COM2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void USART4_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM3->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM3->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback != NULL) {
|
||||
IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback(COM3);
|
||||
}
|
||||
}
|
||||
|
||||
void USART5_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM4->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM4->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback != NULL) {
|
||||
IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback(COM4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
#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]; //读写缓冲区
|
||||
uint32_t HostId; //串口号
|
||||
|
||||
// /**
|
||||
// * @brief Shell写函数
|
||||
// * @param ComId 串口号,ch 数据
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// signed short ShellWrite(char* ch, unsigned short Len)
|
||||
// {
|
||||
// UsartSendStr(HostId, (uint8_t* )ch,Len);
|
||||
// return Len;
|
||||
// }
|
||||
// /**
|
||||
// * @brief Shell读函数 - 中断回调实现
|
||||
// * @param Vector 中断向量号
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void LetterShellIrqFunc(uint32_t Vector)
|
||||
// {
|
||||
// uint8_t ch = 0x00;
|
||||
// ch = UsartReceiveChar(Vector);
|
||||
//
|
||||
// shellHandler(&Host, ch);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @brief 初始化Shell
|
||||
// * @param ComId 串口号,baud 波特率
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void LetterShellInit(uint32_t ComId, uint32_t baud)
|
||||
// {
|
||||
// HostId = ComId;
|
||||
//
|
||||
// //初始化串口
|
||||
// UsartStdConfig(ComId, baud);
|
||||
// //设置串口回调函数
|
||||
// InterruptRegister(TTY_COM_IRQN, LetterShellIrqFunc);
|
||||
// //设置中断等级
|
||||
// InterruptSetLevel(TTY_COM_IRQN,1,1);
|
||||
// //注册写函数
|
||||
// Host.write = ShellWrite;
|
||||
//
|
||||
// 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);
|
||||
@@ -16,7 +16,7 @@ Purpose : Implementation of low-level functions for I/O with the
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifdef defined (__SEGGER__)
|
||||
#if defined (__SEGGER__)
|
||||
#include "__SEGGER_RTL_Int.h"
|
||||
#include "stdio.h"
|
||||
#include "Bsp.h"
|
||||
|
||||
+3
-4
@@ -20,7 +20,7 @@
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifdef defined (__GNUC__)
|
||||
#if defined (__GNUC__)
|
||||
/* Includes */
|
||||
#include "Bsp.h"
|
||||
|
||||
@@ -69,7 +69,7 @@ __attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
*/
|
||||
PUTCHAR_PROTOTYPE
|
||||
{
|
||||
UsartSendChar(TTY_COM, ch); //阻塞式无限等待
|
||||
ComSendChar(TTY_COM, ch); //阻塞式无限等待
|
||||
return ch;
|
||||
}
|
||||
|
||||
@@ -83,8 +83,7 @@ PUTCHAR_PROTOTYPE
|
||||
GETCHAR_PROTOTYPE
|
||||
{
|
||||
uint8_t ch = 0;
|
||||
ch = UsartReceiveChar(TTY_COM);
|
||||
|
||||
ch = ComReceiveChar(TTY_COM);
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
+33
-53
@@ -1,39 +1,25 @@
|
||||
#include "Bsp.h"
|
||||
|
||||
extern const COM_CONFIG COM_PERIPH[];
|
||||
|
||||
/**
|
||||
* @brief 初始化UART口外设的时钟
|
||||
* @note void
|
||||
* @param void
|
||||
* @param ComX:串口号
|
||||
* @retval void
|
||||
*/
|
||||
void UartClockEnable(const COM_MAP_T *ComX)
|
||||
{
|
||||
if (ComX->Periph == USART1)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == USART2) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == USART3) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == UART4) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == UART5) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
}
|
||||
ComX->ClockCmd(ComX->ClockTree,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化USART口
|
||||
* @param ComId 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
* @param Comx 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
|
||||
* @retval void
|
||||
*/
|
||||
void UartInit(const COM_MAP_T *Comx, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
void ComInit(const COM_MAP_T *ComX, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
{
|
||||
USART_InitTypeDef UsartInitSt;
|
||||
|
||||
@@ -45,76 +31,70 @@ void UartInit(const COM_MAP_T *Comx, uint32_t baud, uint8_t DataBits, uint8_t St
|
||||
UsartInitSt.USART_Parity = Parity;
|
||||
UsartInitSt.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
UsartInitSt.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
USART_Init(Comx->Periph, &UsartInitSt);
|
||||
|
||||
UartClockEnable(ComX);
|
||||
USART_Init(ComX->Periph.UartId, &UsartInitSt);
|
||||
//配置中断
|
||||
USART_ITConfig(Comx->Periph, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_ITConfig(ComX->Periph.UartId, USART_IT_RXNE, ENABLE);
|
||||
//启用串口
|
||||
USART_Cmd(Comx->Periph, ENABLE);
|
||||
USART_Cmd(ComX->Periph.UartId, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART口发送数据
|
||||
* @param ComId 串口号 Data数据
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
* @param ComX 串口号 Data数据
|
||||
* @retval void
|
||||
*/
|
||||
void UartSendChar(uint32_t ComId,uint8_t Data)
|
||||
void ComSendChar(const COM_MAP_T *ComX,uint8_t Data)
|
||||
{
|
||||
USART_SendData((USART_TypeDef*)ComId, Data);
|
||||
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
|
||||
USART_SendData(ComX->Periph.UartId, Data);
|
||||
while (USART_GetFlagStatus(ComX->Periph.UartId, USART_FLAG_TC) != SET);
|
||||
}
|
||||
/**
|
||||
* @brief USART口发送字符串
|
||||
* @param ComId 串口号 Data数据 Len 长度
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
* @param ComX 串口号 Data数据 Len 长度
|
||||
* @retval void
|
||||
*/
|
||||
void UartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len)
|
||||
void ComSendStr(const COM_MAP_T *ComX,uint8_t *Data, uint64_t Len)
|
||||
{
|
||||
for (uint64_t i = 0;i < Len;i++)
|
||||
{
|
||||
USART_SendData((USART_TypeDef*)ComId, Data[i]);
|
||||
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
|
||||
USART_SendData(ComX->Periph.UartId, Data[i]);
|
||||
while (USART_GetFlagStatus(ComX->Periph.UartId, USART_FLAG_TC) != SET);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART口发送数据
|
||||
* @param ComId 串口号
|
||||
* @retval 读取的数据
|
||||
* @note void
|
||||
* @example void
|
||||
* @param ComX 串口号
|
||||
* @retval 读取的数据
|
||||
*/
|
||||
uint8_t UartReceiveChar(uint32_t ComId)
|
||||
uint8_t ComReceiveChar(const COM_MAP_T *ComX)
|
||||
{
|
||||
return USART_ReceiveData((USART_TypeDef*)ComId);
|
||||
return USART_ReceiveData(ComX->Periph.UartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通用USART配置
|
||||
* @note void
|
||||
* @param ComId 串口号 baud 波特率
|
||||
* @param ComX 串口号 baud 波特率
|
||||
* @retval void
|
||||
*/
|
||||
void UartStdConfig(COM_MAP_T ComX, uint32_t baud)
|
||||
void ComStdConfig(const COM_MAP_T *ComX, uint32_t Baud)
|
||||
{
|
||||
UartInit(&ComX, baud, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No);
|
||||
ComInit(ComX, Baud, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 高级串口配置
|
||||
* @note void
|
||||
* @param ComId 串口号 baud 波特率 Data Bits 数据位 StopBits 停止位 Parity校验位
|
||||
* @param ComX 串口号 baud 波特率 Data Bits 数据位 StopBits 停止位 Parity校验位
|
||||
* @retval void
|
||||
*/
|
||||
void UartAdvConfig(const COM_MAP_T *ComX, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
void ComAdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
{
|
||||
UartInit(ComX, baud, DataBits, StopBits, Parity);
|
||||
ComInit(ComX, Baud, DataBits, StopBits, Parity);
|
||||
}
|
||||
|
||||
unsigned int CalcBaudTransIoSpeed(unsigned int Baud) {
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Vendored
-472
@@ -1,472 +0,0 @@
|
||||
/**
|
||||
* @file shell.h
|
||||
* @author Letter (NevermindZZT@gmail.com)
|
||||
* @brief letter shell
|
||||
* @version 3.0.0
|
||||
* @date 2019-12-30
|
||||
*
|
||||
* @copyright (c) 2020 Letter
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SHELL_H__
|
||||
#define __SHELL_H__
|
||||
|
||||
#include "shell_cfg.h"
|
||||
|
||||
#define SHELL_VERSION "3.1.2" /**< 版本号 */
|
||||
|
||||
|
||||
/**
|
||||
* @brief shell 断言
|
||||
*
|
||||
* @param expr 表达式
|
||||
* @param action 断言失败操作
|
||||
*/
|
||||
#define SHELL_ASSERT(expr, action) \
|
||||
if (!(expr)) { \
|
||||
action; \
|
||||
}
|
||||
|
||||
#if SHELL_USING_LOCK == 1
|
||||
#define SHELL_LOCK(shell) shell->lock(shell)
|
||||
#define SHELL_UNLOCK(shell) shell->unlock(shell)
|
||||
#else
|
||||
#define SHELL_LOCK(shell)
|
||||
#define SHELL_UNLOCK(shell)
|
||||
#endif /** SHELL_USING_LOCK == 1 */
|
||||
/**
|
||||
* @brief shell 命令权限
|
||||
*
|
||||
* @param permission 权限级别
|
||||
*/
|
||||
#define SHELL_CMD_PERMISSION(permission) \
|
||||
(permission & 0x000000FF)
|
||||
|
||||
/**
|
||||
* @brief shell 命令类型
|
||||
*
|
||||
* @param type 类型
|
||||
*/
|
||||
#define SHELL_CMD_TYPE(type) \
|
||||
((type & 0x0000000F) << 8)
|
||||
|
||||
/**
|
||||
* @brief 使能命令在未校验密码的情况下使用
|
||||
*/
|
||||
#define SHELL_CMD_ENABLE_UNCHECKED \
|
||||
(1 << 12)
|
||||
|
||||
/**
|
||||
* @brief 禁用返回值打印
|
||||
*/
|
||||
#define SHELL_CMD_DISABLE_RETURN \
|
||||
(1 << 13)
|
||||
|
||||
/**
|
||||
* @brief 只读属性(仅对变量生效)
|
||||
*/
|
||||
#define SHELL_CMD_READ_ONLY \
|
||||
(1 << 14)
|
||||
|
||||
/**
|
||||
* @brief 命令参数数量
|
||||
*/
|
||||
#define SHELL_CMD_PARAM_NUM(num) \
|
||||
((num & 0x0000000F)) << 16
|
||||
|
||||
#ifndef SHELL_SECTION
|
||||
#if defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||
#define SHELL_SECTION(x) __attribute__((section(x)))
|
||||
#elif defined (__IAR_SYSTEMS_ICC__)
|
||||
#define SHELL_SECTION(x) @ x
|
||||
#elif defined(__GNUC__)
|
||||
#define SHELL_SECTION(x) __attribute__((section(x)))
|
||||
#else
|
||||
#define SHELL_SECTION(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SHELL_USED
|
||||
#if defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||
#define SHELL_USED __attribute__((used))
|
||||
#elif defined (__IAR_SYSTEMS_ICC__)
|
||||
#define SHELL_USED __root
|
||||
#elif defined(__GNUC__)
|
||||
#define SHELL_USED __attribute__((used))
|
||||
#else
|
||||
#define SHELL_USED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief shell float型参数转换
|
||||
*/
|
||||
#define SHELL_PARAM_FLOAT(x) (*(float *)(&x))
|
||||
|
||||
/**
|
||||
* @brief shell 代理函数名
|
||||
*/
|
||||
#define SHELL_AGENCY_FUNC_NAME(_func) agency##_func
|
||||
|
||||
/**
|
||||
* @brief shell代理函数定义
|
||||
*
|
||||
* @param _func 被代理的函数
|
||||
* @param ... 代理参数
|
||||
*/
|
||||
#define SHELL_AGENCY_FUNC(_func, ...) \
|
||||
void SHELL_AGENCY_FUNC_NAME(_func)(int p1, int p2, int p3, int p4, int p5, int p6, int p7) \
|
||||
{ _func(__VA_ARGS__); }
|
||||
|
||||
#if SHELL_USING_CMD_EXPORT == 1
|
||||
|
||||
/**
|
||||
* @brief shell 命令定义
|
||||
*
|
||||
* @param _attr 命令属性
|
||||
* @param _name 命令名
|
||||
* @param _func 命令函数
|
||||
* @param _desc 命令描述
|
||||
*/
|
||||
#define SHELL_EXPORT_CMD(_attr, _name, _func, _desc) \
|
||||
const char shellCmd##_name[] = #_name; \
|
||||
const char shellDesc##_name[] = #_desc; \
|
||||
SHELL_USED const ShellCommand \
|
||||
shellCommand##_name SHELL_SECTION("shellCommand") = \
|
||||
{ \
|
||||
.attr.value = _attr, \
|
||||
.data.cmd.name = shellCmd##_name, \
|
||||
.data.cmd.function = (int (*)())_func, \
|
||||
.data.cmd.desc = shellDesc##_name \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 代理命令定义
|
||||
*
|
||||
* @param _attr 命令属性
|
||||
* @param _name 命令名
|
||||
* @param _func 命令函数
|
||||
* @param _desc 命令描述
|
||||
* @param ... 代理参数
|
||||
*/
|
||||
#define SHELL_EXPORT_CMD_AGENCY(_attr, _name, _func, _desc, ...) \
|
||||
SHELL_AGENCY_FUNC(_func, ##__VA_ARGS__) \
|
||||
SHELL_EXPORT_CMD(_attr, _name, SHELL_AGENCY_FUNC_NAME(_func), _desc)
|
||||
|
||||
/**
|
||||
* @brief shell 变量定义
|
||||
*
|
||||
* @param _attr 变量属性
|
||||
* @param _name 变量名
|
||||
* @param _value 变量值
|
||||
* @param _desc 变量描述
|
||||
*/
|
||||
#define SHELL_EXPORT_VAR(_attr, _name, _value, _desc) \
|
||||
const char shellCmd##_name[] = #_name; \
|
||||
const char shellDesc##_name[] = #_desc; \
|
||||
SHELL_USED const ShellCommand \
|
||||
shellVar##_name SHELL_SECTION("shellCommand") = \
|
||||
{ \
|
||||
.attr.value = _attr, \
|
||||
.data.var.name = shellCmd##_name, \
|
||||
.data.var.value = (void *)_value, \
|
||||
.data.var.desc = shellDesc##_name \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 用户定义
|
||||
*
|
||||
* @param _attr 用户属性
|
||||
* @param _name 用户名
|
||||
* @param _password 用户密码
|
||||
* @param _desc 用户描述
|
||||
*/
|
||||
#define SHELL_EXPORT_USER(_attr, _name, _password, _desc) \
|
||||
const char shellCmd##_name[] = #_name; \
|
||||
const char shellPassword##_name[] = #_password; \
|
||||
const char shellDesc##_name[] = #_desc; \
|
||||
SHELL_USED const ShellCommand \
|
||||
shellUser##_name SHELL_SECTION("shellCommand") = \
|
||||
{ \
|
||||
.attr.value = _attr|SHELL_CMD_TYPE(SHELL_TYPE_USER), \
|
||||
.data.user.name = shellCmd##_name, \
|
||||
.data.user.password = shellPassword##_name, \
|
||||
.data.user.desc = shellDesc##_name \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 按键定义
|
||||
*
|
||||
* @param _attr 按键属性
|
||||
* @param _value 按键键值
|
||||
* @param _func 按键函数
|
||||
* @param _desc 按键描述
|
||||
*/
|
||||
#define SHELL_EXPORT_KEY(_attr, _value, _func, _desc) \
|
||||
const char shellDesc##_value[] = #_desc; \
|
||||
SHELL_USED const ShellCommand \
|
||||
shellKey##_value SHELL_SECTION("shellCommand") = \
|
||||
{ \
|
||||
.attr.value = _attr|SHELL_CMD_TYPE(SHELL_TYPE_KEY), \
|
||||
.data.key.value = _value, \
|
||||
.data.key.function = (void (*)(Shell *))_func, \
|
||||
.data.key.desc = shellDesc##_value \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 代理按键定义
|
||||
*
|
||||
* @param _attr 按键属性
|
||||
* @param _value 按键键值
|
||||
* @param _func 按键函数
|
||||
* @param _desc 按键描述
|
||||
* @param ... 代理参数
|
||||
*/
|
||||
#define SHELL_EXPORT_KEY_AGENCY(_attr, _value, _func, _desc, ...) \
|
||||
SHELL_AGENCY_FUNC(_func, ##__VA_ARGS__) \
|
||||
SHELL_EXPORT_KEY(_attr, _value, SHELL_AGENCY_FUNC_NAME(_func), _desc)
|
||||
#else
|
||||
/**
|
||||
* @brief shell 命令item定义
|
||||
*
|
||||
* @param _attr 命令属性
|
||||
* @param _name 命令名
|
||||
* @param _func 命令函数
|
||||
* @param _desc 命令描述
|
||||
*/
|
||||
#define SHELL_CMD_ITEM(_attr, _name, _func, _desc) \
|
||||
{ \
|
||||
.attr.value = _attr, \
|
||||
.data.cmd.name = #_name, \
|
||||
.data.cmd.function = (int (*)())_func, \
|
||||
.data.cmd.desc = #_desc \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 变量item定义
|
||||
*
|
||||
* @param _attr 变量属性
|
||||
* @param _name 变量名
|
||||
* @param _value 变量值
|
||||
* @param _desc 变量描述
|
||||
*/
|
||||
#define SHELL_VAR_ITEM(_attr, _name, _value, _desc) \
|
||||
{ \
|
||||
.attr.value = _attr, \
|
||||
.data.var.name = #_name, \
|
||||
.data.var.value = (void *)_value, \
|
||||
.data.var.desc = #_desc \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 用户item定义
|
||||
*
|
||||
* @param _attr 用户属性
|
||||
* @param _name 用户名
|
||||
* @param _password 用户密码
|
||||
* @param _desc 用户描述
|
||||
*/
|
||||
#define SHELL_USER_ITEM(_attr, _name, _password, _desc) \
|
||||
{ \
|
||||
.attr.value = _attr|SHELL_CMD_TYPE(SHELL_TYPE_USER), \
|
||||
.data.user.name = #_name, \
|
||||
.data.user.password = #_password, \
|
||||
.data.user.desc = #_desc \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell 按键item定义
|
||||
*
|
||||
* @param _attr 按键属性
|
||||
* @param _value 按键键值
|
||||
* @param _func 按键函数
|
||||
* @param _desc 按键描述
|
||||
*/
|
||||
#define SHELL_KEY_ITEM(_attr, _value, _func, _desc) \
|
||||
{ \
|
||||
.attr.value = _attr|SHELL_CMD_TYPE(SHELL_TYPE_KEY), \
|
||||
.data.key.value = _value, \
|
||||
.data.key.function = (void (*)(Shell *))_func, \
|
||||
.data.key.desc = #_desc \
|
||||
}
|
||||
|
||||
#define SHELL_EXPORT_CMD(_attr, _name, _func, _desc)
|
||||
#define SHELL_EXPORT_CMD_AGENCY(_attr, _name, _func, _desc, ...)
|
||||
#define SHELL_EXPORT_VAR(_attr, _name, _value, _desc)
|
||||
#define SHELL_EXPORT_USER(_attr, _name, _password, _desc)
|
||||
#define SHELL_EXPORT_KEY(_attr, _value, _func, _desc)
|
||||
#define SHELL_EXPORT_KEY_AGENCY(_attr, _name, _func, _desc, ...)
|
||||
#endif /** SHELL_USING_CMD_EXPORT == 1 */
|
||||
|
||||
/**
|
||||
* @brief shell command类型
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SHELL_TYPE_CMD_MAIN = 0, /**< main形式命令 */
|
||||
SHELL_TYPE_CMD_FUNC, /**< C函数形式命令 */
|
||||
SHELL_TYPE_VAR_INT, /**< int型变量 */
|
||||
SHELL_TYPE_VAR_SHORT, /**< short型变量 */
|
||||
SHELL_TYPE_VAR_CHAR, /**< char型变量 */
|
||||
SHELL_TYPE_VAR_STRING, /**< string型变量 */
|
||||
SHELL_TYPE_VAR_POINT, /**< 指针型变量 */
|
||||
SHELL_TYPE_VAR_NODE, /**< 节点变量 */
|
||||
SHELL_TYPE_USER, /**< 用户 */
|
||||
SHELL_TYPE_KEY, /**< 按键 */
|
||||
} ShellCommandType;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Shell定义
|
||||
*/
|
||||
typedef struct shell_def
|
||||
{
|
||||
struct
|
||||
{
|
||||
const struct shell_command *user; /**< 当前用户 */
|
||||
int activeTime; /**< shell激活时间 */
|
||||
char *path; /**< 当前shell路径 */
|
||||
#if SHELL_USING_COMPANION == 1
|
||||
struct shell_companion_object *companions; /**< 伴生对象 */
|
||||
#endif
|
||||
#if SHELL_KEEP_RETURN_VALUE == 1
|
||||
int retVal; /**< 返回值 */
|
||||
#endif
|
||||
} info;
|
||||
struct
|
||||
{
|
||||
unsigned short length; /**< 输入数据长度 */
|
||||
unsigned short cursor; /**< 当前光标位置 */
|
||||
char *buffer; /**< 输入缓冲 */
|
||||
char *param[SHELL_PARAMETER_MAX_NUMBER]; /**< 参数 */
|
||||
unsigned short bufferSize; /**< 输入缓冲大小 */
|
||||
unsigned short paramCount; /**< 参数数量 */
|
||||
int keyValue; /**< 输入按键键值 */
|
||||
} parser;
|
||||
#if SHELL_HISTORY_MAX_NUMBER > 0
|
||||
struct
|
||||
{
|
||||
char *item[SHELL_HISTORY_MAX_NUMBER]; /**< 历史记录 */
|
||||
unsigned short number; /**< 历史记录数 */
|
||||
unsigned short record; /**< 当前记录位置 */
|
||||
signed short offset; /**< 当前历史记录偏移 */
|
||||
} history;
|
||||
#endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
|
||||
struct
|
||||
{
|
||||
void *base; /**< 命令表基址 */
|
||||
unsigned short count; /**< 命令数量 */
|
||||
} commandList;
|
||||
struct
|
||||
{
|
||||
unsigned char isChecked : 1; /**< 密码校验通过 */
|
||||
unsigned char isActive : 1; /**< 当前活动Shell */
|
||||
unsigned char tabFlag : 1; /**< tab标志 */
|
||||
} status;
|
||||
signed short (*read)(char *, unsigned short); /**< shell读函数 */
|
||||
signed short (*write)(char *, unsigned short); /**< shell写函数 */
|
||||
#if SHELL_USING_LOCK == 1
|
||||
int (*lock)(struct shell_def *); /**< shell 加锁 */
|
||||
int (*unlock)(struct shell_def *); /**< shell 解锁 */
|
||||
#endif
|
||||
} Shell;
|
||||
|
||||
|
||||
/**
|
||||
* @brief shell command定义
|
||||
*/
|
||||
typedef struct shell_command
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned char permission : 8; /**< command权限 */
|
||||
ShellCommandType type : 4; /**< command类型 */
|
||||
unsigned char enableUnchecked : 1; /**< 在未校验密码的情况下可用 */
|
||||
unsigned char disableReturn : 1; /**< 禁用返回值输出 */
|
||||
unsigned char readOnly : 1; /**< 只读 */
|
||||
unsigned char reserve : 1; /**< 保留 */
|
||||
unsigned char paramNum : 4; /**< 参数数量 */
|
||||
} attrs;
|
||||
int value;
|
||||
} attr; /**< 属性 */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
const char *name; /**< 命令名 */
|
||||
int (*function)(); /**< 命令执行函数 */
|
||||
const char *desc; /**< 命令描述 */
|
||||
} cmd; /**< 命令定义 */
|
||||
struct
|
||||
{
|
||||
const char *name; /**< 变量名 */
|
||||
void *value; /**< 变量值 */
|
||||
const char *desc; /**< 变量描述 */
|
||||
} var; /**< 变量定义 */
|
||||
struct
|
||||
{
|
||||
const char *name; /**< 用户名 */
|
||||
const char *password; /**< 用户密码 */
|
||||
const char *desc; /**< 用户描述 */
|
||||
} user; /**< 用户定义 */
|
||||
struct
|
||||
{
|
||||
int value; /**< 按键键值 */
|
||||
void (*function)(Shell *); /**< 按键执行函数 */
|
||||
const char *desc; /**< 按键描述 */
|
||||
} key; /**< 按键定义 */
|
||||
} data;
|
||||
} ShellCommand;
|
||||
|
||||
/**
|
||||
* @brief shell节点变量属性
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
void *var; /**< 变量引用 */
|
||||
int (*get)(); /**< 变量get方法 */
|
||||
int (*set)(); /**< 变量set方法 */
|
||||
} ShellNodeVarAttr;
|
||||
|
||||
|
||||
#define shellSetPath(_shell, _path) (_shell)->info.path = _path
|
||||
#define shellGetPath(_shell) ((_shell)->info.path)
|
||||
|
||||
#define shellDeInit(shell) shellRemove(shell)
|
||||
|
||||
void shellInit(Shell *shell, char *buffer, unsigned short size);
|
||||
void shellRemove(Shell *shell);
|
||||
unsigned short shellWriteString(Shell *shell, const char *string);
|
||||
void shellPrint(Shell *shell, char *fmt, ...);
|
||||
void shellScan(Shell *shell, char *fmt, ...);
|
||||
Shell* shellGetCurrent(void);
|
||||
void shellHandler(Shell *shell, char data);
|
||||
void shellWriteEndLine(Shell *shell, char *buffer, int len);
|
||||
void shellTask(void *param);
|
||||
int shellRun(Shell *shell, const char *cmd);
|
||||
|
||||
|
||||
|
||||
#if SHELL_USING_COMPANION == 1
|
||||
/**
|
||||
* @brief shell伴生对象定义
|
||||
*/
|
||||
typedef struct shell_companion_object
|
||||
{
|
||||
int id; /**< 伴生对象ID */
|
||||
void *obj; /**< 伴生对象 */
|
||||
struct shell_companion_object *next; /**< 下一个伴生对象 */
|
||||
} ShellCompanionObj;
|
||||
|
||||
|
||||
signed char shellCompanionAdd(Shell *shell, int id, void *object);
|
||||
signed char shellCompanionDel(Shell *shell, int id);
|
||||
void *shellCompanionGet(Shell *shell, int id);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
-188
@@ -1,188 +0,0 @@
|
||||
/**
|
||||
* @file shell_cfg.h
|
||||
* @author Letter (nevermindzzt@gmail.com)
|
||||
* @brief shell config
|
||||
* @version 3.0.0
|
||||
* @date 2019-12-31
|
||||
*
|
||||
* @copyright (c) 2019 Letter
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SHELL_CFG_H__
|
||||
#define __SHELL_CFG_H__
|
||||
|
||||
|
||||
/**
|
||||
* @brief 是否使用默认shell任务while循环,使能宏`SHELL_USING_TASK`后此宏有意义
|
||||
* 使能此宏,则`shellTask()`函数会一直循环读取输入,一般使用操作系统建立shell
|
||||
* 任务时使能此宏,关闭此宏的情况下,一般适用于无操作系统,在主循环中调用`shellTask()`
|
||||
*/
|
||||
#define SHELL_TASK_WHILE 0
|
||||
|
||||
/**
|
||||
* @brief 是否使用命令导出方式
|
||||
* 使能此宏后,可以使用`SHELL_EXPORT_CMD()`等导出命令
|
||||
* 定义shell命令,关闭此宏的情况下,需要使用命令表的方式
|
||||
*/
|
||||
#define SHELL_USING_CMD_EXPORT 1
|
||||
|
||||
/**
|
||||
* @brief 是否使用shell伴生对象
|
||||
* 一些扩展的组件(文件系统支持,日志工具等)需要使用伴生对象
|
||||
*/
|
||||
#define SHELL_USING_COMPANION 0
|
||||
|
||||
/**
|
||||
* @brief 支持shell尾行模式
|
||||
*/
|
||||
#define SHELL_SUPPORT_END_LINE 0
|
||||
|
||||
/**
|
||||
* @brief 是否在输出命令列表中列出用户
|
||||
*/
|
||||
#define SHELL_HELP_LIST_USER 0
|
||||
|
||||
/**
|
||||
* @brief 是否在输出命令列表中列出变量
|
||||
*/
|
||||
#define SHELL_HELP_LIST_VAR 0
|
||||
|
||||
/**
|
||||
* @brief 是否在输出命令列表中列出按键
|
||||
*/
|
||||
#define SHELL_HELP_LIST_KEY 0
|
||||
|
||||
/**
|
||||
* @brief 是否在输出命令列表中展示命令权限
|
||||
*/
|
||||
#define SHELL_HELP_SHOW_PERMISSION 1
|
||||
|
||||
/**
|
||||
* @brief 使用LF作为命令行回车触发
|
||||
* 可以和SHELL_ENTER_CR同时开启
|
||||
*/
|
||||
#define SHELL_ENTER_LF 1
|
||||
|
||||
/**
|
||||
* @brief 使用CR作为命令行回车触发
|
||||
* 可以和SHELL_ENTER_LF同时开启
|
||||
*/
|
||||
#define SHELL_ENTER_CR 1
|
||||
|
||||
/**
|
||||
* @brief 使用CRLF作为命令行回车触发
|
||||
* 不可以和SHELL_ENTER_LF或SHELL_ENTER_CR同时开启
|
||||
*/
|
||||
#define SHELL_ENTER_CRLF 0
|
||||
|
||||
/**
|
||||
* @brief 使用执行未导出函数的功能
|
||||
* 启用后,可以通过`exec [addr] [args]`直接执行对应地址的函数
|
||||
* @attention 如果地址错误,可能会直接引起程序崩溃
|
||||
*/
|
||||
#define SHELL_EXEC_UNDEF_FUNC 0
|
||||
|
||||
/**
|
||||
* @brief shell命令参数最大数量
|
||||
* 包含命令名在内,超过16个参数并且使用了参数自动转换的情况下,需要修改源码
|
||||
*/
|
||||
#define SHELL_PARAMETER_MAX_NUMBER 8
|
||||
|
||||
/**
|
||||
* @brief 历史命令记录数量
|
||||
*/
|
||||
#define SHELL_HISTORY_MAX_NUMBER 5
|
||||
|
||||
/**
|
||||
* @brief 双击间隔(ms)
|
||||
* 使能宏`SHELL_LONG_HELP`后此宏生效,定义双击tab补全help的时间间隔
|
||||
*/
|
||||
#define SHELL_DOUBLE_CLICK_TIME 200
|
||||
|
||||
/**
|
||||
* @brief 快速帮助
|
||||
* 作用于双击tab的场景,当使能此宏时,双击tab不会对命令进行help补全,而是直接显示对应命令的帮助信息
|
||||
*/
|
||||
#define SHELL_QUICK_HELP 1
|
||||
|
||||
/**
|
||||
* @brief 保存命令返回值
|
||||
* 开启后会默认定义一个`RETVAL`变量,会保存上一次命令执行的返回值,可以在随后的命令中进行调用
|
||||
* 如果命令的`SHELL_CMD_DISABLE_RETURN`标志被设置,则该命令不会更新`RETVAL`
|
||||
*/
|
||||
#define SHELL_KEEP_RETURN_VALUE 0
|
||||
|
||||
/**
|
||||
* @brief 管理的最大shell数量
|
||||
*/
|
||||
#define SHELL_MAX_NUMBER 5
|
||||
|
||||
/**
|
||||
* @brief shell格式化输出的缓冲大小
|
||||
* 为0时不使用shell格式化输出
|
||||
*/
|
||||
#define SHELL_PRINT_BUFFER 512
|
||||
|
||||
/**
|
||||
* @brief shell格式化输入的缓冲大小
|
||||
* 为0时不使用shell格式化输入
|
||||
* @note shell格式化输入会阻塞shellTask, 仅适用于在有操作系统的情况下使用
|
||||
*/
|
||||
#define SHELL_SCAN_BUFFER 0
|
||||
|
||||
/**
|
||||
* @brief 获取系统时间(ms)
|
||||
* 定义此宏为获取系统Tick,如`HAL_GetTick()`
|
||||
* @note 此宏不定义时无法使用双击tab补全命令help,无法使用shell超时锁定
|
||||
*/
|
||||
#define SHELL_GET_TICK() 0
|
||||
|
||||
/**
|
||||
* @brief 使用锁
|
||||
* @note 使用shell锁时,需要对加锁和解锁进行实现
|
||||
*/
|
||||
#define SHELL_USING_LOCK 0
|
||||
|
||||
/**
|
||||
* @brief shell内存分配
|
||||
* shell本身不需要此接口,若使用shell伴生对象,需要进行定义
|
||||
*/
|
||||
#define SHELL_MALLOC(size) 0
|
||||
|
||||
/**
|
||||
* @brief shell内存释放
|
||||
* shell本身不需要此接口,若使用shell伴生对象,需要进行定义
|
||||
*/
|
||||
#define SHELL_FREE(obj) 0
|
||||
|
||||
/**
|
||||
* @brief 是否显示shell信息
|
||||
*/
|
||||
#define SHELL_SHOW_INFO 1
|
||||
|
||||
/**
|
||||
* @brief 是否在登录后清除命令行
|
||||
*/
|
||||
#define SHELL_CLS_WHEN_LOGIN 1
|
||||
|
||||
/**
|
||||
* @brief shell默认用户
|
||||
*/
|
||||
#define SHELL_DEFAULT_USER "letter"
|
||||
|
||||
/**
|
||||
* @brief shell默认用户密码
|
||||
* 若默认用户不需要密码,设为""
|
||||
*/
|
||||
#define SHELL_DEFAULT_USER_PASSWORD ""
|
||||
|
||||
/**
|
||||
* @brief shell自动锁定超时
|
||||
* shell当前用户密码有效的时候生效,超时后会自动重新锁定shell
|
||||
* 设置为0时关闭自动锁定功能,时间单位为`SHELL_GET_TICK()`单位
|
||||
* @note 使用超时锁定必须保证`SHELL_GET_TICK()`有效
|
||||
*/
|
||||
#define SHELL_LOCK_TIMEOUT 0 * 60 * 1000
|
||||
|
||||
#endif
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* @file shell_ext.h
|
||||
* @author Letter (NevermindZZT@gmail.com)
|
||||
* @brief shell extensions
|
||||
* @version 3.0.0
|
||||
* @date 2019-12-31
|
||||
*
|
||||
* @copyright (c) 2019 Letter
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SHELL_EXT_H__
|
||||
#define __SHELL_EXT_H__
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
/**
|
||||
* @brief 数字类型
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NUM_TYPE_DEC, /**< 十进制整型 */
|
||||
NUM_TYPE_BIN, /**< 二进制整型 */
|
||||
NUM_TYPE_OCT, /**< 八进制整型 */
|
||||
NUM_TYPE_HEX, /**< 十六进制整型 */
|
||||
NUM_TYPE_FLOAT /**< 浮点型 */
|
||||
} ShellNumType;
|
||||
|
||||
unsigned int shellExtParsePara(Shell *shell, char *string);
|
||||
int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[]);
|
||||
|
||||
#endif
|
||||
Vendored
-1995
File diff suppressed because it is too large
Load Diff
-1995
File diff suppressed because it is too large
Load Diff
-103
@@ -1,103 +0,0 @@
|
||||
/**
|
||||
* @file shell_cmd_list.c
|
||||
* @author Letter (NevermindZZT@gmail.com)
|
||||
* @brief shell cmd list
|
||||
* @version 3.0.0
|
||||
* @date 2020-01-17
|
||||
*
|
||||
* @copyright (c) 2020 Letter
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
#if SHELL_USING_CMD_EXPORT != 1
|
||||
|
||||
extern int shellSetVar(char *name, int value);
|
||||
extern void shellUp(Shell *shell);
|
||||
extern void shellDown(Shell *shell);
|
||||
extern void shellRight(Shell *shell);
|
||||
extern void shellLeft(Shell *shell);
|
||||
extern void shellTab(Shell *shell);
|
||||
extern void shellBackspace(Shell *shell);
|
||||
extern void shellDelete(Shell *shell);
|
||||
extern void shellEnter(Shell *shell);
|
||||
extern void shellHelp(int argc, char *argv[]);
|
||||
extern void shellUsers(void);
|
||||
extern void shellCmds(void);
|
||||
extern void shellVars(void);
|
||||
extern void shellKeys(void);
|
||||
extern void shellClear(void);
|
||||
#if SHELL_EXEC_UNDEF_FUNC == 1
|
||||
extern int shellExecute(int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
SHELL_AGENCY_FUNC(shellRun, shellGetCurrent(), (const char *)p1);
|
||||
|
||||
|
||||
/**
|
||||
* @brief shell命令表
|
||||
*
|
||||
*/
|
||||
const ShellCommand shellCommandList[] =
|
||||
{
|
||||
{.attr.value=SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_USER),
|
||||
.data.user.name = SHELL_DEFAULT_USER,
|
||||
.data.user.password = SHELL_DEFAULT_USER_PASSWORD,
|
||||
.data.user.desc = "default user"},
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC),
|
||||
setVar, shellSetVar, set var),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0), 0x1B5B4100, shellUp, up),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0), 0x1B5B4200, shellDown, down),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x1B5B4300, shellRight, right),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x1B5B4400, shellLeft, left),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0), 0x09000000, shellTab, tab),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x08000000, shellBackspace, backspace),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x7F000000, shellDelete, delete),
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x1B5B337E, shellDelete, delete),
|
||||
#if SHELL_ENTER_LF == 1
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x0A000000, shellEnter, enter),
|
||||
#endif
|
||||
#if SHELL_ENTER_CR == 1
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x0D000000, shellEnter, enter),
|
||||
#endif
|
||||
#if SHELL_ENTER_CRLF == 1
|
||||
SHELL_KEY_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x0D0A0000, shellEnter, enter),
|
||||
#endif
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_DISABLE_RETURN,
|
||||
help, shellHelp, show command info\r\nhelp [cmd]),
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||
users, shellUsers, list all user),
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||
cmds, shellCmds, list all cmd),
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||
vars, shellVars, list all var),
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||
keys, shellKeys, list all key),
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||
clear, shellClear, clear console),
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||
sh, SHELL_AGENCY_FUNC_NAME(shellRun), run command directly),
|
||||
#if SHELL_EXEC_UNDEF_FUNC == 1
|
||||
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_DISABLE_RETURN,
|
||||
exec, shellExecute, execute function undefined),
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief shell命令表大小
|
||||
*
|
||||
*/
|
||||
const unsigned short shellCommandCount
|
||||
= sizeof(shellCommandList) / sizeof(ShellCommand);
|
||||
|
||||
#endif
|
||||
-87
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* @file shell_companion.c
|
||||
* @author Letter (nevermindzzt@gmail.com)
|
||||
* @brief shell companion object support
|
||||
* @version 3.0.3
|
||||
* @date 2020-07-22
|
||||
*
|
||||
* @copyright (c) 2020 Letter
|
||||
*
|
||||
*/
|
||||
#include "shell.h"
|
||||
|
||||
#if SHELL_USING_COMPANION == 1
|
||||
/**
|
||||
* @brief shell添加伴生对象
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param id 伴生对象ID
|
||||
* @param object 伴生对象
|
||||
* @return signed char 0 添加成功 -1 添加失败
|
||||
*/
|
||||
signed char shellCompanionAdd(Shell *shell, int id, void *object)
|
||||
{
|
||||
ShellCompanionObj *companions = shell->info.companions;
|
||||
ShellCompanionObj *node = SHELL_MALLOC(sizeof(ShellCompanionObj));
|
||||
SHELL_ASSERT(node, return -1);
|
||||
node->id = id;
|
||||
node->obj = object;
|
||||
node->next = companions;
|
||||
shell->info.companions = node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell删除伴生对象
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param id 伴生对象ID
|
||||
* @return signed char 0 删除成功 -1 无匹配对象
|
||||
*/
|
||||
signed char shellCompanionDel(Shell *shell, int id)
|
||||
{
|
||||
ShellCompanionObj *companions = shell->info.companions;
|
||||
ShellCompanionObj *front = companions;
|
||||
while (companions)
|
||||
{
|
||||
if (companions->id == id)
|
||||
{
|
||||
if (companions == shell->info.companions && !(companions->next))
|
||||
{
|
||||
shell->info.companions = (void *)0;
|
||||
}
|
||||
else
|
||||
{
|
||||
front->next = companions->next;
|
||||
}
|
||||
SHELL_FREE(companions);
|
||||
return 0;
|
||||
}
|
||||
front = companions;
|
||||
companions = companions->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell获取伴生对象
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param id 伴生对象ID
|
||||
* @return void* 伴生对象,无匹配对象时返回NULL
|
||||
*/
|
||||
void *shellCompanionGet(Shell *shell, int id)
|
||||
{
|
||||
SHELL_ASSERT(shell, return (void *)0);
|
||||
ShellCompanionObj *companions = shell->info.companions;
|
||||
while (companions)
|
||||
{
|
||||
if (companions->id == id)
|
||||
{
|
||||
return companions->obj;
|
||||
}
|
||||
companions = companions->next;
|
||||
}
|
||||
return (void *)0;
|
||||
}
|
||||
#endif /** SHELL_USING_COMPANION == 1 */
|
||||
-447
@@ -1,447 +0,0 @@
|
||||
/**
|
||||
* @file shell_ext.c
|
||||
* @author Letter (NevermindZZT@gmail.com)
|
||||
* @brief shell extensions
|
||||
* @version 3.0.0
|
||||
* @date 2019-12-31
|
||||
*
|
||||
* @copyright (c) 2019 Letter
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shell_cfg.h"
|
||||
#include "shell.h"
|
||||
#include "shell_ext.h"
|
||||
|
||||
|
||||
extern ShellCommand* shellSeekCommand(Shell *shell,
|
||||
const char *cmd,
|
||||
ShellCommand *base,
|
||||
unsigned short compareLength);
|
||||
extern int shellGetVarValue(Shell *shell, ShellCommand *command);
|
||||
|
||||
/**
|
||||
* @brief 判断数字进制
|
||||
*
|
||||
* @param string 参数字符串
|
||||
* @return ShellNumType 进制
|
||||
*/
|
||||
static ShellNumType shellExtNumType(char *string)
|
||||
{
|
||||
char *p = string;
|
||||
ShellNumType type = NUM_TYPE_DEC;
|
||||
|
||||
if ((*p == '0') && ((*(p + 1) == 'x') || (*(p + 1) == 'X')))
|
||||
{
|
||||
type = NUM_TYPE_HEX;
|
||||
}
|
||||
else if ((*p == '0') && ((*(p + 1) == 'b') || (*(p + 1) == 'B')))
|
||||
{
|
||||
type = NUM_TYPE_BIN;
|
||||
}
|
||||
else if (*p == '0')
|
||||
{
|
||||
type = NUM_TYPE_OCT;
|
||||
}
|
||||
|
||||
while (*p++)
|
||||
{
|
||||
if (*p == '.' && *(p + 1) != 0)
|
||||
{
|
||||
type = NUM_TYPE_FLOAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 字符转数字
|
||||
*
|
||||
* @param code 字符
|
||||
* @return char 数字
|
||||
*/
|
||||
static char shellExtToNum(char code)
|
||||
{
|
||||
if ((code >= '0') && (code <= '9'))
|
||||
{
|
||||
return code -'0';
|
||||
}
|
||||
else if ((code >= 'a') && (code <= 'f'))
|
||||
{
|
||||
return code - 'a' + 10;
|
||||
}
|
||||
else if ((code >= 'A') && (code <= 'F'))
|
||||
{
|
||||
return code - 'A' + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析字符参数
|
||||
*
|
||||
* @param string 字符串参数
|
||||
* @return char 解析出的字符
|
||||
*/
|
||||
static char shellExtParseChar(char *string)
|
||||
{
|
||||
char *p = string + 1;
|
||||
char value = 0;
|
||||
|
||||
if (*p == '\\')
|
||||
{
|
||||
switch (*(p + 1))
|
||||
{
|
||||
case 'b':
|
||||
value = '\b';
|
||||
break;
|
||||
case 'r':
|
||||
value = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
value = '\n';
|
||||
break;
|
||||
case 't':
|
||||
value = '\t';
|
||||
break;
|
||||
case '0':
|
||||
value = 0;
|
||||
break;
|
||||
default:
|
||||
value = *(p + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value = *p;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析字符串参数
|
||||
*
|
||||
* @param string 字符串参数
|
||||
* @return char* 解析出的字符串
|
||||
*/
|
||||
static char* shellExtParseString(char *string)
|
||||
{
|
||||
char *p = string;
|
||||
unsigned short index = 0;
|
||||
|
||||
if (*string == '\"')
|
||||
{
|
||||
p = ++string;
|
||||
}
|
||||
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '\\')
|
||||
{
|
||||
*(string + index) = shellExtParseChar(p - 1);
|
||||
p++;
|
||||
}
|
||||
else if (*p == '\"')
|
||||
{
|
||||
*(string + index) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(string + index) = *p;
|
||||
}
|
||||
p++;
|
||||
index ++;
|
||||
}
|
||||
*(string + index) = 0;
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析数字参数
|
||||
*
|
||||
* @param string 字符串参数
|
||||
* @return unsigned int 解析出的数字
|
||||
*/
|
||||
static unsigned int shellExtParseNumber(char *string)
|
||||
{
|
||||
ShellNumType type = NUM_TYPE_DEC;
|
||||
char radix = 10;
|
||||
char *p = string;
|
||||
char offset = 0;
|
||||
signed char sign = 1;
|
||||
unsigned int valueInt = 0;
|
||||
float valueFloat = 0.0;
|
||||
unsigned int devide = 0;
|
||||
|
||||
if (*string == '-')
|
||||
{
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
type = shellExtNumType(string + ((sign == -1) ? 1 : 0));
|
||||
|
||||
switch ((char)type)
|
||||
{
|
||||
case NUM_TYPE_HEX:
|
||||
radix = 16;
|
||||
offset = 2;
|
||||
break;
|
||||
|
||||
case NUM_TYPE_OCT:
|
||||
radix = 8;
|
||||
offset = 1;
|
||||
break;
|
||||
|
||||
case NUM_TYPE_BIN:
|
||||
radix = 2;
|
||||
offset = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
p = string + offset + ((sign == -1) ? 1 : 0);
|
||||
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '.')
|
||||
{
|
||||
devide = 1;
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
valueInt = valueInt * radix + shellExtToNum(*p);
|
||||
devide *= 10;
|
||||
p++;
|
||||
}
|
||||
if (type == NUM_TYPE_FLOAT && devide != 0)
|
||||
{
|
||||
valueFloat = (float)valueInt / devide * sign;
|
||||
return *(unsigned int *)(&valueFloat);
|
||||
}
|
||||
else
|
||||
{
|
||||
return valueInt * sign;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析变量参数
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param var 变量
|
||||
* @return unsigned int 变量值
|
||||
*/
|
||||
static unsigned int shellExtParseVar(Shell *shell, char *var)
|
||||
{
|
||||
ShellCommand *command = shellSeekCommand(shell,
|
||||
var + 1,
|
||||
shell->commandList.base,
|
||||
0);
|
||||
if (command)
|
||||
{
|
||||
return shellGetVarValue(shell, command);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析参数
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param string 参数
|
||||
* @return unsigned int 解析结果
|
||||
*/
|
||||
unsigned int shellExtParsePara(Shell *shell, char *string)
|
||||
{
|
||||
if (*string == '\'' && *(string + 1))
|
||||
{
|
||||
return (unsigned int)shellExtParseChar(string);
|
||||
}
|
||||
else if (*string == '-' || (*string >= '0' && *string <= '9'))
|
||||
{
|
||||
return (unsigned int)shellExtParseNumber(string);
|
||||
}
|
||||
else if (*string == '$' && *(string + 1))
|
||||
{
|
||||
return shellExtParseVar(shell, string);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
return (unsigned int)shellExtParseString(string);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 执行命令
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param command 命令
|
||||
* @param argc 参数个数
|
||||
* @param argv 参数
|
||||
* @return int 返回值
|
||||
*/
|
||||
int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[])
|
||||
{
|
||||
unsigned int params[SHELL_PARAMETER_MAX_NUMBER] = {0};
|
||||
int paramNum = command->attr.attrs.paramNum > (argc - 1) ?
|
||||
command->attr.attrs.paramNum : (argc - 1);
|
||||
for (int i = 0; i < argc - 1; i++)
|
||||
{
|
||||
params[i] = shellExtParsePara(shell, argv[i + 1]);
|
||||
}
|
||||
switch (paramNum)
|
||||
{
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 1
|
||||
case 0:
|
||||
return command->data.cmd.function();
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 1 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 2
|
||||
case 1:
|
||||
return command->data.cmd.function(params[0]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 2 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 3
|
||||
case 2:
|
||||
return command->data.cmd.function(params[0], params[1]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 3 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 4
|
||||
case 3:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 4 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 5
|
||||
case 4:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 5 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 6
|
||||
case 5:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 6 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 7
|
||||
case 6:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 7 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 8
|
||||
case 7:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 8 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 9
|
||||
case 8:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 9 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 10
|
||||
case 9:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 10 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 11
|
||||
case 10:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8], params[9]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 11 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 12
|
||||
case 11:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8], params[9],
|
||||
params[10]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 12 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 13
|
||||
case 12:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8], params[9],
|
||||
params[10], params[11]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 13 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 14
|
||||
case 13:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8], params[9],
|
||||
params[10], params[11],
|
||||
params[12]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 14 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 15
|
||||
case 14:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8], params[9],
|
||||
params[10], params[11],
|
||||
params[12], params[13]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 15 */
|
||||
#if SHELL_PARAMETER_MAX_NUMBER >= 16
|
||||
case 15:
|
||||
return command->data.cmd.function(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7],
|
||||
params[8], params[9],
|
||||
params[10], params[11],
|
||||
params[12], params[13],
|
||||
params[14]);
|
||||
// break;
|
||||
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 16 */
|
||||
default:
|
||||
return -1;
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
+1
Submodule ThirdParty/LetterShellV3 added at 252bc7116a
Reference in New Issue
Block a user