[DemoCode下载] 【新唐资料分享月】+FreeRTOS嵌入式操作系统移植

[复制链接]
4260|6
 楼主| wujianwei3980 发表于 2016-12-22 11:54 | 显示全部楼层 |阅读模式
FreeRTOS嵌入式操作系统移植@新唐NUC1XX M051 ARM--Cortex-M0 源码下载,供大家参考

NUC100_FreeRTOS_Keil_IAR.zip

4.7 MB, 下载次数: 341

qjwlj145 发表于 2016-12-26 10:08 | 显示全部楼层
下载看看
ysdx06010302 发表于 2017-6-11 09:35 | 显示全部楼层
freertos用的是6,有点就了。
稳稳の幸福 发表于 2017-6-12 08:25 | 显示全部楼层
可以可以,非常不错。
稳稳の幸福 发表于 2017-6-12 08:28 | 显示全部楼层
  1. /* Standard includes. */
  2. #include <stdio.h>

  3. /* Scheduler includes. */
  4. #include "FreeRTOS.h"
  5. #include "task.h"
  6. #include "queue.h"

  7. /* NUC1xx driver includes. */
  8. #include "DrvUART.h"
  9. #include "DrvGPIO.h"
  10. #include "DrvSYS.h"

  11. /* Demo app includes. */
  12. #include "NUC1xx_Test.h"
  13. #include "App_Cfg.h"

  14. #if BLOCK_Q_TEST
  15. #include "BlockQ.h"
  16. #endif

  17. #if SUICID_TEST
  18. #include "death.h"
  19. #endif

  20. #if MATH_TEST
  21. #include "integer.h"
  22. #endif

  23. #if BLOCK_TM_TEST
  24. #include "blocktim.h"
  25. #endif

  26. #if SEM_TEST
  27. #include "semtest.h"
  28. #endif

  29. #if POLL_Q_TEST
  30. #include "PollQ.h"
  31. #endif

  32. #if LED_TEST
  33. #include "flash.h"
  34. #include "partest.h"
  35. #endif

  36. #if REMUTEX_TEST
  37. #include "recmutex.h"
  38. #endif

  39. #if COUNTSEM_TEST
  40. #include "countsem.h"
  41. #endif

  42. #if GENQ_TEST
  43. #include "GenQTest.h"
  44. #endif

  45. #if DYNAMIC_TEST
  46. #include "dynamic.h"
  47. #endif

  48. #if QPEEK_TEST
  49. #include "QPeek.h"
  50. #endif

  51. #if ALT_QUEUE_TEST
  52. #include "AltQTest.h"
  53. #endif

  54. #if ALT_BLOCKQ_TEST
  55. #include "AltBlckQ.h"
  56. #endif

  57. #if ALT_BLOCK_TEST
  58. #include "AltBlock.h"
  59. #endif

  60. #if ALT_POLLQ_TEST
  61. #include "AltPollQ.h"
  62. #endif

  63. #if MATH_F_TEST
  64. #include "flop.h"
  65. #endif

  66. #if INTQ_TEST
  67. #include "IntQueue.h"
  68. #endif

  69. /* Task priorities. */
  70. #define mainQUEUE_POLL_PRIORITY                                ( tskIDLE_PRIORITY + 2 )
  71. #define mainBLOCK_Q_PRIORITY                                ( tskIDLE_PRIORITY + 2 )
  72. #define mainSEM_TEST_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
  73. #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
  74. #define mainCHECK_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 3 )
  75. #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
  76. #define mainFLASH_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
  77. #define mainUART_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
  78. #define mainGENQ_TASK_PRIORITY                                ( tskIDLE_PRIORITY )

  79. #define mainCHECK_TASK_STACK_SIZE                        ( configMINIMAL_STACK_SIZE )

  80. /* The time between cycles of the 'check' task. */
  81. #define mainCHECK_DELAY                                                ( ( portTickType ) 5000 / portTICK_RATE_MS )

  82. /*-----------------------------------------------------------*/

  83. /*
  84. * Configure the clocks, GPIO and other peripherals as required by the demo.
  85. */
  86. static void prvSetupHardware( void );

  87. static void NUC1xx_UART_Init(void);

  88. /*
  89. * Checks the status of all the demo tasks then prints a message to the
  90. * display.  The message will be either PASS - and include in brackets the
  91. * maximum measured jitter time (as described at the to of the file), or a
  92. * message that describes which of the standard demo tasks an error has been
  93. * discovered in.
  94. *
  95. * Messages are written directly to the terminal.
  96. */
  97. #if CHECK_TEST
  98. static void vCheckTask( void *pvParameters );
  99. #endif

  100. /*-----------------------------------------------------------*/
  101. int main( void )
  102. {
  103. #ifdef DEBUG
  104.   debug();
  105. #endif

  106.         /* Configure realitive hardware platform. */
  107.         prvSetupHardware();
  108.        
  109.         /* Start the standard demo tasks. */
  110. #if LED_TEST
  111.         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
  112. #endif
  113. #if POLL_Q_TEST
  114.         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
  115. #endif
  116. #if BLOCK_Q_TEST
  117.         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
  118. #endif
  119. #if SEM_TEST
  120.         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
  121. #endif
  122. #if MATH_TEST
  123.         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
  124. #endif
  125. #if BLOCK_TM_TEST
  126.         vCreateBlockTimeTasks();
  127. #endif
  128. #if REMUTEX_TEST
  129.         vStartRecursiveMutexTasks();
  130. #endif
  131. #if COUNTSEM_TEST
  132.         vStartCountingSemaphoreTasks();
  133. #endif
  134. #if GENQ_TEST
  135.         vStartGenericQueueTasks( mainGENQ_TASK_PRIORITY );
  136. #endif
  137. #if DYNAMIC_TEST
  138.         vStartDynamicPriorityTasks();
  139. #endif
  140. #if QPEEK_TEST
  141.         vStartQueuePeekTasks();
  142. #endif
  143. #if ALT_QUEUE_TEST
  144.         vStartAltGenericQueueTasks( tskIDLE_PRIORITY );
  145. #endif
  146. #if ALT_BLOCKQ_TEST
  147.         vStartAltBlockingQueueTasks( tskIDLE_PRIORITY + 2 );
  148. #endif
  149. #if ALT_BLOCK_TEST
  150.         vCreateAltBlockTimeTasks();
  151. #endif
  152. #if ALT_POLLQ_TEST
  153.         vStartAltPolledQueueTasks( tskIDLE_PRIORITY + 2 );
  154. #endif
  155. #if MATH_F_TEST
  156.         vStartMathTasks( tskIDLE_PRIORITY );
  157. #endif
  158. #if INTQ_TEST
  159.         vStartInterruptQueueTasks();
  160. #endif

  161.         /* Start user demo tasks. */
  162. #if UART_TEST
  163.         vStartUARTTasks( mainUART_TASK_PRIORITY );
  164. #endif
  165. #if THREAD_TEST
  166.         vStartThreadTasks();
  167. #endif
  168. #if QUEUE_TEST
  169.         vStartQueueTasks();
  170. #endif

  171.         /* Start the tasks defined within this file/specific to this demo. */
  172. #if CHECK_TEST
  173.     xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", mainCHECK_TASK_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );       
  174. #endif

  175.         /* The suicide tasks must be created last as they need to know how many
  176.         tasks were running prior to their creation in order to ascertain whether
  177.         or not the correct/expected number of tasks are running at any given time. */
  178. #if SUICID_TEST
  179.     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
  180. #endif       
  181.         /* Start the scheduler. */
  182.         vTaskStartScheduler();

  183.         /* Will only get here if there was not enough heap space to create the
  184.         idle task. */
  185.         return 0;
  186. }
  187. /*-----------------------------------------------------------*/
  188. #if CHECK_TEST
  189. static void vCheckTask( void *pvParameters )
  190. {
  191. portTickType xLastExecutionTime;
  192. static unsigned portBASE_TYPE times = 0;

  193.         printf( "Check begin...\n" );

  194.         xLastExecutionTime = xTaskGetTickCount();

  195.     for( ;; )
  196.         {
  197.                 /* Perform this check every mainCHECK_DELAY milliseconds. */
  198.                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );

  199.                 /* Has an error been found in any task? */
  200.         #if BLOCK_Q_TEST
  201.         if( xAreBlockingQueuesStillRunning() != pdTRUE )
  202.                 {
  203.                         printf( "ERROR IN BLOCK Q\n" );
  204.                 }
  205.         #endif
  206.         #if BLOCK_TM_TEST
  207.                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
  208.                 {
  209.                         printf("ERROR IN BLOCK TIME\n");
  210.                 }
  211.     #endif
  212.         #if SEM_TEST
  213.                 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
  214.         {
  215.                         printf( "ERROR IN SEMAPHORE\n" );
  216.         }
  217.         #endif
  218.         #if POLL_Q_TEST
  219.         else if( xArePollingQueuesStillRunning() != pdTRUE )
  220.         {
  221.                         printf( "ERROR IN POLL Q\n" );
  222.         }
  223.         #endif
  224.         #if SUICID_TEST
  225.         else if( xIsCreateTaskStillRunning() != pdTRUE )
  226.         {
  227.                         printf( "ERROR IN CREATE\n" );
  228.         }
  229.         #endif
  230.         #if MATH_TEST
  231.         else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
  232.         {
  233.                         printf( "ERROR IN MATH\n" );
  234.         }
  235.         #endif
  236.         #if REMUTEX_TEST       
  237.                 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
  238.         {
  239.                         printf( "ERROR IN REMUTEX\n" );
  240.         }
  241.         #endif
  242.         #if COUNTSEM_TEST       
  243.                 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
  244.                 {
  245.                         printf( "ERROR IN COUNTSEM\n" );
  246.                 }
  247.         #endif
  248.         #if GENQ_TEST       
  249.                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
  250.                 {
  251.                         printf( "ERROR IN GENQUEUE\n" );
  252.                 }       
  253.         #endif
  254.         #if DYNAMIC_TEST       
  255.                 else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
  256.                 {
  257.                         printf( "ERROR IN DYNAMIC TEST\n" );
  258.                 }       
  259.         #endif
  260.         #if QPEEK_TEST       
  261.                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
  262.                 {
  263.                         printf( "ERROR IN Q_PEEK\n" );
  264.                 }       
  265.         #endif
  266.         #if ALT_QUEUE_TEST       
  267.                 else if( xAreAltGenericQueueTasksStillRunning() != pdTRUE )
  268.                 {
  269.                         printf( "ERROR IN ALT_QUEUE\n" );
  270.                 }       
  271.         #endif
  272.         #if ALT_BLOCKQ_TEST       
  273.                 else if( xAreAltBlockingQueuesStillRunning() != pdTRUE )
  274.                 {
  275.                         printf( "ERROR IN ALT_BLOCKQ\n" );
  276.                 }       
  277.         #endif
  278.         #if ALT_BLOCK_TEST       
  279.                 else if( xAreAltBlockTimeTestTasksStillRunning() != pdTRUE )
  280.                 {
  281.                         printf( "ERROR IN ALT_BLOCK\n" );
  282.                 }       
  283.         #endif
  284.         #if ALT_POLLQ_TEST       
  285.                 else if( xAreAltPollingQueuesStillRunning() != pdTRUE )
  286.                 {
  287.                         printf( "ERROR IN ALT_POLLQ\n" );
  288.                 }       
  289.         #endif
  290.         #if MATH_F_TEST       
  291.                 else if( xAreMathsTaskStillRunning() != pdTRUE )
  292.                 {
  293.                         printf( "ERROR IN FLOP\n" );
  294.                 }       
  295.         #endif
  296.         #if INTQ_TEST       
  297.                 else if( xAreIntQueueTasksStillRunning() != pdTRUE )
  298.                 {
  299.                         printf( "ERROR IN INTQ\n" );
  300.                 }       
  301.         #endif
  302.                 else
  303.                 {
  304.                         printf( "ALL Test Pass %d times! \n",  ++times );
  305.                 }
  306.         }
  307. }
  308. #endif
  309. /*-----------------------------------------------------------*/

  310. static void prvSetupHardware( void )
  311. {
  312.         UNLOCKREG();

  313.         /* Enable external 12M Crystal oscillation. */
  314.         SYSCLK->PWRCON.XTL12M_EN = 1;

  315.         /* Enable the 64 clock cycle delay. */
  316.         SYSCLK->PWRCON.WU_DLY = 1;

  317.         /* Enable PLL. */
  318.         SYSCLK->PLLCON.PD = 0;
  319.         SYSCLK->PLLCON.OE = 0;

  320.         /* Select PLL output as system clock source. */
  321.         SYSCLK->CLKSEL0.HCLK_S = 2;

  322.         /* Configure SysTick clock source. */
  323.         SYSCLK->CLKSEL0.STCLK_S = 3;

  324.         /* Initialize NUC1xx MUC UART0. */
  325.         NUC1xx_UART_Init();
  326. }
  327. /*-----------------------------------------------------------*/

  328. void NUC1xx_UART_Init(void)
  329. {
  330.         /* Set UART Pin. */
  331.         SYS->GPBMFP.UART0_RX = 1;
  332.         SYS->GPBMFP.UART0_TX = 1;
  333.         SYS->GPBMFP.UART0_nRTS = 1;
  334.         SYS->GPBMFP.UART0_nCTS = 1;

  335.         /* Reset IP */
  336.         SYS->IPRSTC2.UART0_RST = 1;
  337.         SYS->IPRSTC2.UART0_RST = 0;

  338.         /* Enable UART clock */
  339.         SYSCLK->APBCLK.UART0_EN = 1;

  340.         /* Select UART clock source */
  341.     SYSCLK->CLKSEL1.UART_S = 0;
  342.     SYSCLK->PWRCON.XTL12M_EN = 1;
  343.    
  344.         /* Select UART clock source */
  345.     SYSCLK->CLKSEL1.UART_S = 0;

  346.         /* Tx FIFO Reset & Rx FIFO Reset & FIFO Mode Enable */
  347.           UART0->FCR.TFR = 1;
  348.           UART0->FCR.RFR = 1;

  349.         /* Set Rx Trigger Level */
  350.         UART0->FCR.RFITL = 0;  

  351.         /* Set Parity & Data bits & Stop bits */
  352.         UART0->LCR.SPE = 0;
  353.         UART0->LCR.EPE = 0;
  354.         UART0->LCR.PBE = 0;
  355.        
  356.         UART0->LCR.WLS = 3;
  357.         UART0->LCR.NSB = 0;
  358.        
  359.         /* Set Time-Out */
  360.         UART0->TOR = 0;

  361.         /* Set baudrate 115200bps. */
  362.         UART0->BAUD.DIVX_EN = 1;
  363.         UART0->BAUD.DIVX1 = 1;
  364.         UART0->BAUD.DIVX = 15;
  365.         UART0->BAUD.DIV = 102;
  366. }
稳稳の幸福 发表于 2017-6-12 08:28 | 显示全部楼层
用了不少预编译。
643757107 发表于 2017-6-12 14:41 | 显示全部楼层
RTOS比裸奔好学吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:分享资源,共同进步

99

主题

3237

帖子

10

粉丝
快速回复 在线客服 返回列表 返回顶部