/**
 * \file    msq.h
 * \brief   SAL message queue
 *
 * \par     Copyright (c) 2018 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  James
 * \date    2018-03-14
 * \version 
 * 
 * \history 
 *  Date        Note
 *  2018-03-14  Original Creation
 * 
 */
 
#ifndef __MSQ_H_
#define __MSQ_H_

#include "arch.h"

#if SAL_MSQ_ENABLED

#include "types.h"

#pragma pack(1)

#define SAL_MSQ_SIZE	32

typedef struct msq_s
{
    u32_t type:5,
          bitmap:3,
          val1:8,
          val2:8,
          val3:8;
} msq_t;

enum
{
    SAL_MSQ_NULL,					///< NULL message
    SAL_MSQ_UART,					///< uart received message
    SAL_MSQ_UART1,					///< uart1 received message
    SAL_MSQ_I2C_SLA,				///< I2C slave rx message
    SAL_MSQ_I2C1_SLA,				///< I2C slave rx message
    SAL_MSQ_SPI_SLA,				///< SPI slave rx message
    SAL_MSQ_EX_ISR,					///< External interrupt message
    SAL_MSQ_TEST = 0x0F,			///< specific for test message
    SAL_MSQ_MAX,
};

#pragma pack()


#define SAL_MSQ_TYPE(msgptr)            (((msq_t *)(msgptr))->type)
#define SAL_MSQ_VALUE1_VALID(msgptr)    ((((msq_t *)(msgptr))->bitmap) & 0x1)
#define SAL_MSQ_VALUE2_VALID(msgptr)    ((((msq_t *)(msgptr))->bitmap) & 0x2)
#define SAL_MSQ_VALUE3_VALID(msgptr)    ((((msq_t *)(msgptr))->bitmap) & 0x4)
#define SAL_MSQ_VALUE1(msgptr)          (((msq_t *)(msgptr))->val1)
#define SAL_MSQ_VALUE2(msgptr)          (((msq_t *)(msgptr))->val2)
#define SAL_MSQ_VALUE3(msgptr)          (((msq_t *)(msgptr))->val3)


/** \brief Message queue initialization
 *
 */
void msq_init(void);

/** \brief Push message queue data 
 *
 * \param msg       Message queue data 
 */
void msq_push(msq_t msg);

/** \brief Push message data to queue
 *
 * \param msq_type  The message queue type to be pushed
 * \param val       The value to be pushed
 * \param va2       The value to be pushed
 */
void msq_push_msg(u32_t msq_type, u32_t bitmap, u32_t val1, u32_t val2, u32_t val3);

/** \brief Pop message queue data 
 *
 * \param p_msg     Message queue data 
 */
void msq_pop(msq_t *p_msg);
#endif /* SAL_MSQ_ENABLED */

#endif /* #ifndef __MSQ_H_ */

