-1

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.

Jonas
  • 121,568
  • 97
  • 310
  • 388
angel
  • 1

1 Answers1

0

Refer to the description of xTaskCreate() at this link.

Here is the prototype for 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. 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. 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(). That is what your error messages are telling you.

Try changing the prototype of your task function to this:

void rotate_task(void *angle_ptr)
kkrambo
  • 6,643
  • 1
  • 17
  • 30
  • Thank you so much for your reply, but unfortunately it did not do the trick: `/project/test/Venetian_blinds/servo.c: In function 'rotate_task': /project/test/Venetian_blinds/servo.c:29:15: warning: dereferencing 'void *' pointer [enabled by default] int angle = *angle_ptr; ^ /project/test/Venetian_blinds/servo.c:29:15: error: void value not ignored as it ought to be make: *** [/opt/esp-open-rtos/common.mk:219: build/program//servo.o] Error 1` – angel Dec 10 '21 at 15:48
  • @angel Now that `angle_ptr` is a `void *`, you need to cast it to an `int *` before dereferencing the pointer and assigning its value to `angle`. Like this, `int angle = *((int *)angle_ptr);` – kkrambo Dec 14 '21 at 16:33