void UART0_Init(void) { UART1_PutString("\r\n UART0 init..."); UART0_Connect_to_MKGPS(UART0_BAUD_RATE); // initialize txd buffer Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN); // initialize rxd buffer Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN); UART1_PutString("ok"); }
void Video_Init() { Video_Open(); Video_Set_Para(); Buffer_Init(); Video_Streamon(); }
void SerialInit() { //attach events; lower level initializing USART_InitStructure(); if(!USART_TransComplete_Attach(&TC_Handler)) { while(1); } if(!USART_TransRegEmpty_Attach(&TXE_Handler)) { while(1); } if(!USART_ByteReceived_Attach(&RXNE_Handler)) { while(1); } //initialize Serial object Buffer_Init(&Serial.InputBuffer); fifo_initialize(&Serial.fifo_output, SERIAL_SIZE_FIFO_OUT); Serial_ByteReceived_Detach(); Serial_VariableReceived_Detach(); Serial_InpBufOver_Detach(); Serial_OutBufOver_Detach(); free(Serial.Pattern); Serial.Pattern = NULL; Serial.PatternLength = 0; Serial.State = SERIAL_STATE_INITIALIZED; }
UINT8 CDC_InterfaceReq_Handler(void) { UINT8 u8State=uSETUP; switch(Setup_Pkt->bRequest) { case GET_INTERFACE: EP_IN_Transfer(EP0,&gu8Interface,1); break; case GET_LINE_CODING: EP_IN_Transfer(EP0,(UINT8*)&LineCoding,7); break; case SET_LINE_CODING: u8CDCState=SET_LINE_CODING; u8State=uDATA; break; case SET_CONTROL_LINE_STATE: u8CDCState=SET_CONTROL_LINE_STATE; u8State=uSETUP; break; case LOADER_MODE: Buffer_Init(CDC_OUT_Data,CDC_BUFFER_SIZE); FLAG_SET(LOADER,gu8USB_Flags); CDC_OUT_Data[0]=0xFF; break; } return(u8State); }
void allocateBuffer(size_t sizeOfBuffer) { free(m_pCharacterArray); m_pCharacterArray = (char*)malloc(sizeOfBuffer); memset(m_pCharacterArray, m_fillChar, sizeOfBuffer); Buffer_Init(&m_buffer, m_pCharacterArray, sizeOfBuffer); }
//----------------------------------------------------------------- void USB_ConfigInit(void) { GPIO_InitTypeDef GPIO_InitStructure; UART1_PutString("\r\n USB init..."); #ifdef MCLK96MHZ //USB clock = MCLK/2 = 48MHz SCU_USBCLKConfig(SCU_USBCLK_MCLK2); #else //USB clock = MCLK = 48MHz SCU_USBCLKConfig(SCU_USBCLK_MCLK); #endif //Enable USB clock SCU_AHBPeriphClockConfig(__USB,ENABLE); SCU_AHBPeriphReset(__USB,DISABLE); SCU_AHBPeriphClockConfig(__USB48M,ENABLE); //Configure GPIO0 (D+ Pull-Up on P0.1) SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); SCU_APBPeriphReset(__GPIO0,DISABLE); // GPIO_DeInit(P0.1); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; GPIO_Init (GPIO0, &GPIO_InitStructure); // initialize the rx fifo, block UART IRQ geting a byte from fifo fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine); // initialize txd buffer Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); // initialize rxd buffer Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); VIC_ITCmd(USBLP_ITLine, ENABLE); USB_Init(); UART1_PutString("ok"); }
uint32_t Platform_CommHasReceiveData(void) { if (isReceiveBufferEmpty()) { Buffer_Init(&g_receiveBuffer, (char*)g_emptyPacket, strlen(g_emptyPacket)); return 0; } return 1; }
void WriteHexValueToGdbConsole(uint32_t Value) { Buffer BufferObject; char StringBuffer[11]; Buffer_Init(&BufferObject, StringBuffer, sizeof(StringBuffer)); Buffer_WriteString(&BufferObject, "0x"); Buffer_WriteUIntegerAsHex(&BufferObject, Value); Buffer_WriteChar(&BufferObject, '\0'); WriteStringToGdbConsole(StringBuffer); }
/*********************************************************************//** * @brief Initialize and Configure SPI device * @param[in] SPIx SPI peripheral definition, should be LPC_SPI * @return None ***********************************************************************/ void SPI_Config (LPC_SPI_TypeDef *SPIx) { // Pin configuration for SPI PINSEL_CFG_Type PinCfg; // SPI Configuration structure variable SPI_CFG_Type SPI_ConfigStruct; if(SPIx == LPC_SPI) { /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PinCfg.Funcnum = 0; PINSEL_ConfigPin(&PinCfg); } /* SPI_ConfigStruct.CPHA = SPI_CPHA_SECOND; SPI_ConfigStruct.CPOL = SPI_CPOL_LO; SPI_ConfigStruct.ClockRate = SPI_CLOCK; SPI_ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST; SPI_ConfigStruct.Databit = SPI_DATABIT_8; SPI_ConfigStruct.Mode = SPI_MASTER_MODE;*/ // initialize SPI configuration structure to default SPI_ConfigStructInit(&SPI_ConfigStruct); SPI_ConfigStruct.ClockRate = 3000000; SPI_ConfigStruct.Databit = SPI_DATABIT_8; // Initialize SPI peripheral with parameter given in structure above SPI_Init(LPC_SPI, &SPI_ConfigStruct); CS_Init(); // Chip Select Init Buffer_Init(); // Empty Buffer }
void CDC_Init(void) { u8CDCState=0; /* USB Initialization */ USB_Init(); u8CDCState=WAITING_FOR_ENUMERATION; /* Line Coding Initialization */ LineCoding.DTERate=LWordSwap(9600); LineCoding.CharFormat=0; LineCoding.ParityType=0; LineCoding.Databits=0x08; /* Initialize Data Buffers */ Buffer_Init(CDC_OUT_Data,CDC_BUFFER_SIZE); }
void CDC_Init(void) { u8CDCState=0; /* USB Initialization */ USB_Init(); /** Enable SOF ouput */ PORTC_PCR7 |= PORT_PCR_MUX(3); /* Line Coding Initialization */ //LineCoding.DTERate=LWordSwap(9600); LineCoding.DTERate=(9600); LineCoding.CharFormat=0; LineCoding.ParityType=0; LineCoding.Databits=0x08; /* Initialize Data Buffers */ Buffer_Init(CDC_OUT_Data,CDC_BUFFER_SIZE); }
void InitBuffer(void) { Buffer_Init(&g_mri.buffer, Platform_GetPacketBuffer(), Platform_GetPacketBufferSize()); }
/* Select the Transfer mode : Polling, Interrupt or DMA */ static void appSSPTest(void) { int key; DEBUGOUT(sspTransferModeSel); dmaChSSPTx = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, LPC_GPDMA_SSP_TX); dmaChSSPRx = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, LPC_GPDMA_SSP_RX); xf_setup.length = BUFFER_SIZE; xf_setup.tx_data = Tx_Buf; xf_setup.rx_data = Rx_Buf; while (1) { key = 0xFF; do { key = DEBUGIN(); } while ((key & 0xFF) == 0xFF); Buffer_Init(); switch (key) { case SSP_POLLING_SEL: /* SSP Polling Read Write Mode */ DEBUGOUT(sspWaitingMenu); xf_setup.rx_cnt = xf_setup.tx_cnt = 0; Chip_SSP_RWFrames_Blocking(LPC_SSP, &xf_setup); if (Buffer_Verify() == 0) { DEBUGOUT(sspPassedMenu); } else { DEBUGOUT(sspFailedMenu); } break; case SSP_INTERRUPT_SEL: DEBUGOUT(sspIntWaitingMenu); isXferCompleted = 0; xf_setup.rx_cnt = xf_setup.tx_cnt = 0; Chip_SSP_Int_FlushData(LPC_SSP);/* flush dummy data from SSP FiFO */ if (SSP_DATA_BYTES(ssp_format.bits) == 1) { Chip_SSP_Int_RWFrames8Bits(LPC_SSP, &xf_setup); } else { Chip_SSP_Int_RWFrames16Bits(LPC_SSP, &xf_setup); } Chip_SSP_Int_Enable(LPC_SSP); /* enable interrupt */ while (!isXferCompleted) {} if (Buffer_Verify() == 0) { DEBUGOUT(sspPassedMenu); } else { DEBUGOUT(sspFailedMenu); } break; case SSP_DMA_SEL: /* SSP DMA Read and Write: fixed on 8bits */ DEBUGOUT(sspDMAWaitingMenu); isDmaTxfCompleted = isDmaRxfCompleted = 0; Chip_SSP_DMA_Enable(LPC_SSP); /* data Tx_Buf --> SSP */ Chip_GPDMA_Transfer(LPC_GPDMA, dmaChSSPTx, (uint32_t) &Tx_Buf[0], LPC_GPDMA_SSP_TX, GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA, BUFFER_SIZE); /* data SSP --> Rx_Buf */ Chip_GPDMA_Transfer(LPC_GPDMA, dmaChSSPRx, LPC_GPDMA_SSP_RX, (uint32_t) &Rx_Buf[0], GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA, BUFFER_SIZE); while (!isDmaTxfCompleted || !isDmaRxfCompleted) {} if (Buffer_Verify() == 0) { DEBUGOUT(sspPassedMenu); } else { DEBUGOUT(sspFailedMenu); } Chip_SSP_DMA_Disable(LPC_SSP); break; case 'q': case 'Q': Chip_GPDMA_Stop(LPC_GPDMA, dmaChSSPTx); Chip_GPDMA_Stop(LPC_GPDMA, dmaChSSPRx); return; default: break; } DEBUGOUT(sspTransferModeSel); } }
/*********************************************************************//** * @brief c_entry: Main MICROWIRE program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { uint32_t cnt; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Initialize SSP pin connect * P0.6 - SSEL1 * P0.7 - SCK1 * P0.8 - MISO1 * P0.9 - MOSI1 */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); /* * Initialize SSP pin connect * P0.15 - SCK * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* Initializing Master SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Re-configure SSP to MicroWire frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_MICROWIRE; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_M, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_M, ENABLE); /* Initializing Slave SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); /* Re-configure mode for SSP device */ SSP_ConfigStruct.Mode = SSP_SLAVE_MODE; // Re-configure SSP to MicroWire frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_MICROWIRE; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_S, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_S, ENABLE); /* Initializing Buffer section ------------------------------------------------- */ Buffer_Init(); /* Start Transmit/Receive between Master and Slave ----------------------------- */ pRdBuf_M = (uint8_t *)&Master_Rx_Buf[0]; RdIdx_M = 0; DatLen_M = BUFFER_SIZE; pWrBuf_S = (uint8_t *)&Slave_Tx_Buf[0]; WrIdx_S = 0; DatLen_S = BUFFER_SIZE; /* Force Last command to Read command as default */ Last_cmd = MicroWire_RD_CMD; /* Clear all remaining data in RX FIFO */ while (SSP_GetStatus(SSPDEV_M, SSP_STAT_RXFIFO_NOTEMPTY)) { SSP_ReceiveData(SSPDEV_M); } while (SSP_GetStatus(SSPDEV_S, SSP_STAT_RXFIFO_NOTEMPTY)) { SSP_ReceiveData(SSPDEV_S); } for (cnt = 0; cnt < BUFFER_SIZE; cnt++) { /* The slave must initialize data in FIFO for immediately transfer from master * due to last received command */ if (Last_cmd == MicroWire_RD_CMD) { // Then send the respond to master, this contains data ssp_MW_SendRSP(SSPDEV_S, (uint16_t) *(pWrBuf_S + WrIdx_S++)); } else { // Then send the respond to master, this contains data ssp_MW_SendRSP(SSPDEV_S, 0xFF); } /* Master must send a read command to slave, * the slave then respond with its data in FIFO */ ssp_MW_SendCMD(SSPDEV_M, MicroWire_RD_CMD); // Master receive respond *(pRdBuf_M + RdIdx_M++) = (uint8_t) ssp_MW_GetRSP(SSPDEV_M); // Re-assign Last command Last_cmd = ssp_MW_GetCMD(SSPDEV_S); } /* Verify buffer */ Buffer_Verify(); _DBG_("Verify success!\n\r"); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; I2C_M_SETUP_Type transferMCfg; uint32_t tempp; uint8_t *pdat; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; #if ((USEDI2CDEV_M == 0)) PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); #endif #if ((USEDI2CDEV_M == 2)) PinCfg.Funcnum = 2; PinCfg.Pinnum = 10; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 11; PINSEL_ConfigPin(&PinCfg); #endif // Initialize Slave I2C peripheral I2C_Init(I2CDEV_M, 100000); /* Enable Slave I2C operation */ I2C_Cmd(I2CDEV_M, ENABLE); /* Transmit -------------------------------------------------------- */ _DBG_("Press '1' to transmit"); while (_DG != '1'); _DBG_("Start Transmit..."); /* Initialize buffer */ Buffer_Init(1); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = Master_Buf; transferMCfg.tx_length = sizeof(Master_Buf); transferMCfg.rx_data = NULL; transferMCfg.rx_length = 0; transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); /* Receive -------------------------------------------------------- */ _DBG_("Press '2' to receive"); while(_DG != '2'); _DBG_("Receive..."); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = NULL ; transferMCfg.tx_length = 0; transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); pdat = Master_Buf; // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } #if 1 /* Transmit and receive -------------------------------------------------------- */ _DBG_("Press '3' to Transmit, then repeat start and receive..."); while (_DG != '3'); /* Initialize buffer */ Buffer_Init(0); master_test[0] = 0xAA; master_test[1] = 0x55; /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = master_test ; transferMCfg.tx_length = sizeof(master_test); transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); #endif pdat = Master_Buf; // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } I2C_DeInit(I2CDEV_M); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Initialize buffer */ _DBG_("Initialize Buffer..."); Buffer_Init(); /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG_("Start transfer..."); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG(compl_menu); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief Main GPDMA program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Initialize buffer */ _DBG_("Initialize Buffer..."); Buffer_Init(); /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG_("Start transfer..."); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG(compl_menu); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief Main I2C master and slave program body **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; I2C_OWNSLAVEADDR_CFG_Type OwnSlavAdr; I2C_M_SETUP_Type transferMCfg; I2C_S_SETUP_Type transferSCfg; uint32_t tempp; uint8_t *sp, *dp; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* Initialize debug */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; #if ((USEDI2CDEV_M == 0) || (USEDI2CDEV_S == 0)) PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); #endif #if ((USEDI2CDEV_M == 2) || (USEDI2CDEV_S == 2)) PinCfg.Funcnum = 2; PinCfg.Pinnum = 10; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 11; PINSEL_ConfigPin(&PinCfg); #endif // Initialize Master I2C peripheral I2C_Init(I2CDEV_M, 100000); // Initialize Slave I2C peripheral I2C_Init(I2CDEV_S, 100000); /* Set Own slave address for I2C device */ OwnSlavAdr.GeneralCallState = ENABLE; OwnSlavAdr.SlaveAddrChannel= 0; OwnSlavAdr.SlaveAddrMaskValue = 0xFF; OwnSlavAdr.SlaveAddr_7bit = I2CDEV_S_OWN_ADDR; I2C_SetOwnSlaveAddr(I2CDEV_S, &OwnSlavAdr); /* * Note: The master should be set higher priority than * the slave that let interrupt in master can appear * in slave's timeout condition. * A higher interrupt priority has lower number level!!! */ /* Configure interrupt for I2C in NVIC of ARM core */ #if ((USEDI2CDEV_M == 0) || (USEDI2CDEV_S == 0)) /* Disable I2C0 interrupt */ NVIC_DisableIRQ(I2C0_IRQn); #if (USEDI2CDEV_M == 0) /* preemption = 1, sub-priority = 0 */ NVIC_SetPriority(I2C0_IRQn, ((0x00<<3)|0x01)); #else /* preemption = 1, sub-priority = 2 */ NVIC_SetPriority(I2C0_IRQn, ((0x02<<3)|0x01)); #endif #endif /* ((USEDI2CDEV_M == 0) || (USEDI2CDEV_S == 0)) */ #if ((USEDI2CDEV_M == 2) || (USEDI2CDEV_S == 2)) /* Disable I2C2 interrupt */ NVIC_DisableIRQ(I2C2_IRQn); #if (USEDI2CDEV_M == 2) /* preemption = 1, sub-priority = 0 */ NVIC_SetPriority(I2C2_IRQn, ((0x00<<3)|0x01)); #else /* preemption = 1, sub-priority = 2 */ NVIC_SetPriority(I2C2_IRQn, ((0x02<<3)|0x01)); #endif #endif /* Enable Master I2C operation */ I2C_Cmd(I2CDEV_M, ENABLE); /* Enable Slave I2C operation */ I2C_Cmd(I2CDEV_S, ENABLE); #if 1 /* MASTER SEND DATA TO SLAVE -------------------------------------------------------- */ /* Force complete flag for the first time of running */ complete_S = RESET; complete_M = RESET; _DBG_("Master transmit data to slave..."); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferSCfg.tx_data = NULL; transferSCfg.tx_length = 0; transferSCfg.rx_data = Slave_Buf; transferSCfg.rx_length = sizeof(Slave_Buf); transferSCfg.callback = SlaveCallback; I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_INTERRUPT); /* Then start I2C master device */ transferMCfg.sl_addr7bit = I2CDEV_S_OWN_ADDR; transferMCfg.tx_data = Master_Buf; transferMCfg.tx_length = sizeof(Master_Buf); transferMCfg.rx_data = NULL; transferMCfg.rx_length = 0; transferMCfg.retransmissions_max = 3; transferMCfg.callback = MasterCallback; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT); /* Wait until both of them complete */ while ((complete_M == RESET) || (complete_S == RESET)); // verify data sp = Master_Buf; dp = Slave_Buf; for (tempp = sizeof(Master_Buf); tempp; tempp--){ if(*sp++ != *dp++){ _DBG_("Verify data error!"); } } // Success! if (tempp == 0){ _DBG_("Verify data successfully!"); } /* MASTER RECEIVE DATA FROM SLAVE -------------------------------------------------------- */ /* Force complete flag for the first time of running */ complete_S = RESET; complete_M = RESET; _DBG_("Master read data from slave..."); /* Initialize buffer */ Buffer_Init(1); /* Start I2C slave device first */ transferSCfg.tx_data = Slave_Buf; transferSCfg.tx_length = sizeof(Slave_Buf); transferSCfg.rx_data = NULL; transferSCfg.rx_length = 0; transferSCfg.callback = SlaveCallback; I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_INTERRUPT); /* Then start I2C master device */ transferMCfg.sl_addr7bit = I2CDEV_S_OWN_ADDR; transferMCfg.tx_data = NULL; transferMCfg.tx_length = 0; transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; transferMCfg.callback = MasterCallback; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT); /* Wait until both of them complete */ while ((complete_M == RESET) || (complete_S == RESET)); // verify data sp = Master_Buf; dp = Slave_Buf; for (tempp = sizeof(Master_Buf); tempp; tempp--){ if(*sp++ != *dp++){ _DBG_("Verify data error!"); } } // Success! if (tempp == 0){ _DBG_("Verify data successfully!"); } #endif #if 1 // TEST----------------------------------------------------------- // Master transmit two bytes, then repeat start and reading from slave // a number of byte /* Force complete flag for the first time of running */ complete_S = RESET; complete_M = RESET; _DBG_("Master transmit data to slave first, then repeat start and read data from slave..."); /* Initialize buffer */ Buffer_Init(1); master_test[0] = 0xAA; master_test[1] = 0x55; slave_test[0] = 0x00; slave_test[1] = 0x00; /* Start I2C slave device first */ transferSCfg.tx_data = Slave_Buf; transferSCfg.tx_length = sizeof(Slave_Buf); transferSCfg.rx_data = slave_test; transferSCfg.rx_length = sizeof(slave_test); transferSCfg.callback = SlaveCallback; I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_INTERRUPT); /* Then start I2C master device */ transferMCfg.sl_addr7bit = I2CDEV_S_OWN_ADDR; transferMCfg.tx_data = master_test; transferMCfg.tx_length = sizeof(master_test); transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; transferMCfg.callback = MasterCallback; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT); /* Wait until both of them complete */ while ((complete_M == RESET) || (complete_S == RESET)); // verify data sp = Master_Buf; dp = Slave_Buf; for (tempp = sizeof(Master_Buf); tempp; tempp--){ if(*sp++ != *dp++){ _DBG_("Verify data error!"); } } // Success! if (tempp == 0){ _DBG_("Verify data successfully!"); } sp = master_test; dp = slave_test; for (tempp = sizeof(master_test); tempp; tempp--){ if(*sp++ != *dp++){ _DBG_("Verify data error!"); } } // Success! if (tempp == 0){ _DBG_("Verify data successfully!"); } #endif while (1){ tempp++; } /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main TI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Initialize SSP pin connect * P0.6 - SSEL1 * P0.7 - SCK1 * P0.8 - MISO1 * P0.9 - MOSI1 */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); /* * Initialize SSP pin connect * P0.15 - SCK * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* Initializing Master SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Re-configure SSP to TI frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_M, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_M, ENABLE); /* Initializing Slave SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); /* Re-configure mode for SSP device */ SSP_ConfigStruct.Mode = SSP_SLAVE_MODE; // Re-configure SSP to TI frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_S, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_S, ENABLE); /* Interrupt configuration section ------------------------------------------------- */ #if ((USEDSSPDEV_S == 0) || (USEDSSPDEV_M == 0)) /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SSP0_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SSP0_IRQn); #endif #if ((USEDSSPDEV_S == 1) || (USEDSSPDEV_M == 1)) /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SSP1_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SSP1_IRQn); #endif /* Initializing Buffer section ------------------------------------------------- */ Buffer_Init(); /* Start Transmit/Receive between Master and Slave ----------------------------- */ complete_S = FALSE; complete_M = FALSE; /* Slave must be ready first */ ssp_SlaveReadWrite(SSPDEV_S, Slave_Rx_Buf, Slave_Tx_Buf, BUFFER_SIZE); /* Then Master can start its transferring */ ssp_MasterReadWrite(SSPDEV_M, Master_Rx_Buf, Master_Tx_Buf, BUFFER_SIZE); /* Wait for complete */ while ((complete_S == FALSE) || (complete_M == FALSE)); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify success!\n\r"); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { uint32_t i; GPDMA_Channel_CFG_Type GPDMACfg; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; I2S_DMAConf_Type I2S_DMAStruct; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); //Initialize buffer Buffer_Init(); _DBG_("Press '1' to initialize buffer..."); while(_DG !='1'); _DBG_("Transmit Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2STXBuffer[i]);_DBG_(""); } _DBG_("Receive Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); /* Initialize I2S */ I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); _DBG_("Press '2' to initialize DMA..."); while(_DG !='2'); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* Initialize GPDMA controller */ GPDMA_Init(); LPC_GPDMA->DMACConfig = 0x01; /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* * Configure GPDMA channel 0 ------------------------------------------------------------- * Used for I2S Transmit */ // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = BUFFER_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = GPDMA_CONN_I2S_Channel_0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); _DBG_("DMA Channel 0 setting finised..."); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* * Configure GPDMA channel 1 ------------------------------------------------------------- * Used for UART0 Receive */ // Setup GPDMA channel -------------------------------- // channel 1 GPDMACfg.ChannelNum = 1; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = BUFFER_SIZE+1; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection - unused GPDMACfg.SrcConn = GPDMA_CONN_I2S_Channel_1; // Destination connection GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); _DBG_("DMA Channel 1 setting finised..."); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Enable GPDMA channel 0 & 1 GPDMA_ChannelCmd(0, ENABLE); GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); _DBG_("Press '3' to start I2S transfer process..."); while(_DG !='3'); _DBG_("I2S Start..."); I2S_DMAStruct.DMAIndex = I2S_DMA_2; I2S_DMAStruct.depth = 8; I2S_DMAConfig(LPC_I2S, &I2S_DMAStruct, I2S_RX_MODE); I2S_DMAStruct.DMAIndex = I2S_DMA_1; I2S_DMAStruct.depth = 1; I2S_DMAConfig(LPC_I2S, &I2S_DMAStruct, I2S_TX_MODE); I2S_Start(LPC_I2S); I2S_DMACmd(LPC_I2S, I2S_DMA_2, I2S_RX_MODE, ENABLE); I2S_DMACmd(LPC_I2S, I2S_DMA_1, I2S_TX_MODE, ENABLE); while ((Channel0_TC == 0)||(Channel1_TC == 0) ); _DBG_("I2S Finish..."); _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE+1;i++) { _DBH32(I2SRXBuffer[i]); if(I2SRXBuffer[i]==0) { _DBG_(" ->Dummy data"); } else _DBG_(""); } I2S_DeInit(LPC_I2S); while(1); return 1; }
void allocateBuffer(const char* pBufferString) { free(m_pCharacterArray); m_pCharacterArray = NULL; Buffer_Init(&m_buffer, (char*)pBufferString, strlen(pBufferString)); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { I2C_M_SETUP_Type transferMCfg; uint32_t tempp; uint8_t *pdat; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ #if ((I2CDEV_M == 0)) PINSEL_ConfigPin (5, 2, 5); PINSEL_ConfigPin (5, 3, 5); #elif ((I2CDEV_M == 1)) PINSEL_ConfigPin (0, 19, 3); PINSEL_ConfigPin (0, 20, 3); PINSEL_SetOpenDrainMode(0, 19, ENABLE); PINSEL_SetOpenDrainMode(0, 20, ENABLE); PINSEL_SetPinMode(0, 19, PINSEL_BASICMODE_PLAINOUT); PINSEL_SetPinMode(0, 20, PINSEL_BASICMODE_PLAINOUT); #elif ((I2CDEV_M == 2)&& (_CURR_USING_OEM_BRD != LPC4088_OEM_BOARD)) PINSEL_ConfigPin (0, 10, 2); PINSEL_ConfigPin (0, 11, 2); PINSEL_SetOpenDrainMode(0, 10, ENABLE); PINSEL_SetOpenDrainMode(0, 11, ENABLE); PINSEL_SetPinMode(0, 10, PINSEL_BASICMODE_PLAINOUT); PINSEL_SetPinMode(0, 11, PINSEL_BASICMODE_PLAINOUT); #else #error "Please choose the correct peripheral." #endif // Initialize Slave I2C peripheral I2C_Init((en_I2C_unitId)I2CDEV_M, 100000); /* Enable Slave I2C operation */ I2C_Cmd((en_I2C_unitId)I2CDEV_M, I2C_MASTER_MODE, ENABLE); /* Transmit -------------------------------------------------------- */ _DBG_("Press '1' to transmit"); while (_DG != '1'); /* Initialize buffer */ Buffer_Init(1); _DBG_("Transmit Data: "); Buffer_Print((uint8_t*)Master_Buf, sizeof(Master_Buf)); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = Master_Buf; transferMCfg.tx_length = sizeof(Master_Buf); transferMCfg.rx_data = NULL; transferMCfg.rx_length = 0; transferMCfg.retransmissions_max = 3; transferMCfg.tx_count = 0; transferMCfg.rx_count = 0; transferMCfg.retransmissions_count = 0; #if (I2CDEV_TRANSFER_POLLING == 0) complete = FALSE; I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT); while(!complete) ; #else I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); #endif /* Receive -------------------------------------------------------- */ _DBG_("Press '2' to receive"); while(_DG != '2'); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = NULL ; transferMCfg.tx_length = 0; transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; transferMCfg.tx_count = 0; transferMCfg.rx_count = 0; transferMCfg.retransmissions_count = 0; #if (I2CDEV_TRANSFER_POLLING == 0) complete = FALSE; I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT); while(!complete) ; #else I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); #endif pdat = (uint8_t*)Master_Buf; _DBG_("Receive Data: "); Buffer_Print((uint8_t*)Master_Buf, sizeof(Master_Buf)); // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat != (tempp)){ _DBG_("Verify error "); break; } pdat++; } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } /* Transmit and receive -------------------------------------------------------- */ _DBG_("Press '3' to Transmit, then repeat start and receive..."); while (_DG != '3'); /* Initialize buffer */ Buffer_Init(0); master_test[0] = 0xAA; master_test[1] = 0x55; /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = master_test ; transferMCfg.tx_length = sizeof(master_test); transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.tx_count = 0; transferMCfg.rx_count = 0; transferMCfg.retransmissions_count = 0; transferMCfg.retransmissions_max = 3; #if (I2CDEV_TRANSFER_POLLING == 0) complete = FALSE; I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_INTERRUPT); while(!complete) ; #else I2C_MasterTransferData((en_I2C_unitId)I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); #endif pdat = (uint8_t*)Master_Buf; _DBG_("Transmit Data: "); Buffer_Print((uint8_t*)master_test, sizeof(master_test)); _DBG_("Receive Data: "); Buffer_Print((uint8_t*)Master_Buf, sizeof(Master_Buf)); // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error: "); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } I2C_DeInit((en_I2C_unitId)I2CDEV_M); /* Loop forever */ while(1); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Main Program */ I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; PINSEL_CFG_Type PinCfg; uint32_t i; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); /* Initialize I2S peripheral ------------------------------------*/ /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); Buffer_Init(); I2S_Init(LPC_I2S); /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); I2S_Stop(LPC_I2S, I2S_TX_MODE); I2S_Stop(LPC_I2S, I2S_RX_MODE); NVIC_EnableIRQ(I2S_IRQn); /* RX FIFO depth is 1, TX FIFO depth is 8. */ I2S_IRQConfig(LPC_I2S,I2S_TX_MODE,8); I2S_IRQConfig(LPC_I2S,I2S_RX_MODE,1); I2S_IRQCmd(LPC_I2S,I2S_RX_MODE,ENABLE); I2S_Start(LPC_I2S); /* I2S transmit ---------------------------------------------------*/ while ( I2SWriteLength < BUFFER_SIZE ) { while(I2S_GetLevel(LPC_I2S, I2S_TX_MODE)==TXFIFO_FULL); I2S_Send(LPC_I2S, I2STXBuffer[I2SWriteLength++]); } I2STXDone = 1; /* Wait for transmit/receive complete */ while ( !I2SRXDone || !I2STXDone ); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Verify RX and TX Buffer */ if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } return 0; }
/*********************************************************************//** * @brief Main I2C master and slave program body **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; I2C_OWNSLAVEADDR_CFG_Type OwnSlavAdr; I2C_S_SETUP_Type transferSCfg; uint32_t tempp; uint8_t *pdat; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* Initialize debug */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; #if ((USEDI2CDEV_S == 0)) PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); #endif #if ((USEDI2CDEV_S == 2)) PinCfg.Funcnum = 2; PinCfg.Pinnum = 10; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 11; PINSEL_ConfigPin(&PinCfg); #endif // Initialize Slave I2C peripheral I2C_Init(I2CDEV_S, 100000); /* Set Own slave address for I2C device */ OwnSlavAdr.GeneralCallState = ENABLE; OwnSlavAdr.SlaveAddrChannel= 0; OwnSlavAdr.SlaveAddrMaskValue = 0xFF; OwnSlavAdr.SlaveAddr_7bit = I2CDEV_S_OWN_ADDR; I2C_SetOwnSlaveAddr(I2CDEV_S, &OwnSlavAdr); /* Enable Slave I2C operation */ I2C_Cmd(I2CDEV_S, ENABLE); _DBG_("Press '1' to start"); while (_DG != '1'); /* Reading -------------------------------------------------------- */ _DBG_("Start Reading..."); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferSCfg.tx_data = NULL; transferSCfg.tx_length = 0; transferSCfg.rx_data = Slave_Buf; transferSCfg.rx_length = sizeof(Slave_Buf); I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_POLLING); pdat = Slave_Buf; // Verify for (tempp = 0; tempp < sizeof(Slave_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Slave_Buf)){ _DBG_("Verify successfully"); } /* Transmit -------------------------------------------------------- */ _DBG_("Start Transmit..."); /* Initialize buffer */ Buffer_Init(1); /* Start I2C slave device first */ transferSCfg.tx_data = Slave_Buf; transferSCfg.tx_length = sizeof(Slave_Buf); transferSCfg.rx_data = NULL; transferSCfg.rx_length = 0; I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_POLLING); _DBG_("Complete!"); #if 1 /* Receive and transmit -------------------------------------------------------- */ _DBG_("Start Receive, wait for repeat start and transmit..."); /* Initialize buffer */ Buffer_Init(1); slave_test[0] = 0xAA; slave_test[1] = 0x55; /* Start I2C slave device first */ transferSCfg.tx_data = Slave_Buf; transferSCfg.tx_length = sizeof(Slave_Buf); transferSCfg.rx_data = slave_test; transferSCfg.rx_length = sizeof(slave_test); I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_POLLING); _DBG_("Receive Data:"); _DBH(slave_test[0]); _DBG_(""); _DBH(slave_test[1]); _DBG_(""); _DBG_("Complete!"); #endif /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main SSP program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { #if __DMA_USED__ GPDMA_Channel_CFG_Type GPDMACfg; #else SSP_DATA_SETUP_Type xferConfig; #endif /* * Initialize SSP pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ #if (_SSP_NO_USING == 0) PINSEL_ConfigPin(0, 15, 2); PINSEL_ConfigPin(0, 16, 2); PINSEL_ConfigPin(0, 17, 2); PINSEL_ConfigPin(0, 18, 2); #elif (_SSP_NO_USING == 1) PINSEL_ConfigPin(0, 6, 2); PINSEL_ConfigPin(0, 7, 2); PINSEL_SetFilter(0, 7, 0); PINSEL_ConfigPin(0, 8, 2); PINSEL_SetFilter(0, 8, 0); PINSEL_ConfigPin(0, 9, 2); PINSEL_SetFilter(0, 9, 0); #else PINSEL_ConfigPin(1, 0, 4); PINSEL_ConfigPin(1, 8, 4); PINSEL_ConfigPin(1, 1, 4); PINSEL_ConfigPin(1, 4, 4); #endif /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP, ENABLE); _DBG_("Press '1' to start transfer..."); while (_DG != '1'); /* Initialize Buffer */ _DBG_("Init buffer"); Buffer_Init(); _DBG_("Start transfer..."); #if __DMA_USED__ /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Configure GPDMA channel 0 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &Tx_Buf; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(Tx_Buf); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = SSP_TX_SRC_DMA_CONN; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &Rx_Buf; // Transfer size GPDMACfg.TransferSize = sizeof(Rx_Buf); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = SSP_RX_SRC_DMA_CONN; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); #else xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SSP_ReadWrite(LPC_SSP, &xferConfig, SSP_TRANSFER_POLLING); #endif // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ while(1); }
/*********************************************************************//** * @brief Main I2S program body **********************************************************************/ int c_entry (void) { /* Main Program */ uint32_t i; uint8_t ch; uint8_t dummy=0; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; I2S_PinCFG_Type I2S_PinStruct; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif NVIC_SetPriorityGrouping(0x06); debug_frmwrk_init(); print_menu(); _DBG_("Press '1' to initialize buffer..."); while(_DG !='1'); Buffer_Init(); _DBG_("Transmit Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2STXBuffer[i]);_DBG_(""); } _DBG_("Receive Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Initializes pin corresponding to I2S function */ I2S_PinStruct.CLK_Pin=I2S_STX_CLK_P0_7; I2S_PinStruct.WS_Pin=I2S_STX_WS_P0_8; I2S_PinStruct.SDA_Pin=I2S_STX_SDA_P0_9; I2S_PinStruct.MCLK_Pin=I2S_TX_MCLK_P4_29; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_clk_pin[I2S_PinStruct.CLK_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_ws_pin[I2S_PinStruct.WS_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_sda_pin[I2S_PinStruct.SDA_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_tx_mclk_pin[I2S_PinStruct.MCLK_Pin])); // Configure pinsel for I2S_RX I2S_PinStruct.CLK_Pin=I2S_SRX_CLK_P0_4; I2S_PinStruct.WS_Pin=I2S_SRX_WS_P0_5; I2S_PinStruct.SDA_Pin=I2S_SRX_SDA_P0_6; I2S_PinStruct.MCLK_Pin=I2S_RX_MCLK_P4_28; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_clk_pin[I2S_PinStruct.CLK_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_ws_pin[I2S_PinStruct.WS_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_sda_pin[I2S_PinStruct.SDA_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_rx_mclk_pin[I2S_PinStruct.MCLK_Pin])); I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz (x=8,y=51 - automatic setting) * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_0; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ClkConfig.fpin = I2S_4PIN_ENABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); // I2S_SetBitRate(I2S, 1, I2S_RX_MODE); I2S_Start(LPC_I2S); _DBG_("Press '2' to start I2S transfer process..."); while(_DG !='2'); _DBG_("I2S Start ..."); while(I2STXDone == 0||I2SRXDone == 0){ if(I2STXDone ==0){ while (I2S_GetLevel(LPC_I2S,I2S_TX_MODE)!=0x00); I2S_Send(LPC_I2S,I2STXBuffer[I2SWriteLength]); I2SWriteLength +=1; if(I2SWriteLength == BUFFER_SIZE) I2STXDone = 1; } if(I2SRXDone == 0) { while(I2S_GetLevel(LPC_I2S,I2S_RX_MODE)==0x00); if(dummy == 0) //dummy receive { i = I2S_Receive(LPC_I2S); if(i!=0) { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = i; I2SReadLength +=1; dummy = 1; } } else { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = I2S_Receive(LPC_I2S); I2SReadLength +=1; } if(I2SReadLength == BUFFER_SIZE) I2SRXDone = 1; } } _DBG_("I2S Finish..."); _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } while(1); }
/*********************************************************************//** * @brief Main I2C master and slave program body **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; I2C_M_SETUP_Type transferMCfg; uint32_t tempp; uint8_t *pdat; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* Initialize debug */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; #if ((USEDI2CDEV_M == 0)) PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); #endif #if ((USEDI2CDEV_M == 2)) PinCfg.Funcnum = 2; PinCfg.Pinnum = 10; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 11; PINSEL_ConfigPin(&PinCfg); #endif // Initialize Slave I2C peripheral I2C_Init(I2CDEV_M, 100000); /* Enable Slave I2C operation */ I2C_Cmd(I2CDEV_M, ENABLE); /* Transmit -------------------------------------------------------- */ _DBG_("Press '1' to transmit"); while (_DG != '1'); _DBG_("Start Transmit..."); /* Initialize buffer */ Buffer_Init(1); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = Master_Buf; transferMCfg.tx_length = sizeof(Master_Buf); transferMCfg.rx_data = NULL; transferMCfg.rx_length = 0; transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); /* Receive -------------------------------------------------------- */ _DBG_("Press '2' to receive"); while(_DG != '2'); _DBG_("Receive..."); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = NULL ; transferMCfg.tx_length = 0; transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); pdat = Master_Buf; // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } #if 1 /* Transmit and receive -------------------------------------------------------- */ _DBG_("Press '3' to Transmit, then repeat start and receive..."); while (_DG != '3'); /* Initialize buffer */ Buffer_Init(0); master_test[0] = 0xAA; master_test[1] = 0x55; /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = master_test ; transferMCfg.tx_length = sizeof(master_test); transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); #endif pdat = Master_Buf; // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } I2C_DeInit(I2CDEV_M); /* Loop forever */ while(1); return 1; }
void VVW_Init(VarintVectorWriter *w, size_t cap) { w->lastValue = 0; w->nmemb = 0; Buffer_Init(&w->buf, cap); }
/*********************************************************************//** * @brief c_entry: Main SPI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; SPI_DATA_SETUP_Type xferConfig; /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PinCfg.Funcnum = 0; PINSEL_ConfigPin(&PinCfg); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); SPI_ConfigStruct.CPHA = SPI_CPHA_SECOND; SPI_ConfigStruct.CPOL = SPI_CPOL_LO; SPI_ConfigStruct.ClockRate = 2000000; SPI_ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST; SPI_ConfigStruct.Databit = SPI_DATABIT_SIZE; SPI_ConfigStruct.Mode = SPI_MASTER_MODE; // Initialize SPI peripheral with parameter given in structure above SPI_Init(LPC_SPI, &SPI_ConfigStruct); /* Initialize Buffer */ Buffer_Init(); xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete"); SPI_DeInit(LPC_SPI); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief Main SSP program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; PINSEL_CFG_Type PinCfg; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initializing SSP device section ------------------------------------------------------ */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP0, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP0, ENABLE); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Initializing Buffer section ----------------------------------------------------------- */ Buffer_Init(); /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Configure GPDMA channel 0 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &dma_src; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(dma_src); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_SSP0_Tx; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback0); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &dma_dst; // Transfer size GPDMACfg.TransferSize = sizeof(dma_dst); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_SSP0_Rx; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback1); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; _DBG_("Start transfer..."); // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP0, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP0, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ while(1); return 1; }