打印
[DemoCode下载]

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

[复制链接]
3836|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wujianwei3980|  楼主 | 2016-12-22 11:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
FreeRTOS嵌入式操作系统移植@新唐NUC1XX M051 ARM--Cortex-M0 源码下载,供大家参考

NUC100_FreeRTOS_Keil_IAR.zip

4.7 MB

沙发
qjwlj145| | 2016-12-26 10:08 | 只看该作者
下载看看

使用特权

评论回复
板凳
ysdx06010302| | 2017-6-11 09:35 | 只看该作者
freertos用的是6,有点就了。

使用特权

评论回复
地板
稳稳の幸福| | 2017-6-12 08:25 | 只看该作者
可以可以,非常不错。

使用特权

评论回复
5
稳稳の幸福| | 2017-6-12 08:28 | 只看该作者
/* Standard includes. */
#include <stdio.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

/* NUC1xx driver includes. */
#include "DrvUART.h"
#include "DrvGPIO.h"
#include "DrvSYS.h"

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

#if BLOCK_Q_TEST
#include "BlockQ.h"
#endif

#if SUICID_TEST
#include "death.h"
#endif

#if MATH_TEST
#include "integer.h"
#endif

#if BLOCK_TM_TEST
#include "blocktim.h"
#endif

#if SEM_TEST
#include "semtest.h"
#endif

#if POLL_Q_TEST
#include "PollQ.h"
#endif

#if LED_TEST
#include "flash.h"
#include "partest.h"
#endif

#if REMUTEX_TEST
#include "recmutex.h"
#endif

#if COUNTSEM_TEST
#include "countsem.h"
#endif

#if GENQ_TEST
#include "GenQTest.h"
#endif

#if DYNAMIC_TEST
#include "dynamic.h"
#endif

#if QPEEK_TEST
#include "QPeek.h"
#endif

#if ALT_QUEUE_TEST
#include "AltQTest.h"
#endif

#if ALT_BLOCKQ_TEST
#include "AltBlckQ.h"
#endif

#if ALT_BLOCK_TEST
#include "AltBlock.h"
#endif

#if ALT_POLLQ_TEST
#include "AltPollQ.h"
#endif

#if MATH_F_TEST
#include "flop.h"
#endif

#if INTQ_TEST
#include "IntQueue.h"
#endif

/* Task priorities. */
#define mainQUEUE_POLL_PRIORITY                                ( tskIDLE_PRIORITY + 2 )
#define mainBLOCK_Q_PRIORITY                                ( tskIDLE_PRIORITY + 2 )
#define mainSEM_TEST_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
#define mainCHECK_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 3 )
#define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
#define mainFLASH_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
#define mainUART_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
#define mainGENQ_TASK_PRIORITY                                ( tskIDLE_PRIORITY )

#define mainCHECK_TASK_STACK_SIZE                        ( configMINIMAL_STACK_SIZE )

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

/*-----------------------------------------------------------*/

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

static void NUC1xx_UART_Init(void);

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

/*-----------------------------------------------------------*/
int main( void )
{
#ifdef DEBUG
  debug();
#endif

        /* Configure realitive hardware platform. */
        prvSetupHardware();
       
        /* Start the standard demo tasks. */
#if LED_TEST
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
#endif
#if POLL_Q_TEST
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
#endif
#if BLOCK_Q_TEST
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
#endif
#if SEM_TEST
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
#endif
#if MATH_TEST
        vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
#endif
#if BLOCK_TM_TEST
        vCreateBlockTimeTasks();
#endif
#if REMUTEX_TEST
        vStartRecursiveMutexTasks();
#endif
#if COUNTSEM_TEST
        vStartCountingSemaphoreTasks();
#endif
#if GENQ_TEST
        vStartGenericQueueTasks( mainGENQ_TASK_PRIORITY );
#endif
#if DYNAMIC_TEST
        vStartDynamicPriorityTasks();
#endif
#if QPEEK_TEST
        vStartQueuePeekTasks();
#endif
#if ALT_QUEUE_TEST
        vStartAltGenericQueueTasks( tskIDLE_PRIORITY );
#endif
#if ALT_BLOCKQ_TEST
        vStartAltBlockingQueueTasks( tskIDLE_PRIORITY + 2 );
#endif
#if ALT_BLOCK_TEST
        vCreateAltBlockTimeTasks();
#endif
#if ALT_POLLQ_TEST
        vStartAltPolledQueueTasks( tskIDLE_PRIORITY + 2 );
#endif
#if MATH_F_TEST
        vStartMathTasks( tskIDLE_PRIORITY );
#endif
#if INTQ_TEST
        vStartInterruptQueueTasks();
#endif

        /* Start user demo tasks. */
#if UART_TEST
        vStartUARTTasks( mainUART_TASK_PRIORITY );
#endif
#if THREAD_TEST
        vStartThreadTasks();
#endif
#if QUEUE_TEST
        vStartQueueTasks();
#endif

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

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

        /* Will only get here if there was not enough heap space to create the
        idle task. */
        return 0;
}
/*-----------------------------------------------------------*/
#if CHECK_TEST
static void vCheckTask( void *pvParameters )
{
portTickType xLastExecutionTime;
static unsigned portBASE_TYPE times = 0;

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

        xLastExecutionTime = xTaskGetTickCount();

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

                /* Has an error been found in any task? */
        #if BLOCK_Q_TEST
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN BLOCK Q\n" );
                }
        #endif
        #if BLOCK_TM_TEST
                else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
                {
                        printf("ERROR IN BLOCK TIME\n");
                }
    #endif
        #if SEM_TEST
                else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
        {
                        printf( "ERROR IN SEMAPHORE\n" );
        }
        #endif
        #if POLL_Q_TEST
        else if( xArePollingQueuesStillRunning() != pdTRUE )
        {
                        printf( "ERROR IN POLL Q\n" );
        }
        #endif
        #if SUICID_TEST
        else if( xIsCreateTaskStillRunning() != pdTRUE )
        {
                        printf( "ERROR IN CREATE\n" );
        }
        #endif
        #if MATH_TEST
        else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
        {
                        printf( "ERROR IN MATH\n" );
        }
        #endif
        #if REMUTEX_TEST       
                else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
        {
                        printf( "ERROR IN REMUTEX\n" );
        }
        #endif
        #if COUNTSEM_TEST       
                else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN COUNTSEM\n" );
                }
        #endif
        #if GENQ_TEST       
                else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN GENQUEUE\n" );
                }       
        #endif
        #if DYNAMIC_TEST       
                else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN DYNAMIC TEST\n" );
                }       
        #endif
        #if QPEEK_TEST       
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN Q_PEEK\n" );
                }       
        #endif
        #if ALT_QUEUE_TEST       
                else if( xAreAltGenericQueueTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN ALT_QUEUE\n" );
                }       
        #endif
        #if ALT_BLOCKQ_TEST       
                else if( xAreAltBlockingQueuesStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN ALT_BLOCKQ\n" );
                }       
        #endif
        #if ALT_BLOCK_TEST       
                else if( xAreAltBlockTimeTestTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN ALT_BLOCK\n" );
                }       
        #endif
        #if ALT_POLLQ_TEST       
                else if( xAreAltPollingQueuesStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN ALT_POLLQ\n" );
                }       
        #endif
        #if MATH_F_TEST       
                else if( xAreMathsTaskStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN FLOP\n" );
                }       
        #endif
        #if INTQ_TEST       
                else if( xAreIntQueueTasksStillRunning() != pdTRUE )
                {
                        printf( "ERROR IN INTQ\n" );
                }       
        #endif
                else
                {
                        printf( "ALL Test Pass %d times! \n",  ++times );
                }
        }
}
#endif
/*-----------------------------------------------------------*/

static void prvSetupHardware( void )
{
        UNLOCKREG();

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

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

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

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

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

        /* Initialize NUC1xx MUC UART0. */
        NUC1xx_UART_Init();
}
/*-----------------------------------------------------------*/

void NUC1xx_UART_Init(void)
{
        /* Set UART Pin. */
        SYS->GPBMFP.UART0_RX = 1;
        SYS->GPBMFP.UART0_TX = 1;
        SYS->GPBMFP.UART0_nRTS = 1;
        SYS->GPBMFP.UART0_nCTS = 1;

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

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

        /* Select UART clock source */
    SYSCLK->CLKSEL1.UART_S = 0;
    SYSCLK->PWRCON.XTL12M_EN = 1;
   
        /* Select UART clock source */
    SYSCLK->CLKSEL1.UART_S = 0;

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

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

        /* Set Parity & Data bits & Stop bits */
        UART0->LCR.SPE = 0;
        UART0->LCR.EPE = 0;
        UART0->LCR.PBE = 0;
       
        UART0->LCR.WLS = 3;
        UART0->LCR.NSB = 0;
       
        /* Set Time-Out */
        UART0->TOR = 0;

        /* Set baudrate 115200bps. */
        UART0->BAUD.DIVX_EN = 1;
        UART0->BAUD.DIVX1 = 1;
        UART0->BAUD.DIVX = 15;
        UART0->BAUD.DIV = 102;
}

使用特权

评论回复
6
稳稳の幸福| | 2017-6-12 08:28 | 只看该作者
用了不少预编译。

使用特权

评论回复
7
643757107| | 2017-6-12 14:41 | 只看该作者
RTOS比裸奔好学吗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

99

主题

3237

帖子

10

粉丝