公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

XMC1100实验之八:FreeRTOS操作系统

XMC1100实验之八:FreeRTOS操作系统

User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted

本来准备移植一下FreeRTOS,发现官方的源码包已经有XMC1100的Port了.

首先下载源码包:

https://sourceforge.net/projects/freertos/files/latest/download?source=files


安装就是解压,解压后,打开这个目录:

.FreeRTOSv9.0.0FreeRTOSDemoCORTEX_M0_Infineon_XMC1000_IAR_Keil_GCC

根据你的工具选择工程文件,使用Keil就打开这个:

RTOSDemo.uvproj

直接就可以运行看结果了,

不过官方Demo把串口也当做LED了,改改这里:


void vParTestInitialise( void )
{
#define UART_RX P1_3
#define UART_TX P1_2

    XMC_GPIO_CONFIG_t uart_tx;
    XMC_GPIO_CONFIG_t uart_rx;
    XMC_UART_CH_CONFIG_t uart_config;
    
/*Initialize the UART driver */
    uart_tx.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7;
    uart_rx.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
 /* Configure UART channel */
  uart_config.data_bits = 8U;
  uart_config.stop_bits = 1U;
  uart_config.baudrate = 115200;
  uart_config.frame_length = 8;
    uart_config.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE;
  XMC_UART_CH_Init(XMC_UART0_CH1, &uart_config);
  XMC_UART_CH_SetInputSource(XMC_UART0_CH1, XMC_UART_CH_INPUT_RXD,USIC0_C1_DX0_P1_3);
 
    /* Start UART channel */
  XMC_UART_CH_Start(XMC_UART0_CH1);

  /* Configure pins */
    XMC_GPIO_Init(UART_TX, &uart_tx);
  XMC_GPIO_Init(UART_RX, &uart_rx);
    
  sprintf(g_Buf, " Start @%u MHz ",
                    SystemCoreClock/1000000    );
    DbgPrintf(g_Buf);            
    
    LED_Initialize();
}



/* LED GPIO Pins */
static const GPIO_PIN LED_PIN[] =
{
  { XMC_GPIO_PORT0, 7 },
  { XMC_GPIO_PORT0, 5 },
  { XMC_GPIO_PORT0, 6 },
//  { XMC_GPIO_PORT1, 2 },
//  { XMC_GPIO_PORT1, 3 },
  { XMC_GPIO_PORT1, 4 },
  { XMC_GPIO_PORT1, 5 }
};

#define LED_COUNT (sizeof(LED_PIN)/sizeof(GPIO_PIN))


/**
  fn          int32_t LED_Initialize (void)
  rief       Initialize LEDs
  eturns
   -   0: function succeeded
   -  -1: function failed
*/
void LED_Initialize (void)
{
    XMC_GPIO_SetMode(XMC_GPIO_PORT0, 5, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN);
    XMC_GPIO_SetMode(XMC_GPIO_PORT0, 6, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN);
    XMC_GPIO_SetMode(XMC_GPIO_PORT0, 7, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN);

    XMC_GPIO_SetMode(XMC_GPIO_PORT1, 4, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN);
    XMC_GPIO_SetMode(XMC_GPIO_PORT1, 5, XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN);
}

再改一下这个函数:

        if( ulReceivedValue == 100UL )
        {
            vParTestToggleLED( 0 );
            vParTestToggleLED( 1 );
            vParTestToggleLED( 2 );
            vParTestToggleLED( 3 );
            vParTestToggleLED( 4 );
            
//            sprintf(g_Buf, " Toogle "    );
//            DbgPrintf(g_Buf);            
                        
            ulReceivedValue = 0U;
        }


官方Demo的定时Tick设为500Hz. 至此可以看结果了.

0 点赞
3280 次查看
11 评论
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted
FreeRTOSConfig.h就是这个RTOS的配置文件 可以改如下参数: #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 1 #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 11000 ) ) #define configMAX_TASK_NAME_LEN ( 5 )
0 点赞
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted
#define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 #define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_MALLOC_FAILED_HOOK 1 #define configUSE_APPLICATION_TASK_TAG 0 #define configUSE_COUNTING_SEMAPHORES 1 #define configGENERATE_RUN_TIME_STATS 0 #define configUSE_QUEUE_SETS 1
0 点赞
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted
/* Co-routine definitions. */ #define configUSE_CO_ROUTINES 0 #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Software timer definitions. */ #define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY ( 2 ) #define configTIMER_QUEUE_LENGTH 5 #define configTIMER_TASK_STACK_DEPTH ( 80 )
0 点赞
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted
/* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskCleanUpResources 1 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_eTaskGetState 1
0 点赞
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted
FreeRTOS比RTX要流行点, 至于两者的对比, 以后单独写一写.
0 点赞
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted
官方的Demo中已经有了TC1782的Port 还没有看到TC2系列的Port, 等过几天我在TC275的板子上移植一下
0 点赞
User12775
Level 5
Level 5
1000 replies posted 750 replies posted 500 replies posted

SafeRTOS就是FreeRTOS的变种, 加强了安全功能,

感觉OS方面的贴子关注度更低了.

自顶一贴!

0 点赞
dayundaner
Level 1
Level 1
1000 replies posted 750 replies posted 500 replies posted

楼主好人。点赞

0 点赞
WuAiJiDian
Level 1
Level 1
50 replies posted 25 replies posted 10 replies posted
学习一下
0 点赞
纳尼
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

这些从哪里下载呀,最近再关注基于TC的RTOS

0 点赞
Maui
Level 3
Level 3
50 replies posted 25 replies posted 10 replies posted
有批量使用的案例吗?
0 点赞