1 /** mbed Microcontroller Library
2   ******************************************************************************
3   * @file    spdio_api.h
4   * @author
5   * @version V1.0.0
6   * @brief   This file provides following mbed SPDIO API
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2015, Realtek Semiconductor Corp.
11   * All rights reserved.
12   *
13   * This module is a confidential and proprietary property of RealTek and
14   * possession or use of this module requires written permission of RealTek.
15   ******************************************************************************
16   */
17 #ifndef __SPDIO_API_H__
18 #define __SPDIO_API_H__
19 
20 #include <osdep_service.h>
21 
22 /** @addtogroup spdio_api SPDIO
23  *  @ingroup    hal
24  *  @brief      spdio functions
25  *  @{
26  */
27 
28 ///@name Ameba Common
29 ///@{
30 
31 #define SPDIO_API_DBG
32 
33 #ifdef SPDIO_API_DBG
34 #define SPDIO_API_PRINTK(fmt, args...)		printf(fmt"\r\n",## args)
35 #define _SPDIO_API_PRINTK(fmt, args...)		printf(fmt,## args)
36 #else
37 #define SPDIO_API_PRINTK(fmt, args...)
38 #define _SPDIO_API_PRINTK(fmt, args...)
39 #endif
40 
41 #define SPDIO_DMA_ALIGN_4			4
42 #define SPDIO_RX_BUFSZ_ALIGN(x)	((((x-1)>>6)+1)<<6) //alignement to 64
43 
44 #define SPDIO_RXDESC_SZ	24
45 
46 /*Don't modify this enum table*/
47 enum spdio_rx_data_t{
48 	SPDIO_RX_DATA_NULL = 0x00,
49 	SPDIO_RX_DATA_ETH = 0x83, //an ethernet packet received
50 	SPDIO_RX_DATA_ATCMD = 0x11, //an AT command packet received
51 	SPDIO_RX_DATA_USER = 0x41, //defined by user
52 };
53 
54 enum spdio_tx_data_t{
55 	SPDIO_TX_DATA_NULL = 0x00,
56 	SPDIO_TX_DATA_ETH = 0x82, //an ethernet packet sent
57 	SPDIO_TX_DATA_ATCMDRSP = 0x10, //an AT command response packet sent
58 	SPDIO_TX_DATA_USER = 0x40, // defined by user
59 };
60 
61 struct spdio_buf_t{
62 	void *priv; //priv data from user
63 	u32 buf_allocated; //The spdio buffer allocated address
64 	u16 size_allocated; //The actual allocated size
65 	u32 buf_addr; //The spdio buffer physical address, it must be 4-bytes aligned
66 	u16 buf_size;
67 	u8 type; //The type of the data which this buffer carries, spdio_rx_data_t and spdio_tx_data_t
68 	u8 reserved;
69 };
70 
71 struct spdio_t {
72 	void *priv; //not used by user
73 	u32 tx_bd_num; //for spdio send data to host, 2 bd for one packet, so this value must be rounded to 2
74 	u32 rx_bd_num; //for spdio receive data from host
75 	u32 rx_bd_bufsz; //buffer size = desired packet length + 24(spdio header info), must be rounded to 64
76 	struct spdio_buf_t *rx_buf; //buffer array for spdio receive assigned by user, rx_bd_bufsz * rx_bd_num
77 
78 	/**
79 	 *@brief pointer to callback function defined by user,
80 	 		called by spdio when one packet receive done
81 	 *@param priv: a pointer to spdio_t structure which is used to initilize spdio interface
82 	 *@param pbuf: a pointer to spdio_buf_t structure which is spdio receive buffer
83 	 *@param pdata: the actual received packet payload
84 	 *@param size: the actual payload length
85 	 *@param type: the received packet type, spdio_rx_data_t
86 	 *@retval SUCCESS or FAIL
87 	 */
88 	char (*rx_done_cb)(void *priv, void* pbuf, u8 *pdata, u16 size, u8 type);
89 
90 	/**
91 	 *@brief pointer to callback function defined by user,
92 	 		called by spdio when one packet sent done
93 	 *@param priv: a pointer to spdio_t structure which is used to initilize spdio interface
94 	 *@param pbuf: a pointer to spdio_buf_t structure which carries the transmit packet
95 	 *@retval SUCCESS or FAIL
96 	 */
97 	char (*tx_done_cb)(void *priv, void* pbuf);
98 };
99 
100 /**
101   * @brief  Gets example setting for spdio obj.
102   * @param  obj: a pointer to an spdio_t structure which will be initialized with an example settings
103   * @retval None
104   */
105 void spdio_structinit(struct spdio_t *obj);
106 
107 /**
108   * @brief  Initialize spdio interface.
109   * @param  obj, a pointer to a spdio_t structure which should be initialized by user,
110   *		and which will be used to initialize spdio interface
111   *		obj->tx_bd_num: spdio write bd number, needs 2 bd for one transaction
112   *		obj->rx_bd_num: spdio read bd number
113   *		obj->rx_bd_bufsz: spdio read buffer size
114   *		obj->rx_buf: spdio read buffer array
115   * @retval None
116   */
117 void spdio_init(struct spdio_t *obj);
118 
119 /**
120   * @brief  Deinitialize spdio interface.
121   * @param  obj: a pointer to spdio_t structure which is already initialized
122   * @retval None
123   */
124 void spdio_deinit(struct spdio_t *obj);
125 
126 /**
127   * @brief  spdio write function.
128   * @param  obj: a pointer to spdio_t structure which is already initialized
129   * @param  pbuf: a pointer to spdio_buf_t structure which carries the payload
130   * @retval SUCCESS or FAIL
131   */
132 s8 spdio_tx(struct spdio_t *obj, struct spdio_buf_t *pbuf);
133 
134 /**
135   * @brief  an obj which will be used to initialize sdio interface
136   *		so it must be initialized before calling HalSdioInit();
137   */
138 extern struct spdio_t *g_spdio_priv;
139 
140 ///@}
141 
142 /*\@}*/
143 
144 #endif //#ifndef __SPDIO_API_H__