【K70EK_T7_MQX例程】014log(记录)操作

By Mcuzone

调试串口波特率:115200-uart2
基于MDKK70-EK_T7硬件平台
关键词: Freescale 飞思卡尔 Kinetis MQX Cortex-M4 K70 MDKK70 核心板 开发板 例程 demo log

记录10个用户输入的字符到log中,再从log中调出记录。

串口输出:
Please type in 10 characters:
1234567890
Log contains:
Time: 6176.469922, c=1, i=0
Time: 6176.766809, c=2, i=1
Time: 6177.214118, c=3, i=2
Time: 6177.774664, c=4, i=3
Time: 6178.302033, c=5, i=4
Time: 6178.870361, c=6, i=5
Time: 6179.614513, c=7, i=6
Time: 6179.998342, c=8, i=7
Time: 6180.414304, c=9, i=8
Time: 6180.990527, c=0, i=9


程序:
#define MAIN_TASK  10
#define MY_LOG     1
extern void main_task(uint_32 initial_data);

const TASK_TEMPLATE_STRUCT  MQX_template_list[] = 
{
   /* Task Index, Function,  Stack, Priority,   Name,        Attributes,          Param, Time Slice */
    { MAIN_TASK,  main_task, 2000,  8,          "Main",      MQX_AUTO_START_TASK, 0,     0 },
    { 0 }
};

typedef struct entry_struct
{
   LOG_ENTRY_STRUCT   HEADER;
   _mqx_uint          C;
   _mqx_uint          I;
} ENTRY_STRUCT, _PTR_ ENTRY_STRUCT_PTR;


/*TASK*----------------------------------------------------------
*
* Task Name : main_task
* Comments  :
*   This task logs 10 keystroke entries then prints out the log.
*END*-----------------------------------------------------------*/

void main_task
   (
      uint_32 initial_data
   )
{
   ENTRY_STRUCT entry;
   _mqx_uint    result;
   _mqx_uint    i;
   uchar        c;

   /* Create the log component */
   result = _log_create_component();
   if (result != MQX_OK) {
      printf("Main task: _log_create_component failed");
      _task_block();  
   }

   /* Create a log */
   result = _log_create(MY_LOG,
      10 * (sizeof(ENTRY_STRUCT)/sizeof(_mqx_uint)), 0);
   if (result != MQX_OK) {
      printf("Main task: _log_create failed");   
      _task_block();  
   }

   /* Write the data to the log */   
   printf("Please type in 10 characters:\n");
   for (i = 0; i < 10; i++) {
      c = getchar();
      result = _log_write(MY_LOG, 2, (_mqx_uint)c, i);
      if (result != MQX_OK) {
         printf("Main task: _log_write failed");   
      }
   }

   /* Read data from the log */
   printf("\nLog contains:\n");
   while (_log_read(MY_LOG, LOG_READ_OLDEST_AND_DELETE, 2,
      (LOG_ENTRY_STRUCT_PTR)&entry) == MQX_OK)
   {
      printf("Time: %lu.%03u%03u, c=%c, i=%u\n",
         entry.HEADER.SECONDS,
         (_mqx_uint)entry.HEADER.MILLISECONDS,
         (_mqx_uint)entry.HEADER.MICROSECONDS,
         (uchar)entry.C & 0xff,
         entry.I);
   }

   /* Destroy the log */
   _log_destroy(MY_LOG);

   _task_block();

}
串口输出:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值