单片机/MCU论坛
直播中

卢松涛

12年用户 450经验值
擅长:嵌入式技术
私信 关注

【MAX32660试用体验】freertos+dht11+rgy灯

` 本帖最后由 lustao 于 2019-4-3 13:15 编辑

freertos+dht11+rgy灯
Maxim带的例子有freertos的,看着研究了下,加在vTask0加了 2019-3-12 15:36:19   用彩色灯制作红绿灯程序,加在vTask1加了6 天前DHT11程序

  1. /*******************************************************************************
  2. * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included
  12. * in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  18. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Except as contained in this notice, the name of Maxim Integrated
  23. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  24. * Products, Inc. Branding Policy.
  25. *
  26. * The mere transfer of this software does not imply any licenses
  27. * of trade secrets, proprietary technology, copyrights, patents,
  28. * trademarks, maskwork rights, or any other form of intellectual
  29. * property whatsoever. Maxim Integrated Products, Inc. retains all
  30. * ownership rights.
  31. ********************************************************************************/

  32. /* **** Includes **** */
  33. /* config.h is the required application configuration; RAM layout, stack, chip type etc. */
  34. #include "mxc_config.h"
  35. #include "board.h"

  36. #include
  37. #include
  38. #include
  39. #include
  40. #include
  41. #include

  42. /* FreeRTOS */
  43. #include "FreeRTOS.h"
  44. #include "task.h"
  45. #include "semphr.h"

  46. /* FreeRTOS+ */
  47. #include "FreeRTOS_CLI.h"

  48. /* Maxim CMSIS SDK */
  49. #include "rtc.h"
  50. #include "uart.h"
  51. #include "lp.h"
  52. #include "led.h"
  53. #include "board.h"
  54. #include "pb.h"

  55. /* FreeRTOS+CLI */
  56. void vRegisterCLICommands(void);

  57. /* Mutual exclusion (mutex) semaphores */
  58. SemaphoreHandle_t xGPIOmutex;

  59. /* Task IDs */
  60. TaskHandle_t cmd_task_id;

  61. /* Enables/disables tick-less mode */
  62. unsigned int disable_tickless = 1;

  63. /* **** macros **** */
  64. /* Stringification macros */
  65. #define STRING(x) STRING_(x)
  66. #define STRING_(x) #x

  67. /* Console ISR selection */
  68. #if (CONSOLE_UART==0)
  69. #define UARTx_IRQHandler UART0_IRQHandler
  70. #define UARTx_IRQn UART0_IRQn
  71. #elif (CONSOLE_UART==1)
  72. #define UARTx_IRQHandler UART1_IRQHandler
  73. #define UARTx_IRQn UART1_IRQn
  74. #else
  75. #error "Please update ISR macro for UART CONSOLE_UART"
  76. #endif

  77. extern mxc_uart_regs_t *ConsoleUART; /* Set by board.c */
  78. gpio_cfg_t uart_rx_pin = { PORT_0, PIN_6, GPIO_FUNC_IN, GPIO_PAD_PULL_UP};

  79. /* **** Definitions **** */
  80. volatile int buttonPressed = 0;
  81. gpio_cfg_t dht_in = {PORT_0, PIN_4, GPIO_FUNC_IN, GPIO_PAD_NONE};
  82. #define SECS_PER_HR         (60 * 60)
  83. #define SECS_PER_DAY        (24 * SECS_PER_HR)

  84. #define MSEC_TO_RSSA(x) (0 - ((x * 256) / 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */
  85. /* Array sizes */
  86. #define CMD_LINE_BUF_SIZE  80
  87. #define OUTPUT_BUF_SIZE  512



  88. /**
  89. * @brief   vTask0
  90. * @details
  91. */
  92. void vTask0(void *pvParameters)
  93. {

  94.     gpio_cfg_t gpio_out0 = {PORT_0, PIN_9, GPIO_FUNC_OUT, GPIO_PAD_NONE};
  95.         gpio_cfg_t gpio_out1 = {PORT_0, PIN_13, GPIO_FUNC_OUT, GPIO_PAD_NONE};
  96.         /*int count = 0;*/

  97.         /* Setup output pin  FOR led. */

  98.         GPIO_Config(&gpio_out0);


  99.         GPIO_Config(&gpio_out1);

  100.         printf("
  101. ***** GPIO led  ******
  102. ");
  103.         printf(
  104.                         "1. This example outputs the same state onto P0.9 (led) and outputs the same state onto P0.13 (led).
  105. ");

  106.         while (1) {
  107.                 GPIO_OutClr(&gpio_out1);
  108.                 GPIO_OutClr(&gpio_out0);
  109.             TickType_t xLastWakeTime;


  110.             /* Get task start time */
  111.             xLastWakeTime = xTaskGetTickCount();
  112.         GPIO_OutSet(&gpio_out0);
  113.         /* Wait 1 second until next run */
  114.         vTaskDelayUntil(&xLastWakeTime, configTICK_RATE_HZ*10);            // wait for 10 seconds
  115.   GPIO_OutClr(&gpio_out0);
  116.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  117. // mxc_delay(MXC_DELAY_MSEC(300));
  118.   GPIO_OutSet(&gpio_out0);
  119.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  120.   GPIO_OutClr(&gpio_out0);
  121.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  122.   GPIO_OutSet(&gpio_out0);
  123.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  124.   GPIO_OutClr(&gpio_out0);
  125.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  126.   GPIO_OutSet(&gpio_out0);
  127.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  128.                 GPIO_OutSet(&gpio_out1);
  129.             xLastWakeTime = xTaskGetTickCount();
  130.                 GPIO_OutSet(&gpio_out0);
  131.         vTaskDelayUntil(&xLastWakeTime, configTICK_RATE_HZ*2);
  132.                 //mxc_delay(MXC_DELAY_MSEC(2000));
  133.                 GPIO_OutClr(&gpio_out1);
  134.                 GPIO_OutClr(&gpio_out0);
  135.             xLastWakeTime = xTaskGetTickCount();
  136.         GPIO_OutSet(&gpio_out1);
  137.         vTaskDelayUntil(&xLastWakeTime, configTICK_RATE_HZ*10);            // wait for 10 seconds
  138.   GPIO_OutClr(&gpio_out1);
  139.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  140.   GPIO_OutSet(&gpio_out1);
  141.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  142.   GPIO_OutClr(&gpio_out1);
  143.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  144.   GPIO_OutSet(&gpio_out1);
  145.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  146.   GPIO_OutClr(&gpio_out1);
  147.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  148.   GPIO_OutSet(&gpio_out1);
  149.   vTaskDelay( 300 * configTICK_RATE_HZ/1000);
  150.                 GPIO_OutSet(&gpio_out1);
  151.             xLastWakeTime = xTaskGetTickCount();
  152.                 GPIO_OutSet(&gpio_out0);
  153.         vTaskDelayUntil(&xLastWakeTime, configTICK_RATE_HZ*2);
  154.                 //mxc_delay(MXC_DELAY_MSEC(2000));
  155.                 GPIO_OutClr(&gpio_out1);
  156.                 GPIO_OutClr(&gpio_out0);

  157.         }
  158. }

  159. void printTime(void)
  160. {
  161.     int day, hr, min, sec;
  162.     double subsec;

  163.     subsec = RTC_GetSubSecond() / 256.0;
  164.     sec = RTC_GetSecond();

  165.     day = sec / SECS_PER_DAY;
  166.     sec -= day * SECS_PER_DAY;

  167.     hr = sec / SECS_PER_HR;
  168.     sec -= hr * SECS_PER_HR;

  169.     min = sec /60;
  170.     sec -= min * 60;

  171.     subsec += sec;

  172.     printf("Current Time (dd:hh:mm:ss.subs): %02d:%02d:%02d:%05.2f
  173. ", day, hr, min, subsec);
  174. }
  175. void MicroSeconds(int us) {

  176.     /* Demonstrates the TMR driver delay */
  177.     //    TMR_Delay(MXC_TMR0, USEC(us), NULL); // todo check if this is μsec or msec
  178.     uint32_t i = 0;
  179.     for( i=0; i < us * 4; i++) {
  180.         asm(" nop");
  181.     }
  182. }

  183. /*从DHT11读取一个位,返回值:1/0。
  184. 每一bit数据都以50us的低电平时序开始,高电平的宽度决定了bit数据位的0或1,
  185. 高电平状态在26~28us时,表示数据位为0,高电平状态在70us时,表示数据位为1.
  186. DHT11_DQ_IN是读取对应端口引脚的输入电平,在读之前,该引脚要配置为上拉下拉输入模式
  187. */
  188. char DHT11_Read_Bit(void)
  189. {
  190.         char retry=0;
  191. while(GPIO_InGet(&dht_in)&&retry<100)//读取高电平中,等待变为低电平,/*&&与<的优先级是<高于&&*/
  192. {
  193. retry++;
  194. MicroSeconds(1);//SysTickDelay(1);
  195. }
  196. retry=0;
  197. while(!GPIO_InGet(&dht_in)&&retry<100)//读取低电平中,等待变高电平
  198. {
  199. retry++;
  200. MicroSeconds( 1);//SysTickDelay(1);
  201. }
  202. MicroSeconds( 40);//SysTickDelay(40);//等待40us
  203. if(GPIO_InGet(&dht_in))return 1;
  204. else return 0;
  205. }

  206. char DhtReadByte(void)
  207. {
  208.         char j,dat;
  209.     dat=0;

  210. for(j=0;j<8;j++)
  211. {

  212.     dat<<=1;
  213.    dat|=DHT11_Read_Bit();
  214. }

  215. return(dat);  }


  216. void vTask1(void *pvParameters)
  217. {
  218.    // gpio_cfg_t dht_in = {PORT_0, PIN_4, GPIO_FUNC_IN, GPIO_PAD_NONE};
  219.     gpio_cfg_t dht_out = {PORT_0, PIN_4, GPIO_FUNC_OUT, GPIO_PAD_NONE};
  220.         int count = 0;

  221.         printf("
  222. ***** DHT11  on P0.4 ******
  223. ");
  224.         printf(
  225.                         "1.  An interrupt is set up on P0.12.  when that interrupt occurs.using a push button (S1) to start DHT11
  226. ");
  227.     /* Wait 1 second until next run */
  228.           vTaskDelay(  configTICK_RATE_HZ);
  229.             int i=0;
  230.         char check;    // 校验字节
  231.         char TemHig,TemLow,HumiHig,HumiLow;
  232.             while (1) {
  233.                 if (buttonPressed) {
  234.                     // Show the time elapsed.
  235.                     printTime();
  236.                     printf("buttonPressed    count = %d
  237. ", count++);
  238.                     // Delay for switch debouncing.
  239.                     vTaskDelay(  configTICK_RATE_HZ/10);//TMR_Delay(MXC_TMR0, MSEC(100), &sys_tmr_cfg);
  240.                     printf("configTICK_RATE_HZ = %d
  241. ", configTICK_RATE_HZ);
  242.                     // Re-arm switch detection.
  243.                     i++;
  244.                     buttonPressed = 0;

  245.                     GPIO_Config(&dht_out);
  246.                     GPIO_OutClr(&dht_out);
  247.                           // 主机拉低18ms  DelayMs(18);
  248.                     vTaskDelay( 19* configTICK_RATE_HZ/1000);//TMR_Delay(MXC_TMR0, MSEC(18), &sys_tmr_cfg);
  249.                     vTaskSuspendAll();
  250.                     GPIO_OutSet(&dht_out);
  251.                     MicroSeconds( 20);
  252.                     GPIO_Config(&dht_in);            
  253.                     xTaskResumeAll();
  254.                     vTaskDelay( 10* configTICK_RATE_HZ);//TMR_Delay(MXC_TMR0, MSEC(15000), &sys_tmr_cfg);       //  主机延时15s
  255.                     GPIO_Config(&dht_out);
  256.                     GPIO_OutClr(&dht_out);
  257.                           // 主机拉低18ms  DelayMs(18);
  258.                     vTaskDelay( 19* configTICK_RATE_HZ/1000);//TMR_Delay(MXC_TMR0, MSEC(18), &sys_tmr_cfg);
  259.                     vTaskSuspendAll();
  260.                     GPIO_OutSet(&dht_out);
  261.                     MicroSeconds( 20);
  262.                     GPIO_Config(&dht_in);            
  263.                     while (!GPIO_InGet(&dht_in));   
  264.                     while (GPIO_InGet(&dht_in));   
  265.                     HumiHig = DhtReadByte();
  266.                     HumiLow = DhtReadByte();  
  267.                     TemHig  = DhtReadByte();
  268.                     TemLow  = DhtReadByte();  
  269.                     check   = DhtReadByte();
  270.                     xTaskResumeAll();
  271.                     
  272.                     if(check==HumiHig + HumiLow + TemHig + TemLow)   
  273.                     {printf("HumiHig   = %d. %d
  274. ", HumiHig,HumiLow);
  275.                     printf("TemHig   = %d. %d
  276. ", TemHig,TemLow);
  277.                     printf("check   = %d
  278. ", check);}
  279.                     else{
  280.                             printf(" error check .count = %d
  281. ", count);
  282.                             printTime();
  283.                     }


  284.                 }
  285.                 else{
  286.                     vTaskDelay( 100* configTICK_RATE_HZ/1000);
  287.                 }
  288.             }

  289. }
  290. /**  
  291. * @brief   vTickTockTask
  292. * @details This task writes the current RTOS tick time to the console
  293. */
  294. void vTickTockTask(void *pvParameters)
  295. {
  296.     TickType_t ticks = 0;
  297.     TickType_t xLastWakeTime;

  298.     /* Get task start time */
  299.     xLastWakeTime = xTaskGetTickCount();
  300.   
  301.     while (1) {
  302.         ticks = xTaskGetTickCount();
  303.         printf("Uptime is 0x%08x (%u seconds), tickless-idle is %s
  304. ",
  305.             ticks, ticks / configTICK_RATE_HZ,
  306.             disable_tickless ? "disabled" : "ENABLED");
  307.         vTaskDelayUntil(&xLastWakeTime, (configTICK_RATE_HZ * 60));
  308.     }
  309. }

  310. /**
  311. * @brief   UART0_IRQHandler
  312. * @details This function overrides the weakly-declared interrupt handler
  313. *          in system_max326xx.c and is needed for asynchronous UART
  314. *          calls to work properly
  315. */
  316. void UARTx_IRQHandler(void)
  317. {
  318.     UART_Handler(ConsoleUART);
  319. }

  320. /**
  321. * @brief   vCmdLineTask_cb
  322. * @details Callback on asynchronous reads to wake the waiting command
  323. *          processor task
  324. */
  325. void vCmdLineTask_cb(uart_req_t *req, int error)
  326. {
  327.     BaseType_t xHigherPriorityTaskWoken;

  328.     /* Wake the task */
  329.     xHigherPriorityTaskWoken = pdFALSE;
  330.     vTaskNotifyGiveFromISR(cmd_task_id, &xHigherPriorityTaskWoken);
  331.     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
  332. }

  333. /**
  334. * @brief   vCmdLineTask
  335. * @details The command line task provides a prompt on the serial
  336. *          interface and takes input from the user to evaluate
  337. *          via the FreeRTOS+CLI parser.
  338. * @note    FreeRTOS+CLI is part of FreeRTOS+ and has
  339. *          different licensing requirements. Please see
  340. *          http://www.freertos.org/FreeRTOS-Plus for more information
  341. */
  342. void vCmdLineTask(void *pvParameters)
  343. {
  344.     unsigned char tmp;
  345.     unsigned int index;     /* Index into buffer */
  346.     unsigned int x;
  347.     char buffer[CMD_LINE_BUF_SIZE];      /* Buffer for input */
  348.     char output[OUTPUT_BUF_SIZE];        /* Buffer for output */
  349.     BaseType_t xMore;
  350.     uart_req_t async_read_req;
  351.   
  352.     memset(buffer, 0, CMD_LINE_BUF_SIZE);
  353.     index = 0;
  354.    
  355.     /* Register available CLI commands */
  356.     vRegisterCLICommands();

  357.     /* Enable UART0 interrupt */
  358.     NVIC_ClearPendingIRQ(UARTx_IRQn);
  359.     NVIC_DisableIRQ(UARTx_IRQn);
  360.     NVIC_SetPriority(UARTx_IRQn, 1);
  361.     NVIC_EnableIRQ(UARTx_IRQn);

  362.     /* Async read will be used to wake process */
  363.     async_read_req.data = &tmp;
  364.     async_read_req.len = 1;
  365.     async_read_req.callback = vCmdLineTask_cb;
  366.   
  367.     printf("
  368. Enter 'help' to view a list of available commands.
  369. ");
  370.     printf("cmd> ");
  371.     fflush(stdout);
  372.         
  373.     while (1) {
  374.         /* Register async read request */
  375.         if (UART_ReadAsync(ConsoleUART, &async_read_req) != E_NO_ERROR) {
  376.             printf("Error registering async request. Command line unavailable.
  377. ");
  378.         vTaskDelay(portMAX_DELAY);
  379.         }
  380.         /* Hang here until ISR wakes us for a character */
  381.         ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
  382.         /* Check that we have a valid character */
  383.         if (async_read_req.num > 0) {
  384.            /* Process character */
  385.             do {
  386.                     if (tmp == 0x08) {
  387.                     /* Backspace */
  388.                         if (index > 0) {
  389.                             index--;
  390.                             printf("x08 x08");
  391.                         }
  392.                         fflush(stdout);
  393.                     } else if (tmp == 0x03) {
  394.                     /* ^C abort */
  395.                         index = 0;
  396.                         printf("^C");
  397.                         printf("
  398. cmd> ");
  399.                         fflush(stdout);
  400.                     } else if ((tmp == '
    ') || (tmp == '
  401. ')) {
  402.                         printf("
  403. ");
  404.                         /* Null terminate for safety */
  405.                         buffer[index] = 0x00;
  406.                         /* Evaluate */
  407.                         do {
  408.                             xMore = FreeRTOS_CLIProcessCommand(buffer, output, OUTPUT_BUF_SIZE);
  409.                             /* If xMore == pdTRUE, then output buffer contains no null termination, so
  410.                              *  we know it is OUTPUT_BUF_SIZE. If pdFALSE, we can use strlen.
  411.                              */
  412.                             for (x = 0; x < (xMore == pdTRUE ? OUTPUT_BUF_SIZE : strlen(output)) ; x++) {
  413.                                 putchar(*(output+x));
  414.                             }
  415.                         } while (xMore != pdFALSE);
  416.                         /* New prompt */
  417.                         index = 0;
  418.                         printf("
  419. cmd> ");
  420.                         fflush(stdout);
  421.                     } else if (index < CMD_LINE_BUF_SIZE) {
  422.                         putchar(tmp);
  423.                         buffer[index++] = tmp;
  424.                         fflush(stdout);
  425.                     } else {
  426.                         /* Throw away data and beep terminal */
  427.                         putchar(0x07);
  428.                         fflush(stdout);
  429.                     }
  430.                          /* If more characters are ready, process them here */
  431.             } while ((UART_NumReadAvail(MXC_UART_GET_UART(CONSOLE_UART)) > 0) &&
  432.                 UART_Read(MXC_UART_GET_UART(CONSOLE_UART), (uint8_t *)&tmp, 1, NULL));
  433.         }
  434.     }
  435. }

  436. #if configUSE_TICKLESS_IDLE
  437. /**
  438. * @brief   freertos_permit_tickless
  439. * @details Determine if any hardware activity should prevent
  440. *          low-power tickless operation.
  441. */
  442. int freertos_permit_tickless(void)
  443. {
  444.   if (disable_tickless == 1) {
  445.     return E_BUSY;
  446.   }

  447.   return UART_PrepForSleep(MXC_UART_GET_UART(CONSOLE_UART));
  448. }

  449. void buttonHandler(void *pb)
  450. {

  451.   buttonPressed = 1;
  452. }
  453. #endif

  454. void RTC_IRQHandler(void)
  455. {
  456.   MXC_RTC->ctrl &= ~(MXC_F_RTC_CTRL_ALSF);
  457. }

  458. /**
  459. * @brief   main()
  460. * @detials This program demonstrates FreeRTOS tasks, mutexes,
  461. *          and the FreeRTOS+CLI extension.
  462. */
  463. int main(void)
  464. {
  465. #if configUSE_TICKLESS_IDLE
  466.     /* The RTC must be enabled for tickless operation */
  467.     sys_cfg_rtc_t sys_cfg;
  468.     sys_cfg.tmr = MXC_TMR0;
  469.     RTC_Init(MXC_RTC, 0, 0, &sys_cfg);
  470.     RTC_EnableRTCE(MXC_RTC);
  471.     NVIC_ClearPendingIRQ(RTC_IRQn);
  472.     NVIC_EnableIRQ(RTC_IRQn);
  473.     LP_EnableRTCAlarmWakeup();
  474. #endif

  475. #if configUSE_TICKLESS_IDLE
  476.     /* Configure wake-up for GPIO pin corresponding to pushbutton */
  477.     LP_EnableGPIOWakeup((gpio_cfg_t *)&pb_pin[0]);
  478.     PB_RegisterCallback(0, buttonHandler);
  479. #endif
  480.   
  481.     /* Print banner (RTOS scheduler not running) */
  482.     printf("
  483. -=- %s FreeRTOS (%s) Demo -=-
  484. ", STRING(TARGET), tskKERNEL_VERSION_NUMBER);
  485. #if configUSE_TICKLESS_IDLE
  486.     printf("Tickless idle is configured. Type 'tickless 1' to enable.
  487. ");
  488. #endif

  489.     /* Create mutexes */
  490.     xGPIOmutex = xSemaphoreCreateMutex();
  491.     if (xGPIOmutex == NULL) {
  492.         printf("xSemaphoreCreateMutex failed to create a mutex.
  493. ");
  494.     } else {
  495.     /* Configure task */
  496.         if ((xTaskCreate(vTask0, (const char *)"Task0",
  497.                          configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) ||
  498.                 (xTaskCreate(vTask1, (const char *)"Task1",
  499.                          configMINIMAL_STACK_SIZE+128, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) ||
  500.                 (xTaskCreate(vTickTockTask, (const char *)"TickTock",
  501.                          2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+2, NULL) != pdPASS) ||
  502.                 (xTaskCreate(vCmdLineTask, (const char *)"CmdLineTask",
  503.                          configMINIMAL_STACK_SIZE+CMD_LINE_BUF_SIZE+OUTPUT_BUF_SIZE, NULL, tskIDLE_PRIORITY+1, &cmd_task_id) != pdPASS)) {
  504.             printf("xTaskCreate() failed to create a task.
  505. ");
  506.         } else {
  507.             /* Start scheduler */
  508.             printf("Starting scheduler.
  509. ");
  510.             vTaskStartScheduler();
  511.         }
  512.     }
  513.   
  514.     /* This code is only reached if the scheduler failed to start */
  515.     printf("ERROR: FreeRTOS did not start due to above error!
  516. ");
  517.     while (1) {
  518.         __NOP();
  519.     }

  520.   /* Quiet GCC warnings */
  521.   return -1;
  522. }


检测运行成功
无标题.png

com

  1. -=- 32660 FreeRTOS (V8.2.1) Demo -=-
  2. Tickless idle is configured. Type 'tickless 1' to enable.
  3. Starting scheduler.
  4. Uptime is 0x00000000 (0 seconds), tickless-idle is disabled


  5. ***** GPIO led  ******

  6. 1. This example outputs the same state onto P0.9 (led) and outputs the same state onto P0.13 (led).


  7. ***** DHT11  on P0.4 ******

  8. 1.  An interrupt is set up on P0.12.  when that interrupt occurs.using a push button (S1) to start DHT11


  9. Enter 'help' to view a list of available commands.
  10. cmd> ps
  11. Task          State  Priority  Stack    #
  12. ************************************************
  13. CmdLineTask     R       1       449     4
  14. IDLE            R       0       97      5
  15. Task0           B       1       70      1
  16. TickTock        B       2       126     3
  17. Task1           B       1       192     2

  18. cmd> Current Time (dd:hh:mm:ss.subs): 00:00:00:23.33
  19. buttonPressed    count = 0
  20. configTICK_RATE_HZ =
  21. HumiHig   = 28. 0
  22. TemHig   = 16. 9
  23. check   = 53
  24. ps
  25. Task          State  Priority  Stack    #
  26. ************************************************
  27. CmdLineTask     R       1       398     4
  28. IDLE            R       0       97      5
  29. Task0           B       1       70      1
  30. TickTock        B       2       126     3
  31. Task1           B       1       90      2

  32. cmd> Uptime is 0x00003c00 (60 seconds), tickless-idle is disabled
  33. Uptime is 0x00007800 (120 seconds), tickless-idle is disabled
  34. ps
  35. Task          State  Priority  Stack    #
  36. ************************************************
  37. CmdLineTask     R       1       398     4
  38. IDLE            R       0       97      5
  39. Task0           B       1       70      1
  40. TickTock        B       2       100     3
  41. Task1           B       1       90      2

  42. cmd> Current Time (dd:hh:mm:ss.subs): 00:00:02:42.38
  43. buttonPressed    count = 1
  44. configTICK_RATE_HZ =
  45. HumiHig   = 28. 0
  46. TemHig   = 17. 1
  47. check   = 46
  48. Uptime is 0x0000b401 (180 seconds), tickless-idle is disabled
  49. Uptime is 0x0000f000 (240 seconds), tickless-idle is disabled
  50. Current Time (dd:hh:mm:ss.subs): 00:00:04:00.53
  51. buttonPressed    count = 2
  52. configTICK_RATE_HZ =
  53. HumiHig   = 29. 0
  54. TemHig   = 17. 0
  55. check   = 46
  56. Current Time (dd:hh:mm:ss.subs): 00:00:04:26.76
  57. buttonPressed    count = 3
  58. configTICK_RATE_HZ =
  59. HumiHig   = 29. 0
  60. TemHig   = 17. 0
  61. check   = 46
  62. Current Time (dd:hh:mm:ss.subs): 00:00:04:42.96
  63. buttonPressed    count = 4
  64. configTICK_RATE_HZ =
  65. HumiHig   = 47. 0
  66. TemHig   = 17. 5
  67. check   = 69
  68. Uptime is 0x00012c00 (300 seconds), tickless-idle is disabled
  69. Uptime is 0x00016800 (360 seconds), tickless-idle is disabled


` 891599515.jpg

更多回帖

发帖
×
20
完善资料,
赚取积分