简体   繁体   English

警告:传递“xTaskCreate”的参数 1

[英]warning: passing argument 1 of 'xTaskCreate'

when compiling it gives this error?编译时出现此错误? But I don't know why?但我不知道为什么? Maybe I have looked at it for too long and I don't see it anymore?也许我看了太久,我再也看不到了?

CC /project/test/Venetian_blinds/servo.c
/project/test/Venetian_blinds/servo.c: In function 'servo_rotate_to_angle':
/project/test/Venetian_blinds/servo.c:51:3: warning: passing argument 1 of 'xTaskCreate' from incompatible pointer type [enabled by default]
xTaskCreate(&rotate_task, "rotate_task", 256, angle_ptr, 2, NULL);
^
In file included from /project/test/Venetian_blinds/servo.c:7:0:
/opt/esp-open-rtos/FreeRTOS/Source/include/task.h:330:13: note: expected 'TaskFunction_t' but argument is of type 'void (*)(int *)'
BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
^

on the code:在代码上:

#include <FreeRTOS.h>
#include <esp/uart.h>
#include <esp8266.h>
#include <pwm.h>
#include <stdio.h>
#include <stdlib.h>
#include <task.h>
#include "servo.h"

#define PWM_GPIO 13

// My SG90 works on 500µs ~ 2650µs (spec: 500µ ~ 2400µ)
uint16_t calc_duty_from_angle(int angle) {
  return (0.025 + (0.1325 - 0.025) * (double)angle / 180) * UINT16_MAX;
}

void servo_init() {
  printf("pwm_init(1, [%d])\n", PWM_GPIO);

  uint8_t pins[1] = {PWM_GPIO};
  pwm_init(1, pins, false);

  printf("pwm_set_freq(50)     # 50 Hz\n");
  pwm_set_freq(50);
}

void rotate_task(int *angle_ptr) {
  static bool running = false;
  int angle = *angle_ptr;
  free(angle_ptr);

  while (running) {
    vTaskDelay(100 / portTICK_PERIOD_MS);
  }
  running = true;

  printf("rotate servo to angle %d\n", angle);
  pwm_set_duty(calc_duty_from_angle(angle));
  pwm_start();
  vTaskDelay(500 / portTICK_PERIOD_MS);
  pwm_stop();
  vTaskDelay(50 / portTICK_PERIOD_MS);

  running = false;
  vTaskDelete(NULL);
}

void servo_rotate_to_angle(int angle) {
  int *angle_ptr = malloc(sizeof(int));
  *angle_ptr = angle;
  xTaskCreate(rotate_task, "rotate_task", 256, angle_ptr, 2, NULL);
}

I really tried everything I could come up with but not with the solution.我真的尝试了我能想出的一切,但没有找到解决方案。 And I can't get my head around it..... does anyone know how to fix this error?而且我无法理解它.....有人知道如何解决这个错误吗?

anyone?任何人?

Thanks in advance.提前致谢。

Refer to the description of xTaskCreate() at this link .请参阅此链接xTaskCreate()的说明。

Here is the prototype for xTaskCreate() .这是xTaskCreate()的原型。

 BaseType_t xTaskCreate(    TaskFunction_t pvTaskCode,
                            const char * const pcName,
                            configSTACK_DEPTH_TYPE usStackDepth,
                            void *pvParameters,
                            UBaseType_t uxPriority,
                            TaskHandle_t *pxCreatedTask
                          );

Notice that the type of the first parameter is TaskFunction_t .请注意,第一个参数的类型是TaskFunction_t Here is another link that describes how to implement a task .这是另一个描述如何实现任务的链接。 The important excerpt is this:重要的摘录是这样的:

The type TaskFunction_t is defined as a function that returns void and takes a void pointer as its only parameter. TaskFunction_t 类型定义为 function,它返回 void 并将 void 指针作为其唯一参数。 All functions that implement a task should be of this type.所有实现任务的函数都应该属于这种类型。

Your rotate_task() function has a parameter of int * instead of void * so it does not match the TaskFunction_t type required by xTaskCreate() .您的rotate_task() function 有一个参数int *而不是void *因此它与xTaskCreate()所需的TaskFunction_t类型不匹配。 That is what your error messages are telling you.这就是您的错误消息告诉您的内容。

Try changing the prototype of your task function to this:尝试将您的任务 function 的原型更改为:

void rotate_task(void *angle_ptr)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用void指针作为参数传递函数会发出警告 - Passing a function with void pointer as argument gives warning 从不兼容的指针类型警告传递参数 - Passing argument from incompatible pointer type warning 警告:传递&#39;memcpy&#39;的参数1会使指针从整数开始而无需强制转换 - warning: passing argument 1 of ‘memcpy’ makes pointer from integer without a cast 警告传递&#39;finder&#39;的参数2使指针从整数开始而无需强制转换 - Warning passing argument 2 of 'finder' makes pointer from integer without a cast 警告:传递&#39;fopen&#39;的参数2会使指针从整数开始而无需强制转换 - warning: passing argument 2 of ‘fopen’ makes pointer from integer without a cast 警告:从不兼容的指针类型传递“gets”的参数 1 - warning: passing argument 1 of 'gets' from incompatible pointer type 警告:从不兼容的指针类型[默认启用]传递参数' - warning: passing argument ’from incompatible pointer type [enabled by default]' 警告:&#39;strcat&#39;的参数2中的指针目标在签名方面有所不同 - warning: pointer targets in passing argument 2 of ‘strcat’ differ in signedness 警告:从不兼容的指针类型传递“ getsockname”的参数2 - warning: passing argument 2 of ‘getsockname’ from incompatible pointer type 警告:传递“Proc_Start”参数 3 中的指针目标的符号不同 - warning: pointer targets in passing argument 3 of 'Proc_Start' differ in signedness
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM