Compare commits
2 Commits
42ceefc5ad
...
9f38c6ea75
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f38c6ea75 | |||
| 4f108bc26a |
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "ThirdParty/LetterShellV3"]
|
||||||
|
path = ThirdParty/LetterShellV3
|
||||||
|
url = https://git.linuxacme.com/iorebuild/LetterShellV3.git
|
||||||
+18
-14
@@ -2,7 +2,13 @@
|
|||||||
#define __BSP_H__
|
#define __BSP_H__
|
||||||
|
|
||||||
#include "VoiletTypeDef.h"
|
#include "VoiletTypeDef.h"
|
||||||
#include "Voilet.h"
|
|
||||||
|
/* Extra Library Enable */
|
||||||
|
#define USE_SHELL //系统使用Shell
|
||||||
|
|
||||||
|
#ifdef USE_SHELL
|
||||||
|
#include "LetterShell.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ARRAY_LEN(arr) (sizeof(arr) / sizeof((arr)[0]))
|
#define ARRAY_LEN(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||||
|
|
||||||
@@ -26,12 +32,17 @@ typedef enum {
|
|||||||
void VoiletBspInit(void);
|
void VoiletBspInit(void);
|
||||||
|
|
||||||
/* BSP */
|
/* BSP */
|
||||||
void AllPeriphClockDisable(void);
|
|
||||||
void LedOn(uint8_t Chnl);
|
void LedOn(uint8_t Chnl);
|
||||||
void LedOff(uint8_t Chnl);
|
void LedOff(uint8_t Chnl);
|
||||||
void LedSet(uint8_t Chnl,uint8_t Value);
|
void LedSet(uint8_t Chnl,uint8_t Value);
|
||||||
void LedToggle(uint8_t Chnl);
|
void LedToggle(uint8_t Chnl);
|
||||||
|
|
||||||
|
//Interrupt
|
||||||
|
void IrqInit(void);
|
||||||
|
void IrqRegister(unsigned int Irq, void(*Func)(void *Param));
|
||||||
|
void IrqConfig(uint32_t Irq, uint8_t NvicPrePriority, uint8_t NvicSubPriority);
|
||||||
|
void IrqDisable(uint32_t Irq);
|
||||||
|
|
||||||
//System Delay
|
//System Delay
|
||||||
void DelayConfig(void);
|
void DelayConfig(void);
|
||||||
unsigned int DwtCntGet(void);
|
unsigned int DwtCntGet(void);
|
||||||
@@ -39,18 +50,16 @@ void DelayUs(unsigned int Us);
|
|||||||
void DelayMs(unsigned int Ms);
|
void DelayMs(unsigned int Ms);
|
||||||
|
|
||||||
/* GPIO */
|
/* GPIO */
|
||||||
void GpioClockEnable(const GPIO_MAP_T *GpioX);
|
|
||||||
void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed);
|
void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed);
|
||||||
void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value);
|
void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value);
|
||||||
unsigned char GpioGet(const GPIO_MAP_T *GpioX);
|
unsigned char GpioGet(const GPIO_MAP_T *GpioX);
|
||||||
|
|
||||||
/* UART */
|
/* UART */
|
||||||
void UartClockEnable(const COM_MAP_T *ComX);
|
void ComSendChar(const COM_MAP_T *ComX,uint8_t Data);
|
||||||
// void UartSendChar(uint32_t ComId,uint8_t Data);
|
void ComSendStr(const COM_MAP_T *ComX,uint8_t* Data, uint64_t Len);
|
||||||
// void UartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len);
|
uint8_t ComReceiveChar(const COM_MAP_T *ComX);
|
||||||
// void UartStdConfig(COM_MAP_T ComX, uint32_t baud);
|
void ComStdConfig(const 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);
|
void ComAdvConfig(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)
|
|
||||||
|
|
||||||
// /* 板级BSP头文件 */
|
// /* 板级BSP头文件 */
|
||||||
// #include "Board.h"
|
// #include "Board.h"
|
||||||
@@ -86,11 +95,6 @@ void UartClockEnable(const COM_MAP_T *ComX);
|
|||||||
// void LedOn(uint8_t Chnl);
|
// 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
|
// //Usart
|
||||||
// void SystemUsartInit(void);
|
// void SystemUsartInit(void);
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include "Bsp.h"
|
#include "Bsp.h"
|
||||||
|
|
||||||
void LetterShellInit(uint32_t ComId, uint32_t baud);
|
void LetterShellInit(const COM_MAP_T *ComX, uint32_t Baud);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+138
-121
@@ -11,163 +11,180 @@
|
|||||||
#define INTERRUPT_DISABLE __set_PRIMASK(1); //关闭中断
|
#define INTERRUPT_DISABLE __set_PRIMASK(1); //关闭中断
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GPIO_TypeDef *Periph;
|
void (*IrqCallback)(void *Param);
|
||||||
|
}IRQ_MAP_T;
|
||||||
|
|
||||||
|
#define IRQ_NUM 0xFF //中断数量
|
||||||
|
#define NVIC_GROUP_LEVEL NVIC_PriorityGroup_2 //中断组
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GPIO_TypeDef *GpioPort;
|
||||||
unsigned short GpioPin;
|
unsigned short GpioPin;
|
||||||
|
} GPIO_PERIPH_T;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State);
|
||||||
|
unsigned int ClockTree;
|
||||||
|
GPIO_PERIPH_T Periph;
|
||||||
} GPIO_MAP_T;
|
} GPIO_MAP_T;
|
||||||
|
|
||||||
// ==================== GPIOA 组 ====================
|
// ==================== GPIOA 组 ====================
|
||||||
#ifdef GPIOA
|
#ifdef GPIOA
|
||||||
#define GPIO0 {GPIOA, GPIO_Pin_0}
|
#define GPIO0 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_0}}
|
||||||
#define GPIO1 {GPIOA, GPIO_Pin_1}
|
#define GPIO1 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_1}}
|
||||||
#define GPIO2 {GPIOA, GPIO_Pin_2}
|
#define GPIO2 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_2}}
|
||||||
#define GPIO3 {GPIOA, GPIO_Pin_3}
|
#define GPIO3 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_3}}
|
||||||
#define GPIO4 {GPIOA, GPIO_Pin_4}
|
#define GPIO4 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_4}}
|
||||||
#define GPIO5 {GPIOA, GPIO_Pin_5}
|
#define GPIO5 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_5}}
|
||||||
#define GPIO6 {GPIOA, GPIO_Pin_6}
|
#define GPIO6 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_6}}
|
||||||
#define GPIO7 {GPIOA, GPIO_Pin_7}
|
#define GPIO7 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_7}}
|
||||||
#define GPIO8 {GPIOA, GPIO_Pin_8}
|
#define GPIO8 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_8}}
|
||||||
#define GPIO9 {GPIOA, GPIO_Pin_9}
|
#define GPIO9 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_9}}
|
||||||
#define GPIO10 {GPIOA, GPIO_Pin_10}
|
#define GPIO10 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_10}}
|
||||||
#define GPIO11 {GPIOA, GPIO_Pin_11}
|
#define GPIO11 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_11}}
|
||||||
#define GPIO12 {GPIOA, GPIO_Pin_12}
|
#define GPIO12 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_12}}
|
||||||
#define GPIO13 {GPIOA, GPIO_Pin_13}
|
#define GPIO13 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_13}}
|
||||||
#define GPIO14 {GPIOA, GPIO_Pin_14}
|
#define GPIO14 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_14}}
|
||||||
#define GPIO15 {GPIOA, GPIO_Pin_15}
|
#define GPIO15 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOA, {GPIOA, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIOB
|
#ifdef GPIOB
|
||||||
// ==================== GPIOB 组 ====================
|
// ==================== GPIOB 组 ====================
|
||||||
#define GPIO16 {GPIOB, GPIO_Pin_0}
|
#define GPIO16 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_0}}
|
||||||
#define GPIO17 {GPIOB, GPIO_Pin_1}
|
#define GPIO17 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_1}}
|
||||||
#define GPIO18 {GPIOB, GPIO_Pin_2}
|
#define GPIO18 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_2}}
|
||||||
#define GPIO19 {GPIOB, GPIO_Pin_3}
|
#define GPIO19 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_3}}
|
||||||
#define GPIO20 {GPIOB, GPIO_Pin_4}
|
#define GPIO20 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_4}}
|
||||||
#define GPIO21 {GPIOB, GPIO_Pin_5}
|
#define GPIO21 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_5}}
|
||||||
#define GPIO22 {GPIOB, GPIO_Pin_6}
|
#define GPIO22 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_6}}
|
||||||
#define GPIO23 {GPIOB, GPIO_Pin_7}
|
#define GPIO23 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_7}}
|
||||||
#define GPIO24 {GPIOB, GPIO_Pin_8}
|
#define GPIO24 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_8}}
|
||||||
#define GPIO25 {GPIOB, GPIO_Pin_9}
|
#define GPIO25 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_9}}
|
||||||
#define GPIO26 {GPIOB, GPIO_Pin_10}
|
#define GPIO26 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_10}}
|
||||||
#define GPIO27 {GPIOB, GPIO_Pin_11}
|
#define GPIO27 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_11}}
|
||||||
#define GPIO28 {GPIOB, GPIO_Pin_12}
|
#define GPIO28 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_12}}
|
||||||
#define GPIO29 {GPIOB, GPIO_Pin_13}
|
#define GPIO29 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_13}}
|
||||||
#define GPIO30 {GPIOB, GPIO_Pin_14}
|
#define GPIO30 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_14}}
|
||||||
#define GPIO31 {GPIOB, GPIO_Pin_15}
|
#define GPIO31 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOB, {GPIOB, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIOC
|
#ifdef GPIOC
|
||||||
// ==================== GPIOC 组 ====================
|
// ==================== GPIOC 组 ====================
|
||||||
#define GPIO32 {GPIOC, GPIO_Pin_0}
|
#define GPIO32 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_0}}
|
||||||
#define GPIO33 {GPIOC, GPIO_Pin_1}
|
#define GPIO33 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_1}}
|
||||||
#define GPIO34 {GPIOC, GPIO_Pin_2}
|
#define GPIO34 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_2}}
|
||||||
#define GPIO35 {GPIOC, GPIO_Pin_3}
|
#define GPIO35 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_3}}
|
||||||
#define GPIO36 {GPIOC, GPIO_Pin_4}
|
#define GPIO36 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_4}}
|
||||||
#define GPIO37 {GPIOC, GPIO_Pin_5}
|
#define GPIO37 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_5}}
|
||||||
#define GPIO38 {GPIOC, GPIO_Pin_6}
|
#define GPIO38 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_6}}
|
||||||
#define GPIO39 {GPIOC, GPIO_Pin_7}
|
#define GPIO39 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_7}}
|
||||||
#define GPIO40 {GPIOC, GPIO_Pin_8}
|
#define GPIO40 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_8}}
|
||||||
#define GPIO41 {GPIOC, GPIO_Pin_9}
|
#define GPIO41 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_9}}
|
||||||
#define GPIO42 {GPIOC, GPIO_Pin_10}
|
#define GPIO42 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_10}}
|
||||||
#define GPIO43 {GPIOC, GPIO_Pin_11}
|
#define GPIO43 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_11}}
|
||||||
#define GPIO44 {GPIOC, GPIO_Pin_12}
|
#define GPIO44 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_12}}
|
||||||
#define GPIO45 {GPIOC, GPIO_Pin_13}
|
#define GPIO45 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_13}}
|
||||||
#define GPIO46 {GPIOC, GPIO_Pin_14}
|
#define GPIO46 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_14}}
|
||||||
#define GPIO47 {GPIOC, GPIO_Pin_15}
|
#define GPIO47 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOC, {GPIOC, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIOD
|
#ifdef GPIOD
|
||||||
// ==================== GPIOD 组 ====================
|
// ==================== GPIOD 组 ====================
|
||||||
#define GPIO48 {GPIOD, GPIO_Pin_0}
|
#define GPIO48 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_0}}
|
||||||
#define GPIO49 {GPIOD, GPIO_Pin_1}
|
#define GPIO49 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_1}}
|
||||||
#define GPIO50 {GPIOD, GPIO_Pin_2}
|
#define GPIO50 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_2}}
|
||||||
#define GPIO51 {GPIOD, GPIO_Pin_3}
|
#define GPIO51 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_3}}
|
||||||
#define GPIO52 {GPIOD, GPIO_Pin_4}
|
#define GPIO52 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_4}}
|
||||||
#define GPIO53 {GPIOD, GPIO_Pin_5}
|
#define GPIO53 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_5}}
|
||||||
#define GPIO54 {GPIOD, GPIO_Pin_6}
|
#define GPIO54 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_6}}
|
||||||
#define GPIO55 {GPIOD, GPIO_Pin_7}
|
#define GPIO55 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_7}}
|
||||||
#define GPIO56 {GPIOD, GPIO_Pin_8}
|
#define GPIO56 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_8}}
|
||||||
#define GPIO57 {GPIOD, GPIO_Pin_9}
|
#define GPIO57 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_9}}
|
||||||
#define GPIO58 {GPIOD, GPIO_Pin_10}
|
#define GPIO58 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_10}}
|
||||||
#define GPIO59 {GPIOD, GPIO_Pin_11}
|
#define GPIO59 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_11}}
|
||||||
#define GPIO60 {GPIOD, GPIO_Pin_12}
|
#define GPIO60 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_12}}
|
||||||
#define GPIO61 {GPIOD, GPIO_Pin_13}
|
#define GPIO61 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_13}}
|
||||||
#define GPIO62 {GPIOD, GPIO_Pin_14}
|
#define GPIO62 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_14}}
|
||||||
#define GPIO63 {GPIOD, GPIO_Pin_15}
|
#define GPIO63 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOD, {GPIOD, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIOE
|
#ifdef GPIOE
|
||||||
// ==================== GPIOE 组 ====================
|
// ==================== GPIOE 组 ====================
|
||||||
#define GPIO64 {GPIOE, GPIO_Pin_0}
|
#define GPIO64 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_0}}
|
||||||
#define GPIO65 {GPIOE, GPIO_Pin_1}
|
#define GPIO65 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_1}}
|
||||||
#define GPIO66 {GPIOE, GPIO_Pin_2}
|
#define GPIO66 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_2}}
|
||||||
#define GPIO67 {GPIOE, GPIO_Pin_3}
|
#define GPIO67 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_3}}
|
||||||
#define GPIO68 {GPIOE, GPIO_Pin_4}
|
#define GPIO68 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_4}}
|
||||||
#define GPIO69 {GPIOE, GPIO_Pin_5}
|
#define GPIO69 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_5}}
|
||||||
#define GPIO70 {GPIOE, GPIO_Pin_6}
|
#define GPIO70 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_6}}
|
||||||
#define GPIO71 {GPIOE, GPIO_Pin_7}
|
#define GPIO71 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_7}}
|
||||||
#define GPIO72 {GPIOE, GPIO_Pin_8}
|
#define GPIO72 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_8}}
|
||||||
#define GPIO73 {GPIOE, GPIO_Pin_9}
|
#define GPIO73 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_9}}
|
||||||
#define GPIO74 {GPIOE, GPIO_Pin_10}
|
#define GPIO74 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_10}}
|
||||||
#define GPIO75 {GPIOE, GPIO_Pin_11}
|
#define GPIO75 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_11}}
|
||||||
#define GPIO76 {GPIOE, GPIO_Pin_12}
|
#define GPIO76 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_12}}
|
||||||
#define GPIO77 {GPIOE, GPIO_Pin_13}
|
#define GPIO77 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_13}}
|
||||||
#define GPIO78 {GPIOE, GPIO_Pin_14}
|
#define GPIO78 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_14}}
|
||||||
#define GPIO79 {GPIOE, GPIO_Pin_15}
|
#define GPIO79 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOE, {GPIOE, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIOF
|
#ifdef GPIOF
|
||||||
// ==================== GPIOF 组 ====================
|
// ==================== GPIOF 组 ====================
|
||||||
#define GPIO80 {GPIOF, GPIO_Pin_0}
|
#define GPIO80 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_0}}
|
||||||
#define GPIO81 {GPIOF, GPIO_Pin_1}
|
#define GPIO81 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_1}}
|
||||||
#define GPIO82 {GPIOF, GPIO_Pin_2}
|
#define GPIO82 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_2}}
|
||||||
#define GPIO83 {GPIOF, GPIO_Pin_3}
|
#define GPIO83 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_3}}
|
||||||
#define GPIO84 {GPIOF, GPIO_Pin_4}
|
#define GPIO84 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_4}}
|
||||||
#define GPIO85 {GPIOF, GPIO_Pin_5}
|
#define GPIO85 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_5}}
|
||||||
#define GPIO86 {GPIOF, GPIO_Pin_6}
|
#define GPIO86 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_6}}
|
||||||
#define GPIO87 {GPIOF, GPIO_Pin_7}
|
#define GPIO87 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_7}}
|
||||||
#define GPIO88 {GPIOF, GPIO_Pin_8}
|
#define GPIO88 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_8}}
|
||||||
#define GPIO89 {GPIOF, GPIO_Pin_9}
|
#define GPIO89 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_9}}
|
||||||
#define GPIO90 {GPIOF, GPIO_Pin_10}
|
#define GPIO90 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_10}}
|
||||||
#define GPIO91 {GPIOF, GPIO_Pin_11}
|
#define GPIO91 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_11}}
|
||||||
#define GPIO92 {GPIOF, GPIO_Pin_12}
|
#define GPIO92 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_12}}
|
||||||
#define GPIO93 {GPIOF, GPIO_Pin_13}
|
#define GPIO93 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_13}}
|
||||||
#define GPIO94 {GPIOF, GPIO_Pin_14}
|
#define GPIO94 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_14}}
|
||||||
#define GPIO95 {GPIOF, GPIO_Pin_15}
|
#define GPIO95 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOF, {GPIOF, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIOG
|
#ifdef GPIOG
|
||||||
// ==================== GPIOG 组 ====================
|
// ==================== GPIOG 组 ====================
|
||||||
#define GPIO96 {GPIOG, GPIO_Pin_0}
|
#define GPIO96 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_0}}
|
||||||
#define GPIO97 {GPIOG, GPIO_Pin_1}
|
#define GPIO97 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_1}}
|
||||||
#define GPIO98 {GPIOG, GPIO_Pin_2}
|
#define GPIO98 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_2}}
|
||||||
#define GPIO99 {GPIOG, GPIO_Pin_3}
|
#define GPIO99 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_3}}
|
||||||
#define GPIO100 {GPIOG, GPIO_Pin_4}
|
#define GPIO100 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_4}}
|
||||||
#define GPIO101 {GPIOG, GPIO_Pin_5}
|
#define GPIO101 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_5}}
|
||||||
#define GPIO102 {GPIOG, GPIO_Pin_6}
|
#define GPIO102 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_6}}
|
||||||
#define GPIO103 {GPIOG, GPIO_Pin_7}
|
#define GPIO103 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_7}}
|
||||||
#define GPIO104 {GPIOG, GPIO_Pin_8}
|
#define GPIO104 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_8}}
|
||||||
#define GPIO105 {GPIOG, GPIO_Pin_9}
|
#define GPIO105 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_9}}
|
||||||
#define GPIO106 {GPIOG, GPIO_Pin_10}
|
#define GPIO106 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_10}}
|
||||||
#define GPIO107 {GPIOG, GPIO_Pin_11}
|
#define GPIO107 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_11}}
|
||||||
#define GPIO108 {GPIOG, GPIO_Pin_12}
|
#define GPIO108 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_12}}
|
||||||
#define GPIO109 {GPIOG, GPIO_Pin_13}
|
#define GPIO109 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_13}}
|
||||||
#define GPIO110 {GPIOG, GPIO_Pin_14}
|
#define GPIO110 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_14}}
|
||||||
#define GPIO111 {GPIOG, GPIO_Pin_15}
|
#define GPIO111 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_15}}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GPIOEND {(GPIO_TypeDef *)0xFFFFFFFF, 0xFFFF}
|
typedef struct {
|
||||||
|
USART_TypeDef *UartId;
|
||||||
|
unsigned int Irqn;
|
||||||
|
} COM_PERIPH_T;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
USART_TypeDef *Periph;
|
void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State);
|
||||||
unsigned int Irqn;
|
unsigned int ClockTree;
|
||||||
|
COM_PERIPH_T Periph;
|
||||||
} COM_MAP_T;
|
} COM_MAP_T;
|
||||||
|
|
||||||
#ifdef USART1
|
#ifdef USART1
|
||||||
#define COM0 {USART1,USART1_IRQn}
|
#define COM0 (&(COM_MAP_T){RCC_APB2PeriphClockCmd, RCC_APB2Periph_USART1, {USART1,USART1_IRQn}})
|
||||||
#endif
|
#endif
|
||||||
#ifdef USART2
|
#ifdef USART2
|
||||||
#define COM1 {USART2,USART2_IRQn}
|
#define COM1 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART2, {USART2,USART2_IRQn}})
|
||||||
#endif
|
#endif
|
||||||
#ifdef USART3
|
#ifdef USART3
|
||||||
#define COM2 {USART3,USART3_IRQn}
|
#define COM2 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_USART3,{USART3,USART3_IRQn}})
|
||||||
#endif
|
#endif
|
||||||
#ifdef UART4
|
#ifdef UART4
|
||||||
#define COM3 {UART4,UART4_IRQn}
|
#define COM3 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART4,{UART4,UART4_IRQn}})
|
||||||
#endif
|
#endif
|
||||||
#define COM4 {UART5,UART5_IRQn}
|
#define COM4 (&(COM_MAP_T){RCC_APB1PeriphClockCmd, RCC_APB1Periph_UART5,{UART5,UART5_IRQn}})
|
||||||
|
|
||||||
#endif //VOILETTYPEDEF_H
|
#endif //VOILETTYPEDEF_H
|
||||||
|
|||||||
@@ -1,64 +1,5 @@
|
|||||||
#include "Bsp.h"
|
#include "Bsp.h"
|
||||||
|
|
||||||
void AllPeriphClockDisable(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 关闭所有外设时钟
|
|
||||||
* @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
|
|
||||||
|
|
||||||
#ifdef USART1
|
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USART2
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USART3
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef UART4
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef UART5
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// #ifdef USE_DIGITAL_OUTPUT
|
// #ifdef USE_DIGITAL_OUTPUT
|
||||||
// GPIO_ST DigiTalOutPut[DO_NUM] =
|
// GPIO_ST DigiTalOutPut[DO_NUM] =
|
||||||
|
|||||||
+8
-26
@@ -8,26 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
void GpioClockEnable(const GPIO_MAP_T *GpioX)
|
void GpioClockEnable(const GPIO_MAP_T *GpioX)
|
||||||
{
|
{
|
||||||
if(GpioX->Periph == GPIOA)
|
GpioX->ClockCmd(GpioX->ClockTree,ENABLE);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief 配置GPIO口
|
* @brief 配置GPIO口
|
||||||
@@ -39,11 +20,12 @@ void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_Ty
|
|||||||
{
|
{
|
||||||
GPIO_InitTypeDef GpioInitSt;
|
GPIO_InitTypeDef GpioInitSt;
|
||||||
|
|
||||||
GpioInitSt.GPIO_Pin = GpioX->GpioPin;
|
GpioInitSt.GPIO_Pin = GpioX->Periph.GpioPin;
|
||||||
GpioInitSt.GPIO_Mode = GpioMode;
|
GpioInitSt.GPIO_Mode = GpioMode;
|
||||||
GpioInitSt.GPIO_Speed = GpioSpeed;
|
GpioInitSt.GPIO_Speed = GpioSpeed;
|
||||||
|
//打开外设时钟
|
||||||
GPIO_Init(GpioX->Periph, &GpioInitSt);
|
GpioClockEnable(GpioX);
|
||||||
|
GPIO_Init(GpioX->Periph.GpioPort, &GpioInitSt);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief 改变GPIO口状态
|
* @brief 改变GPIO口状态
|
||||||
@@ -55,11 +37,11 @@ void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
|
|||||||
{
|
{
|
||||||
if (Value == (uint8_t)RESET)
|
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)
|
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)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+120
-114
@@ -1,114 +1,120 @@
|
|||||||
// #include "Bsp.h"
|
#include "Bsp.h"
|
||||||
//
|
|
||||||
// INTERRUPT_ST Interrupt[INTERRUPT_NUM];
|
#define IRQ_NULL ((void *)0)
|
||||||
//
|
|
||||||
// /**
|
IRQ_MAP_T IRQ_PERIPH[IRQ_NUM] = {0x00};
|
||||||
// * @brief 中断回调函数初始化为空
|
|
||||||
// * @param void
|
/**
|
||||||
// * @retval void
|
* @brief 中断回调函数初始化为空
|
||||||
// * @note 初始化系统中断
|
* @note 初始化系统中断
|
||||||
// * @example void
|
* @param void
|
||||||
// */
|
* @retval void
|
||||||
// void SystemInterruptInit(void)
|
*/
|
||||||
// {
|
void IrqInit(void)
|
||||||
// //设定系统中断组
|
{
|
||||||
// NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
//设定系统中断组
|
||||||
// //清空结构体
|
NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||||
// for (uint8_t i = 0;i < INTERRUPT_NUM;i++)
|
for (uint8_t i = 0; i < IRQ_NUM; i++) {
|
||||||
// {
|
IRQ_PERIPH[i].IrqCallback = IRQ_NULL;
|
||||||
// Interrupt[i].CallBack = NULL;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
/**
|
||||||
// /**
|
* @brief 中断回调函数注册
|
||||||
// * @brief 中断回调函数注册
|
* @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||||
// * @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
* @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||||
// * @retval void
|
* @retval void
|
||||||
// * @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
*/
|
||||||
// * @example void
|
void IrqRegister(unsigned int Irq, void(*Func)(void *Param))
|
||||||
// */
|
{
|
||||||
// void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t))
|
IRQ_PERIPH[Irq].IrqCallback = Func;
|
||||||
// {
|
}
|
||||||
// Interrupt[Irqn].CallBack = Func;
|
|
||||||
// }
|
/**
|
||||||
//
|
* @brief 中断NVIC配置
|
||||||
// /**
|
* @note 设定一个中断的优先级
|
||||||
// * @brief 中断NVIC配置
|
* @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||||
// * @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
* @retval void
|
||||||
// * @retval void
|
*/
|
||||||
// * @note 设定一个中断的优先级
|
void IrqConfig(uint32_t Irq, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||||
// * @example void
|
{
|
||||||
// */
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
// void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
|
||||||
// {
|
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||||
//
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||||
// NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
}
|
||||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
||||||
// NVIC_Init(&NVIC_InitStructure);
|
/**
|
||||||
// }
|
* @brief 关闭中断
|
||||||
//
|
* @note void
|
||||||
// /**
|
* @param Vector:中断号
|
||||||
// * @brief 关闭中断
|
* @retval void
|
||||||
// * @param Vector:中断号
|
*/
|
||||||
// * @retval void
|
void IrqDisable(uint32_t Irq)
|
||||||
// * @note void
|
{
|
||||||
// * @example void
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
// */
|
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||||
// void InterruptDisable(uint32_t Vector)
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||||
// {
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
// NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
}
|
||||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
||||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
void USART1_IRQHandler(void)
|
||||||
// NVIC_Init(&NVIC_InitStructure);
|
{
|
||||||
// }
|
if (USART_GetFlagStatus(COM0->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||||
//
|
{
|
||||||
// void USART1_IRQHandler(void)
|
USART_ClearFlag(COM0->Periph.UartId, USART_FLAG_ORE);
|
||||||
// {
|
}
|
||||||
// if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET)
|
if (IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||||
// {
|
IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback(COM0);
|
||||||
// USART_ClearFlag(USART1, USART_FLAG_ORE);
|
}
|
||||||
// }
|
}
|
||||||
// (*Interrupt[USART1_IRQn].CallBack)((uint32_t)USART1);
|
|
||||||
// }
|
void USART2_IRQHandler(void)
|
||||||
//
|
{
|
||||||
// void USART2_IRQHandler(void)
|
if (USART_GetFlagStatus(COM1->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||||
// {
|
{
|
||||||
// if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET)
|
USART_ClearFlag(COM1->Periph.UartId, USART_FLAG_ORE);
|
||||||
// {
|
}
|
||||||
// USART_ClearFlag(USART2, USART_FLAG_ORE);
|
if (IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||||
// }
|
IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback(COM1);
|
||||||
// (*Interrupt[USART2_IRQn].CallBack)((uint32_t)USART2);
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// void USART3_IRQHandler(void)
|
void USART3_IRQHandler(void)
|
||||||
// {
|
{
|
||||||
// if (USART_GetFlagStatus(USART3, USART_FLAG_ORE) == SET)
|
if (USART_GetFlagStatus(COM2->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||||
// {
|
{
|
||||||
// USART_ClearFlag(USART3, USART_FLAG_ORE);
|
USART_ClearFlag(COM2->Periph.UartId, USART_FLAG_ORE);
|
||||||
// }
|
}
|
||||||
// (*Interrupt[USART3_IRQn].CallBack)((uint32_t)USART3);
|
if (IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||||
// }
|
IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback(COM1);
|
||||||
//
|
}
|
||||||
//
|
}
|
||||||
// void USART4_IRQHandler(void)
|
|
||||||
// {
|
|
||||||
// if (USART_GetFlagStatus(UART4, USART_FLAG_ORE) == SET)
|
void USART4_IRQHandler(void)
|
||||||
// {
|
{
|
||||||
// USART_ClearFlag(UART4, USART_FLAG_ORE);
|
if (USART_GetFlagStatus(COM3->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||||
// }
|
{
|
||||||
// (*Interrupt[UART4_IRQn].CallBack)((uint32_t)UART4);
|
USART_ClearFlag(COM3->Periph.UartId, USART_FLAG_ORE);
|
||||||
// }
|
}
|
||||||
//
|
if (IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||||
// void USART5_IRQHandler(void)
|
IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback(COM3);
|
||||||
// {
|
}
|
||||||
// if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) == SET)
|
}
|
||||||
// {
|
|
||||||
// USART_ClearFlag(UART5, USART_FLAG_ORE);
|
void USART5_IRQHandler(void)
|
||||||
// }
|
{
|
||||||
// (*Interrupt[UART5_IRQn].CallBack)((uint32_t)UART5);
|
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 != IRQ_NULL) {
|
||||||
|
IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback(COM4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+49
-52
@@ -2,65 +2,62 @@
|
|||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
/* 板级BSP头文件 */
|
/* 板级BSP头文件 */
|
||||||
#include "Bsp.h"
|
#include "Bsp.h"
|
||||||
|
#include "Voilet.h"
|
||||||
|
|
||||||
#define WR_BUFFER_SIZE 512
|
#define WR_BUFFER_SIZE 512
|
||||||
|
|
||||||
/* 1. 创建shell对象,开辟shell缓冲区 */
|
/* 1. 创建shell对象,开辟shell缓冲区 */
|
||||||
Shell Host; //Shell实例化
|
Shell Host; //Shell实例化
|
||||||
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
|
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
|
||||||
uint32_t HostId; //串口号
|
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
|
||||||
|
* @param ComId 串口号,baud 波特率
|
||||||
|
* @retval void
|
||||||
|
* @note void
|
||||||
|
* @example void
|
||||||
|
*/
|
||||||
|
void LetterShellInit(const COM_MAP_T *ComX, uint32_t Baud)
|
||||||
|
{
|
||||||
|
//初始化串口
|
||||||
|
ComStdConfig(ComX, Baud);
|
||||||
|
//设置串口回调函数
|
||||||
|
IrqRegister(ComX->Periph.Irqn, LetterShellIrqFunc);
|
||||||
|
//设置中断等级
|
||||||
|
IrqConfig(ComX->Periph.Irqn,1,1);
|
||||||
|
//注册写函数
|
||||||
|
Host.write = ShellWrite;
|
||||||
|
//初始化LetterShell
|
||||||
|
shellInit(&Host, HostBuffer, WR_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @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 打印版本号
|
// * @brief 打印版本号
|
||||||
// * @param void
|
// * @param void
|
||||||
|
|||||||
+29
-55
@@ -3,37 +3,21 @@
|
|||||||
/**
|
/**
|
||||||
* @brief 初始化UART口外设的时钟
|
* @brief 初始化UART口外设的时钟
|
||||||
* @note void
|
* @note void
|
||||||
* @param void
|
* @param ComX:串口号
|
||||||
* @retval void
|
* @retval void
|
||||||
*/
|
*/
|
||||||
void UartClockEnable(const COM_MAP_T *ComX)
|
void UartClockEnable(const COM_MAP_T *ComX)
|
||||||
{
|
{
|
||||||
if (ComX->Periph == USART1)
|
ComX->ClockCmd(ComX->ClockTree,ENABLE);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化USART口
|
* @brief 初始化USART口
|
||||||
* @param ComId 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
|
|
||||||
* @retval void
|
|
||||||
* @note 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;
|
USART_InitTypeDef UsartInitSt;
|
||||||
|
|
||||||
@@ -45,76 +29,66 @@ void UartInit(const COM_MAP_T *Comx, uint32_t baud, uint8_t DataBits, uint8_t St
|
|||||||
UsartInitSt.USART_Parity = Parity;
|
UsartInitSt.USART_Parity = Parity;
|
||||||
UsartInitSt.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
UsartInitSt.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||||
UsartInitSt.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
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口发送数据
|
* @brief USART口发送数据
|
||||||
* @param ComId 串口号 Data数据
|
|
||||||
* @retval void
|
|
||||||
* @note 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);
|
USART_SendData(ComX->Periph.UartId, Data);
|
||||||
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
|
while (USART_GetFlagStatus(ComX->Periph.UartId, USART_FLAG_TC) != SET);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief USART口发送字符串
|
* @brief USART口发送字符串
|
||||||
* @param ComId 串口号 Data数据 Len 长度
|
|
||||||
* @retval void
|
|
||||||
* @note 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++)
|
for (uint64_t i = 0;i < Len;i++)
|
||||||
{
|
{
|
||||||
USART_SendData((USART_TypeDef*)ComId, Data[i]);
|
USART_SendData(ComX->Periph.UartId, Data[i]);
|
||||||
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
|
while (USART_GetFlagStatus(ComX->Periph.UartId, USART_FLAG_TC) != SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USART口发送数据
|
* @brief USART口发送数据
|
||||||
* @param ComId 串口号
|
|
||||||
* @retval 读取的数据
|
|
||||||
* @note void
|
* @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配置
|
* @brief 通用USART配置
|
||||||
* @note void
|
* @note void
|
||||||
* @param ComId 串口号 baud 波特率
|
* @param ComX 串口号 baud 波特率
|
||||||
* @retval void
|
* @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 高级串口配置
|
* @brief 高级串口配置
|
||||||
* @note void
|
* @note void
|
||||||
* @param ComId 串口号 baud 波特率 Data Bits 数据位 StopBits 停止位 Parity校验位
|
* @param ComX 串口号 baud 波特率 Data Bits 数据位 StopBits 停止位 Parity校验位
|
||||||
* @retval void
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
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