Exemplo n.º 1
0
/**
 * Brief Transmit Done Interrupt Callback function
 */
void TxDone_UsrCBS(void)
{
	TxDoneCount++;
	_DBG_("Tx done");
}
Exemplo n.º 2
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	PINSEL_CFG_Type PinCfg;
	EXTI_InitTypeDef EXTICfg;

	/* 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 LEDs
	 * - If using MCB1700 board:
	 * 		LEDs: P1.28 and P1.29 are available
	 * - If using IAR1700 board:
	 * 		LEDs: LED1(P1.25) and LED2(P0.4) are available
	 * Turn off LEDs after initialize
	 */
	InitLED();

	/* Initialize EXT pin and registers
	 * - If using MCB1700 board: EXTI0 is configured
	 * - If using IAR1700 board: EXTI2 is configured
	 */
#ifdef MCB_LPC_1768
	/* P2.10 as /EINT0 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 10;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);
#elif defined (IAR_LPC_1768)
	/* P2.12 as /EINT2 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 12;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);
#endif

	EXTI_Init();

	EXTICfg.EXTI_Line = _EXTINT;
	/* edge sensitive */
	EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
	EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
	EXTI_ClearEXTIFlag(_EXTINT);
	EXTI_Config(&EXTICfg);

	NVIC_SetPriorityGrouping(4);
	NVIC_SetPriority(_EXT_IRQ, 0);
	NVIC_EnableIRQ(_EXT_IRQ);

	_DBG_("First LED is blinking in normal mode...\n\r"	\
		  "Press '1' to enter system in sleep mode.\n\r"\
		  "If you want to wake-up the system, press INT/WAKE-UP button.");
	while(_DG !='1')
	{
		//Blink first LED
#ifdef MCB_LPC_1768
		//blink LED P1.28
		GPIO_SetValue(1, (1<<28));
		delay();
		GPIO_ClearValue(1, (1<<28));
		delay();
#elif defined (IAR_LPC_1768)
		//blink LED1 (P1.25)
		GPIO_SetValue(1, (1<<25));
		delay();
		GPIO_ClearValue(1, (1<<25));
		delay();
#endif
	}

	_DBG_("Sleeping...");
	// Enter target power down mode
	CLKPWR_Sleep();

	// MCU will be here after waking up
	_DBG_("System wake-up! Second LED is blinking...");
	//turn off first LED
#ifdef MCB_LPC_1768
	GPIO_ClearValue(1, (1<<29));
#elif defined (IAR_LPC_1768)
	GPIO_SetValue(1, (1<<25));
#endif
	while (1)
	{
		//Blink second LED
#ifdef MCB_LPC_1768
		//blink LED P1.29
		GPIO_SetValue(1, (1<<29));
		delay();
		GPIO_ClearValue(1, (1<<29));
		delay();
#elif defined (IAR_LPC_1768)
		//blink LED2 (P0.4)
		GPIO_SetValue(0, (1<<4));
		delay();
		GPIO_ClearValue(0, (1<<4));
		delay();
#endif
	}
}
Exemplo n.º 3
0
/*********************************************************************//**
 * @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);
}
Exemplo n.º 4
0
void printCoords(int32_t x, int32_t y, int32_t t) {
    _DBG_("The coordinate position of the Pololu robot is: ( ");_DBD32(x);_DBG_(" , ");_DBD32(y);_DBG_(" , ");_DBD32(t);_DBG_(" )");
}
Exemplo n.º 5
0
/**
 * @brief Main program body
 */
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	GPDMA_Channel_CFG_Type GPDMACfg;
	uint32_t adc_value, tmp;

	// 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 -------------------------------------------- */

	/* Disable GPDMA interrupt */
	NVIC_DisableIRQ(DMA_IRQn);
	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01));

	/*
	 * Init LPC_ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);

	/* Configuration for ADC :
	 * 	Frequency at 1Mhz
	 *  ADC channel 2, generate interrupt to make a request for DMA source
	 */
	ADC_Init(LPC_ADC, 1000000);
	ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,SET);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,SET);

	/* Initialize GPDMA controller */
	GPDMA_Init();

	// Setup GPDMA channel --------------------------------
	// channel 0
	GPDMACfg.ChannelNum = 0;
	// Source memory - unused
	GPDMACfg.SrcMemAddr = 0;
	// Destination memory
	GPDMACfg.DstMemAddr = (uint32_t) &adc_value;
	// Transfer size
	GPDMACfg.TransferSize = DMA_SIZE;
	// Transfer width - unused
	GPDMACfg.TransferWidth = 0;
	// Transfer type
	GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M;
	// Source connection
	GPDMACfg.SrcConn = GPDMA_CONN_ADC;
	// 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;

	/* Enable GPDMA interrupt */
	NVIC_EnableIRQ(DMA_IRQn);

	while (1) {

		// Enable GPDMA channel 0
		GPDMA_ChannelCmd(0, ENABLE);

		ADC_StartCmd(LPC_ADC,ADC_START_NOW);
		/* Wait for GPDMA processing complete */;
		while ((Channel0_TC == 0) );

		// Disable GPDMA channel 0
		GPDMA_ChannelCmd(0, DISABLE);

		//Display the result of conversion on the UART0
		_DBG("ADC value on channel 2: ");
		_DBD32(ADC_DR_RESULT(adc_value));
		_DBG_("");

		// Wait for a while
		for(tmp = 0; tmp < 1000000; tmp++);

		// Re-setup channel
		GPDMA_Setup(&GPDMACfg, GPDMA_Callback);

		/* Reset terminal counter */
		Channel0_TC = 0;
		/* Reset Error counter */
		Channel0_Err = 0;
	}
	ADC_DeInit(LPC_ADC);
	return 1;
}
Exemplo n.º 6
0
/*********************************************************************//**
 * @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;
}
Exemplo n.º 7
0
void attach() {
    _DBG_("I'm attached, YAY!");
}
Exemplo n.º 8
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	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;
}
Exemplo n.º 10
0
/*********************************************************************//**
 * @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) {                       /* 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;
}
Exemplo n.º 12
0
/* Init the LPC17xx ethernet */
BOOL_8 tapdev_init(void)
{
	/* EMAC configuration type */
	EMAC_CFG_Type Emac_Config;
	/* pin configuration */
	PINSEL_CFG_Type PinCfg;
	/* EMAC address */
	uint8_t EMACAddr[] = {EMAC_ADDR0, EMAC_ADDR1, EMAC_ADDR2, \
						EMAC_ADDR3, EMAC_ADDR4, EMAC_ADDR5};

#if AUTO_NEGOTIATION_ENA != 0
	Emac_Config.Mode = EMAC_MODE_AUTO;
#else
	#if (FIX_SPEED == SPEED_100)
		#if (FIX_DUPLEX == FULL_DUPLEX)
			Emac_Config.Mode = EMAC_MODE_100M_FULL;
		#elif (FIX_DUPLEX == HALF_DUPLEX)
			Emac_Config.Mode = EMAC_MODE_100M_HALF;
		#else
			#error Does not support this duplex option
		#endif
	#elif (FIX_SPEED == SPEED_10)
		#if (FIX_DUPLEX == FULL_DUPLEX)
				Emac_Config.Mode = EMAC_MODE_10M_FULL;
		#elif (FIX_DUPLEX == HALF_DUPLEX)
				Emac_Config.Mode = EMAC_MODE_10M_HALF;
		#else
			#error Does not support this duplex option
		#endif
	#else
		#error Does not support this speed option
	#endif
#endif

	/*
	 * Enable P1 Ethernet Pins:
	 * P1.0 - ENET_TXD0
	 * P1.1 - ENET_TXD1
	 * P1.4 - ENET_TX_EN
	 * P1.8 - ENET_CRS
	 * P1.9 - ENET_RXD0
	 * P1.10 - ENET_RXD1
	 * P1.14 - ENET_RX_ER
	 * P1.15 - ENET_REF_CLK
	 * P1.16 - ENET_MDC
	 * P1.17 - ENET_MDIO
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;

	PinCfg.Pinnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 1;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 4;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 8;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 9;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 10;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 14;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 15;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 16;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 17;
	PINSEL_ConfigPin(&PinCfg);

	_DBG_("Init EMAC module");
	sprintf(db,"MAC addr: %X-%X-%X-%X-%X-%X \n\r", \
			 EMACAddr[0],  EMACAddr[1],  EMACAddr[2], \
			  EMACAddr[3],  EMACAddr[4],  EMACAddr[5]);
	DB;

	Emac_Config.Mode = EMAC_MODE_AUTO;
	Emac_Config.pbEMAC_Addr = EMACAddr;
	// Initialize EMAC module with given parameter
	if (EMAC_Init(&Emac_Config) == ERROR){
		return (FALSE);
	}

	_DBG_("Init EMAC complete");

	return (TRUE);
}
Exemplo n.º 13
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{

	/* Data Packet format */
	EMAC_PACKETBUF_Type DataPacket;

	uint8_t *txptr;
	uint32_t i = 0;

#if TX_ONLY
	uint32_t j;
#endif

#if BOUNCE_RX
	uint8_t *rxptr;
#endif

#if ENABLE_HASH
	uint8_t dstAddr[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
#endif

	/* Initialize system clock */
	SystemInit();

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

	NVIC_SetPriorityGrouping(4);  //sets PRIGROUP to 3:2 (XXX:YY)

	/*
	 * Init LED
	 */
	LED_Init();

	/*
	 * Initialize debug via UART
	 */
	debug_frmwrk_init();

	// Init EMAC
	Usr_Init_Emac();


#if TX_ONLY
	EINT0_Init();
	txptr = (uint8_t *)gTxBuf;
	/* pre-format the transmit packets */
	PacketGen(txptr);
#endif

#if ENABLE_HASH
  EMAC_SetHashFilter(dstAddr, ENABLE);
#endif


#if BOUNCE_RX
  /* copy just received data from RX buffer to TX buffer and send out */
  txptr = (uint8_t *)gTxBuf;
  rxptr = (uint8_t *)gRxBuf;
#endif

#if ENABLE_WOL

  _DBG_("Enter Sleep mode now...");
  /*
   * On default state, All Multicast frames, All Broadcast frames and Frame that matched
   * with station address (unicast) are accepted.
   * To make WoL is possible, enable Rx Magic Packet and RxFilter Enable WOL
   */
  EMAC_SetFilterMode((EMAC_RFC_PFILT_WOL_EN | EMAC_RFC_MAGP_WOL_EN), ENABLE);

	for (i = 0; i < 5; i++){
		LED_Blink(PD_LED_PIN);	/* Indicating system is in power down now. */
	}

	// Disable irq interrupt
	__disable_irq();

	/* Currently, support Sleep mode */
    /* enter sleep mode */
    LPC_SC->PCON = 0x0;

    /* Sleep Mode*/
    __WFI();

    // CPU will be suspend here...

	/* From power down to WOL, the PLL needs to be reconfigured,
	otherwise, the CCLK will be generated from 4Mhz IRC instead
	of main OSC 12Mhz */
	/* Initialize system clock */
	SystemInit();

	/*
	 * Initialize debug via UART
	 */
	debug_frmwrk_init();
	/*
	 * Init LED
	 */
	LED_Init();
	_DBG_("Wake up from sleep mode");

	/* Calling EMACInit() is overkill which also initializes the PHY, the
	main reason to do that is to make sure the descriptors and descriptor
	status for both TX and RX are clean and ready to use. It won't go wrong. */
	Usr_Init_Emac();
	// Re-Enable irq interrupt
	__enable_irq();

#endif										/* endif ENABLE_WOL */

#if BOUNCE_RX
while( 1 )
{
	LED_Blink(BLINK_LED_PIN);
	if ( PacketReceived == TRUE )
	{
	  PacketReceived = FALSE;
		/* Reverse Source and Destination, then copy the body */
		memcpy( (uint8_t *)txptr, (uint8_t *)(rxptr+6), 6);
		memcpy( (uint8_t *)(txptr+6), (uint8_t *)rxptr, 6);
		memcpy( (uint8_t *)(txptr+12), (uint8_t *)(rxptr+12), (ReceiveLength - 12));
		_DBG_("Send packet");
		DataPacket.pbDataBuf = (uint32_t *)txptr;
		DataPacket.ulDataLen = ReceiveLength;
		EMAC_WritePacketBuffer(&DataPacket);
		EMAC_UpdateTxProduceIndex();
	}
}
#endif										/* endif BOUNCE_RX */

#if TX_ONLY
	/* Transmit packets only */
	while ( 1 ) {
		while (Pressed == RESET){
			LED_Blink(BLINK_LED_PIN);
		}
		Pressed = RESET;
		txptr = (uint8_t *)gTxBuf;
		_DBG_("Send packet");
		LED_Blink(TX_LED_PIN);
		DataPacket.pbDataBuf = (uint32_t *)txptr;
		// Note that there're 4-byte CRC added
		DataPacket.ulDataLen = TX_PACKET_SIZE + 4;
		EMAC_WritePacketBuffer(&DataPacket);
		EMAC_UpdateTxProduceIndex();
		for ( j = 0; j < 0x200000; j++ );	/* delay */
	}
#endif										/* endif TX_ONLY */

  return 0;
}
Exemplo n.º 14
0
/**
 * User EMAC initialization
 */
void Usr_Init_Emac(void)
{
	/* EMAC configuration type */
	EMAC_CFG_Type Emac_Config;
	/* pin configuration */
	PINSEL_CFG_Type PinCfg;
	uint32_t i;


	/*
	 * Enable P1 Ethernet Pins:
	 * P1.0 - ENET_TXD0
	 * P1.1 - ENET_TXD1
	 * P1.4 - ENET_TX_EN
	 * P1.8 - ENET_CRS
	 * P1.9 - ENET_RXD0
	 * P1.10 - ENET_RXD1
	 * P1.14 - ENET_RX_ER
	 * P1.15 - ENET_REF_CLK
	 * P1.16 - ENET_MDC
	 * P1.17 - ENET_MDIO
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;

	PinCfg.Pinnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 1;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 4;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 8;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 9;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 10;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 14;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 15;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 16;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 17;
	PINSEL_ConfigPin(&PinCfg);

	_DBG_("Init EMAC module");
	sprintf(db_,"MAC[1..6] addr: %X-%X-%X-%X-%X-%X \n\r", \
			 EMACAddr[0],  EMACAddr[1],  EMACAddr[2], \
			  EMACAddr[3],  EMACAddr[4],  EMACAddr[5]);
	DB;

	Emac_Config.Mode = EMAC_MODE_AUTO;
	Emac_Config.pbEMAC_Addr = EMACAddr;
	// Initialize EMAC module with given parameter
	while (EMAC_Init(&Emac_Config) == ERROR){
		// Delay for a while then continue initializing EMAC module
		_DBG_("Error during initializing EMAC, restart after a while");
		for (i = 0x100000; i; i--);
	}
	_DBG_("Setup callback functions");
	// Setup callback functions
	EMAC_SetupIntCBS(EMAC_INT_RX_OVERRUN, RxOverrun_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_RX_ERR, RxError_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_RX_FIN, RxFinish_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_RX_DONE, RxDone_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_TX_UNDERRUN, TxUnderrun_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_TX_ERR, TxError_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_TX_FIN, TxFinish_UsrCBS);
	EMAC_SetupIntCBS(EMAC_INT_TX_DONE, TxDone_UsrCBS);
#if ENABLE_WOL
	EMAC_SetupIntCBS(EMAC_INT_WAKEUP, WoL_UsrCBS);
#endif
	// Enable all interrupt
	EMAC_IntCmd((EMAC_INT_RX_OVERRUN | EMAC_INT_RX_ERR | EMAC_INT_RX_FIN \
			| EMAC_INT_RX_DONE | EMAC_INT_TX_UNDERRUN | EMAC_INT_TX_ERR \
			| EMAC_INT_TX_FIN | EMAC_INT_TX_DONE), ENABLE);
	NVIC_SetPriority(ENET_IRQn, 0);
	NVIC_EnableIRQ(ENET_IRQn);
	_DBG_("Initialize EMAC complete");
}
/*********************************************************************//**
 * @brief		c_entry: Main ADC 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();

	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);

	/*
	 * Init P2.10
	 *
	 */
	PinCfg.Funcnum = 1; //EINT0
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 10;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);

	/* Configuration for ADC:
	 *  select: ADC channel 2 (if using MCB1700 board)
	 *  		ADC channel 5 (if using IAR-LPC1768 board)
	 *  ADC conversion rate = 200KHz
	 */
	ADC_Init(LPC_ADC, 200000);
	ADC_IntConfig(LPC_ADC,_ADC_INT,ENABLE);
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
	ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING);

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(ADC_IRQn, ((0x01<<3)|0x01));

	while(1)
	{
		adc_value = 0;

		// Start conversion on EINT0 falling edge
		ADC_StartCmd(LPC_ADC,ADC_START_ON_EINT0);

		/* Enable ADC in NVIC */
		NVIC_EnableIRQ(ADC_IRQn);

		_DBG("Press INT0 button to start ADC conversion on AD0.2...");_DBG_("");
		while(adc_value==0);

		//Display the result of conversion on the UART0
		_DBG("ADC value on channel 2: ");

		_DBD32(adc_value);
		_DBG_("");
	}
	ADC_DeInit(LPC_ADC);
	return (0);
}
Exemplo n.º 16
0
/*************************************************************************
 * Function Name: uip_log
 * Parameters: none
 *
 * Return: none
 *
 * Description: Events logging
 *
 *************************************************************************/
void uip_log (char *m)
{
	_DBG("uIP log message: ");
	_DBG(m);
	_DBG_("");
}
Exemplo n.º 17
0
/*********************************************************************//**
 * @brief		Error Loop (called by Buffer_Verify() if any error)
 * @param[in]	none
 * @return 		None
 **********************************************************************/
void Error_Loop(void)
{
	/* Loop forever */
	_DBG_("Verify fail!\n\r");
	while (1);
}
Exemplo n.º 18
0
/*************************************************************************
 * Function Name: main
 * Parameters: none
 *
 * Return: none
 *
 * Description: main
 *
 *************************************************************************/
int c_entry(void)
{
	UNS_32 i, delay;
	uip_ipaddr_t ipaddr;
	struct timer periodic_timer, arp_timer;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	_DBG_("Hello NXP Semiconductors");
	_DBG_("uIP porting on LPC17xx");


	// Initialize LED for system tick timer
	LED_Init();

	_DBG_("Init Clock");
	// Sys timer init 1/100 sec tick
	clock_init();

	timer_set(&periodic_timer, CLOCK_SECOND / 2); /*0.5s */
	timer_set(&arp_timer, CLOCK_SECOND * 10);	/*10s */

	_DBG_("Init EMAC");
	// Initialize the ethernet device driver
	while(!tapdev_init()){
		// Delay for a while then continue initializing EMAC module
		_DBG_("Error during initializing EMAC, restart after a while");
		for (delay = 0x100000; delay; delay--);
	}


#if 1

	_DBG_("Init uIP");
	// Initialize the uIP TCP/IP stack.
	uip_init();

	// init MAC address
	uip_ethaddr.addr[0] = EMAC_ADDR0;
	uip_ethaddr.addr[1] = EMAC_ADDR1;
	uip_ethaddr.addr[2] = EMAC_ADDR2;
	uip_ethaddr.addr[3] = EMAC_ADDR3;
	uip_ethaddr.addr[4] = EMAC_ADDR4;
	uip_ethaddr.addr[5] = EMAC_ADDR5;
	uip_setethaddr(uip_ethaddr);


	uip_ipaddr(ipaddr, 192,168,0,100);
	sprintf(_db, "Set own IP address: %d.%d.%d.%d \n\r", \
			((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], \
			((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3]);
	DB;
	uip_sethostaddr(ipaddr);

	uip_ipaddr(ipaddr, 192,168,0,1);
	sprintf(_db, "Set Router IP address: %d.%d.%d.%d \n\r", \
			((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], \
			((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3]);
	DB;
	uip_setdraddr(ipaddr);

	uip_ipaddr(ipaddr, 255,255,255,0);
	sprintf(_db, "Set Subnet mask: %d.%d.%d.%d \n\r", \
			((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], \
			((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3]);
	DB;
	uip_setnetmask(ipaddr);

	// Initialize the HTTP server ----------------------------
	_DBG_("Init HTTP");
	httpd_init();
	_DBG_("Init complete!");

  while(1)
  {
    uip_len = tapdev_read(uip_buf);
    if(uip_len > 0)
    {
      if(BUF->type == htons(UIP_ETHTYPE_IP))
      {
	      uip_arp_ipin();
	      uip_input();
	      /* If the above function invocation resulted in data that
	         should be sent out on the network, the global variable
	         uip_len is set to a value > 0. */

	      if(uip_len > 0)
        {
	        uip_arp_out();
	        tapdev_send(uip_buf,uip_len);
	      }
      }
      else if(BUF->type == htons(UIP_ETHTYPE_ARP))
      {
        uip_arp_arpin();
	      /* If the above function invocation resulted in data that
	         should be sent out on the network, the global variable
	         uip_len is set to a value > 0. */
	      if(uip_len > 0)
        {
	        tapdev_send(uip_buf,uip_len);
	      }
      }
    }
    else if(timer_expired(&periodic_timer))
    {
      timer_reset(&periodic_timer);
      for(i = 0; i < UIP_CONNS; i++)
      {
      	uip_periodic(i);
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if(uip_len > 0)
        {
          uip_arp_out();
          tapdev_send(uip_buf,uip_len);
        }
      }
#if UIP_UDP
      for(i = 0; i < UIP_UDP_CONNS; i++) {
        uip_udp_periodic(i);
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if(uip_len > 0) {
          uip_arp_out();
          tapdev_send();
        }
      }
#endif /* UIP_UDP */
      /* Call the ARP timer function every 10 seconds. */
      if(timer_expired(&arp_timer))
      {
        timer_reset(&arp_timer);
        uip_arp_timer();
      }
    }
  }
#endif

  while (1);
}
Exemplo n.º 19
0
/*********************************************************************//**
 * @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;
	uint32_t tmp;

	/*
	 * 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);

	_DBG_("Press '1' to start transfer...");

	while (_DG != '1');

	_DBG_("Init buffer");
	/* Initialize Buffer */
	Buffer_Init();

	CS_Init();

	_DBG_("Start transfer...");
	CS_Force(0);
	// delay for a while
	for (tmp = 10000; tmp; tmp--);
	xferConfig.tx_data = Tx_Buf;
	xferConfig.rx_data = Rx_Buf;
	xferConfig.length = BUFFER_SIZE;
	SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING);
	// delay for a while
	for (tmp = 10000; tmp; tmp--);
	CS_Force(1);
	_DBG_("Complete!");

	// Verify buffer after transferring
	Buffer_Verify();
	_DBG_("Verify complete!");
	SPI_DeInit(LPC_SPI);
    /* Loop forever */
    while(1);
    return 1;
}
Exemplo n.º 20
0
/******************************************************************************
			RPC IPC Buffer Pool Config Init
*******************************************************************************/
RPC_Result_t RPC_IPC_Init(RpcProcessorType_t rpcProcType)
{
	PACKET_InterfaceType_t itype;
	Int8 index;
	int ret;

#if defined(CNEON_COMMON) && defined(FUSE_APPS_PROCESSOR)
	/* wait for CP RPC ready - need to find better way */
	OSTASK_Sleep(TICKS_ONE_SECOND / 10);
#endif /* (CNEON_COMMON) && (FUSE_APPS_PROCESSOR) */
	memset(ipcBufList, 0, sizeof(ipcBufList));

	for (itype = INTERFACE_START; itype < INTERFACE_TOTAL; itype++) {

		if (itype >= INTERFACE_CAPI2 && itype < INTERFACE_PACKET) {
			ipcBufList[itype].max_pkts[0] = CFG_RPC_CMD_MAX_PACKETS;
			ipcBufList[itype].max_pkts[1] =
			    CFG_RPC_CMD_MAX_PACKETS2;
			ipcBufList[itype].max_pkts[2] =
			    CFG_RPC_CMD_MAX_PACKETS3;

			ipcBufList[itype].pkt_size[0] = CFG_RPC_CMD_PKT_SIZE;
			ipcBufList[itype].pkt_size[1] = CFG_RPC_CMD_PKT_SIZE2;
			ipcBufList[itype].pkt_size[2] = CFG_RPC_CMD_PKT_SIZE3;

			ipcBufList[itype].start_threshold =
			    CFG_RPC_CMD_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_CMD_END_THRESHOLD;

			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_Capi2Cp : IPC_EP_Capi2App;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_Capi2App : IPC_EP_Capi2Cp;
		} else if (itype == INTERFACE_DRX) {
			ipcBufList[itype].max_pkts[0] = CFG_RPC_DRX_MAX_PACKETS;
			ipcBufList[itype].pkt_size[0] = CFG_RPC_DRX_PKT_SIZE;

			ipcBufList[itype].start_threshold =
			    CFG_RPC_DRX_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_DRX_END_THRESHOLD;

			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_DrxCP : IPC_EP_DrxAP;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_DrxAP : IPC_EP_DrxCP;
		} else if (itype == INTERFACE_PACKET) {
			for (index = 0; index < MAX_CHANNELS; index++) {
				ipcBufList[itype].pkt_size[(int)index] =
				    CFG_RPC_PKTDATA_PKT_SIZE;
				ipcBufList[itype].max_pkts[(int)index] =
				    (rpcProcType ==
				     RPC_COMMS) ?
				    CFG_RPC_PKTDATA_MAX_NW2TE_PACKETS :
				    CFG_RPC_PKTDATA_MAX_TE2NW_PACKETS;
			}
			ipcBufList[itype].start_threshold =
			    CFG_RPC_PKT_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_PKT_END_THRESHOLD;

			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_PsCpData : IPC_EP_PsAppData;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_PsAppData : IPC_EP_PsCpData;
		} else if (itype == INTERFACE_USB_EEM) {
			for (index = 0; index < MAX_CHANNELS; index++) {
				ipcBufList[itype].pkt_size[(int)index] =
				    CFG_RPC_EEMDATA_PKT_SIZE;
				ipcBufList[itype].max_pkts[(int)index] =
				    CFG_RPC_EEMDATA_MAX_PACKETS;
			}
			ipcBufList[itype].start_threshold =
			    CFG_RPC_EEM_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_EEM_END_THRESHOLD;

#ifdef IPC_EP_EemAP
			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_EemCP : IPC_EP_EemAP;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_EemAP : IPC_EP_EemCP;
#endif
		} else if (itype == INTERFACE_CSD) {
			for (index = 0; index < MAX_CHANNELS; index++) {
				ipcBufList[itype].pkt_size[(int)index] =
				    CFG_RPC_CSDDATA_PKT_SIZE;
				ipcBufList[itype].max_pkts[(int)index] =
				    CFG_RPC_CSDDATA_MAX_PACKETS;
			}
			ipcBufList[itype].start_threshold =
			    CFG_RPC_CSD_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_CSD_END_THRESHOLD;

			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_CsdCpCSDData :
			    IPC_EP_CsdAppCSDData;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_CsdAppCSDData :
			    IPC_EP_CsdCpCSDData;
		} else if (itype == INTERFACE_LOGGING) {
#if !defined(UNDER_CE) &&  !defined(UNDER_LINUX)	/*modify for UDP log */
			for (index = 0; index < MAX_CHANNELS; index++) {
				ipcBufList[itype].pkt_size[index] =
				    CFG_RPC_LOG_PKT_SIZE;
				ipcBufList[itype].max_pkts[index] =
				    CFG_RPC_LOG_MAX_PACKETS;
			}
			ipcBufList[itype].start_threshold =
			    CFG_RPC_LOG_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_LOG_END_THRESHOLD;

			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_LogCp : IPC_EP_LogApps;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_LogApps : IPC_EP_LogCp;
#endif
		} else if (itype == INTERFACE_SERIAL) {
			ipcBufList[itype].max_pkts[0] =
			    CFG_RPC_SERIALDATA_MAX_PACKETS;
			ipcBufList[itype].max_pkts[1] =
			    CFG_RPC_SERIALDATA_MAX_PACKETS2;

			ipcBufList[itype].pkt_size[0] =
			    CFG_RPC_SERIALDATA_PKT_SIZE;
			ipcBufList[itype].pkt_size[1] =
			    CFG_RPC_SERIALDATA_PKT_SIZE2;

			ipcBufList[itype].start_threshold =
			    CFG_RPC_SERIAL_START_THRESHOLD;
			ipcBufList[itype].end_threshold =
			    CFG_RPC_SERIAL_END_THRESHOLD;

			ipcBufList[itype].srcEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_SerialCP : IPC_EP_SerialAP;
			ipcBufList[itype].destEpId =
			    (rpcProcType ==
			     RPC_COMMS) ? IPC_EP_SerialAP : IPC_EP_SerialCP;
		} else
			xassert(0, itype);

	}

	RPC_LOCK_INIT;

#ifdef USE_KTHREAD_HANDOVER
	ret = MsgQueueInit(&rpcMQhandle, rpcKthreadFn,
			   "RpcKThread", 0, NULL, "krpc_wake_lock");

	if (ret != 0) {
		_DBG_(RPC_TRACE("RPC_IPC_Init: MsgQueueInit failed\n"));
		printk(KERN_CRIT "RPC_IPC_Init: MsgQueueInit fail\n");
		return RPC_RESULT_ERROR;
	}
#endif
	sCPResetting = FALSE;
	sIsNotifyingCPReset = FALSE;
	/* register notification handler for silent CP reset */
	sIPCResetClientId =
	    IPCAP_RegisterCPResetHandler(RPC_PACKET_RPCNotificationHandler);

	rpc_wake_lock_init();
	recvRpcPkts = 0;
	freeRpcPkts = 0;
	return RPC_RESULT_OK;
}
Exemplo n.º 21
0
void detach() {
    _DBG_("I'm detached, BOO!");
    printCoords(coord_x, coord_y, convertToDeg(theta));
}
Exemplo n.º 22
0
PACKET_BufHandle_t RPC_PACKET_AllocateBufferEx(PACKET_InterfaceType_t
					       interfaceType,
					       UInt32 requiredSize,
					       UInt8 channel, UInt32 waitTime)
{
	int index = -1;
	IPC_Buffer bufHandle = 0;

	if (sCPResetting) {
		_DBG_(RPC_TRACE
		      ("RPC_PACKET_AllocateBufferEx: cp resetting, ignore req\n"));
		return NULL;
	}

	/*Determine the pool index for the interface */
	RPC_LOCK;
	if (interfaceType == INTERFACE_PACKET) {
		index = 0;	/*All channels use the same buffer pool */
	} else {
		for (index = 0; index < MAX_CHANNELS; index++) {
			if (ipcBufList[interfaceType].pkt_size[index] >=
			    requiredSize)
				break;
		}
		if (index >= MAX_CHANNELS) {
			_DBG_(RPC_TRACE
			      ("RPC_PACKET_AllocateBuffer itype=%d invalid channel %d\r\n",
			       interfaceType, index));
			RPC_UNLOCK;
			return NULL;
		}
	}

	/*Create the pool om demand */
	if (ipcInfoList[interfaceType].ipc_buf_pool[index] == 0)
		RPC_CreateBufferPool(interfaceType, index);

	if (interfaceType == INTERFACE_PACKET && DETAIL_DATA_LOG_ENABLED)
		_DBG_(RPC_TRACE_DATA_DETAIL
		      ("RPC_PACKET_AllocateBuffer(%c) PKT BEFORE %d\r\n",
		       (gRpcProcType == RPC_COMMS) ? 'C' : 'A', requiredSize));

	RPC_UNLOCK;
	if (waitTime == PKT_ALLOC_NOWAIT)
		bufHandle =
		    IPC_AllocateBuffer(ipcInfoList[interfaceType].ipc_buf_pool
				       [index]);
	else
		bufHandle =
		    IPC_AllocateBufferWait(ipcInfoList
					   [interfaceType].ipc_buf_pool[index],
					   waitTime);

	if (interfaceType == INTERFACE_PACKET && DETAIL_DATA_LOG_ENABLED)
		_DBG_(RPC_TRACE_DATA_DETAIL
		      ("RPC_PACKET_AllocateBuffer(%c) PKT AFTER %d\r\n",
		       (gRpcProcType == RPC_COMMS) ? 'C' : 'A', requiredSize));

	if (0 == bufHandle) {
		_DBG_(RPC_TRACE
		      ("RPC_PACKET_AllocateBuffer failed %d, %d, %d\r\n",
		       (int)interfaceType, (int)requiredSize, (int)index));
	}

	if (bufHandle)
		IPC_BufferSetDataSize(bufHandle, requiredSize);

	return (PACKET_BufHandle_t) bufHandle;
}
Exemplo n.º 23
0
/*********************************************************************//**
 * @brief       c_entry: Main MCPWM program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry(void)
{
    // MCPWM Channel configuration data
    MCPWM_CHANNEL_CFG_Type channelsetup[3];

    uint32_t i;

    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    _DBG_(menu);

    /* Pin configuration for MCPWM function:
     * Assign:  - P1.19 as MCOA0 - Motor Control Channel 0 Output A
     *          - P1.22 as MCOB0 - Motor Control Channel 0 Output B
     *          - P1.25 as MCOA1 - Motor Control Channel 1 Output A
     *          - P1.26 as MCOB1 - Motor Control Channel 1 Output B
     *          - P1.28 as MCOA2 - Motor Control Channel 2 Output A
     *          - P1.29 as MCOB2 - Motor Control Channel 2 Output B
     *          - P1.20 as MCI0  - Motor Control Feed Back Channel 0
     * Warning: According to Errata.lpc1768-18.March.2010: Input pin (MIC0-2)
     * on the Motor Control PWM peripheral are not functional
     */

    //MCOA0 — Motor control PWM channel 0, output A
    PINSEL_ConfigPin (1, 19, 4);

    //MCI0 — Motor control PWM channel 0 input
    PINSEL_ConfigPin (1, 20, 4);

    //MCOB0 — Motor control PWM channel 0, output B
    PINSEL_ConfigPin (1, 22, 4);

    // Motor control PWM channel 1, output A.
    PINSEL_ConfigPin (1, 25, 4);

    //MCOB1 — Motor control PWM channel 1, output B.
    PINSEL_ConfigPin (1, 26, 4);

    //MCOA2 — Motor control PWM channel 2, output A.
    PINSEL_ConfigPin (1, 28, 4);

    //MCOB2 — Motor control PWM channel 2, output B.
    PINSEL_ConfigPin (1, 29, 1);

    /* Disable interrupt for MCPWM  */
    NVIC_DisableIRQ(MCPWM_IRQn);

    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(MCPWM_IRQn, ((0x01<<3)|0x01));

    /* Init MCPWM peripheral */
    MCPWM_Init(LPC_MCPWM);

    channelsetup[0].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[0].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[0].channelDeadtimeEnable = DISABLE;
    channelsetup[0].channelDeadtimeValue = 0;
    channelsetup[0].channelUpdateEnable = ENABLE;
    channelsetup[0].channelTimercounterValue = 0;
    channelsetup[0].channelPeriodValue = 300;
    channelsetup[0].channelPulsewidthValue = 0;

    channelsetup[1].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[1].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[1].channelDeadtimeEnable = DISABLE;
    channelsetup[1].channelDeadtimeValue = 0;
    channelsetup[1].channelUpdateEnable = ENABLE;
    channelsetup[1].channelTimercounterValue = 0;
    channelsetup[1].channelPeriodValue = 300;
    channelsetup[1].channelPulsewidthValue = 100;

    channelsetup[2].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[2].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[2].channelDeadtimeEnable = DISABLE;
    channelsetup[2].channelDeadtimeValue = 0;
    channelsetup[2].channelUpdateEnable = ENABLE;
    channelsetup[2].channelTimercounterValue = 0;
    channelsetup[2].channelPeriodValue = 300;
    channelsetup[2].channelPulsewidthValue = 200;

    MCPWM_ConfigChannel(LPC_MCPWM, MCPWM_CHANNEL_0, &channelsetup[0]);
    MCPWM_ConfigChannel(LPC_MCPWM, MCPWM_CHANNEL_1, &channelsetup[1]);
    MCPWM_ConfigChannel(LPC_MCPWM, MCPWM_CHANNEL_2, &channelsetup[2]);

#if (MCPWM_WORKING_MODE == DC_MODE_TEST)
    /*
     * - DC mode enabled.
     * - Invert Output enabled
     * - A0 and A1 output pin is internally routed to A0 signal
     */
    MCPWM_DCMode(LPC_MCPWM, ENABLE, ENABLE, (MCPWM_PATENT_A0|MCPWM_PATENT_A1));
#elif (MCPWM_WORKING_MODE == AC_MODE_TEST)
    // AC mode is enabled.
    MCPWM_ACMode(LPC_MCPWM, ENABLE);
#endif

#if CAPTURE_MODE_TEST
    /*
     * Capture mode in this case is used to detect the falling edge on MCO0B output pin.
     * The MCFB0 input pin therefore must be connected to MCO0B. (P1.20 - P1.22)
     * - Capture Channel 0.
     * - Capture falling edge on MCFB0 input pin.
     * - Interrupt enabled on capture event.
     */
    captureCfg.captureChannel = MCPWM_CHANNEL_0;
    captureCfg.captureFalling = ENABLE;
    captureCfg.captureRising = DISABLE;
    captureCfg.hnfEnable = DISABLE;
    captureCfg.timerReset = DISABLE;
    MCPWM_ConfigCapture(LPC_MCPWM, MCPWM_CHANNEL_0, &captureCfg);

    // Reset flag for the first time
    CapFlag = RESET;

    // Enable interrupt for capture event on MCI0 (MCFB0)
    MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE);

    /* Enable interrupt for MCPWM  */
    NVIC_EnableIRQ(MCPWM_IRQn);
#endif

    MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE);

    // Main loop
    while (1)
    {
        //delay
        for(i = 0; i < 100000; i++);

        channelsetup[0].channelPulsewidthValue = (channelsetup[0].channelPulsewidthValue >= 300) ?
                                                        0 : channelsetup[0].channelPulsewidthValue + 20;
        channelsetup[1].channelPulsewidthValue = (channelsetup[1].channelPulsewidthValue >= 300) ?
                                                        0 : channelsetup[1].channelPulsewidthValue + 20;
        channelsetup[2].channelPulsewidthValue = (channelsetup[2].channelPulsewidthValue >= 300) ?
                                                        0 : channelsetup[2].channelPulsewidthValue + 20;

        _DBG_("Update!");

        MCPWM_WriteToShadow(LPC_MCPWM, MCPWM_CHANNEL_0, &channelsetup[0]);
        MCPWM_WriteToShadow(LPC_MCPWM, MCPWM_CHANNEL_1, &channelsetup[1]);
        MCPWM_WriteToShadow(LPC_MCPWM, MCPWM_CHANNEL_2, &channelsetup[2]);

#if CAPTURE_MODE_TEST
        // Check capture flag is set or not
        if (CapFlag)
        {
            // Print out the value
            _DBG("Capture Value: ");

            _DBD32(CapVal); _DBG_("");

            // Must be re-configure the Capture Feature as below for the next capturing,
            //unless, it will not capture anything more.

            // Setup a new capture event
            MCPWM_ConfigCapture(LPC_MCPWM, MCPWM_CHANNEL_0, &captureCfg);

            // Re-Enable interrupt for capture event on MCI0 (MCFB0)
            MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE);

            // Reset flag
            CapFlag = RESET;
        }
#endif
    }

}
Exemplo n.º 24
0
static void RPC_BufferDelivery(IPC_Buffer bufHandle)
{
	PACKET_InterfaceType_t ifType;
	RPC_IPCInfo_t *pInfo;
	Int32 isReservedPkt = 0;
	int ret;
	RPC_Result_t result = RPC_RESULT_ERROR;
	UInt8 *pCid = (UInt8 *)IPC_BufferHeaderPointer(bufHandle);
	IPC_EndpointId_T destId = IPC_BufferDestinationEndpointId(bufHandle);
	int type = GetInterfaceType(destId);
	PACKET_BufHandle_t pktBufHandle = (PACKET_BufHandle_t) bufHandle;

	if (type == -1 || pCid == NULL) {
		IPC_FreeBuffer(bufHandle);
		_DBG_(RPC_TRACE("RPC_BufferDelivery FAIL pkt=%d t=%d cid=%d",
				pktBufHandle, type, pCid));
		return;
	}
	pInfo = &ipcInfoList[type];
	ifType = (PACKET_InterfaceType_t)type;
	if (pInfo->pktIndCb == NULL && pInfo->filterPktIndCb == NULL) {
		IPC_FreeBuffer(bufHandle);
		_DBG_(RPC_TRACE("RPC_BufferDelivery FAIL No Cbk pkt=%d\r\n",
				pktBufHandle));
		return;
	}
	if (ifType != INTERFACE_PACKET) {
		IPC_U32 uParam;
		/*For bckward compatibility, remove in future release */

		uParam = IPC_BufferUserParameterGet(bufHandle);
		if (uParam == CAPI2_RESERVE_POOL_ID) {
			/* TBD: Add recovery mechanism */
			IPC_FreeBuffer(bufHandle);
			_DBG_(RPC_TRACE
			      ("RPC_BufferDelivery RESERVED (Drop) h=%d if=%d rcvPkts=%d freePkts=%d\r\n",
			       (int)bufHandle, (int)type,
			       (int)recvRpcPkts, (int)freeRpcPkts));
			return;
		}

		isReservedPkt = RPC_PACKET_IsReservedPkt(pktBufHandle);
		/* Log incoming packet */
		rpcLogNewPacket(pktBufHandle, ifType, pInfo, pCid,
				isReservedPkt);

	}

	if (pInfo->pktIndCb != NULL && isReservedPkt == 0)
		result = pInfo->pktIndCb((PACKET_InterfaceType_t)type,
					 (UInt8)pCid[0], pktBufHandle);

	if (result == RPC_RESULT_PENDING)
		return;		/* Sysrpc packet come here */
	if (pInfo->filterPktIndCb == NULL) {
		IPC_FreeBuffer(bufHandle);
		rpcLogFreePacket((PACKET_InterfaceType_t)type, pktBufHandle);
		return;		/* net or vt interface pkt come here */
	}
#ifdef USE_KTHREAD_HANDOVER
	if (isReservedPkt &&
	    MsgQueueCount(&rpcMQhandle) >= CFG_RPC_CMD_MAX_PACKETS) {
		IPC_FreeBuffer(bufHandle);
		rpcLogFreePacket((PACKET_InterfaceType_t)type, pktBufHandle);
		_DBG_(RPC_TRACE("RPC_BufferDelivery(rz) RpcQ FULL h=%d c=%d\n",
				(int)bufHandle, MsgQueueCount(&rpcMQhandle)));
		return;
	}

	/* Post it to RPC Thread */
	ret = MsgQueueAdd(&rpcMQhandle, (void *)bufHandle);

	if (ret != 0) {
		IPC_FreeBuffer(bufHandle);
		rpcLogFreePacket((PACKET_InterfaceType_t)type, pktBufHandle);
		_DBG_(RPC_TRACE("RPC_BufferDelivery Queue FAIL h=%d r=%d\n",
				(int)bufHandle, ret));
		return;
	}
	RpcDbgUpdatePktState((int)bufHandle, PKT_STATE_RPC_POST);

	result = RPC_RESULT_PENDING;
#else
	/* If using workerqueue instead of tasklet,
	   filterPktIndCb can be called directly */
	result = pInfo->filterPktIndCb((PACKET_InterfaceType_t)type,
				       (UInt8)pCid[0], (PACKET_BufHandle_t)
				       bufHandle);
#endif

	/* If Packet not consumed by secondary client then return */

	//Coverity [DEADCODE]
	if (result != RPC_RESULT_PENDING) {
		/* Packet was never consumed */
		/* coverity [dead_error_line] */
		IPC_FreeBuffer(bufHandle);
		rpcLogFreePacket((PACKET_InterfaceType_t)type, pktBufHandle);
		_DBG_(RPC_TRACE("RPC_BufferDelivery filterCb FAIL h=%d r=%d\n",
				(int)bufHandle, ret));
		return;
	}

	_DBG_(RPC_TRACE("RPC_BufferDelivery filterCb OK h=%d\n",
			(int)bufHandle));
	return;
}
/*********************************************************************//**
 * @brief		c_entry: Main CAN program body
 * @param[in]	none
 * @return 		none
 **********************************************************************/
void c_entry(void)
{
	uint32_t i;
	volatile uint32_t cnt;
	CAN_ERROR error;

	CANRxCount = CANTxCount = 0;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	print_menu();

	/* Pin configuration
	 * CAN1: select P0.0 as RD1. P0.1 as TD1
	 * CAN2: select P0.4 as RD2, P0.5 as RD2
	 */

	PINSEL_ConfigPin (0, 0, 1);

	PINSEL_ConfigPin (0, 1, 1);

#if (RECVD_CAN_NO != CAN_1)
	PINSEL_ConfigPin (0, 4, 2);

	PINSEL_ConfigPin (0, 5, 2);
#endif

	//Initialize CAN1 & CAN2
	CAN_Init(CAN_1, 125000);

#if (RECVD_CAN_NO != CAN_1)
	CAN_Init(RECVD_CAN_NO, 125000);
#endif

	//Enable Receive Interrupt
	CAN_IRQCmd(RECVD_CAN_NO, CANINT_FCE, ENABLE);
	CAN_IRQCmd(RECVD_CAN_NO, CANINT_RIE, ENABLE);

	//Enable CAN Interrupt
	NVIC_EnableIRQ(CAN_IRQn);

	/* First, we send 10 messages:
	 * - message 0,2,4,6,8 have id in AFLUT >>> will be received
	 * - message 1,3,5,7,9 don't have id in AFLUT >>> will be ignored
	 * Then, we change AFLUT by load/remove entries in AFLUT and re-send messages
	 * - message 1,3,5,7,9 have id in AFLUT >>> will be received
	 * - message 0,2,4,6,8 don't have id in AFLUT >>> will be ignored
	 * Note that: FullCAN Object must be read from FullCAN Object Section next to AFLUT
	 */
	/*-------------------------Init Message & AF Look-up Table------------------------*/

	_DBG_("Test Acceptance Filter function...");

	_DBG_("Press '1' to initialize message and AF Loop-up Table...");_DBG_("");
	while(_DG !='1');

	/* initialize Transmit Message */
	CAN_InitAFMessage();

	_DBG_("Init message finished!!!");

	/* initialize AF Look-up Table sections*/
	CAN_SetupAFTable();

	/* install AF Look-up Table */
	error = CAN_SetupAFLUT(&AFTable);
	if (error != CAN_OK)
	{
		_DBG_("Setup AF: ERROR...");
		while (1); // AF Table has error
	}
	else
	{
		_DBG_("Setup AF: SUCCESSFUL!!!");_DBG_("");
	}

	/*-------------------------Send messages------------------------*/
	_DBG_("Press '2' to start CAN transferring operation...");_DBG_("");
	while(_DG !='2');

	for (i = 0; i < CAN_TX_MSG_CNT; i++)
	{
		CAN_SendMsg(CAN_1, (CAN_MSG_Type *)&AFTxMsg[i]);

		PrintMessage((CAN_MSG_Type *)&AFTxMsg[i]);_DBG_("");

		for(cnt=0;cnt<10000;cnt++); //transmit delay

		CANTxCount++;
	}

	_DBG_("Sending finished !!!");_DBG_("");

	if(CANRxCount == 0)
	{
		_DBG_(">>> No message is recieved. Please check the connection between 2 CANs!!!");_DBG_("");
	}

	/*-------------------------Display Received messages------------------------*/
	_DBG_("Press '3' to display received messages...");_DBG_("");
	while(_DG !='3');

	for (i = 0; i < CAN_RX_MSG_CNT; i++)
	{
		PrintMessage((CAN_MSG_Type *)&AFRxMsg[i]);_DBG_("");
	}

	/*-------------------------Change AFLUT Table --------------------*/
	_DBG_("Press '4' to change AF look-up table...");_DBG_("");
	while(_DG !='4');

	CAN_ChangeAFTable();

	_DBG_("Change AFLUT: FINISHED!!!");

	//CAN_SetAFMode(LPC_CANAF, CAN_eFCAN);
	CAN_SetAFMode(CAN_EFCAN);

	CAN_InitAFMessage();

	CANRxCount = CANTxCount = 0;

	/*-------------------------Re-Send messages------------------------*/
	_DBG_("Press '5' to re-send messages...");_DBG_("");
	while(_DG !='5');

	for (i = 0; i < CAN_TX_MSG_CNT; i++)
	{
		CAN_SendMsg(CAN_1, (CAN_MSG_Type *)&AFTxMsg[i]);

		PrintMessage((CAN_MSG_Type *)&AFTxMsg[i]);_DBG_("");

		for(cnt=0;cnt<10000;cnt++); //transmit delay

		CANTxCount++;
	}

	/*-------------------------Display received messages------------------------*/
	_DBG_("Re-Sending finished !!!");_DBG_("");

	if(CANRxCount == 0)
	{
		_DBG_(">>> No message is recieved. Please check the connection between 2 CANs!!!");_DBG_("");
	}

	_DBG_("Press '6' to display received messages...");_DBG_("");
	while(_DG !='6');

	for (i = 0; i < CAN_RX_MSG_CNT; i++)
	{
		PrintMessage((CAN_MSG_Type *)&AFRxMsg[i]);_DBG_("");
	}

	_DBG_("Demo terminal !!!");

	CAN_DeInit(CAN_1);

#if (RECVD_CAN_NO != CAN_1)
	CAN_DeInit(CAN_2);
#endif

	while (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);
}
Exemplo n.º 27
0
/*********************************************************************//**
 * @brief		Print menu
 * @param[in]	none
 * @return 		None
 **********************************************************************/
void print_menu(void)
{
	_DBG_(menu);
}
Exemplo n.º 28
0
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	PINSEL_CFG_Type PinCfg1;
#endif
	uint32_t tmp;
	uint32_t adc_value;
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Because the potentiometer on different boards (MCB & IAR) connect
	 * with different ADC channel, so we have to configure correct ADC channel
	 * on each board respectively.
	 * If you want to check other ADC channels, you have to wire this ADC pin directly
	 * to potentiometer pin (please see schematic doc for more reference)
	 */
#ifdef MCB_LPC_1768
	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	/*
	 * Init ADC pin connect
	 * AD0.3 on P0.26
	 */
	PinCfg1.Funcnum = 1;
	PinCfg1.OpenDrain = 0;
	PinCfg1.Pinmode = 0;
	PinCfg1.Pinnum = 26;
	PinCfg1.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg1);
#endif
#elif defined (IAR_LPC_1768)
	/* select P1.31 as AD0.5 */
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 31;
	PinCfg.Portnum = 1;
	PINSEL_ConfigPin(&PinCfg);
#endif


	/* Configuration for ADC:
	 *  select: ADC channel 2 (if using MCB1700 board)
	 *  		ADC channel 5 (if using IAR-LPC1768 board)
	 *  ADC conversion rate = 200KHz
	 */
	ADC_Init(LPC_ADC, 200000);
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE);
#endif

#ifdef MCB_LPC17XX_ADC_INJECT_TEST
	FIO_ByteSetDir(1, 3, POLL_LED, 1);
	FIO_ByteClearValue(1, 3, POLL_LED);
	// Enable GPIO interrupt P2.10
	GPIO_IntCmd(2,(1<<10),1);
	NVIC_EnableIRQ(EINT3_IRQn);
#endif

	//Start burst conversion
	ADC_BurstCmd(LPC_ADC,ENABLE);
	while(1)
	{
#ifdef MCB_LPC_1768
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
		_DBG("ADC value on channel 2: ");
#elif defined (IAR_LPC_1768)
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_5);
		_DBG("ADC value on channel 5: ");
#endif
		_DBD32(adc_value);
		_DBG_("");
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_3);
		_DBG("ADC value on channel 3: ");
		_DBD32(adc_value);
		_DBG_("");
#endif
		// Wait for a while
		for(tmp = 0; tmp < 1500000; tmp++);
	}
	ADC_DeInit(LPC_ADC);
	return (0);
}
/*********************************************************************//**
 * @brief		c_entry: Main SSP program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	uint8_t tmpchar[2] = {0, 0};
	PINSEL_CFG_Type PinCfg;
	__IO FlagStatus exitflag;

	/*
	 * Initialize SPI pin connect
	 * P0.15 - SCK
	 * P0.16 - SSEL - used as GPIO
	 * 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;
	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();

	// 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);

	// Initialize /CS pin to GPIO function
	CS_Init();

	// Enable SSP peripheral
	SSP_Cmd(LPC_SSP0, ENABLE);

    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(SSP0_IRQn, ((0x01<<3)|0x01));
    /* Enable SSP0 interrupt */
    NVIC_EnableIRQ(SSP0_IRQn);

	/* First, send some command to reset SC16IS740 chip via SSP bus interface
	 * note driver /CS pin to low state before transferring by CS_Enable() function
	 */
    complete = RESET;
	CS_Force(0);
	xferConfig.tx_data = iocon_cfg;
	xferConfig.rx_data = sspreadbuf;
	xferConfig.length = sizeof (iocon_cfg);
	SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_INTERRUPT);
	while (complete == RESET);
	CS_Force(1);

	complete = RESET;
	CS_Force(0);
	xferConfig.tx_data = iodir_cfg;
	xferConfig.rx_data = sspreadbuf;
	xferConfig.length = sizeof (iodir_cfg);
	SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_INTERRUPT);
	while (complete == RESET);
	CS_Force(1);

	// Reset exit flag
	exitflag = RESET;

	/* Read some data from the buffer */
	while (exitflag == RESET)
	{
		while((tmpchar[0] = _DG) == 0);

		if (tmpchar[0] == 27){
			/* ESC key, set exit flag */
			_DBG_(menu2);
			exitflag = SET;
		}
		else if (tmpchar[0] == 'r'){
			print_menu();
		} else {
			if (tmpchar[0] == '1')
			{
				// LEDs are ON now...
				CS_Force(0);
				xferConfig.tx_data = iostate_on;
				xferConfig.rx_data = sspreadbuf;
				xferConfig.length = sizeof (iostate_on);
				SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
				CS_Force(1);
			}
			else if (tmpchar[0] == '2')
			{
				// LEDs are OFF now...
				CS_Force(0);
				xferConfig.tx_data = iostate_off;
				xferConfig.rx_data = sspreadbuf;
				xferConfig.length = sizeof (iostate_off);
				SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
				CS_Force(1);
			}
			/* Then Echo it back */
			_DBG_(tmpchar);
		}
	}

    // wait for current transmission complete - THR must be empty
    while (UART_CheckBusy(LPC_UART0) == SET );

    // DeInitialize UART0 peripheral
    UART_DeInit(LPC_UART0);

    /* Loop forever */
    while(1);
    return 1;
}
Exemplo n.º 30
0
/**
 * Brief Transmit Finish Interrupt Callback function
 */
void TxFinish_UsrCBS(void)
{
	TxFinishedCount++;
	_DBG_("Tx finish");
}