#include "include.h"
#include "func.h"
#include "wireless_service.h"

#if FUNC_WIRELESS_EN

AT(.text.app.proc.bt)
void func_wireless_sub_process(void)
{
    ble_app_proc();
}

AT(.text.app.proc.bt)
void func_wireless_process(void)
{
    func_process();

    if (bTransmitEn)
    {
        func_wireless_sub_process();
    }
    else
    {
        wireless_service_proc();
    }

#if SYS_OFF_TIME
    if(sys_cb.pwroff_delay == 0) {
        func_cb.sta = FUNC_PWROFF;
        return;
    }
#endif

#if SYS_SLEEP_LEVEL
    if(sleep_process(bt_is_sleep)) {

    }
#endif
}

AT(.text.func.bt)
void func_wireless_init(void)
{
    bsp_wireless_init();
}

AT(.text.func.bt)
void func_wireless_enter(void)
{
    msg_queue_clear();

    ble_set_work_mode(MODE_WIRELESS);

    func_wireless_init();
}

AT(.text.func.bt)
void func_wireless_exit(void)
{
    wireless_off();

    func_cb.last = FUNC_WIRELESS;
}

AT(.text.func.bt)
void func_wireless(void)
{
    printf("%s\n", __func__);

    func_wireless_enter();

    while (func_cb.sta == FUNC_WIRELESS) {
        func_wireless_process();
        if (bTransmitEn)
        {
            //func_wireless_message(msg_dequeue());
        }
    }

    func_wireless_exit();
}

#endif
