ucosiii 移植
生活随笔
收集整理的這篇文章主要介紹了
ucosiii 移植
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近想在 f429 上面使用 mdk526 版本的 IDE,配合 HAL 和ucosiii??紤]到的方法是對比 v7 開發板的 ucosiii 和裸機程序,找出需要修改的地方,然后對比 v6 開發板的 ucosiii 和 裸機程序,然后把相應的修改融合起來即可。
一。 V7開發板 ucosiii 和 裸機程序對比差別:
工程配置中頭文件包含增加了:
....\uCOS-III\uC-CPU
....\uCOS-III\uC-CPU\ARM-Cortex-M\ARMv7-M\RealView
....\uCOS-III\uC-LIB
....\uCOS-III\uCOS-III\Source
....\uCOS-III\uCOS-III\Ports\ARM-Cortex-M\ARMv7-M\RealView增加整個 UCOSIII文件夾,包含 uC-CPU, uC-LIB,uCOS-III。
修改了 bsp_timer.c 文件
void bsp_InitTimer(void)
{
...
#if uCOS_EN == 0
SysTick_Config(SystemCoreClock / 1000);
#endif
...
}
#if uCOS_EN == 0
/*
*********************************************************************************************************
* 函 數 名: bsp_DelayMS
* 功能說明: ms級延遲,延遲精度為正負1ms
* 形 參: n : 延遲長度,單位1 ms。 n 應大于2
* 返 回 值: 無
*********************************************************************************************************
*/
void bsp_DelayMS(uint32_t n)
{
...
}
void bsp_DelayUS(uint32_t n)
{
...
}
#endif
void bsp_StartTimer(uint8_t _id, uint32_t _period)
{
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
...
void bsp_StartAutoTimer(uint8_t _id, uint32_t _period)
{
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
...
void bsp_StopTimer(uint8_t _id)
{
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
int32_t bsp_GetRunTime(void)
{
int32_t runtime;
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
int32_t bsp_CheckRunTime(int32_t _LastTime)
{
int32_t now_time;
int32_t time_diff;
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
#if uCOS_EN == 0
/*
*********************************************************************************************************
* 函 數 名: SysTick_Handler
* 功能說明: 系統嘀嗒定時器中斷服務程序。啟動文件中引用了該函數。
* 形 參: 無
* 返 回 值: 無
*********************************************************************************************************
*/
void SysTick_Handler(void)
{
...
}
#endif
- 修改 bsp_uart_fifo.c
static void UartSend(UART_T *_pUart, uint8_t *_ucaBuf, uint16_t _usLen)
{
uint16_t i;
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
static uint8_t UartGetChar(UART_T *_pUart, uint8_t *_pByte)
{
uint16_t usCount;
#if uCOS_EN == 1
CPU_SR_ALLOC();
#endif
- 修改 bsp.c
#include "includes.h"
/*
*********************************************************************************************************
* 函數聲明
*********************************************************************************************************
*/
static void SystemClock_Config(void);
static void CPU_CACHE_Enable(void);
static void MPU_Config(void);
/*
*********************************************************************************************************
* 函 數 名: System_Init
* 功能說明: 系統初始化,主要是MPU,Cache和系統時鐘配置
* 形 參:無
* 返 回 值: 無
*********************************************************************************************************
*/
void System_Init(void)
{
/* 配置MPU */
MPU_Config();
...
#if Enable_EventRecorder == 1
/* 初始化EventRecorder并開啟 */
EventRecorderInitialize(EventRecordAll, 1U);
EventRecorderStart();
#endif
}
/*
*********************************************************************************************************
* 函 數 名: bsp_Init
* 功能說明: 初始化所有的硬件設備。該函數配置CPU寄存器和外設的寄存器并初始化一些全局變量。只需要調用一次
* 形 參: 無
* 返 回 值: 無
*********************************************************************************************************
*/
void bsp_Init(void)
{
//bsp_InitDWT(); /* 初始化CM7內核的時鐘周期計數器 */
bsp_InitKey(); /* 按鍵初始化,要放在滴答定時器之前,因為按鈕檢測是通過滴答定時器掃描 */
bsp_InitUart(); /* 初始化串口 */
...
/*
*********************************************************************************************************
* 函 數 名: bsp_DelayMS
* 功能說明: 為了讓底層驅動在帶RTOS和裸機情況下有更好的兼容性
* 專門制作一個阻塞式的延遲函數,在底層驅動中ms毫秒延遲主要用于初始化,并不會影響實時性。
* 形 參: n 延遲長度,單位1 ms
* 返 回 值: 無
*********************************************************************************************************
*/
void bsp_DelayMS(uint32_t _ulDelayTime)
{
bsp_DelayUS(1000*_ulDelayTime);
}
/*
*********************************************************************************************************
* 函 數 名: bsp_DelayUS
* 功能說明: 這里的延時采用CPU的內部計數實現,32位計數器
* OSSchedLock(&err);
* bsp_DelayUS(5);
* OSSchedUnlock(&err); 根據實際情況看看是否需要加調度鎖或選擇關中斷
* 形 參: _ulDelayTime 延遲長度,單位1 us
* 返 回 值: 無
* 說 明: 1. 主頻168MHz的情況下,32位計數器計滿是2^32/168000000 = 25.565秒
* 建議使用本函數做延遲的話,延遲在1秒以下。
* 2. 實際通過示波器測試,微妙延遲函數比實際設置實際多運行0.25us左右的時間。
* 下面數據測試條件:
* (1). MDK5.15,優化等級0, 不同的MDK優化等級對其沒有影響。
* (2). STM32F407IGT6
* (3). 測試方法:
* GPIOI->BSRRL = GPIO_Pin_8;
* bsp_DelayUS(10);
* GPIOI->BSRRH = GPIO_Pin_8;
* -------------------------------------------
* 測試 實際執行
* bsp_DelayUS(1) 1.2360us
* bsp_DelayUS(2) 2.256us
* bsp_DelayUS(3) 3.256us
* bsp_DelayUS(4) 4.256us
* bsp_DelayUS(5) 5.276us
* bsp_DelayUS(6) 6.276us
* bsp_DelayUS(7) 7.276us
* bsp_DelayUS(8) 8.276us
* bsp_DelayUS(9) 9.276us
* bsp_DelayUS(10) 10.28us
* 3. 兩個32位無符號數相減,獲取的結果再賦值給32位無符號數依然可以正確的獲取差值。
* 假如A,B,C都是32位無符號數。
* 如果A > B 那么A - B = C,這個很好理解,完全沒有問題
* 如果A < B 那么A - B = C, C的數值就是0xFFFFFFFF - B + A + 1。這一點要特別注意,正好用于本函數。
*********************************************************************************************************
*/
void bsp_DelayUS(uint32_t _ulDelayTime)
{
uint32_t tCnt, tDelayCnt;
uint32_t tStart;
tStart = (uint32_t)CPU_TS_TmrRd(); /* 剛進入時的計數器值 */
tCnt = 0;
tDelayCnt = _ulDelayTime * (SystemCoreClock / 1000000); /* 需要的節拍數 */
while(tCnt < tDelayCnt)
{
tCnt = (uint32_t)CPU_TS_TmrRd() - tStart; /* 求減過程中,如果發生第一次32位計數器重新計數,依然可以正確計算 */
}
}
- 修改 bsp.h
/* CPU空閑時執行的函數 */
//#define CPU_IDLE() bsp_Idle()
/* 使能在源文件中使用uCOS-III的函數, 這里的源文件主要是指BSP驅動文件 */
#define uCOS_EN 1
#if uCOS_EN == 1
#include "os.h"
#define ENABLE_INT() CPU_CRITICAL_EXIT() /* 使能全局中斷 */
#define DISABLE_INT() CPU_CRITICAL_ENTER() /* 禁止全局中斷 */
#else
/* 開關全局中斷的宏 */
#define ENABLE_INT() __set_PRIMASK(0) /* 使能全局中斷 */
#define DISABLE_INT() __set_PRIMASK(1) /* 禁止全局中斷 */
#endif
/* 提供給其他C文件調用的函數 */
void bsp_Init(void);
void bsp_Idle(void);
void System_Init(void);
增加 bsp_clk.c, bsp_clk.h, bsp_cpu.c, bsp_int.h, bsp_int_armv7m.c, bsp_os.c, bsp_os.h。
修改 stm32h7xx_it.c
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
- 增加 app_cfg.h, cpu_cfg.h, includes.h, lib_cfg.h, os_app_hooks.c, os_app_hooks.h, os_cfg.h, os_cfg_app.h, stm32h7xx_hal_timebase_tim.c。
總結
以上是生活随笔為你收集整理的ucosiii 移植的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring(5) -(14) poin
- 下一篇: 《模式识别导论》特性选择与特征提取概要