パラメータを適応変化させる事により圧縮率を向上させた動的ライス・ゴロム符号を利用した可逆圧縮方式。圧縮ソフト、圧縮率のMATLABシミュレーションは詳細はInterface誌2011年8月号に掲載されるRX62Nマイコン連動特集にて掲載予定。

Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Wed Mar 30 06:05:24 2011 +0000
Revision:
0:d920d64db582
alpha

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lynxeyed_atsu 0:d920d64db582 1 /***********************************************************************//**
lynxeyed_atsu 0:d920d64db582 2 * @file i2s_irq_test.c
lynxeyed_atsu 0:d920d64db582 3 * @purpose This example describes how to use I2S transfer in interrupt
lynxeyed_atsu 0:d920d64db582 4 * mode
lynxeyed_atsu 0:d920d64db582 5 * @version 2.0
lynxeyed_atsu 0:d920d64db582 6 * @date 21. May. 2010
lynxeyed_atsu 0:d920d64db582 7 * @author NXP MCU SW Application Team
lynxeyed_atsu 0:d920d64db582 8 *---------------------------------------------------------------------
lynxeyed_atsu 0:d920d64db582 9 * Software that is described herein is for illustrative purposes only
lynxeyed_atsu 0:d920d64db582 10 * which provides customers with programming information regarding the
lynxeyed_atsu 0:d920d64db582 11 * products. This software is supplied "AS IS" without any warranties.
lynxeyed_atsu 0:d920d64db582 12 * NXP Semiconductors assumes no responsibility or liability for the
lynxeyed_atsu 0:d920d64db582 13 * use of the software, conveys no license or title under any patent,
lynxeyed_atsu 0:d920d64db582 14 * copyright, or mask work right to the product. NXP Semiconductors
lynxeyed_atsu 0:d920d64db582 15 * reserves the right to make changes in the software without
lynxeyed_atsu 0:d920d64db582 16 * notification. NXP Semiconductors also make no representation or
lynxeyed_atsu 0:d920d64db582 17 * warranty that such application will be suitable for the specified
lynxeyed_atsu 0:d920d64db582 18 * use without further testing or modification.
lynxeyed_atsu 0:d920d64db582 19 **********************************************************************/
lynxeyed_atsu 0:d920d64db582 20 #include "lpc17xx_i2s.h"
lynxeyed_atsu 0:d920d64db582 21 #include "lpc17xx_libcfg.h"
lynxeyed_atsu 0:d920d64db582 22 #include "lpc17xx_pinsel.h"
lynxeyed_atsu 0:d920d64db582 23 //#include "lpc17xx_gpdma.h"
lynxeyed_atsu 0:d920d64db582 24 //#include "debug_frmwrk.h"
lynxeyed_atsu 0:d920d64db582 25 #include "lpc17xx_clkpwr.h"
lynxeyed_atsu 0:d920d64db582 26 #include "i2s_irq_test.h"
lynxeyed_atsu 0:d920d64db582 27 #include "mbed.h"
lynxeyed_atsu 0:d920d64db582 28
lynxeyed_atsu 0:d920d64db582 29
lynxeyed_atsu 0:d920d64db582 30
lynxeyed_atsu 0:d920d64db582 31 /* Example group ----------------------------------------------------------- */
lynxeyed_atsu 0:d920d64db582 32 /** @defgroup I2S_IRQ I2S_IRQ
lynxeyed_atsu 0:d920d64db582 33 * @ingroup I2S_Examples
lynxeyed_atsu 0:d920d64db582 34 * @{
lynxeyed_atsu 0:d920d64db582 35 */
lynxeyed_atsu 0:d920d64db582 36
lynxeyed_atsu 0:d920d64db582 37
lynxeyed_atsu 0:d920d64db582 38 /************************** PRIVATE VARIABLES ***********************/
lynxeyed_atsu 0:d920d64db582 39
lynxeyed_atsu 0:d920d64db582 40 volatile uint8_t I2STXDone = 0;
lynxeyed_atsu 0:d920d64db582 41 volatile uint8_t I2SRXDone = 0;
lynxeyed_atsu 0:d920d64db582 42
lynxeyed_atsu 0:d920d64db582 43 volatile uint32_t *I2STXBuffer = (uint32_t*)(I2S_BUFFER_SRC);
lynxeyed_atsu 0:d920d64db582 44 volatile uint32_t *I2SRXBuffer = (uint32_t *)(I2S_BUFFER_DST);
lynxeyed_atsu 0:d920d64db582 45
lynxeyed_atsu 0:d920d64db582 46 volatile uint32_t I2SReadLength = 0;
lynxeyed_atsu 0:d920d64db582 47 volatile uint32_t I2SWriteLength = 0;
lynxeyed_atsu 0:d920d64db582 48
lynxeyed_atsu 0:d920d64db582 49 uint8_t tx_depth_irq = 0;
lynxeyed_atsu 0:d920d64db582 50 uint8_t rx_depth_irq = 0;
lynxeyed_atsu 0:d920d64db582 51 uint8_t dummy=0;
lynxeyed_atsu 0:d920d64db582 52
lynxeyed_atsu 0:d920d64db582 53
lynxeyed_atsu 0:d920d64db582 54 /************************** PRIVATE FUNCTIONS *************************/
lynxeyed_atsu 0:d920d64db582 55 void I2S_IRQHandler(void);
lynxeyed_atsu 0:d920d64db582 56 void Buffer_Init(void);
lynxeyed_atsu 0:d920d64db582 57 Bool Buffer_Verify(void);
lynxeyed_atsu 0:d920d64db582 58 void print_menu(void);
lynxeyed_atsu 0:d920d64db582 59
lynxeyed_atsu 0:d920d64db582 60 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
lynxeyed_atsu 0:d920d64db582 61 /*********************************************************************//**
lynxeyed_atsu 0:d920d64db582 62 * @brief I2S IRQ Handler
lynxeyed_atsu 0:d920d64db582 63 * @param[in] None
lynxeyed_atsu 0:d920d64db582 64 * @return None
lynxeyed_atsu 0:d920d64db582 65 **********************************************************************/
lynxeyed_atsu 0:d920d64db582 66 /*void I2S_IRQHandler()
lynxeyed_atsu 0:d920d64db582 67 {
lynxeyed_atsu 0:d920d64db582 68 uint32_t RXLevel = 0;
lynxeyed_atsu 0:d920d64db582 69
lynxeyed_atsu 0:d920d64db582 70 //Check RX interrupt
lynxeyed_atsu 0:d920d64db582 71 if(I2S_GetIRQStatus(LPC_I2S, I2S_RX_MODE))
lynxeyed_atsu 0:d920d64db582 72 {
lynxeyed_atsu 0:d920d64db582 73 RXLevel = I2S_GetLevel(LPC_I2S, I2S_RX_MODE);
lynxeyed_atsu 0:d920d64db582 74 if ( (RXLevel != RXFIFO_EMPTY) && !I2SRXDone )
lynxeyed_atsu 0:d920d64db582 75 {
lynxeyed_atsu 0:d920d64db582 76 while ( RXLevel > 0 )
lynxeyed_atsu 0:d920d64db582 77 {
lynxeyed_atsu 0:d920d64db582 78 if ( I2SReadLength == BUFFER_SIZE )
lynxeyed_atsu 0:d920d64db582 79 {
lynxeyed_atsu 0:d920d64db582 80 //Stop RX
lynxeyed_atsu 0:d920d64db582 81 I2S_Stop(LPC_I2S, I2S_RX_MODE);
lynxeyed_atsu 0:d920d64db582 82 // Disable RX
lynxeyed_atsu 0:d920d64db582 83 I2S_IRQCmd(LPC_I2S, I2S_RX_MODE, DISABLE);
lynxeyed_atsu 0:d920d64db582 84 I2SRXDone = 1;
lynxeyed_atsu 0:d920d64db582 85 break;
lynxeyed_atsu 0:d920d64db582 86 }
lynxeyed_atsu 0:d920d64db582 87 else
lynxeyed_atsu 0:d920d64db582 88 {
lynxeyed_atsu 0:d920d64db582 89 I2SRXBuffer[I2SReadLength++] = LPC_I2S->I2SRXFIFO;
lynxeyed_atsu 0:d920d64db582 90 }
lynxeyed_atsu 0:d920d64db582 91 RXLevel--;
lynxeyed_atsu 0:d920d64db582 92 }
lynxeyed_atsu 0:d920d64db582 93 }
lynxeyed_atsu 0:d920d64db582 94 }
lynxeyed_atsu 0:d920d64db582 95 return;
lynxeyed_atsu 0:d920d64db582 96 }
lynxeyed_atsu 0:d920d64db582 97 */
lynxeyed_atsu 0:d920d64db582 98 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
lynxeyed_atsu 0:d920d64db582 99 /*********************************************************************//**
lynxeyed_atsu 0:d920d64db582 100 * @brief Initialize buffer
lynxeyed_atsu 0:d920d64db582 101 * @param[in] None
lynxeyed_atsu 0:d920d64db582 102 * @return None
lynxeyed_atsu 0:d920d64db582 103 **********************************************************************/
lynxeyed_atsu 0:d920d64db582 104 void Buffer_Init(void) {
lynxeyed_atsu 0:d920d64db582 105 uint32_t i;
lynxeyed_atsu 0:d920d64db582 106 for ( i = 0; i < BUFFER_SIZE; i++ ) /* clear buffer */
lynxeyed_atsu 0:d920d64db582 107 {
lynxeyed_atsu 0:d920d64db582 108 I2STXBuffer[i] = i |(i << 16);
lynxeyed_atsu 0:d920d64db582 109 I2SRXBuffer[i] = 0;
lynxeyed_atsu 0:d920d64db582 110 }
lynxeyed_atsu 0:d920d64db582 111
lynxeyed_atsu 0:d920d64db582 112 }
lynxeyed_atsu 0:d920d64db582 113
lynxeyed_atsu 0:d920d64db582 114 /*********************************************************************//**
lynxeyed_atsu 0:d920d64db582 115 * @brief Verify buffer
lynxeyed_atsu 0:d920d64db582 116 * @param[in] none
lynxeyed_atsu 0:d920d64db582 117 * @return TRUE - if two buffers are similar
lynxeyed_atsu 0:d920d64db582 118 * FALSE - if two buffers are different
lynxeyed_atsu 0:d920d64db582 119 **********************************************************************/
lynxeyed_atsu 0:d920d64db582 120 Bool Buffer_Verify(void) {
lynxeyed_atsu 0:d920d64db582 121 uint32_t i;
lynxeyed_atsu 0:d920d64db582 122 uint32_t *pTX = (uint32_t *) &I2STXBuffer[0];
lynxeyed_atsu 0:d920d64db582 123 uint32_t *pRX = (uint32_t *) &I2SRXBuffer[1];
lynxeyed_atsu 0:d920d64db582 124 /* Because first element of RX is dummy 0 value, so we just verify
lynxeyed_atsu 0:d920d64db582 125 * from 2nd element
lynxeyed_atsu 0:d920d64db582 126 */
lynxeyed_atsu 0:d920d64db582 127 for (i = 1; i < BUFFER_SIZE; i++) {
lynxeyed_atsu 0:d920d64db582 128 if (*pTX++ != *pRX++) {
lynxeyed_atsu 0:d920d64db582 129 return FALSE;
lynxeyed_atsu 0:d920d64db582 130 }
lynxeyed_atsu 0:d920d64db582 131 }
lynxeyed_atsu 0:d920d64db582 132 return TRUE;
lynxeyed_atsu 0:d920d64db582 133 }
lynxeyed_atsu 0:d920d64db582 134
lynxeyed_atsu 0:d920d64db582 135 // for mbed
lynxeyed_atsu 0:d920d64db582 136 void mbed_i2s_init(void){
lynxeyed_atsu 0:d920d64db582 137
lynxeyed_atsu 0:d920d64db582 138 //GPDMA_Channel_CFG_Type GPDMACfg; // DMA
lynxeyed_atsu 0:d920d64db582 139 I2S_MODEConf_Type I2S_ClkConfig;
lynxeyed_atsu 0:d920d64db582 140 I2S_CFG_Type I2S_ConfigStruct;
lynxeyed_atsu 0:d920d64db582 141 //I2S_DMAConf_Type I2S_DMAStruct; // DMA
lynxeyed_atsu 0:d920d64db582 142 PINSEL_CFG_Type PinCfg;
lynxeyed_atsu 0:d920d64db582 143
lynxeyed_atsu 0:d920d64db582 144 // uint32_t i;
lynxeyed_atsu 0:d920d64db582 145 /* Initialize debug via UART0
lynxeyed_atsu 0:d920d64db582 146 * 115200bps
lynxeyed_atsu 0:d920d64db582 147 * 8 data bit
lynxeyed_atsu 0:d920d64db582 148 * No parity
lynxeyed_atsu 0:d920d64db582 149 * 1 stop bit
lynxeyed_atsu 0:d920d64db582 150 * No flow control
lynxeyed_atsu 0:d920d64db582 151 */
lynxeyed_atsu 0:d920d64db582 152 // debug_frmwrk_init();
lynxeyed_atsu 0:d920d64db582 153 // print menu screen
lynxeyed_atsu 0:d920d64db582 154 // print_menu();
lynxeyed_atsu 0:d920d64db582 155
lynxeyed_atsu 0:d920d64db582 156
lynxeyed_atsu 0:d920d64db582 157 /* Initialize I2S peripheral ------------------------------------*/
lynxeyed_atsu 0:d920d64db582 158 /* Pin configuration:
lynxeyed_atsu 0:d920d64db582 159 * Assign: - P0.4 as I2SRX_CLK <- No use
lynxeyed_atsu 0:d920d64db582 160 * - P0.5 as I2SRX_WS <- No use
lynxeyed_atsu 0:d920d64db582 161 * - P0.6 as I2SRX_SDA <- No use
lynxeyed_atsu 0:d920d64db582 162 * - P0.7 as I2STX_CLK
lynxeyed_atsu 0:d920d64db582 163 * - P0.8 as I2STX_WS
lynxeyed_atsu 0:d920d64db582 164 * - P0.9 as I2STX_SDA
lynxeyed_atsu 0:d920d64db582 165 */
lynxeyed_atsu 0:d920d64db582 166 PinCfg.Funcnum = 1;
lynxeyed_atsu 0:d920d64db582 167 PinCfg.OpenDrain = 0;
lynxeyed_atsu 0:d920d64db582 168 PinCfg.Pinmode = 0;
lynxeyed_atsu 0:d920d64db582 169 PinCfg.Portnum = 0;
lynxeyed_atsu 0:d920d64db582 170 //PinCfg.Pinnum = 4;
lynxeyed_atsu 0:d920d64db582 171 //PINSEL_ConfigPin(&PinCfg);
lynxeyed_atsu 0:d920d64db582 172 //PinCfg.Pinnum = 5;
lynxeyed_atsu 0:d920d64db582 173 //PINSEL_ConfigPin(&PinCfg);
lynxeyed_atsu 0:d920d64db582 174 //PinCfg.Pinnum = 6;
lynxeyed_atsu 0:d920d64db582 175 //PINSEL_ConfigPin(&PinCfg);
lynxeyed_atsu 0:d920d64db582 176 PinCfg.Pinnum = 7;
lynxeyed_atsu 0:d920d64db582 177 PINSEL_ConfigPin(&PinCfg);
lynxeyed_atsu 0:d920d64db582 178 PinCfg.Pinnum = 8;
lynxeyed_atsu 0:d920d64db582 179 PINSEL_ConfigPin(&PinCfg);
lynxeyed_atsu 0:d920d64db582 180 PinCfg.Pinnum = 9;
lynxeyed_atsu 0:d920d64db582 181 PINSEL_ConfigPin(&PinCfg);
lynxeyed_atsu 0:d920d64db582 182
lynxeyed_atsu 0:d920d64db582 183 //Buffer_Init();
lynxeyed_atsu 0:d920d64db582 184 I2S_Init(LPC_I2S);
lynxeyed_atsu 0:d920d64db582 185
lynxeyed_atsu 0:d920d64db582 186 /* setup:
lynxeyed_atsu 0:d920d64db582 187 * - wordwidth: 16 bits
lynxeyed_atsu 0:d920d64db582 188 * - stereo mode
lynxeyed_atsu 0:d920d64db582 189 * - master mode for I2S_TX and slave for I2S_RX
lynxeyed_atsu 0:d920d64db582 190 * - ws_halfperiod is 31
lynxeyed_atsu 0:d920d64db582 191 * - not use mute mode
lynxeyed_atsu 0:d920d64db582 192 * - use reset and stop mode
lynxeyed_atsu 0:d920d64db582 193 * - select the fractional rate divider clock output as the source,
lynxeyed_atsu 0:d920d64db582 194 * - disable 4-pin mode
lynxeyed_atsu 0:d920d64db582 195 * - MCLK ouput is disable
lynxeyed_atsu 0:d920d64db582 196 * - Frequency = 44.1 kHz
lynxeyed_atsu 0:d920d64db582 197 * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and
lynxeyed_atsu 0:d920d64db582 198 * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK
lynxeyed_atsu 0:d920d64db582 199 * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK)
lynxeyed_atsu 0:d920d64db582 200 */
lynxeyed_atsu 0:d920d64db582 201
lynxeyed_atsu 0:d920d64db582 202 /* Audio Config*/
lynxeyed_atsu 0:d920d64db582 203 I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16;
lynxeyed_atsu 0:d920d64db582 204 I2S_ConfigStruct.mono = I2S_STEREO;
lynxeyed_atsu 0:d920d64db582 205 I2S_ConfigStruct.stop = I2S_STOP_ENABLE;
lynxeyed_atsu 0:d920d64db582 206 I2S_ConfigStruct.reset = I2S_RESET_ENABLE;
lynxeyed_atsu 0:d920d64db582 207 I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE;
lynxeyed_atsu 0:d920d64db582 208 I2S_ConfigStruct.mute = I2S_MUTE_DISABLE;
lynxeyed_atsu 0:d920d64db582 209 I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct);
lynxeyed_atsu 0:d920d64db582 210
lynxeyed_atsu 0:d920d64db582 211 //I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE;
lynxeyed_atsu 0:d920d64db582 212 //I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct);
lynxeyed_atsu 0:d920d64db582 213
lynxeyed_atsu 0:d920d64db582 214 /* Clock Mode Config*/
lynxeyed_atsu 0:d920d64db582 215 CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_I2S,CLKPWR_PCLKSEL_CCLK_DIV_4);
lynxeyed_atsu 0:d920d64db582 216 I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK;
lynxeyed_atsu 0:d920d64db582 217 I2S_ClkConfig.fpin = I2S_4PIN_DISABLE;
lynxeyed_atsu 0:d920d64db582 218 I2S_ClkConfig.mcena = I2S_MCLK_DISABLE;
lynxeyed_atsu 0:d920d64db582 219 I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE);
lynxeyed_atsu 0:d920d64db582 220 //I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE);
lynxeyed_atsu 0:d920d64db582 221
lynxeyed_atsu 0:d920d64db582 222
lynxeyed_atsu 0:d920d64db582 223 //I2S_FreqConfig(LPC_I2S, (uint16_t)44100, I2S_TX_MODE); <- No use bacause I2S_TX is Slave mode
lynxeyed_atsu 0:d920d64db582 224 I2S_SetBitRate(LPC_I2S, 0, I2S_TX_MODE); //FOR SLAVE MODE TX
lynxeyed_atsu 0:d920d64db582 225 //I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE);
lynxeyed_atsu 0:d920d64db582 226
lynxeyed_atsu 0:d920d64db582 227 I2S_Stop(LPC_I2S, I2S_TX_MODE);
lynxeyed_atsu 0:d920d64db582 228 //I2S_Stop(LPC_I2S, I2S_RX_MODE);
lynxeyed_atsu 0:d920d64db582 229
lynxeyed_atsu 0:d920d64db582 230
lynxeyed_atsu 0:d920d64db582 231
lynxeyed_atsu 0:d920d64db582 232
lynxeyed_atsu 0:d920d64db582 233 NVIC_EnableIRQ(I2S_IRQn);
lynxeyed_atsu 0:d920d64db582 234
lynxeyed_atsu 0:d920d64db582 235 /* RX FIFO depth is 1, TX FIFO depth is 8. */
lynxeyed_atsu 0:d920d64db582 236 I2S_IRQConfig(LPC_I2S,I2S_TX_MODE,8);
lynxeyed_atsu 0:d920d64db582 237 //I2S_IRQConfig(LPC_I2S,I2S_RX_MODE,1);
lynxeyed_atsu 0:d920d64db582 238 //I2S_IRQCmd(LPC_I2S,I2S_TX_MODE,ENABLE);
lynxeyed_atsu 0:d920d64db582 239
lynxeyed_atsu 0:d920d64db582 240
lynxeyed_atsu 0:d920d64db582 241
lynxeyed_atsu 0:d920d64db582 242
lynxeyed_atsu 0:d920d64db582 243
lynxeyed_atsu 0:d920d64db582 244 I2S_Start(LPC_I2S);
lynxeyed_atsu 0:d920d64db582 245
lynxeyed_atsu 0:d920d64db582 246 }
lynxeyed_atsu 0:d920d64db582 247
lynxeyed_atsu 0:d920d64db582 248
lynxeyed_atsu 0:d920d64db582 249
lynxeyed_atsu 0:d920d64db582 250
lynxeyed_atsu 0:d920d64db582 251
lynxeyed_atsu 0:d920d64db582 252
lynxeyed_atsu 0:d920d64db582 253
lynxeyed_atsu 0:d920d64db582 254
lynxeyed_atsu 0:d920d64db582 255
lynxeyed_atsu 0:d920d64db582 256
lynxeyed_atsu 0:d920d64db582 257
lynxeyed_atsu 0:d920d64db582 258 #ifdef DEBUG
lynxeyed_atsu 0:d920d64db582 259 /*******************************************************************************
lynxeyed_atsu 0:d920d64db582 260 * @brief Reports the name of the source file and the source line number
lynxeyed_atsu 0:d920d64db582 261 * where the CHECK_PARAM error has occurred.
lynxeyed_atsu 0:d920d64db582 262 * @param[in] file Pointer to the source file name
lynxeyed_atsu 0:d920d64db582 263 * @param[in] line assert_param error line source number
lynxeyed_atsu 0:d920d64db582 264 * @return None
lynxeyed_atsu 0:d920d64db582 265 *******************************************************************************/
lynxeyed_atsu 0:d920d64db582 266 void check_failed(uint8_t *file, uint32_t line)
lynxeyed_atsu 0:d920d64db582 267 {
lynxeyed_atsu 0:d920d64db582 268 /* User can add his own implementation to report the file name and line number,
lynxeyed_atsu 0:d920d64db582 269 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
lynxeyed_atsu 0:d920d64db582 270
lynxeyed_atsu 0:d920d64db582 271 /* Infinite loop */
lynxeyed_atsu 0:d920d64db582 272 while(1);
lynxeyed_atsu 0:d920d64db582 273 }
lynxeyed_atsu 0:d920d64db582 274 #endif
lynxeyed_atsu 0:d920d64db582 275
lynxeyed_atsu 0:d920d64db582 276 /*
lynxeyed_atsu 0:d920d64db582 277 * @}
lynxeyed_atsu 0:d920d64db582 278 */