【问题标题】:FreeRTOS getting the current timeFreeRTOS 获取当前时间
【发布时间】:2017-06-22 09:52:31
【问题描述】:

我有在 FreeRTOS 上运行的代码,我想对其进行编辑, 它是一个测量压力和温度的代码,我希望有时间这些措施是象征性的。

谁能告诉我如何在我的机器上获取当前时间或日期?

谢谢。

这是我现在正在使用的代码。

//#include <stdio.h>
//#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include "platform.h"
#include "printf.h"
#include "lps331ap.h"

static void app_task(void *);

int main(int argc, char *argv[])
{

    // Initialize the platform
    platform_init();

    // Create a task for the application
    xTaskCreate(app_task, (const signed char * const) "lps331", configMINIMAL_STACK_SIZE, NULL, 1, NULL);

    // Run
    platform_run();
    return 0;
}

static void app_task(void *param)
{
    uint32_t pres;
    int16_t temp;
    int count=0;

   // FILE* fichier = NULL;

    printf("# Testing LPS331AP\n");

    printf("# Initializing LPS331AP...\n");
    lps331ap_powerdown();

    printf("# Setting LPS331AP pressure sensor\n");
    lps331ap_set_datarate(LPS331AP_P_12_5HZ_T_12_5HZ);

    while (1)
    {
        lps331ap_read_pres(&pres);
        lps331ap_read_temp(&temp);
        //fichier = fopen("test.txt", "w");
        //fprintf(fichier,"%f", pres / 4096.0);
        //fprintf(fichier,"%f", 42.5 + temp / 480.0 );
        printf("%d\t",count);

        printf("%f\t", 42.5 + temp / 480.0);

        printf("%f\n", pres / 4096.0);

        count=count+1;
        //fclose(fichier);

        //vTaskDelay(configTICK_RATE_HZ / 10);
        vTaskDelay(2000);
        //vTaskDelay(600000);
    }
}

【问题讨论】:

    标签: date freertos


    【解决方案1】:

    为了测量时间,有xTaskGetTickCount,但这将受限于你的滴答率的分辨率。

    或者,您可以创建另一个以 1 Hz 滴答的任务来增加计数器并将其用作系统时间。

    但是,要获得实际日期,您需要咨询您的开发板并查看它是否具有 RTC。否则,您将需要以某种方式手动获取时间,并使用开发板的硬件计时器来保持此计数。

    您的开发板中肯定有一些硬件时钟,您也可以使用它们来测量时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 2021-12-04
      • 2021-04-14
      • 2011-07-02
      • 2011-12-26
      • 2013-08-07
      相关资源
      最近更新 更多