/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate(); //SystemFrequency = 72000000 by default
  Systick_Init();      //10 ms de bir tick atacak sekilde Systick i baslat

  Gpio_Config();       //Beacon MCU da kullanilacak pinleri konfigure et

  ADF7021_CHIP_POWER_DOWN;        //CE pini asagi cek
  Delay_ms(10);
  ADF7021_LOAD_REGISTER_DISABLE;  //LE pinini yukari cek, load register disable olsun
  Delay_ms(10);
  ADF7021_CHIP_POWER_UP;          //CE pinini yukari cek, ADF7012 enable olsun
  Delay_ms(10);

  SSP1Init();			          // SSP1 portunda SPI konusalim*/
  DACInit();                      // 1.2kHz ve 2kHz sinus olusturmak icin DAC peripheral i baslatalim
  Delay_ms(10);

  Init_Adf7012();                 //Adf7012 registerlarini istedigimiz konfigurasyonda yazalim
  Init_Timer(10);                 //10us intervalinde timer0 baslat
  Enable_Timer();                 //Timer0 enable et


  while ( 1 );                    //main de yapilacak is kalmadi bundan sonra isr lerle devam edecegiz
  return 0;
}
Example #2
0
/*****************************************************************************
**   Main Function  main()
This program has been test on Keil LPC1700 board.
*****************************************************************************/
int main (void)
{
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  UARTInit(0, 57600);	/* baud rate setting */
  UARTInit(1, 57600);	/* baud rate setting */

  while (1) 
  {				/* Loop forever */
	if ( UART0Count != 0 )
	{
	  LPC_UART0->IER = IER_THRE | IER_RLS;			/* Disable RBR */
	  UARTSend( 0, (uint8_t *)UART0Buffer, UART0Count );
	  UART0Count = 0;
	  LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */
	}
	if ( UART1Count != 0 )
	{
	  LPC_UART1->IER = IER_THRE | IER_RLS;			/* Disable RBR */
	  UARTSend( 1, (uint8_t *)UART1Buffer, UART1Count );
	  UART1Count = 0;
	  LPC_UART1->IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */
	}
  }
}
Example #3
0
/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{	    		
  uint32_t counter = 0;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
  
  LPC_GPIO2->FIODIR = 0x000000FF;		/* P1.16..23 defined as Outputs */
  LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */
    
  init_rit_timer( TIME_INTERVAL );		/* 10ms */	
  enable_rit_timer();

  while (1) 
  {					/* Loop forever */
	if ( rit_timer_counter >= (50 * counter) )	   // 0.5s
	{
	  LPC_GPIO2->FIOSET = 1 << counter;
	  counter++;
	  if ( counter > 8 )
	  {
		counter = 0;	
		rit_timer_counter = 0;
		LPC_GPIO2->FIOCLR = 0x000000FF;
	  }
	}
  }
}
Example #4
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
  
  /* Initialize ADC  */
  ADCInit( ADC_CLK );

  while(1)
  {
#if BURST_MODE				/* Interrupt driven only */
	ADCBurstRead();
	while ( !ADCIntDone );
	ADCIntDone = 0;
  	if ( OverRunCounter != 0 )
  	{
  	  while ( 1 );
  	}
#else						/* Not burst mode */
	#if ADC_INTERRUPT_FLAG		/* Interrupt driven */
		for ( i = 0; i < ADC_NUM; i++ )
		{
		  ADCRead( i );
		  while ( !ADCIntDone );
		  ADCIntDone = 0;
		}
	#else  						/* Polling */
		for ( i = 0; i < ADC_NUM; i++ )
		{
		  ADCValue[i] = ADCRead( i );
		}
	#endif	/* Endif interrupt driven */
#endif	/* Endif BURST mode */
	}
}
Example #5
0
int main()
{
    int32_t  rc;
    uint32_t  numBlks, blkSize;
    uint8_t  inquiryResult[INQUIRY_LENGTH];

    /* SystemClockUpdate() updates the SystemFrequency variable */
    SystemClockUpdate();

    UART_Init(57600);          /* Initialize the serial port to view the log messages                       */
    Host_Init();               /* Initialize the lpc17xx host controller                                    */
    rc = Host_EnumDev();       /* Enumerate the device connected                                            */
    if (rc == OK) {
		/* Initialize the mass storage and scsi interfaces */
        rc = MS_Init( &blkSize, &numBlks, inquiryResult );
        if (rc == OK) {
            rc = FAT_Init();   /* Initialize the FAT16 file system                                          */
            if (rc == OK) {
                Main_Copy();   /* Call the application                                                      */
            } else {
                return (0);
            }
        } else {
            return (0);
        }
    } else {							
        return (0);
    }
    while(1);
}
Example #6
0
/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{	
  uint32_t i;
  uint32_t *src_addr, *dest_addr;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
  
  src_addr = (uint32_t *)DMA_SRC;
  dest_addr = (uint32_t *)DMA_DST;
  for ( i = 0; i < DMA_SIZE/4; i++ )
  {
	*src_addr++ = i;
	*dest_addr++ = 0;
  }
	    
  DMA_Init( M2M );
  LPC_GPDMACH0->CConfig |= 0x08001;	/* Enable channel and IE bit */

  while ( !DMATCCount );		/* Wait until DMA is done */

  /* Verify result */
  src_addr = (uint32_t *)DMA_SRC;
  dest_addr = (uint32_t *)DMA_DST;
  for ( i = 0; i < DMA_SIZE/4; i++ )
  {
	if ( *src_addr++ != *dest_addr++ )
	{
	  while ( 1 );	/* fatal error */
	}
  }
  while ( 1 );	/* Done here, never exit from main for easier debugging. */
}
Example #7
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  uint32_t i = 0;
  volatile uint32_t regVal;
#if DAC_DMA_ENABLED
  uint32_t *src_addr;
#else
  uint32_t m;
#endif

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  /* Initialize DAC  */
  DACInit();

#if DAC_DMA_ENABLED
  src_addr  = (uint32_t *)DMA_SRC;
  /* Fill the pattern in the DMA source memory */
  for ( i = 0; i < DATA_LENGTH; i++ )
  {
	*src_addr = (uint32_t)((i<<6)|(DAC_BIAS));	/* pre format the data to DACR register */
	src_addr++;	
  }
  
  DMA_Init();

  /* on DMA channel 0, source is memory, Destination is DAC */
  /* Enable channel and IE bit */
  DMAChannel_Init( 0, M2P ); 
  LPC_DAC->CTRL |= (0x1<<3);	/* DMA enabled on DAC */

  LPC_GPDMACH0->CConfig = 0xC001|(0x00<<1)|(DMA_DAC<<6)|(0x01<<11);
  while ( 1 )
  {
	/* Wait for DMA0 to finish. */
	while ( !DACDMA0Done );
	DACDMA0Done = 0;
	DMAChannel_Init( 0, M2P ); 
	/* Set TC int mask, channel enabled, src peripheral is memory(0x0), 
	dst peripheral is DAC(9), and transfer type is the M2P(1) */
	LPC_GPDMACH0->CConfig = 0xC001|(0x00<<1)|(DMA_DAC<<6)|(0x01<<11);
	/* During the DMA transfer, a saw wave should be seen on the scope. */
  }
#else
  while ( 1 )
  {
	LPC_DAC->CR = (i << 6) | DAC_BIAS;
	i++;
	for(m = 1000; m > 1; m--);
	if ( i == DATA_LENGTH )
	{
	  i = 0;
	}
  }
#endif
}
Example #8
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
	    		
  /* initialize GPIO pins as external interrupts */          
  EINTInit();

  /****** It's an endless loop waiting for external interrupt ******/
  while( 1 );
}
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{ 
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  /* Initialize RTC module */
  RTCInit();

  local_time.RTC_Sec = 0;
  local_time.RTC_Min = 0;
  local_time.RTC_Hour = 0;
  local_time.RTC_Mday = 8;
  local_time.RTC_Wday = 3;
  local_time.RTC_Yday = 12;		/* current date 07/12/2006 */
  local_time.RTC_Mon = 7;
  local_time.RTC_Year = 2006;
  RTCSetTime( local_time );		/* Set local time */

  alarm_time.RTC_Sec = 0;
  alarm_time.RTC_Min = 0;
  alarm_time.RTC_Hour = 0;
  alarm_time.RTC_Mday = 1;
  alarm_time.RTC_Wday = 0;
  alarm_time.RTC_Yday = 1;		/* alarm date 01/01/2007 */
  alarm_time.RTC_Mon = 1;
  alarm_time.RTC_Year = 2007;
  RTCSetAlarm( alarm_time );		/* set alarm time */

  NVIC_EnableIRQ(RTC_IRQn);

  /* mask off alarm mask, turn on IMYEAR in the counter increment interrupt
  register */
  RTCSetAlarmMask(AMRSEC|AMRMIN|AMRHOUR|AMRDOM|AMRDOW|AMRDOY|AMRMON|AMRYEAR);
  LPC_RTC->CIIR = IMMIN | IMYEAR;
  /* 2007/01/01/00:00:00 is the alarm on */
    
  RTCStart();

  while (1) 
  {					/* Loop forever */
	current_time = RTCGetTime();
	if ( alarm_on != 0 )
	{
	  alarm_on = 0;
	  /* Get current time when alarm is on */
	  current_time = RTCGetTime();	
	}
  }

}
/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  uint32_t i, portnum = PORT_NUM;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  if ( portnum == 0 )
	SSP0Init();			/* initialize SSP port */
  else if ( portnum == 1 )
	SSP1Init();
  
  for ( i = 0; i < SSP_BUFSIZE; i++ )
  {
	src_addr[i] = (uint8_t)i;
	dest_addr[i] = 0;
  }

#if TX_RX_ONLY
  /* For the inter-board communication, one board is set as
  master transmit, the other is set to slave receive. */
#if SSP_SLAVE
  /* Slave receive */
  SSPReceive( portnum, (uint8_t *)dest_addr, SSP_BUFSIZE );
  for ( i = 0; i < SSP_BUFSIZE; i++ )
  {
	if ( src_addr[i] != dest_addr[i] )
	{
	  while ( 1 );				/* Verification failure, fatal error */
	} 
  }
#else
  /* Master transmit */
  SSPSend( portnum, (uint8_t *)src_addr, SSP_BUFSIZE);
#endif
#else
  /* TX_RX_ONLY=0, it's either an internal loopback test
  within SSP peripheral or communicate with a serial EEPROM. */
#if LOOPBACK_MODE
  LoopbackTest( portnum, LOCATION_NUM );
#else
  SEEPROMTest( portnum, LOCATION_NUM );
#endif			/* endif NOT LOOPBACK_MODE */
#endif			/* endif NOT TX_RX_ONLY */
  /* Never exit from main(), for easy debugging. */
  while ( 1 );
  return 0;
}
/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{	    		
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
   
  LPC_GPIO2->FIODIR = 0x000000FF;		/* P2.0..7 defined as Outputs */
  LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */
    
  for ( i = 0; i < 2; i++ )
  {  
	init_timer( i , TIME_INTERVAL );	
	enable_timer( i );
  }

  /* Loop forever */
  while (1) 
  {					/* Loop forever */
	if ( (timer0_m0_counter > 0) && (timer0_m0_counter <= BLINK_INTERVAL) )
	{
	  LPC_GPIO2->FIOSET = 1 << 2;
	}
	if ( (timer0_m0_counter > BLINK_INTERVAL) && (timer0_m0_counter <= (BLINK_INTERVAL * 2)) )
	{
	  LPC_GPIO2->FIOCLR = 1 << 2;
	}
	else if ( timer0_m0_counter > (BLINK_INTERVAL * 2) )
	{
	  timer0_m0_counter = 0;
	}
	/* Timer 1 blinky LED 1 */
	if ( (timer1_m0_counter > 0) && (timer1_m0_counter <= BLINK_INTERVAL) )
	{
	  LPC_GPIO2->FIOSET = 1 << 3;
	}
	if ( (timer1_m0_counter > BLINK_INTERVAL) && (timer1_m0_counter <= (BLINK_INTERVAL * 2)) )
	{
	  LPC_GPIO2->FIOCLR = 1 << 3;
	}
	else if ( timer1_m0_counter > (BLINK_INTERVAL * 2) )
	{
	  timer1_m0_counter = 0;
	}
  }
}
int main (void)
{	    		
  uint32_t i, j;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  LPC_GPIO2->FIODIR = 0x000000FF;		/* P2.xx defined as Outputs */
  LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

  while(1)
  {
	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--);
  }
}
Example #13
0
/*******************************************************************************
**   Main Function  main()
*******************************************************************************/
int main (void)
{
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  for ( i = 0; i < BUFSIZE; i++ )
  {
	I2CRdBuffer[i] = 0x00;
  }
  
  I2CSlave0Init();			/* initialize I2c */
//  I2CSlave1Init();			/* initialize I2c */
//  I2CSlave2Init();			/* initialize I2c */

  while ( I2CSlaveState != DATA_NACK );
  /* When the NACK occurs, the master has stopped the 
  communication. Just check the content of I2CRd/WrBuffer. */
  while ( 1 );	/* Never exit from main for easy debugging. */
  return ( 0 );
}
Example #14
0
int main (void) {
    uint8_t i;

    /* SystemClockUpdate() updates the SystemFrequency variable */
    SystemClockUpdate();

    /* Clear receive buffer, handled inside ISR. */
    for ( i = 0; i < BUFSIZE; i++ )
    {
        UARTBuffer[i] = 0x00;
    }

    /* NVIC is installed inside UARTInit file. */
    RS485Init(115200);

    /* To test RS485 mode, connect two boards, one is set to TX and
    the other is RX. The test is conducted on the inter-board communication. */
#if RS485_RX
    /* If RX, do nothing, check the content of UARTBuffer */
    /* To get the test result, program the boards with both TX and RX program,
    power up the board with the RX program first, start the debugger on the
    board with the RX program, power up the board with the TX program, stop
    the debugger, and check the content of the UARTBuffer on the RX program,
    it should be the same as seen on UARTTxBuffer, 0x01-0x02-0x03.... */
    while ( 1 );

#else
    /* If TX. send a string out start with RS485 slave address */
    UARTTxBuffer[0] = RS485_SLAVE_ADR;
    for ( i = 1; i < BUFSIZE; i++ )
    {
        UARTTxBuffer[i] = i;
    }
    RS485Send((uint8_t *)UARTTxBuffer, BUFSIZE);
    while ( 1 );
#endif			/* #endif RS485_RX */

}
Example #15
0
/*******************************************************************************
**   Main Function  main()
*******************************************************************************/
int main (void)
{
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  /* The test program is to connect CLK, WS, and SDA lines between the
  TX and RX. DAO is the master output, DAI is the slave input. This test
  is not a real-world application but test both TX and RX channel in
  a single program. However, due to the sync issue, the TX will start with 
  MUTE data 0 once it starts while RX is not ready. So, it may begins
  with some MUTE value in the beginning of the RX buffer. This is beyond
  control unless throw away the very first few bytes in the RX buffer. 
  In this program, the very first byte is not compared between the TX buffer 
  and RX buffer due to this synchonization issue. */

  /* Configure temp register before reading */
  for ( i = 0; i < BUFSIZE; i++ )	/* clear buffer */
  {
	I2STXBuffer[i] = i;
	I2SRXBuffer[i] = 0;
  }

  I2SInit();				/* initialize I2S */
 
#if I2S_DMA_ENABLED
  DMA_Init();

  /* Select secondary function(I2S) in DMA channels */
  LPC_SC->DMAREQSEL = (0x1<<DMA_I2S_REQ0)|(0x1<<DMA_I2S_REQ1);

  /* on DMA channel 0, Source is memory, destination is I2S TX FIFO, 
  on DMA channel 1, source is I2S RX FIFO, Destination is memory */
  /* Enable channel and IE bit */
  DMAChannel_Init( 0, M2P );
  LPC_GPDMACH0->CConfig |= (0x18001|(0x00<<1)|(DMA_I2S_REQ0<<6)|(0x01<<11));
  DMAChannel_Init( 1, P2M );
  LPC_GPDMACH1->CConfig |= (0x08001|(DMA_I2S_REQ1<<1)|(0x00<<6)|(0x02<<11));
 
  NVIC_EnableIRQ(DMA_IRQn);

  I2SStart();	  

  LPC_I2S->DMA2 = (0x01<<0) | (0x08<<8);	/* Channel 2 is for RX, enable RX first. */
  LPC_I2S->DMA1 = (0x01<<1) | (0x01<<16);	/* Channel 1 is for TX. */

  /* Wait for both DMA0 and DMA1 to finish before verifying. */
  while ( !I2SDMA0Done || !I2SDMA1Done );
#else
  /* Not DMA mode, enable I2S interrupts. */
  NVIC_EnableIRQ(I2S_IRQn);

  /* RX FIFO depth is 1, TX FIFO depth is 8. */
  I2SStart();
  LPC_I2S->IRQ = (8 << 16) | (1 << 8) | (0x01 << 0);

  while ( I2SWriteLength < BUFSIZE )
  {
	while (((LPC_I2S->STATE >> 16) & 0xFF) == TXFIFO_FULL);
	LPC_I2S->TXFIFO = I2STXBuffer[I2SWriteLength++];
  }

  I2STXDone = 1;
  /* Wait for RX and TX complete before comparison */
  while ( !I2SRXDone || !I2STXDone );
#endif

  /* Validate TX and RX buffer */
  for ( i=1; i<BUFSIZE; i++ )
  {
	if ( I2SRXBuffer[i] != I2STXBuffer[i-1] )
	{
	  while ( 1 );	/* Validation error */
	}
  }
  while ( 1 );	/* Don't exit from main when finishing. */
}
Example #16
0
int main (void) 
{
  MCPWM_CHANNEL_SETUP_T channelsetup[3];
  
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
  
  MCPWM_Init();

  channelsetup[0].channelType = 0;
  channelsetup[0].channelPolarity = 0;
  channelsetup[0].channelDeadtimeEnable = 0;
  channelsetup[0].channelDeadtimeValue = 0;
#if SHADOW_UPDATE
  channelsetup[0].channelUpdateEnable = 1;
#else
  channelsetup[0].channelUpdateEnable = 0;
#endif
  channelsetup[0].channelTimercounterValue = 0;
  channelsetup[0].channelPeriodValue = 300;
  channelsetup[0].channelPulsewidthValue = 150;

  channelsetup[1].channelType = 0;
  channelsetup[1].channelPolarity = 0;
  channelsetup[1].channelDeadtimeEnable = 0;
  channelsetup[1].channelDeadtimeValue = 0;
#if SHADOW_UPDATE
  channelsetup[1].channelUpdateEnable = 1;
#else
  channelsetup[1].channelUpdateEnable = 0;
#endif
  channelsetup[1].channelTimercounterValue = 0;
  channelsetup[1].channelPeriodValue = 300;
  channelsetup[1].channelPulsewidthValue = 150;

  channelsetup[2].channelType = 0;
  channelsetup[2].channelPolarity = 0;
  channelsetup[2].channelDeadtimeEnable = 0;
  channelsetup[2].channelDeadtimeValue = 0;
#if SHADOW_UPDATE
  channelsetup[2].channelUpdateEnable = 1;
#else
  channelsetup[2].channelUpdateEnable = 0;
#endif
  channelsetup[2].channelTimercounterValue = 0;
  channelsetup[2].channelPeriodValue = 300;
  channelsetup[2].channelPulsewidthValue = 150;

  if (!MCPWM_Config(0, &channelsetup[0]))
  {
    return 0;
  }
  if (!MCPWM_Config(1, &channelsetup[1]))
  {
    return 0;
  }
  if (!MCPWM_Config(2, &channelsetup[2]))
  {
    return 0;
  }

#if CHANNEL_0_CAPTURE
  MCPWM_CaptureEvent(0, 0x01, 1, 0);
#endif
#if CHANNEL_1_CAPTURE
  MCPWM_CaptureEvent(1, 0x04, 1, 0);
#endif
#if CHANNEL_2_CAPTURE
  MCPWM_CaptureEvent(2, 0x10, 1, 0);
#endif

#if AC_MODE
  MCPWM_acMode(1);
#endif

#if DC_MODE
  MCPWM_dcMode(1, 1, 0x3F);
#endif

  LPC_GPIO3->FIODIR = 0x02000000;
  LPC_GPIO3->FIOSET = 0x02000000;
  delayMs(0, 20);
  LPC_GPIO3->FIOCLR = 0x02000000;

  MCPWM_Start(1,1,1);

  for (;;) {
#if SHADOW_UPDATE
    delayMs(0, 10000);
    channelsetup[0].channelPeriodValue = 150;
    channelsetup[0].channelPulsewidthValue = 75;

    channelsetup[1].channelPeriodValue = 150;
    channelsetup[1].channelPulsewidthValue = 75;

    channelsetup[2].channelPeriodValue = 150;
    channelsetup[2].channelPulsewidthValue = 75;
    if (!MCPWM_WriteToShadow(0, &channelsetup[0]))
    {
      return 0;
    }
    if (!MCPWM_WriteToShadow(1, &channelsetup[1]))
    {
      return 0;
    }
    if (!MCPWM_WriteToShadow(2, &channelsetup[2]))
    {
      return 0;
    }

    delayMs(0, 10000);
    channelsetup[0].channelPeriodValue = 300;
    channelsetup[0].channelPulsewidthValue = 150;

    channelsetup[1].channelPeriodValue = 300;
    channelsetup[1].channelPulsewidthValue = 150;

    channelsetup[2].channelPeriodValue = 300;
    channelsetup[2].channelPulsewidthValue = 150;
    if (!MCPWM_WriteToShadow(0, &channelsetup[0]))
    {
      return 0;
    }
    if (!MCPWM_WriteToShadow(1, &channelsetup[1]))
    {
      return 0;
    }
    if (!MCPWM_WriteToShadow(2, &channelsetup[2]))
    {
      return 0;
    }
#endif
  }
}
Example #17
0
/*****************************************************************************
** Function name:		main
**
** Descriptions:		main routine for CAN module test
**
** parameters:			None
** Returned value:		int
** 
*****************************************************************************/
int main( void )
{
  uint32_t i;
#if (POWERMODE == SLEEP)
  uint32_t j;
#endif
#if UART_ENABLE
  uint8_t textarray[100];
#endif

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
		
#if UART_ENABLE
  UARTInit(0, 57600);
#endif
	
  /* Please note, the bit timing is based on the setting of the 
  PCLK, if different PCLK is used, please read can.h carefully 
  and set your CAN bit timing accordingly. */  
  CAN_Init( BITRATE125K18MHZ );

  /* Enable the CAN Activity Interrupt */
  NVIC_EnableIRQ(CANActivity_IRQn);
	      
  /* send one message from CAN1(TX) and verify received message on 
  CAN2(RX) if it's a match, both CAN TX and RX are working. 
  For more details on acceptance filter program, see Philips
  appnote AN10438 and the zip file associated with this appnote. */
									
  /* GPIOs as outputs */
  LPC_GPIO1->FIODIR |= (1<<28) | (1<<29);
  LPC_GPIO1->FIOCLR  = (1<<28) | (1<<29);
	
  LPC_GPIO2->FIODIR |= (1<<6);
  LPC_GPIO2->FIOCLR  = (1<<6);
	
  /* Clear MsgBuf */
  MsgBuf_RX1.Frame = 0x0;
  MsgBuf_RX1.MsgID = 0x0;
  MsgBuf_RX1.DataA = 0x0;
  MsgBuf_RX1.DataB = 0x0;
  CAN_SetACCF( ACCF_BYPASS );

#if UART_ENABLE
  UARTSend(0, "Initialized\r\n", sizeof("Initialized\r\n"));
#endif

  i = 0;
  canactflag = 0;
  /* Test bypass */
  while ( 1 )
  {
	/* Waken up from deep sleep */
	if (canactflag) 
	{
	  canactflag = 0;
	    
	  /* Re-intialized the PLL and CAN interface */
	  SystemInit();
#if UART_ENABLE
	  UARTInit(0, 57600);
#endif
	  CAN_Init( BITRATE125K18MHZ );
		
#if UART_ENABLE
	  UARTSend(0, "\r\nWake up Complete\r\n", sizeof("\r\nWake up Complete\r\n"));
#endif
	}

	/* IF CAN packet received, turn on LED P1.28 */
	if(CAN1RxDone == TRUE)
	{
	  CAN1RxDone = FALSE;
	  LPC_GPIO1->FIOPIN ^= (1<<28);
			
#if UART_ENABLE
	  UARTSend(0, "\r\nCAN Packet Rx'd\r\n", sizeof("\r\nCAN Packet Rx'd\r\n"));
	  memset(textarray, '\0', sizeof(textarray));
	  sprintf((char *)textarray,"Frame: 0x%08X\r\n"
		"ID:    0x%08X\r\n"
		"DataA: 0x%08X\r\n"
		"DataB: 0x%08X\r\n",
		MsgBuf_RX1.Frame,
		MsgBuf_RX1.MsgID,
		MsgBuf_RX1.DataA,
		MsgBuf_RX1.DataB);
	  UARTSend(0, textarray, sizeof(textarray));
#endif
			
	  /* Message Data */
	  MsgBuf_RX1.Frame = 0x0;
	  MsgBuf_RX1.MsgID = 0x0;
	  MsgBuf_RX1.DataA = 0x0;
	  MsgBuf_RX1.DataB = 0x0;
	}

	/* If P2.10 (INT0) is pressed, go into Deep Sleep */
	if(!(LPC_GPIO2->FIOPIN & (1<<10)))
	{
	  LPC_GPIO1->FIOCLR = (1<<28) | (1<<29);
	  LPC_GPIO2->FIOCLR = (1<<6);
											 				   
#if UART_ENABLE
#if 	(POWERMODE == DEEPSLEEP)
	  UARTSend(0, "\r\nGoing to DEEP SLEEP\r\n", 	sizeof("\r\nGoing to DEEP SLEEP\r\n"));
#elif	(POWERMODE == POWERDOWN)
	  UARTSend(0, "\r\nGoing to POWER DOWN\r\n", 	sizeof("\r\nGoing to POWER DOWN\r\n"));
#else /*(POWERMODE == SLEEP)*/
	  UARTSend(0, "\r\nGoing to SLEEP\r\n", 		sizeof("\r\nGoing to SLEEP\r\n"));
	  /* Delay needed so that UART0 can clear out to prevent unintentional wakeups */
	  for(j = 0; j < 0x1000; j++);
#endif /* POWERMODE */
#endif /* UART_ENABLE */
	
	/* Specify the Powerdown mode */
#if 	(POWERMODE == DEEPSLEEP)
	  /* Specify WFI to enter DEEPSLEEP mode */
	  SCB->SCR		= (1<<2);	
#elif	(POWERMODE == POWERDOWN)
	  /* Specify WFI to enter POWERDOWN mode */
	  SCB->SCR		= 	(1<<2);
	  LPC_SC->PCON   |=	(1<<0);
#else 	/*(POWERMODE == SLEEP)*/
	  /* Default is SLEEP MODE */
#endif
			
	  /* Switching to reduced power mode */
	  __WFI();
	}

	/* Toggle P2.6 LED while CPU is running */
	if(i >= (1<<18))
	{
	  LPC_GPIO2->FIOPIN ^= (1<<6);
	  i = 0;
	} 
	else
	{
	  i++;
	}	
  }
}
Example #18
0
/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void) {
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  UARTInit(0, 115200);
  UARTInit(1, 115200);

  u0_src = (uint8_t *)UART0_DMA_TX_SRC;
  u0_dst = (uint8_t *)UART0_DMA_RX_DST;
  u1_src = (uint8_t *)UART1_DMA_TX_SRC;
  u1_dst = (uint8_t *)UART1_DMA_RX_DST;
  for ( i = 0; i < UART_DMA_SIZE; i++ )
  {
	*u0_src++ = *u1_src++ = ConvertDigital(i);
	*u0_dst++ = *u1_dst++ = 0;
  }

  DMA_Init();

  /* Connect UART0 and UART1 via a RS232 cable. The sequence is, UART DMA starts 
  from UART0 TX, lookback to UART1 RX using channel 0 and 1. Then, UART DMA starts
  from UART1 TX, lookback to UART0 RX using channel 2 and 3.
  So, both M2P+P2M on UART0 and UART1 are tested. */

  /* DMA from UART0 TX to UART1 RX using channel 0 and 1. */
  DMAChannel_Init( 0, M2P );
  LPC_GPDMACH0->CConfig |= 0x0C001|(0x00<<1)|(DMA_UART0_TX<<6)|(0x01 << 11);
  LPC_UART0->FCR |= 0x08;

  /* DMA request was sent inside DMA ISR when DMA is done.
  The data should arrive at UART1 RX already. */
  while ( !UARTDMA0Done );
  UARTDMA0Done = 0;
  while ( !UARTDMA1Done );
  UARTDMA1Done = 0;

  /* Between UART0 TX and UART1 RX, the data should match, or fatal DMA error. */
  u1_src = (uint8_t *)UART0_DMA_TX_SRC;
  u1_dst = (uint8_t *)UART1_DMA_RX_DST;
  for ( i = 0; i < UART_DMA_SIZE; i++ )
  {
	if ( *u1_src++ != *u1_dst++ )
	{
	  while ( 1 );
	}
  }

  /* DMA from UART1 TX to UART0 RX using channel 2 and 3. */
  DMAChannel_Init( 2, M2P );
  NVIC_EnableIRQ(DMA_IRQn);
  LPC_GPDMACH2->CConfig |= 0x0C001|(0x00<<1)|(DMA_UART1_TX<<6)|(0x01 << 11);
  LPC_UART1->FCR |= 0x08;

  /* DMA request was sent inside DMA ISR when DMA is done.
  The data should arrive at UART1 RX already. */
  while ( !UARTDMA2Done );
  UARTDMA2Done = 0;
  while ( !UARTDMA3Done );
  UARTDMA3Done = 0;
  LPC_GPDMA->Sync = (0x1<<DMA_UART0_RX)|(0x1<<DMA_UART1_TX);

  /* The data is transferred from M2U0TX-U1RX-, M2U1TX-U0RX. */
  /* Between UART0 TX and UART0 RX, the data should match, or fatal DMA error. */
  u1_src = (uint8_t *)UART1_DMA_TX_SRC;
  u1_dst = (uint8_t *)UART0_DMA_RX_DST;
  for ( i = 0; i < UART_DMA_SIZE; i++ )
  {
	if ( *u1_src++ != *u1_dst++ )
	{
	  while ( 1 );
	}
  }
  while ( 1 );
  return(0);
}
Example #19
0
/*******************************************************************************
**   Main Function  main()
*******************************************************************************/
int main (void)
{
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  I2C0Init( );			/* initialize I2c0 */
  I2C1Init( );			/* initialize I2c1 */
  I2C2Init( );			/* initialize I2c2 */

  /* In order to start the I2CEngine, the all the parameters 
  must be set in advance, including I2CWriteLength, I2CReadLength,
  I2CCmd, and the I2cMasterBuffer which contains the stream
  command/data to the I2c slave device. 
  (1) If it's a I2C write only, the number of bytes to be written is 
  I2CWriteLength, I2CReadLength is zero, the content will be filled 
  in the I2CMasterBuffer. 
  (2) If it's a I2C read only, the number of bytes to be read is 
  I2CReadLength, I2CWriteLength is 0, the read value will be filled 
  in the I2CMasterBuffer. 
  (3) If it's a I2C Write/Read with repeated start, specify the 
  I2CWriteLength, fill the content of bytes to be written in 
  I2CMasterBuffer, specify the I2CReadLength, after the repeated 
  start and the device address with RD bit set, the content of the 
  reading will be filled in I2CMasterBuffer index at 
  I2CMasterBuffer[I2CWriteLength+2]. 
  
  e.g. Start, DevAddr(W), WRByte1...WRByteN, Repeated-Start, DevAddr(R), 
  RDByte1...RDByteN Stop. The content of the reading will be filled 
  after (I2CWriteLength + two devaddr) bytes. */

  /* Write SLA(W), address and one data byte */
  I2CWriteLength[PORT_USED] = 6;
  I2CReadLength[PORT_USED] = 0;
  I2CMasterBuffer[PORT_USED][0] = PCF8594_ADDR;
  I2CMasterBuffer[PORT_USED][1] = 0x00;		/* address */
  I2CMasterBuffer[PORT_USED][2] = 0x55;		/* Data0 */
  I2CMasterBuffer[PORT_USED][3] = 0xAA;		/* Data1 */
  I2CMasterBuffer[PORT_USED][4] = 0x12;		/* Data0 */
  I2CMasterBuffer[PORT_USED][5] = 0x34;		/* Data1 */
  I2CEngine( PORT_USED );

  /* Be careful with below fixed delay. From device to device, or
  even same device with different write length, or various I2C clock, 
  below delay length may need to be changed accordingly. Having 
  a break point before Write/Read start will be helpful to isolate 
  the problem. */
  for ( i = 0; i < 0x200000; i++ );	/* Delay after write */

  for ( i = 0; i < BUFSIZE; i++ )
  {
	I2CSlaveBuffer[PORT_USED][i] = 0x00;
  }
  /* Write SLA(W), address, SLA(R), and read one byte back. */
  I2CWriteLength[PORT_USED] = 2;
  I2CReadLength[PORT_USED] = 4;
  I2CMasterBuffer[PORT_USED][0] = PCF8594_ADDR;
  I2CMasterBuffer[PORT_USED][1] = 0x00;		/* address */
  I2CMasterBuffer[PORT_USED][2] = PCF8594_ADDR | RD_BIT;
  I2CEngine( PORT_USED );

  /* Check the content of the Master and slave buffer */
  while ( 1 );

}
/*****************************************************************************
** Function name:		main
**
** Descriptions:		main routine for CAN module test
**
** parameters:			None
** Returned value:		int
** 
*****************************************************************************/
int main( void )
{
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  /* Please note, the bit timing is based on the setting of the 
  PCLK, if different PCLK is used, please read can.h carefully 
  and set your CAN bit timing accordingly. */  
  //CAN_Init( BITRATE100K24MHZ );
  CAN_Init( BITRATE125K18MHZ );	

#if CAN_WAKEUP
  CAN_WakeupTest();
#endif
  
  /* send one message from CAN1(TX) and verify received message on 
  CAN2(RX) if it's a match, both CAN TX and RX are working. 
  For more details on acceptance filter program, see Philips
  appnote AN10438 and the zip file associated with this appnote. */

#if !ACCEPTANCE_FILTER_ENABLED
  /* Initialize MsgBuf */
  MsgBuf_TX1.Frame = 0x80080000; /* 29-bit, no RTR, DLC is 8 bytes */
  MsgBuf_TX1.MsgID = 0x00012345; /* CAN ID */
  MsgBuf_TX1.DataA = 0x3C3C3C3C;
  MsgBuf_TX1.DataB = 0xC3C3C3C3;

  MsgBuf_RX2.Frame = 0x0;
  MsgBuf_RX2.MsgID = 0x0;
  MsgBuf_RX2.DataA = 0x0;
  MsgBuf_RX2.DataB = 0x0;
  CAN_SetACCF( ACCF_BYPASS );

  /* Test bypass */
  while ( 1 )
  {
	/* Transmit initial message on CAN 1 */
	while ( !(LPC_CAN1->GSR & (1 << 3)) );
	if ( CAN1_SendMessage( &MsgBuf_TX1 ) == FALSE )
	{
	  continue;
	}
 	if ( CAN2RxDone == TRUE )
	{
	  CAN2RxDone = FALSE;
	  if ( MsgBuf_RX2.Frame & (1 << 10) )	/* by pass mode */
	  {
		MsgBuf_RX2.Frame &= ~(1 << 10 );
	  }
	  if ( ( MsgBuf_TX1.Frame != MsgBuf_RX2.Frame ) ||
			( MsgBuf_TX1.MsgID != MsgBuf_RX2.MsgID ) ||
			( MsgBuf_TX1.DataA != MsgBuf_RX2.DataA ) ||
			( MsgBuf_TX1.DataB != MsgBuf_RX2.DataB ) )
	  {
		while ( 1 );
	  }
	  /* Everything is correct, reset buffer */
	  MsgBuf_RX2.Frame = 0x0;
	  MsgBuf_RX2.MsgID = 0x0;
	  MsgBuf_RX2.DataA = 0x0;
	  MsgBuf_RX2.DataB = 0x0;
	} /* Message on CAN 2 received */
  }
#else
  /* Test Acceptance Filter */
  /* Even though the filter RAM is set for all type of identifiers,
  the test module tests explicit standard identifier only */
  MsgBuf_TX1.Frame = 0x00080000; /* 11-bit, no RTR, DLC is 8 bytes */
  MsgBuf_TX1.MsgID = EXP_STD_ID; /* Explicit Standard ID */
  MsgBuf_TX1.DataA = 0x55AA55AA;
  MsgBuf_TX1.DataB = 0xAA55AA55;

  MsgBuf_RX2.Frame = 0x0;
  MsgBuf_RX2.MsgID = 0x0;
  MsgBuf_RX2.DataA = 0x0;
  MsgBuf_RX2.DataB = 0x0;
  CAN_SetACCF( ACCF_ON );

  while ( 1 )
  {
	/* Transmit initial message on CAN 1 */
	while ( !(LPC_CAN1->GSR & (1 << 3)) );
	if ( CAN1_SendMessage( &MsgBuf_TX1 ) == FALSE )
	{
	  continue;
	}

	/* please note: FULLCAN identifier will NOT be received as it's not set 
	in the acceptance filter. */
 	if ( CAN2RxDone == TRUE )
	{
	  CAN2RxDone = FALSE;
	  /* The frame field is not checked, as ID index varies based on the
	  entries set in the filter RAM. */
	  if ( ( MsgBuf_TX1.MsgID != MsgBuf_RX2.MsgID ) ||
			( MsgBuf_TX1.DataA != MsgBuf_RX2.DataA ) ||
			( MsgBuf_TX1.DataB != MsgBuf_RX2.DataB ) )
	  {
		while ( 1 );
	  }
	  /* Everything is correct, reset buffer */
	  MsgBuf_RX2.Frame = 0x0;
	  MsgBuf_RX2.MsgID = 0x0;
	  MsgBuf_RX2.DataA = 0x0;
	  MsgBuf_RX2.DataB = 0x0;
	} /* Message on CAN 2 received */
  }
#endif
}
Example #21
0
/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  LPC_GPIO2->FIODIR = 0x0000000F;		/* P2.0..3 defined as Outputs */
  LPC_GPIO2->FIOCLR = 0x0000000F;		/* turn off all the LEDs */

  /* Do a P2M DMA transfer using timer match out as a trigger */  
  DMA_Init(P2M);
#if 0
  LPC_GPDMACH0->CConfig |= 0x0C001|(TMR0_M0_REQ<<1)|(0x00<<6)|(0x02<<11);
  LPC_SC->DMAREQSEL = (0x1<<0);
  init_timer( 0, TIME_INTERVAL );	
  enable_timer( 0 );
#endif
#if 0
  LPC_GPDMACH0->CConfig |= 0x0C001|(TMR0_M1_REQ<<1)|(0x00<<6)|(0x02<<11);
  LPC_SC->DMAREQSEL = (0x1<<1);
  init_timer( 0, TIME_INTERVAL );	
  enable_timer( 0 );
#endif
#if 1
  LPC_GPDMACH0->CConfig |= 0x0C001|(TMR1_M0_REQ<<1)|(0x00<<6)|(0x02<<11);
  LPC_SC->DMAREQSEL = (0x1<<2);
  init_timer( 1, TIME_INTERVAL );	
  enable_timer( 1 );
#endif
#if 0
  LPC_GPDMACH0->CConfig |= 0x0C001|(TMR1_M1_REQ<<1)|(0x00<<6)|(0x02<<11);
  LPC_SC->DMAREQSEL = (0x1<<3);
  init_timer( 1, TIME_INTERVAL );	
  enable_timer( 1 );
#endif

  /* When DMADone is set, it indicates that DMA has been triggered 
  by MAT_OUT(0.0). */
  while ( !CH0DMADone );
  CH0DMADone = 0;

  /* Loop forever */
  while (1) 
  {		
	/* Timer 0 blinky LED 0 */
	if ( (timer0_m0_counter > 0) && (timer0_m0_counter <= BLINK_INTERVAL) )
	{
	  LPC_GPIO2->FIOSET = 1 << 2;
	}
	if ( (timer0_m0_counter > BLINK_INTERVAL) && (timer0_m0_counter <= (BLINK_INTERVAL * 2)) )
	{
	  LPC_GPIO2->FIOCLR = 1 << 2;
	}
	else if ( timer0_m0_counter > (BLINK_INTERVAL * 2) )
	{
	  timer0_m0_counter = 0;
	}
	/* Timer 1 blinky LED 1 */
	if ( (timer1_m0_counter > 0) && (timer1_m0_counter <= BLINK_INTERVAL) )
	{
	  LPC_GPIO2->FIOSET = 1 << 3;
	}
	if ( (timer1_m0_counter > BLINK_INTERVAL) && (timer1_m0_counter <= (BLINK_INTERVAL * 2)) )
	{
	  LPC_GPIO2->FIOCLR = 1 << 3;
	}
	else if ( timer1_m0_counter > (BLINK_INTERVAL * 2) )
	{
	  timer1_m0_counter = 0;
	}
  }
}