27 #include "in_compile.h" 33 #define I2S_CH0_BASE_OFS (0x20) 34 #define I2S_CH1_BASE_OFS (0x60) 36 #define MI2S_CH0_BASE (I2S_MASTER_BASE + I2S_CH0_BASE_OFS) 37 #define MI2S_CH1_BASE (I2S_MASTER_BASE + I2S_CH1_BASE_OFS) 39 #define SI2S_CH0_BASE (I2S_SLAVE_BASE + I2S_CH0_BASE_OFS) 40 #define SI2S_CH1_BASE (I2S_SLAVE_BASE + I2S_CH1_BASE_OFS) 42 #define I2S_REG_IER_OFS 0x00000000UL 43 #define I2S_REG_IRER_OFS 0x00000004UL 44 #define I2S_REG_ITER_OFS 0x00000008UL 45 #define I2S_REG_CER_OFS 0x0000000CUL 46 #define I2S_REG_CCR_OFS 0x00000010UL 47 #define I2S_REG_RXFFR_OFS 0x00000014UL 48 #define I2S_REG_TXFFR_OFS 0x00000018UL 49 #define I2S_REG_LRBR_OFS 0x00000000UL 50 #define I2S_REG_LTHR_OFS 0x00000000UL 51 #define I2S_REG_RRBR_OFS 0x00000004UL 52 #define I2S_REG_RTHR_OFS 0x00000004UL 53 #define I2S_REG_RER_OFS 0x00000008UL 54 #define I2S_REG_TER_OFS 0x0000000CUL 55 #define I2S_REG_RCR_OFS 0x00000010UL 56 #define I2S_REG_TCR_OFS 0x00000014UL 57 #define I2S_REG_ISR_OFS 0x00000018UL 58 #define I2S_REG_IMR_OFS 0x0000001CUL 59 #define I2S_REG_ROR_OFS 0x00000020UL 60 #define I2S_REG_TOR_OFS 0x00000024UL 61 #define I2S_REG_RFCR_OFS 0x00000028UL 62 #define I2S_REG_TFCR_OFS 0x0000002CUL 63 #define I2S_REG_RFF_OFS 0x00000030UL 64 #define I2S_REG_TFF_OFS 0x00000034UL 65 #define I2S_REG_RXDMA_OFS 0x000001C0UL 66 #define I2S_REG_RRXDMA_OFS 0x000001C4UL 67 #define I2S_REG_TXDMA_OFS 0x000001C8UL 68 #define I2S_REG_RTXDMA_OFS 0x000001CCUL 176 static INLINE
void i2s_enable(uint32_t base)
178 WR_WORD((base + I2S_REG_IER_OFS), 1);
181 static INLINE
void i2s_disable(uint32_t base)
183 WR_WORD((base + I2S_REG_IER_OFS), 0);
186 static INLINE
void i2s_rx_enable(uint32_t base)
188 WR_WORD((base + I2S_REG_IRER_OFS), 1);
191 static INLINE
void i2s_rx_disable(uint32_t base)
193 WR_WORD((base + I2S_REG_IRER_OFS), 0);
196 static INLINE
void i2s_tx_enable(uint32_t base)
198 WR_WORD((base + I2S_REG_ITER_OFS), 1);
201 static INLINE
void i2s_tx_disable(uint32_t base)
203 WR_WORD((base + I2S_REG_ITER_OFS), 0);
206 static INLINE
void i2s_sclk_enable(uint32_t base)
208 WR_WORD((base + I2S_REG_CER_OFS), 1);
211 static INLINE
void i2s_sclk_disable(uint32_t base)
213 WR_WORD((base + I2S_REG_CER_OFS), 0);
216 #define I2S_CCR_SCLKG 0x00000007UL 217 #define I2S_CCR_WSS 0x00000018UL 219 #define I2S_CCR_SCLKG_NG 0 220 #define I2S_CCR_SCLKG_12 1 221 #define I2S_CCR_SCLKG_16 2 222 #define I2S_CCR_SCLKG_20 3 223 #define I2S_CCR_SCLKG_24 4 226 #define I2S_CCR_WSS_16 0 227 #define I2S_CCR_WSS_24 1 228 #define I2S_CCR_WSS_32 2 229 static INLINE
void i2s_sclk_wss(uint32_t base,
int wss)
231 uint32_t reg = RD_WORD(base + I2S_REG_CCR_OFS);
234 reg |= ((wss & 0x3) << 3);
236 WR_WORD((base + I2S_REG_CCR_OFS), reg);
239 static INLINE
void i2s_sclk_gate(uint32_t base,
int gated_clk)
241 uint32_t reg = RD_WORD(base + I2S_REG_CCR_OFS);
243 reg &= ~I2S_CCR_SCLKG;
244 reg |= (gated_clk & 0x7);
246 WR_WORD((base + I2S_REG_CCR_OFS), reg);
249 static INLINE
void i2s_rx_fifo_reset(uint32_t base)
251 WR_WORD((base + I2S_REG_RXFFR_OFS), 1);
254 static INLINE
void i2s_tx_fifo_reset(uint32_t base)
256 WR_WORD((base + I2S_REG_TXFFR_OFS), 1);
259 static INLINE uint32_t i2s_chx_lrx_data(uint32_t ch_base)
261 return RD_WORD(ch_base + I2S_REG_LRBR_OFS);
264 static INLINE
void i2s_chx_ltx_data(uint32_t ch_base, uint32_t data)
266 WR_WORD((ch_base + I2S_REG_LTHR_OFS), data);
269 static INLINE uint32_t i2s_chx_rrx_data(uint32_t ch_base)
271 return RD_WORD(ch_base + I2S_REG_RRBR_OFS);
274 static INLINE
void i2s_chx_rtx_data(uint32_t ch_base, uint32_t data)
276 WR_WORD((ch_base + I2S_REG_RTHR_OFS), data);
279 static INLINE
void i2s_chx_rx_enable(uint32_t ch_base)
281 WR_WORD((ch_base + I2S_REG_RER_OFS), 1);
284 static INLINE
void i2s_chx_rx_disable(uint32_t ch_base)
286 WR_WORD((ch_base + I2S_REG_RER_OFS), 0);
289 static INLINE
void i2s_chx_tx_enable(uint32_t ch_base)
291 WR_WORD((ch_base + I2S_REG_TER_OFS), 1);
294 static INLINE
void i2s_chx_tx_disable(uint32_t ch_base)
296 WR_WORD((ch_base + I2S_REG_TER_OFS), 0);
299 #define I2S_CHx_RCR_WLEN 0x00000007UL 301 #define I2S_CHx_WLEN_0 0 302 #define I2S_CHx_WLEN_12 1 303 #define I2S_CHx_WLEN_16 2 304 #define I2S_CHx_WLEN_20 3 305 #define I2S_CHx_WLEN_24 4 306 #define I2S_CHx_WLEN_32 5 308 static INLINE
void i2s_chx_rx_wlen(uint32_t ch_base,
int word_len)
310 WR_WORD((ch_base + I2S_REG_RCR_OFS), (word_len & 0x7));
313 #define I2S_CHx_TCR_WLEN 0x00000007UL 315 static INLINE
void i2s_chx_tx_wlen(uint32_t ch_base,
int word_len)
317 WR_WORD((ch_base + I2S_REG_TCR_OFS), (word_len & 0x7));
320 #define I2S_CHx_IT_RXDA 0x00000001UL 321 #define I2S_CHx_IT_RXFO 0x00000002UL 322 #define I2S_CHx_IT_TXFE 0x00000010UL 323 #define I2S_CHx_IT_TXFO 0x00000020UL 324 #define I2S_CHx_IT_ALL 0x00000033UL 326 static INLINE uint32_t i2s_chx_intr_status(uint32_t ch_base)
328 return (RD_WORD(ch_base + I2S_REG_ISR_OFS));
331 static INLINE
void i2s_chx_intr_mask(uint32_t ch_base, uint32_t mask)
333 uint32_t reg = RD_WORD(ch_base + I2S_REG_IMR_OFS);
335 WR_WORD((ch_base + I2S_REG_IMR_OFS), reg);
338 static INLINE
void i2s_chx_intr_unmask(uint32_t ch_base, uint32_t mask)
340 uint32_t reg = RD_WORD(ch_base + I2S_REG_IMR_OFS);
342 WR_WORD((ch_base + I2S_REG_IMR_OFS), reg);
345 static INLINE
void i2s_chx_rov_clr(uint32_t ch_base)
347 RD_WORD(ch_base + I2S_REG_ROR_OFS);
350 static INLINE
void i2s_chx_tov_clr(uint32_t ch_base)
352 RD_WORD(ch_base + I2S_REG_TOR_OFS);
355 #define I2S_CHx_RFCR_RXCHDT 0x0000000FUL 356 static INLINE
void i2s_chx_rfifo_tl(uint32_t ch_base, uint32_t tl)
358 WR_WORD((ch_base + I2S_REG_RFCR_OFS), (tl & 0xF));
361 #define I2S_CHx_TFCR_TXCHDT 0x0000000FUL 362 static INLINE
void i2s_chx_tfifo_tl(uint32_t ch_base, uint32_t tl)
364 WR_WORD((ch_base + I2S_REG_TFCR_OFS), (tl & 0xF));
367 static INLINE
void i2s_chx_rfifo_flush(uint32_t ch_base)
369 WR_WORD((ch_base + I2S_REG_RFF_OFS), 1);
372 static INLINE
void i2s_chx_tfifo_flush(uint32_t ch_base)
374 WR_WORD((ch_base + I2S_REG_TFF_OFS), 1);
377 static INLINE
void i2s_sd_oe(
int id,
int ch_id,
int oe)
379 uint32_t reg = RD_WORD(GLOBAL_REG_I2S_OEN_CTRL);
383 reg &= ~GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_MASTER_PIN0_OEN;
385 reg |= GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_MASTER_PIN0_OEN;
389 reg &= ~GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_MASTER_PIN1_OEN;
391 reg |= GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_MASTER_PIN1_OEN;
397 reg &= ~GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_SLAVE_SD_OEN;
399 reg |= GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_SLAVE_SD_OEN;
403 reg &= ~GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_SLAVE_SD_BKUP_OEN;
405 reg |= GLOBAL_REG_I2S_OEN_CTRL_CTL_I2S_SLAVE_SD_BKUP_OEN;
409 WR_WORD(GLOBAL_REG_I2S_OEN_CTRL, reg);
412 static INLINE
void i2s_txdma_start(uint32_t base)
414 WR_WORD((base + I2S_REG_TXDMA_OFS), 0);
491 int hal_i2s_ch_en(
void *hdl,
int ch_id,
int dir,
int ch_word_sz,
void *buffer0,
void *buffer1, uint16_t buffer_len,
void *arg,
void (*callback)(
void * arg,
int id,
int status) );
Don't care.
Definition: hal_i2s.h:140
i2s_error
I2S driver return code.
Definition: hal_i2s.h:154
Sample rate at 32Khz.
Definition: hal_i2s.h:102
Error. DMA tranfer.
Definition: hal_i2s.h:168
I2S Slave Core.
Definition: hal_i2s.h:80
Stereo data.
Definition: hal_i2s.h:116
i2s_type
I2S data type.
Definition: hal_i2s.h:112
Sample rate at 44.1Khz.
Definition: hal_i2s.h:106
Error. Invalid state.
Definition: hal_i2s.h:160
Channel word size is 32 bits.
Definition: hal_i2s.h:150
Transmit.
Definition: hal_i2s.h:132
int hal_i2s_close(void *hdl)
Close I2S driver.
Channel word size is 24 bits.
Definition: hal_i2s.h:148
Error. I2S channel TX overflow.
Definition: hal_i2s.h:164
Channel word size is 20 bits.
Definition: hal_i2s.h:146
Max sample word size is 16 bits.
Definition: hal_i2s.h:86
i2s_ch_dir
Each I2S channel can be either TX or RX.
Definition: hal_i2s.h:130
Max sample word size is 32 bits.
Definition: hal_i2s.h:90
I2S Channel 1.
Definition: hal_i2s.h:122
Error. Invalid param.
Definition: hal_i2s.h:158
int hal_i2s_ch_en(void *hdl, int ch_id, int dir, int ch_word_sz, void *buffer0, void *buffer1, uint16_t buffer_len, void *arg, void(*callback)(void *arg, int id, int status))
Enable I2S channel.
Error. DMA is not available.
Definition: hal_i2s.h:166
int hal_i2s_ch_dis(void *hdl, int ch_id, int dir)
Disable I2S channel.
void * hal_i2s_open(int id, int sr, int word_sz)
Initialize I2S driver.
Sample rate at 36Khz.
Definition: hal_i2s.h:104
i2s_sr
I2S sample rate.
Definition: hal_i2s.h:94
i2s_ch_word_sz
Each I2S channel word size.
Definition: hal_i2s.h:138
Sample rate at 8Khz.
Definition: hal_i2s.h:96
i2s_id
I2S Core ID.
Definition: hal_i2s.h:76
Channel word size is 16 bits.
Definition: hal_i2s.h:144
Error. I2S channel RX overflow.
Definition: hal_i2s.h:162
Receive.
Definition: hal_i2s.h:134
Sample rate at 24Khz.
Definition: hal_i2s.h:100
I2S Master Core.
Definition: hal_i2s.h:78
Mono data.
Definition: hal_i2s.h:114
Sample rate at 16Khz.
Definition: hal_i2s.h:98
Sample rate at 48Khz.
Definition: hal_i2s.h:108
I2S max channel.
Definition: hal_i2s.h:126
Max sample word size is 24 bits.
Definition: hal_i2s.h:88
i2s_word_size
I2S Core max word size.
Definition: hal_i2s.h:84
I2S Channel 2.
Definition: hal_i2s.h:124
Channel word size is 12 bits.
Definition: hal_i2s.h:142
No error. Good.
Definition: hal_i2s.h:156
i2s_ch_id
Each I2S Core can have 2 Channel.
Definition: hal_i2s.h:120