当前位置:诺佳网 > 电子/半导体 > 处理器/DSP >

【CW32移植Free-RTOS】CW32开发者扶持计划

时间:2023-04-18 | 栏目:处理器/DSP | 点击:

前言

1,Free-RTOS源码下载

2,建立文件夹

3,copy系统源码进入新建的工程文件

4,Keil的工程配置

5,添加工程路径

6,修改RTOS配置

#define INCLUDE_xTaskGetCurrentTaskHandle 1

#define xPortPendSVHandler PendSV_Handler
#define vPortSVCHandler	SVC_Handler
//#define	xPortSysTickHandler	SysTick_Handler



#define configUSE_PREEMPTION		1
#define configUSE_IDLE_HOOK			0
#define configUSE_TICK_HOOK			0
#define configCPU_CLOCK_HZ			( ( unsigned long ) 48000000 )	
#define configTICK_RATE_HZ			( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES		( 5 )
#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE		( ( size_t ) ( 4 * 1024 ) )
#define configMAX_TASK_NAME_LEN		( 16 )
#define configUSE_TRACE_FACILITY	0
#define configUSE_16_BIT_TICKS		0
#define configIDLE_SHOULD_YIELD		1
#include "main.h"
#include "interrupts_cw32f030.h"
#include "cw32f030_gpio.h"
#include "cw32f030_adc.h"
#include "cw32f030_gtim.h"
#include "FreeRTOS.h"
#include "task.h"
void SysTick_Handler(void)
{
	#if (INCLUDE_xTaskGetSchedulerState)
		if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
		{
	#endif 
			xPortSysTickHandler();
	#if (INCLUDE_xTaskGetSchedulerState)
		}
		#endif
}

7,测试代码

注意:因为CW32F030.h内可以没有包含管脚等的.h文件 ,因此新建了一个mian.h 文件

#ifndef __MAIN_H
#define __MAIN_H


#include "base_types.h"
#include "cw32f030.h"
#include "system_cw32f030.h"
#include "interrupts_cw32f030.h"
#include "cw32f030_gpio.h"
#include "cw32f030_rcc.h"
#include "cw32f030_systick.h"
#include "interrupts_cw32f030.h"
#include "system_cw32f030.h"
#endif /* __MAIN_H */
#include "CW32F030.h"                   // Device header
#include "FreeRTOS.h"
#include "main.h"
#include "task.h"
#include "queue.h"

//code 代码空间 ro-data 常量空间 rw-data 已全局变量 zi-data 未全局变量等
//**********************************
//		 宏定义
#define LED_TASK_NVIC		2				//任务优先级
#define LED_TASK_Size  	50				//任务堆栈大小
TaskHandle_t LED_Task_Handler;		//句柄

//*******************************
//			函数申明
void LED_task(void *pvParameters);




void LED_init()
{
    GPIO_InitTypeDef GPIO_InitStruct;
		__RCC_GPIOC_CLK_ENABLE();
		PC13_AFx_GPIO();
		
		GPIO_InitStruct.IT = GPIO_IT_NONE;			//控制脚初始化
		GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
		GPIO_InitStruct.Pins = GPIO_PIN_13;
		GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
		GPIO_Init(CW_GPIOC, &GPIO_InitStruct);

}


void LED1(void *pvParameters)
{
   int i;
	
    while(1)
    {
        PC13_SETLOW();
			  vTaskDelay(100);
				PC13_SETHIGH();
				vTaskDelay(100);
    }
}

int main()
{
	
	  LED_init();
		PC13_SETLOW();
    xTaskCreate(LED1, "LED1", 128, NULL, 1, &LED_Task_Handler);
    /* 启动调度器 */
    vTaskStartScheduler();
    /* 如果程序运行到了这里就表示出错了, 一般是内存不足 */
    return 0;

}

工程下载链接:正在审核

您可能感兴趣的文章:

相关文章