/*******************************************************************************
 * DISCLAIMER
 * This software is supplied by Renesas Electronics Corporation and is only
 * intended for use with Renesas products. No other uses are authorized. This
 * software is owned by Renesas Electronics Corporation and is protected under
 * all applicable laws, including copyright laws.
 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * Renesas reserves the right, without notice, to make changes to this software
 * and to discontinue the availability of this software. By using this software,
 * you agree to the additional terms and conditions found by accessing the
 * following link:
 * http://www.renesas.com/disclaimer*
 * Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
 *******************************************************************************/
/**************************************************************************//**
* @file         dec.h
* @brief        decoder thread header
******************************************************************************/
#ifndef DECODER_H
#define DECODER_H

/******************************************************************************
Includes   <System Includes> , "Project Includes"
******************************************************************************/
#include "main_thread.h"
/******************************************************************************
Typedef definitions
******************************************************************************/
typedef struct {
    uint32_t msg_id;
    uint32_t param1;
    uint32_t param2;
    uint32_t param3;
}msg_dec_t;

/******************************************************************************
Macro definitions
******************************************************************************/
/* message identifier */
enum{
    DEC_MSG_OPEN                /* 0 */
   ,DEC_MSG_PLAY                /* 1 */
   ,DEC_MSG_PAUSE               /* 2 */
   ,DEC_MSG_STOP                /* 3 */
   ,DEC_MSG_END                 /* 4 */
   ,DEC_MSG_REQ_DEC             /* 5 */
   ,DEC_MSG_ERR_STRM            /* 6 */
   ,DEC_MSG_TIMEOUT             /* 7 */
   ,DEC_MSG_DUMMY               /* 8 */
};

/* mode identifier */
enum{
    DEC_MODE_IDLE               /* 0 */
   ,DEC_MODE_OPEN               /* 1 */
   ,DEC_MODE_PLAY               /* 2 */
   ,DEC_MODE_PAUSE              /* 3 */
   ,DEC_MODE_STOP               /* 4 */
   ,DEC_MODE_END_WAIT           /* 5 */
   ,DEC_MODE_DUMMY              /* 6 */
};

/* response message identifier */
#define DEC_RES_ERR             MAIN_EVENT_ERR
#define DEC_RES_OPEN            MAIN_EVENT_OPEN
#define DEC_RES_PLAY            MAIN_EVENT_PLAY
#define DEC_RES_PAUSE           MAIN_EVENT_PAUSE
#define DEC_RES_STOP            MAIN_EVENT_STOP
#define DEC_EVENT_END           MAIN_EVENT_END
#define DEC_RES_END             MAIN_EVENT_END
#define DEC_RES_MAX             MAIN_EVENT_MAX
#define DEC_RES_NON             MAIN_EVENT_NONE

/* error identifier */
#define DEC_OK                  ((int32_t)  1L)     /* decode no error */
#define DEC_ERR                 ((int32_t)  0L)     /* decode error */
#define DEC_ERR_STATE           ((int32_t) -1L)     /* decode error */
#define DEC_ERR_OPEN            ((int32_t) -2L)     /* file open error */
#define DEC_ERR_RATE            ((int32_t) -3L)     /* non supported sampling rate */
#define DEC_ERR_INFO            ((int32_t) -4L)     /* File Header information error */
#define DEC_ERR_FILE_END        ((int32_t) -5L)     /* decoder file end */
#define DEC_ERR_SEEK_START      ((int32_t) -6L)     /* Seek start triger */
#define DEC_ERR_NO_BYTE         ((int32_t) -7L)     /* decode result byte is 0 */

/* buffer no */
#define DEC_BUFF_NO_1           (1UL)
#define DEC_BUFF_NO_2           (2UL)

/* stream format */
#define DEC_CHANNEL_MONO        (1UL)
#define DEC_CHANNEL_STEREO      (2UL)
#define DEC_16BIT_PER_SAMPLE    (16UL)
#define DEC_32BIT_PER_SAMPLE    (32UL)
#define DEC_1BYTE_PER_SAMPLE    (1UL)
#define DEC_2BYTE_PER_SAMPLE    (2UL)
#define DEC_3BYTE_PER_SAMPLE    (3UL)
#define DEC_4BYTE_PER_SAMPLE    (4UL)

/******************************************************************************
Imported global variables and functions (from other files)
******************************************************************************/
extern void DEC_CreateThread (void);
extern void DEC_TerminateThread (void);
extern int32_t DEC_Open (int32_t drive, uint32_t device_address, FIL * file_pointer);
extern int32_t DEC_Play (int32_t drive, uint32_t device_address, FIL * file_pointer);
extern int32_t DEC_Pause (int32_t drive, uint32_t device_address, FIL * file_pointer);
extern int32_t DEC_Stop (int32_t drive, uint32_t device_address, FIL * file_pointer);
extern int32_t DEC_ReqDec (uint32_t buff_no);
extern int32_t DEC_End (void);
extern int32_t DEC_ErrStrm (void);
extern uint32_t * DEC_GetInputBuffAddr(uint32_t buff_no);
extern uint32_t DEC_GetInputBuffSize (void);

/******************************************************************************
Private global variables and functions
******************************************************************************/

#endif	/* DECODER_H */
/* End of File */
