#if 0

#if defined(STM32F769xx) || defined(JANUS2)
#include "cmsis_os2.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "max14830.h"
#include "max14830.h"


#define SPI_TO_UART_ENB

osMessageQueueId_t max14820_rcv_queue_hdl;
const osMessageQueueAttr_t myQueue01_attributes = {
        .name = "myQueue01"
};

osSemaphoreId_t intr_semhandle;
const osSemaphoreAttr_t myBinarySem01_attributes = {
        .name = "myBinarySem01"
};
osSemaphoreId_t recieve_semhandle;
const osSemaphoreAttr_t myBinarySem02_attributes = {
        .name = "myBinarySem02"
};
osSemaphoreId_t transmit_semhandle;
const osSemaphoreAttr_t myBinarySem03_attributes = {
        .name = "myBinarySem03"
};
osSemaphoreId_t callback_semhandle;
const osSemaphoreAttr_t myBinarySem04_attributes = {
        .name = "myBinarySem04"
};

osSemaphoreId_t csn_semhandle;

osThreadId_t myTask02Handle;
osThreadAttr_t attr = {
        .name = "task1",
        .stack_size = 128 * 4,
        .priority = (osPriority_t)osPriorityNormal,
};

osThreadId_t myTask01Handle;
osThreadAttr_t attr1 = {
        .name = "task2",
        .stack_size = 128 * 4,
        .priority = (osPriority_t)osPriorityLow,
};

osTimerId_t port0_tmr_handle;
const osTimerAttr_t myTimer01_attributes = {
        .name = "myTimer01"
};
osTimerId_t port1_tmr_handle;
const osTimerAttr_t myTimer02_attributes = {
        .name = "myTimer02"
};
osTimerId_t port2_tmr_handle;
const osTimerAttr_t myTimer03_attributes = {
        .name = "myTimer03"
};
osTimerId_t port3_tmr_handle;
const osTimerAttr_t myTimer04_attributes = {
        .name = "myTimer04"
};


extern s_max14830_hdle *inst_hdl;
uint8_t irq_id;
uint16_t ch0_sts=1;
uint16_t ch1_sts=1;
uint16_t ch2_sts=1;
uint16_t ch3_sts=1;

void max14830_intr_hdlr();

/* port0_cb function */
void port0_cb(void *argument)
{
    uint8_t buff[MAX1680_FIFO_LEN];
    uint8_t val;
    //DEBUG_CPRINT(("Port 0 timer CB\n\r"));
    max14830_read(inst_hdl,MAX14830_CH0,MAX14830_IRQSTS_REG,1,&val);
    max14830_read(inst_hdl,MAX14830_CH0,MAX14830_RHR_REG,MAX1680_FIFO_LEN,buff);
}

/* port1_cb function */
void port1_cb(void *argument)
{
    uint8_t val;
    uint8_t buff[MAX1680_FIFO_LEN];
    //DEBUG_CPRINT(("Port 1 timer CB\n\r"));
    max14830_read(inst_hdl,MAX14830_CH1,MAX14830_IRQSTS_REG,1,&val);
    max14830_read(inst_hdl,MAX14830_CH1,MAX14830_RHR_REG,MAX1680_FIFO_LEN,buff);
}

/* port2_cb function */
void port2_cb(void *argument)
{
    uint8_t val;
    uint8_t buff[MAX1680_FIFO_LEN];
    //DEBUG_CPRINT(("Port 2 timer CB\n\r"));
    max14830_read(inst_hdl,MAX14830_CH2,MAX14830_IRQSTS_REG,1,&val);
    max14830_read(inst_hdl,MAX14830_CH2,MAX14830_RHR_REG,MAX1680_FIFO_LEN,buff);
}

/* port3_cb function */
void port3_cb(void *argument)
{
    uint8_t val;
    uint8_t buff[MAX1680_FIFO_LEN];
    //DEBUG_CPRINT(("Port 3 timer CB\n\r"));
    max14830_read(inst_hdl,MAX14830_CH3,MAX14830_IRQSTS_REG,1,&val);
    max14830_read(inst_hdl,MAX14830_CH3,MAX14830_RHR_REG,MAX1680_FIFO_LEN,buff);
}

void recieve_task_func(void *argument)
{
    for(;;)
    {
        max14830_intr_hdlr();
    }
}

void rcv_callback_task_func()

{
    //os_itc_msg_handle_t max14830_pld;
    uint32_t max14830_queue_rcv = 0;
    while(1)
    {
        osMessageQueueGet(max14820_rcv_queue_hdl,&max14830_queue_rcv,NULL,osWaitForever);
        //  os_itc_msg_rcv(SPI_TO_UART_CALLBACK_TASK,&max14830_pld,os_wait_forever);
        switch(max14830_queue_rcv)
        {
        case MAX14830_CH0:
            if(inst_hdl->callback0_func != NULL)
            {
                inst_hdl->callback0_func();
            }
            break;
        case MAX14830_CH1:
            if(inst_hdl->callback1_func != NULL)
            {
                inst_hdl->callback1_func();
            }
            break;
        case MAX14830_CH2:
            if(inst_hdl->callback2_func != NULL)
            {
                inst_hdl->callback2_func();
            }
            break;
        case MAX14830_CH3:
            if(inst_hdl->callback3_func != NULL)
            {
                inst_hdl->callback3_func();
            }
            break;
        default:
            break;
        }
    }
}


uint8_t tx_data=(MAX14830_CH0 & 0x60) | (MAX14830_GLOBALIRQ_REG & 0x1F);
extern void* gpio_a;

void max14830_intr_hdlr()
{
    //os_queue_handle_ptr max14830_hdl;
    //os_itc_msg_handle_t max14830_pld;
    //uint32_t max14830_pld = 0;
    while(1)
    {
        osSemaphoreAcquire(intr_semhandle,MAX14830_WAIT_FOREVER);
        if(inst_hdl != NULL)
        {
#ifdef SPI_TO_UART_ENB
            inst_hdl->gpio_write(CSN_Pin, MAX14830_GPIO_RESET);
            inst_hdl->spi_read_write(inst_hdl->io_intf_hdle,&tx_data,&irq_id,1,100);
            inst_hdl->gpio_write(CSN_Pin, MAX14830_GPIO_SET);
#endif
            irq_id = (irq_id & 0x0f);
            if((irq_id & 0x01)==0)
            {
                max14830_rx_ch0_it();

            }
            if((irq_id & 0x02)==0)
            {
                max14830_rx_ch1_it();
            }
            if((irq_id & 0x04)==0)
            {
                max14830_rx_ch2_it();
            }
            if((irq_id & 0x08)==0)
            {
                max14830_rx_ch3_it();  //&data3[cntr]
            }
        }
    }
}



void max14830_start()
{
    intr_semhandle     = osSemaphoreNew(1U, 1U, &myBinarySem01_attributes);
    if (intr_semhandle == NULL)
    {
        printf("Semaphore creation failed!\n\n\r");
    }
    else
    {
        printf("Semaphore created successfully.\n\n\r");
    }
    recieve_semhandle  = osSemaphoreNew(1U, 1U, &myBinarySem01_attributes);
    if (recieve_semhandle == NULL)
    {
        printf("recieve Semaphore creation failed!\n\n\r");
    }
    else
    {
        printf("recieve Semaphore created successfully.\n\n\r");
    }
    transmit_semhandle = osSemaphoreNew(1U, 1U, &myBinarySem01_attributes);
    if (transmit_semhandle == NULL)
    {
        printf("transmit Semaphore creation failed!\n\n\r");
    }
    else
    {
        printf("transmit  Semaphore created successfully.\n\n\r");
    }
    osSemaphoreAcquire(intr_semhandle,100);

    callback_semhandle = osSemaphoreNew(1U, 1U,NULL);

    osMessageQueueNew(16, sizeof(uint32_t), &myQueue01_attributes);

    port0_tmr_handle = osTimerNew(port0_cb, 1, port0_cb, &myTimer01_attributes);
    port1_tmr_handle = osTimerNew(port1_cb, 1, port1_cb, &myTimer02_attributes);
    port2_tmr_handle = osTimerNew(port2_cb, 1, port2_cb, &myTimer03_attributes);
    port3_tmr_handle = osTimerNew(port3_cb, 1, port3_cb, &myTimer04_attributes);

#if 1
    //os_thread_create(SPI_TO_UART_TRANS_TASK,128*4, P_SPI_TO_UART_CONV_TX, "spi_to_uart_transmit_task_thrd",transmit_task_func , NULL, NULL, NULL);
    myTask01Handle = osThreadNew(recieve_task_func, NULL, &attr);
    myTask02Handle = osThreadNew(rcv_callback_task_func, NULL, &attr1);
#endif
}

#endif

#endif
