
#include "freerotsTask.h"

#include "uart_dev.h"
#include "FM_GPIO.h"
#include "FM_ADC.h"
#include "queueUart.h"

#include "stdio.h"

#define Common_TASK_PRIO     5
#define Common_STK_SIZE      256

#define Transmit_TASK_PRIO     5
#define Transmit_STK_SIZE      256

TaskHandle_t CommonTask_Handler;
TaskHandle_t TransmitTask_Handler;
uint8_t data[20] = "hello world\n";

void common_Task(void *pvParameters)
{
	// writePwrCtrlState(Android_PwrCtrl, PwrCtrlOpen);
	// proportionalInt();
    // while(1) {
    //     // printf("task1 entry\r\n");
	// 	printf_adc_data();
    //     USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
	//     uartInterruptSend(g_Upward_uart5_handle, data, 12);
    //     vTaskDelay(1000);
    // }

    while (1) {
        uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
        if (Buff == NULL) {
            log_error("Memory allocation failed\n");
            return;
        }

        queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
        sendBuff->length = sizeof("hello world\n");
        sendBuff->data = Buff + sizeof(queueUartSendInfo);
        strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));

        xQueueSend(upward_uart_Queue, &Buff, 10);
        vTaskDelay(1000);
    }
}

void transmit_Task(void *pvParameters)
{
    while (1) {
        uartQueueSend();
        /* 延时三个系统节拍 */
        vTaskDelay(3);
    }
}

/**
  * @brief  启动
  * @param
  * @retval
  */
void startApp(void)
{
	Init_Upward_uart(115200);
	FM_GPIO_Init();
	FM_ADC_Init();


    uartQueueInit();

    /* create task */
    xTaskCreate((TaskFunction_t )common_Task,
                    (const char*    )"commonTask",
                    (uint16_t       )Common_STK_SIZE,
                    (void*          )NULL,
                    (UBaseType_t    )Common_TASK_PRIO,
                    (TaskHandle_t*  )&CommonTask_Handler);

    xTaskCreate((TaskFunction_t )transmit_Task,
                    (const char*    )"transmitTask",
                    (uint16_t       )Transmit_STK_SIZE,
                    (void*          )NULL,
                    (UBaseType_t    )Transmit_TASK_PRIO,
                    (TaskHandle_t*  )&TransmitTask_Handler);

    vTaskStartScheduler();
}




