main_user.c 2.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

#include "app_Ble_User.h"
#include "gatts_table_creat_demo.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "gatts_table_creat_demo.h"
#include "main_user.h"
#include "Protocol_CRC16.h"
#include "Protocol_User.h"
#include "bt_app_main.h"
#include "app_BT_User.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "string.h"
#include "driver/gpio.h"
#include "MCU_Core_Protocol.h"
#include "Protocol_Lib.h"
#include "app_Ble_User.h"
#include "app_BT_User.h"
#include "bt_app_hf.h"


#define TAG "MAIN_USER"
extern esp_bd_addr_t peer_addr;

uint32_t Sys_1ms_Cnt;

#define SYS_RUN_TASK_1MS (1) 
#define SYS_RUN_TASK_10MS (Sys_1ms_Cnt % 10 == 1) 
#define SYS_RUN_TASK_20MS (Sys_1ms_Cnt % 20 == 2) 
#define SYS_RUN_TASK_50MS (Sys_1ms_Cnt % 50 == 3) 
#define SYS_RUN_TASK_100MS (Sys_1ms_Cnt % 100 == 4) 
#define SYS_RUN_TASK_1000MS (Sys_1ms_Cnt % 1000 == 5) 



uint32_t testcnt;

static void Sys_Run_Tasks(void *arg)
{
    uint8_t i = 0;
    while(1)
    {
        if(Sys_1ms_Cnt < 499)
        {
            Sys_1ms_Cnt ++ ;
        }
        else
        {
            Sys_1ms_Cnt = 0;
        }


        if(SYS_RUN_TASK_10MS)
        {
            Protocol_Send_Service();
            Protocol_Service();

            BT_User_Process();
        }

        if(SYS_RUN_TASK_20MS)
        {
            
        }

        if(SYS_RUN_TASK_50MS)
        {
            Prot_Send_Msg_Process();
        }

        if(SYS_RUN_TASK_100MS)
        {
时昊's avatar
时昊 committed
83
            Ble_MsgRec_Tpms_Timeout();
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        }

        if(SYS_RUN_TASK_1000MS)
        {
            
            simple_ota_service();

            testcnt++;
            if(testcnt >= 10)
            {
                testcnt = 0;

                printf("BT_User.BT_Sts = %d\r\n", BT_User.BT_Sts);
                printf("Ble_User.Ble_Sts = %d\r\n", Ble_User.Ble_Sts);

                // esp_log_buffer_hex(TAG, peer_addr, 6);

时昊's avatar
时昊 committed
101
                // printf("Ble_User.Tpms_Updat = %d\r\n", Ble_User.Tpms_Updat);
102 103 104 105

                // printf("RecCtrl.Sts = %d\r\n", RecCtrl.Sts);


时昊's avatar
时昊 committed
106
                // Ble_Msg_RequestTpms_RLY();
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133



                // if(Prot_User.State < Prot_Normal)
                // {
                //     Prot_User.State = Prot_Normal;

                //     printf("Prot_Normal \r\n");
                // }


            }
        }

        vTaskDelay(1);
    }
    vTaskDelete(NULL);
}

void app_main(void)
{
    Protocol_User_Ctrl_Init();
    BT_User_Init();
    Ble_User_Init();
    Get_Mac_Init();
    bsp_BT_Init();
    // bsp_Ble_Init();
134
    app_tpms_main();
135 136 137 138 139 140 141 142 143
    bsp_Uart_Init();

    printf("KL30 INIT OVER~~~~~~\r\n");

    xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, NULL, 1);
}