diff --git a/ADC.cpp b/Device/ADC.cpp similarity index 100% rename from ADC.cpp rename to Device/ADC.cpp diff --git a/ADC.h b/Device/ADC.h similarity index 100% rename from ADC.h rename to Device/ADC.h diff --git a/CAN.cpp b/Device/CAN.cpp similarity index 83% rename from CAN.cpp rename to Device/CAN.cpp index 00322174..fc345f9b 100644 --- a/CAN.cpp +++ b/Device/CAN.cpp @@ -1,6 +1,6 @@ #include "Sys.h" #include "Port.h" -#include "CAN.h" +#include "Can.h" #include "Platform\stm32.h" @@ -10,25 +10,28 @@ static const Pin g_CAN_Pins_Map2[] = CAN_PINS_REMAP2; static const Pin g_CAN_Pins_Map3[] = CAN_PINS_REMAP3; #endif -CAN::CAN(CAN_TypeDef* port, Mode_TypeDef mode, int remap) +Can::Can(CAN index, Mode_TypeDef mode, int remap) { - Port = port; - Mode = mode; - Remap = remap; + _index = index; + Mode = mode; + Remap = remap; + + _Tx = nullptr; + _Rx = nullptr; /*外设时钟设置*/ //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); /*IO设置*/ #ifdef STM32F1 - if(port == CAN1) + if(index == Can1) { if(remap == 1) GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE); else if(remap == 2) GPIO_PinRemapConfig(GPIO_Remap2_CAN1, ENABLE); } - else if(port == CAN2) + else if(index == Can2) GPIO_PinRemapConfig(GPIO_Remap_CAN2, ENABLE); const Pin* p = g_CAN_Pins_Map; @@ -36,7 +39,7 @@ CAN::CAN(CAN_TypeDef* port, Mode_TypeDef mode, int remap) p = g_CAN_Pins_Map2; else if(remap == 3) p = g_CAN_Pins_Map3; - + AlternatePort tx(p[0]); InputPort rx(p[1], false, InputPort::UP); #endif @@ -48,28 +51,31 @@ CAN::CAN(CAN_TypeDef* port, Mode_TypeDef mode, int remap) #endif /************************CAN通信参数设置**********************************/ + CAN_TypeDef* const g_CANs[] = CANS; /*CAN寄存器初始化*/ - CAN_DeInit(Port); + CAN_DeInit(g_CANs[_index]); + + CAN_InitTypeDef _can; CAN_StructInit(&_can); /*CAN单元初始化*/ _can.CAN_TTCM = DISABLE; //MCR-TTCM 时间触发通信模式使能 - _can.CAN_ABOM = Mode == Mode_Send ? ENABLE : DISABLE; //MCR-ABOM 自动离线管理 + _can.CAN_ABOM = Mode == Mode_Send ? ENABLE : DISABLE; //MCR-ABOM 自动离线管理 _can.CAN_AWUM = Mode == Mode_Send ? ENABLE : DISABLE; //MCR-AWUM 自动唤醒模式 _can.CAN_NART = DISABLE; //MCR-NART 禁止报文自动重传 DISABLE-自动重传 - _can.CAN_RFLM = DISABLE; //MCR-RFLM 接收FIFO 锁定模式 DISABLE-溢出时新报文会覆盖原有报文 - _can.CAN_TXFP = DISABLE; //MCR-TXFP 发送FIFO优先级 DISABLE-优先级取决于报文标示符 + _can.CAN_RFLM = DISABLE; //MCR-RFLM 接收FIFO 锁定模式 DISABLE-溢出时新报文会覆盖原有报文 + _can.CAN_TXFP = DISABLE; //MCR-TXFP 发送FIFO优先级 DISABLE-优先级取决于报文标示符 _can.CAN_Mode = CAN_Mode_Normal; //正常发送模式 _can.CAN_SJW = CAN_SJW_1tq; //BTR-SJW 重新同步跳跃宽度 2个时间单元 _can.CAN_BS1 = CAN_BS1_3tq; //BTR-TS1 时间段1 占用了6个时间单元 _can.CAN_BS2 = CAN_BS2_2tq; //BTR-TS1 时间段2 占用了3个时间单元 _can.CAN_Prescaler = 6; ////BTR-BRP 波特率分频器 定义了时间单元的时间长度 36/(1+6+3)/4 = 0.8Mbps - CAN_Init(Port, &_can); - + CAN_Init(g_CANs[_index], &_can); + if(Mode == Mode_Send) - _TxMsg = new CanTxMsg(); + _Tx = new CanTxMsg(); else { - _RxMsg = new CanRxMsg(); + _Rx = new CanRxMsg(); CAN_FilterInitTypeDef filter; @@ -140,27 +146,37 @@ CAN::CAN(CAN_TypeDef* port, Mode_TypeDef mode, int remap) } } -void CAN::Send(byte* buf, uint len) +Can::~Can() { + auto tx = (CanTxMsg*)_Tx; + delete tx; + + auto rx = (CanRxMsg*)_Rx; + delete rx; +} + +void Can::Send(byte* buf, uint len) +{ + auto tx = (CanTxMsg*)_Tx; switch(Mode) { case STD_Data: case STD_Remote: case STD: - _TxMsg->StdId = 0; - _TxMsg->IDE = CAN_ID_STD; + tx->StdId = 0; + tx->IDE = CAN_ID_STD; break; case EXT_Data: case EXT_Remote: case EXT: - _TxMsg->StdId = 0; - _TxMsg->IDE = CAN_ID_EXT; + tx->StdId = 0; + tx->IDE = CAN_ID_EXT; break; } - _TxMsg->RTR=CAN_RTR_DATA; //发送的是数据 - _TxMsg->DLC=2; //数据长度为2字节 - _TxMsg->Data[0] = 0x12; - _TxMsg->Data[1] = 0x34; + tx->RTR =CAN_RTR_DATA; //发送的是数据 + tx->DLC =2; //数据长度为2字节 + tx->Data[0] = 0x12; + tx->Data[1] = 0x34; // 未完成 } diff --git a/CAN.h b/Device/CAN.h similarity index 60% rename from CAN.h rename to Device/CAN.h index e4149640..c07d2adb 100644 --- a/CAN.h +++ b/Device/CAN.h @@ -1,10 +1,8 @@ #ifndef __CAN_H__ #define __CAN_H__ -#include "Sys.h" - // CAN类 -class CAN +class Can { public: typedef enum @@ -19,26 +17,19 @@ public: Mode_ALL = 0x07 // 接收所有类型 }Mode_TypeDef; - CAN_TypeDef* Port; // 端口 Mode_TypeDef Mode; // 工作模式 - CAN(CAN_TypeDef* port = CAN1, Mode_TypeDef mode = Mode_Send, int remap = 1); - virtual ~CAN() - { - if(_TxMsg) delete _TxMsg; - _TxMsg = nullptr; - if(_RxMsg) delete _RxMsg; - _RxMsg = nullptr; - } + Can(CAN index = Can1, Mode_TypeDef mode = Mode_Send, int remap = 1); + ~Can(); void Send(byte* buf, uint len); - -private: - CAN_InitTypeDef _can; - int Remap; - CanTxMsg* _TxMsg; - CanRxMsg* _RxMsg; +private: + byte _index; + int Remap; + + void* _Tx; + void* _Rx; }; #endif diff --git a/DAC.cpp b/Device/DAC.cpp similarity index 100% rename from DAC.cpp rename to Device/DAC.cpp diff --git a/DAC.h b/Device/DAC.h similarity index 100% rename from DAC.h rename to Device/DAC.h diff --git a/DMA.cpp b/Device/DMA.cpp similarity index 85% rename from DMA.cpp rename to Device/DMA.cpp index f3765f77..d107b202 100644 --- a/DMA.cpp +++ b/Device/DMA.cpp @@ -1,9 +1,11 @@ -#include "DMA.h" +#include "Sys.h" +#include "DMA.h" #include "Platform\stm32.h" bool DMA::Start() { +#ifdef STM32F4 DMA_InitTypeDef DMA_InitStructure; __IO uint32_t Timeout = TIMEOUT_MAX; @@ -16,16 +18,16 @@ bool DMA::Start() /* Check if the DMA Stream is disabled before enabling it. Note that this step is useful when the same Stream is used multiple times: enabled, then disabled then re-enabled... In this case, the DMA Stream disable - will be effective only at the end of the ongoing data transfer and it will - not be possible to re-configure it before making sure that the Enable bit - has been cleared by hardware. If the Stream is used only once, this step might + will be effective only at the end of the ongoing data transfer and it will + not be possible to re-configure it before making sure that the Enable bit + has been cleared by hardware. If the Stream is used only once, this step might be bypassed. */ while (DMA_GetCmdStatus(DMA_STREAM) != DISABLE) { } /* Configure DMA Stream */ - DMA_InitStructure.DMA_Channel = DMA_CHANNEL; + DMA_InitStructure.DMA_Channel = DMA_CHANNEL; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SRC_Const_Buffer; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)DST_Buffer; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToMemory; @@ -36,7 +38,7 @@ bool DMA::Start() DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; + DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; @@ -49,7 +51,7 @@ bool DMA::Start() DMA_Cmd(DMA_STREAM, ENABLE); /* Check if the DMA Stream has been effectively enabled. - The DMA Stream Enable bit is cleared immediately by hardware if there is an + The DMA Stream Enable bit is cleared immediately by hardware if there is an error in the configuration parameters and the transfer is no started (ie. when wrong FIFO threshold is configured ...) */ Timeout = TIMEOUT_MAX; @@ -60,17 +62,21 @@ bool DMA::Start() /* Check if a timeout condition occurred */ if (Timeout == 0) { - /* Manage the error: to simplify the code enter an infinite loop */ - while (1) - { - } + /* Manage the error: to simplify the code enter an infinite loop */ + while (1) + { + } } Interrupt.Enable(DMA_STREAM_IRQ); +#endif + + return true; } bool DMA::WaitForStop() { +#ifdef STM32F4 uint retry = Retry; //while (DMA_GetCurrentMemoryTarget(DMA_STREAM) != 0) while (DMA_GetCmdStatus(DMA_STREAM) != DISABLE) @@ -81,5 +87,6 @@ bool DMA::WaitForStop() return false; } } +#endif return true; -} \ No newline at end of file +} diff --git a/DMA.h b/Device/DMA.h similarity index 90% rename from DMA.h rename to Device/DMA.h index 7aa6f88c..a83d363e 100644 --- a/DMA.h +++ b/Device/DMA.h @@ -1,25 +1,23 @@ #ifndef __DMA_H__ #define __DMA_H__ -#include "Sys.h" - // DMA class DMA { private: byte _index; // 第几个定时器,从0开始 bool _started; - + public: DMA(byte index); ~DMA(); - + int Retry; // 等待重试次数,默认200 int Error; // 错误次数 - + bool Start(); // 开始 bool WaitForStop(); // 停止 - + //typedef void (*TimerHandler)(Timer* tim, void* param); //void Register(TimerHandler handler, void* param = nullptr); diff --git a/Flash.cpp b/Device/Flash.cpp similarity index 100% rename from Flash.cpp rename to Device/Flash.cpp diff --git a/Flash.h b/Device/Flash.h similarity index 100% rename from Flash.h rename to Device/Flash.h diff --git a/I2C.cpp b/Device/I2C.cpp similarity index 100% rename from I2C.cpp rename to Device/I2C.cpp diff --git a/I2C.h b/Device/I2C.h similarity index 100% rename from I2C.h rename to Device/I2C.h diff --git a/Port.cpp b/Device/Port.cpp similarity index 100% rename from Port.cpp rename to Device/Port.cpp diff --git a/Port.h b/Device/Port.h similarity index 100% rename from Port.h rename to Device/Port.h diff --git a/Power.cpp b/Device/Power.cpp similarity index 100% rename from Power.cpp rename to Device/Power.cpp diff --git a/Power.h b/Device/Power.h similarity index 100% rename from Power.h rename to Device/Power.h diff --git a/RTC.cpp b/Device/RTC.cpp similarity index 100% rename from RTC.cpp rename to Device/RTC.cpp diff --git a/RTC.h b/Device/RTC.h similarity index 100% rename from RTC.h rename to Device/RTC.h diff --git a/SerialPort.cpp b/Device/SerialPort.cpp similarity index 100% rename from SerialPort.cpp rename to Device/SerialPort.cpp diff --git a/SerialPort.h b/Device/SerialPort.h similarity index 100% rename from SerialPort.h rename to Device/SerialPort.h diff --git a/Spi.cpp b/Device/Spi.cpp similarity index 100% rename from Spi.cpp rename to Device/Spi.cpp diff --git a/Spi.h b/Device/Spi.h similarity index 100% rename from Spi.h rename to Device/Spi.h diff --git a/Timer.cpp b/Device/Timer.cpp similarity index 100% rename from Timer.cpp rename to Device/Timer.cpp diff --git a/Timer.h b/Device/Timer.h similarity index 100% rename from Timer.h rename to Device/Timer.h diff --git a/WatchDog.cpp b/Device/WatchDog.cpp similarity index 100% rename from WatchDog.cpp rename to Device/WatchDog.cpp diff --git a/WatchDog.h b/Device/WatchDog.h similarity index 100% rename from WatchDog.h rename to Device/WatchDog.h diff --git a/Interrupt.cpp b/Kernel/Interrupt.cpp similarity index 100% rename from Interrupt.cpp rename to Kernel/Interrupt.cpp diff --git a/Interrupt.h b/Kernel/Interrupt.h similarity index 100% rename from Interrupt.h rename to Kernel/Interrupt.h diff --git a/Sys.cpp b/Kernel/Sys.cpp similarity index 100% rename from Sys.cpp rename to Kernel/Sys.cpp diff --git a/Kernel/Sys.h b/Kernel/Sys.h new file mode 100644 index 00000000..171a922e --- /dev/null +++ b/Kernel/Sys.h @@ -0,0 +1,167 @@ +#ifndef _Sys_H_ +#define _Sys_H_ + +#include +#include +#include + +#include "Core\Type.h" +#include "Core\Buffer.h" +#include "Core\Array.h" +#include "Core\ByteArray.h" +#include "Core\SString.h" +#include "Core\Stream.h" +#include "Core\DateTime.h" +#include "Core\Version.h" +#include "Core\List.h" +#include "Core\Dictionary.h" +#include "Core\Delegate.h" + +/* 引脚定义 */ +#include "Platform\Pin.h" + +// 强迫内联 +#define _force_inline __attribute__( ( always_inline ) ) __INLINE + +extern "C" +{ +#if defined(DEBUG) || defined(MSGDEBUG) + +#define debug_printf printf + +#else + +#define debug_printf(format, ...) + +#endif +} + +#ifdef USE_FULL_ASSERT + +// 验证确保对象不为空,并且在有效的内存范围内 +//extern void assert_failed(uint8_t* file, uint32_t line); + +#define assert_ptr(expr) (assert_ptr_(expr) ? (void)0 : assert_failed2("ptr==nullptr", (const char*)__FILE__, __LINE__)) +bool assert_ptr_(const void* p); + +void assert_failed2(cstring msg, cstring file, unsigned int line); +#define assert(expr, msg) ((expr) ? (void)0 : assert_failed2(msg, (const char*)__FILE__, __LINE__)) + +#else + +#define assert_ptr(expr) ((void)0) +#define assert(expr, msg) ((void)0) + +#endif + +#if defined(BOOT) || defined(APP) +struct HandlerRemap +{ + Func pUserHandler; + void* Reserved1; + void* Reserved2; + void* Reserved3; +}; +extern struct HandlerRemap StrBoot; +#endif + +// 判定指针是否在ROM区 +#define IN_ROM_SECTION(p) ( (int)p < 0x20000000 ) + +// 系统类 +class TSys +{ +public: + COM MessagePort;// 消息口,默认0表示USART1 + + uint Clock; // 系统时钟 + uint CystalClock;// 晶振时钟 + + String Name; // 系统名称 + String Company; // 系统厂商 + ushort Code; // 产品代码 + Version Ver; // 系统版本 + byte ID[12]; // 芯片ID。 + ushort DevID; // MCU编码。低字设备版本,高字子版本 + ushort RevID; // MCU编码。低字设备版本,高字子版本 + uint CPUID; // CPUID + ushort FlashSize; // 芯片Flash容量。 + ushort RAMSize; // 芯片RAM容量 + + TSys(); // 构造函数 + + void InitClock(); // 初始化系统时钟 + void Init(); // 初始化系统 + void ShowInfo() const; + uint HeapBase() const; // 堆起始地址,前面是静态分配内存 + uint StackTop() const; // 栈顶,后面是初始化不清零区域 + + UInt64 Ms() const; // 系统启动后的毫秒数 + uint Seconds() const; // 系统绝对当前时间,秒 + + void Sleep(uint ms) const; // 毫秒级延迟 + void Delay(uint us) const; // 微秒级延迟 + typedef void (*FuncU32)(uint param); + FuncU32 OnSleep; + + bool CheckMemory() const; + + void Reset() const; // 重启系统 + + // 系统跟踪 + void InitTrace(void* port) const; + void Trace(int times = 1) const; + +public: + // 创建任务,返回任务编号。dueTime首次调度时间ms,period调度间隔ms,-1表示仅处理一次 + uint AddTask(Action func, void* param, int dueTime = 0, int period = 0, cstring name = nullptr) const; + void RemoveTask(uint& taskid) const; + // 设置任务的开关状态,同时运行指定任务最近一次调度的时间,0表示马上调度 + bool SetTask(uint taskid, bool enable, int msNextTime = -1) const; + // 改变任务周期 + bool SetTaskPeriod(uint taskid, int period) const; + + bool Started; + void Start(); // 开始系统大循环 +}; + +extern TSys Sys; //创建一个全局的Sys对象 会在main函数之前执行构造函数(!!!!!) + +//#include "Time.h" +#include "Interrupt.h" + +void EnterCritical(); +void ExitCritical(); + +//extern uint32_t __REV(uint32_t value); +//extern uint32_t __REV16(uint16_t value); + +uint _REV(uint value); +ushort _REV16(ushort value); + +#endif //_Sys_H_ + +/* +v3.2.2016.0517 核心类独立到目录Core,平台无关,系统无关 + +v3.1.2015.1108 增加系统配置存储模块,增加电源管理模块 + +v3.0.2015.0806 增强系统调度器,支持无阻塞多任务调度 + +v2.8.2014.0927 完成微网通讯架构,封装消息协议,串口及nRF24L01+测试通过 +v2.7.2014.0919 支持抢占式多线程调度 +v2.6.2014.0823 平台文件独立,接管系统初始化控制权 +v2.5.2014.0819 增加堆栈溢出检测模块,重载new/delete实现,仅Debug有效 +v2.4.2014.0811 实现系统多任务调度,一次性编译测试通过,多任务小灯例程4k + 实现以太网精简协议TinyIP,ARP/ICMP/TCP/UDP,混合网络例程7.5k + 增加看门狗、定时器模块 +v2.3.2014.0806 使用双栈增加稳定性,增加RTM优化编译,核心函数强制内联,自动堆栈越界检查 +v2.2.2014.0801 增加引脚保护机制,避免不同模块使用相同引脚导致冲突而难以发现错误 +v2.1.2014.0728 增加中断管理模块,全面接管中断向量表,支持动态修改中断函数,支持多中断共用中断函数。F0需配置RAM从0x200000C0开始 +v2.0.2014.0725 使用C++全新实现SmartOS,支持系统时钟、IO、USART、日志、断言、Spi、NRF24L01、SPIFlash、CAN、Enc28j60,GD32超频 + +v1.3.2014.0624 增加Spi模块和NRF24L01+模块的支持 +v1.2.2014.0604 支持GD32芯片 +v1.1.2014.0513 支持F0/F1的GPIO和串口功能 +v1.0.2014.0506 建立嵌入式系统框架SmartOS,使用纯C语言实现 +*/ diff --git a/Task.cpp b/Kernel/Task.cpp similarity index 100% rename from Task.cpp rename to Kernel/Task.cpp diff --git a/Task.h b/Kernel/Task.h similarity index 100% rename from Task.h rename to Kernel/Task.h diff --git a/Thread.cpp b/Kernel/Thread.cpp similarity index 100% rename from Thread.cpp rename to Kernel/Thread.cpp diff --git a/Thread.h b/Kernel/Thread.h similarity index 100% rename from Thread.h rename to Kernel/Thread.h diff --git a/Time.cpp b/Kernel/Time.cpp similarity index 100% rename from Time.cpp rename to Kernel/Time.cpp diff --git a/Time.h b/Kernel/Time.h similarity index 100% rename from Time.h rename to Kernel/Time.h diff --git a/Debug.cpp b/Kernel/Z_Debug.cpp similarity index 100% rename from Debug.cpp rename to Kernel/Z_Debug.cpp diff --git a/Platform/Pin.h b/Platform/Pin.h index 69aeacab..6be1dae7 100644 --- a/Platform/Pin.h +++ b/Platform/Pin.h @@ -183,4 +183,10 @@ enum TIMER Timer18 = 17, }; +enum CAN +{ + Can1 = 0, + Can2 = 1, +}; + #endif diff --git a/Platform/Pin_STM32F1.h b/Platform/Pin_STM32F1.h index 2512dd0e..843106b0 100644 --- a/Platform/Pin_STM32F1.h +++ b/Platform/Pin_STM32F1.h @@ -122,6 +122,7 @@ } /* 控制器区域网络(CAN)针脚 ------------------------------------------------------------------*/ +#define CANS {CAN1, CAN2} // TX RX #define CAN_PINS {PA12, PA11} // AFIO_MAPR_CAN_REMAP_REMAP1 #define CAN_PINS_REMAP2 {PB9, PB8 } // AFIO_MAPR_CAN_REMAP_REMAP2 diff --git a/Sys.h b/Sys.h index 171a922e..777e8f94 100644 --- a/Sys.h +++ b/Sys.h @@ -1,167 +1 @@ -#ifndef _Sys_H_ -#define _Sys_H_ - -#include -#include -#include - -#include "Core\Type.h" -#include "Core\Buffer.h" -#include "Core\Array.h" -#include "Core\ByteArray.h" -#include "Core\SString.h" -#include "Core\Stream.h" -#include "Core\DateTime.h" -#include "Core\Version.h" -#include "Core\List.h" -#include "Core\Dictionary.h" -#include "Core\Delegate.h" - -/* 引脚定义 */ -#include "Platform\Pin.h" - -// 强迫内联 -#define _force_inline __attribute__( ( always_inline ) ) __INLINE - -extern "C" -{ -#if defined(DEBUG) || defined(MSGDEBUG) - -#define debug_printf printf - -#else - -#define debug_printf(format, ...) - -#endif -} - -#ifdef USE_FULL_ASSERT - -// 验证确保对象不为空,并且在有效的内存范围内 -//extern void assert_failed(uint8_t* file, uint32_t line); - -#define assert_ptr(expr) (assert_ptr_(expr) ? (void)0 : assert_failed2("ptr==nullptr", (const char*)__FILE__, __LINE__)) -bool assert_ptr_(const void* p); - -void assert_failed2(cstring msg, cstring file, unsigned int line); -#define assert(expr, msg) ((expr) ? (void)0 : assert_failed2(msg, (const char*)__FILE__, __LINE__)) - -#else - -#define assert_ptr(expr) ((void)0) -#define assert(expr, msg) ((void)0) - -#endif - -#if defined(BOOT) || defined(APP) -struct HandlerRemap -{ - Func pUserHandler; - void* Reserved1; - void* Reserved2; - void* Reserved3; -}; -extern struct HandlerRemap StrBoot; -#endif - -// 判定指针是否在ROM区 -#define IN_ROM_SECTION(p) ( (int)p < 0x20000000 ) - -// 系统类 -class TSys -{ -public: - COM MessagePort;// 消息口,默认0表示USART1 - - uint Clock; // 系统时钟 - uint CystalClock;// 晶振时钟 - - String Name; // 系统名称 - String Company; // 系统厂商 - ushort Code; // 产品代码 - Version Ver; // 系统版本 - byte ID[12]; // 芯片ID。 - ushort DevID; // MCU编码。低字设备版本,高字子版本 - ushort RevID; // MCU编码。低字设备版本,高字子版本 - uint CPUID; // CPUID - ushort FlashSize; // 芯片Flash容量。 - ushort RAMSize; // 芯片RAM容量 - - TSys(); // 构造函数 - - void InitClock(); // 初始化系统时钟 - void Init(); // 初始化系统 - void ShowInfo() const; - uint HeapBase() const; // 堆起始地址,前面是静态分配内存 - uint StackTop() const; // 栈顶,后面是初始化不清零区域 - - UInt64 Ms() const; // 系统启动后的毫秒数 - uint Seconds() const; // 系统绝对当前时间,秒 - - void Sleep(uint ms) const; // 毫秒级延迟 - void Delay(uint us) const; // 微秒级延迟 - typedef void (*FuncU32)(uint param); - FuncU32 OnSleep; - - bool CheckMemory() const; - - void Reset() const; // 重启系统 - - // 系统跟踪 - void InitTrace(void* port) const; - void Trace(int times = 1) const; - -public: - // 创建任务,返回任务编号。dueTime首次调度时间ms,period调度间隔ms,-1表示仅处理一次 - uint AddTask(Action func, void* param, int dueTime = 0, int period = 0, cstring name = nullptr) const; - void RemoveTask(uint& taskid) const; - // 设置任务的开关状态,同时运行指定任务最近一次调度的时间,0表示马上调度 - bool SetTask(uint taskid, bool enable, int msNextTime = -1) const; - // 改变任务周期 - bool SetTaskPeriod(uint taskid, int period) const; - - bool Started; - void Start(); // 开始系统大循环 -}; - -extern TSys Sys; //创建一个全局的Sys对象 会在main函数之前执行构造函数(!!!!!) - -//#include "Time.h" -#include "Interrupt.h" - -void EnterCritical(); -void ExitCritical(); - -//extern uint32_t __REV(uint32_t value); -//extern uint32_t __REV16(uint16_t value); - -uint _REV(uint value); -ushort _REV16(ushort value); - -#endif //_Sys_H_ - -/* -v3.2.2016.0517 核心类独立到目录Core,平台无关,系统无关 - -v3.1.2015.1108 增加系统配置存储模块,增加电源管理模块 - -v3.0.2015.0806 增强系统调度器,支持无阻塞多任务调度 - -v2.8.2014.0927 完成微网通讯架构,封装消息协议,串口及nRF24L01+测试通过 -v2.7.2014.0919 支持抢占式多线程调度 -v2.6.2014.0823 平台文件独立,接管系统初始化控制权 -v2.5.2014.0819 增加堆栈溢出检测模块,重载new/delete实现,仅Debug有效 -v2.4.2014.0811 实现系统多任务调度,一次性编译测试通过,多任务小灯例程4k - 实现以太网精简协议TinyIP,ARP/ICMP/TCP/UDP,混合网络例程7.5k - 增加看门狗、定时器模块 -v2.3.2014.0806 使用双栈增加稳定性,增加RTM优化编译,核心函数强制内联,自动堆栈越界检查 -v2.2.2014.0801 增加引脚保护机制,避免不同模块使用相同引脚导致冲突而难以发现错误 -v2.1.2014.0728 增加中断管理模块,全面接管中断向量表,支持动态修改中断函数,支持多中断共用中断函数。F0需配置RAM从0x200000C0开始 -v2.0.2014.0725 使用C++全新实现SmartOS,支持系统时钟、IO、USART、日志、断言、Spi、NRF24L01、SPIFlash、CAN、Enc28j60,GD32超频 - -v1.3.2014.0624 增加Spi模块和NRF24L01+模块的支持 -v1.2.2014.0604 支持GD32芯片 -v1.1.2014.0513 支持F0/F1的GPIO和串口功能 -v1.0.2014.0506 建立嵌入式系统框架SmartOS,使用纯C语言实现 -*/ +#include "Kernel\Sys.h" diff --git a/Tool/Build_SmartOS_F1.cs b/Tool/Build_SmartOS_F1.cs index 391116fd..2123cd64 100644 --- a/Tool/Build_SmartOS_F1.cs +++ b/Tool/Build_SmartOS_F1.cs @@ -22,7 +22,11 @@ namespace NewLife.Reflection build.AddIncludes("..\\..\\Lib\\CMSIS"); build.AddIncludes("..\\..\\Lib\\Inc"); build.AddIncludes("..\\Core"); + build.AddIncludes("..\\Kernel"); + build.AddIncludes("..\\Device"); build.AddFiles("..\\Core"); + build.AddFiles("..\\Kernel"); + build.AddFiles("..\\Device"); build.AddFiles("..\\", "*.c;*.cpp", false, "CAN;DMA;Memory"); build.AddFiles("..\\Platform", "Boot_F1.cpp"); build.AddFiles("..\\Platform", "startup_stm32f10x.s");