keil_examples/CAN/cantest.c
/*****************************************************************************
** Function name:		CAN_WakeupTest
**
** Descriptions:		main routine for CAN wakeup test
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
Function name:         CAN_WakeupTest
Descriptions:          main routine for CAN wakeup test

None
Returned value:                None
Function name : CAN_WakeupTest Descriptions : main routine for CAN wakeup test None Returned value : None
void CAN_WakeupTest( void )
{
  uint32_t i, j;
  CAN_SetACCF( ACCF_BYPASS );
  NVIC_EnableIRQ(CANActivity_IRQn);       
  SCB->SCR |= 0x04;		
  LPC_SC->PCON = 0x1;
  __WFI();
  while (1)                            
  {
	if ( CANActivityInterruptFlag )
	{
	  CANActivityInterruptFlag = 0;
	  while ( CAN2RxDone != TRUE );
	  CAN2RxDone = FALSE;
	  SystemInit();
	  CAN_Init( BITRATE125K18MHZ );
	  CAN_SetACCF( ACCF_BYPASS );
	  LPC_GPIO2->FIODIR = 0x000000FF;		
	  LPC_GPIO2->FIOCLR = 0x000000FF;		
	  for ( j = 0; j < 10; j++ )
	  {
		for ( i = 0; i < 0x200000; i++ );
		LPC_GPIO2->FIOSET = 0x000000FF;
		for ( i = 0; i < 0x200000; i++ );
		LPC_GPIO2->FIOCLR = 0x000000FF;
	  }
	  SCB->SCR |= 0x04;		
	  LPC_SC->PCON = 0x1;
	  __WFI();
	}
  }
}
void CAN_WakeupTest ( void ) { uint32_t i , j ; CAN_SetACCF ( ACCF_BYPASS ) ; NVIC_EnableIRQ ( CANActivity_IRQn ) ; SCB -> SCR |= 0x04 ; LPC_SC -> PCON = 0x1 ; __WFI ( ) ; while ( 1 ) { if ( CANActivityInterruptFlag ) { CANActivityInterruptFlag = 0 ; while ( CAN2RxDone != TRUE ) ; CAN2RxDone = FALSE ; SystemInit ( ) ; CAN_Init ( BITRATE125K18MHZ ) ; CAN_SetACCF ( ACCF_BYPASS ) ; LPC_GPIO2 -> FIODIR = 0x000000FF ; LPC_GPIO2 -> FIOCLR = 0x000000FF ; for ( j = 0 ; j < 10 ; j ++ ) { for ( i = 0 ; i < 0x200000 ; i ++ ) ; LPC_GPIO2 -> FIOSET = 0x000000FF ; for ( i = 0 ; i < 0x200000 ; i ++ ) ; LPC_GPIO2 -> FIOCLR = 0x000000FF ; } SCB -> SCR |= 0x04 ; LPC_SC -> PCON = 0x1 ; __WFI ( ) ; } } }
Function name:         CAN_WakeupTest
Descriptions:          main routine for CAN wakeup test
Function name : CAN_WakeupTest Descriptions : main routine for CAN wakeup test
/* enable CAN activity interrupt */ /* Put the MCU into deep sleep mode first. Any CAN message on RX 
  should wake up the MCU. CAN Activity interrupt won't occur until Deepsleep 
  bit is set in SCR. UM needs to be updated regarding this. */ /* Set SLEEPDEEP bit in SCR in Cortex M3 core. */ /* Loop forever */ /* If the MCU is waked up from power down mode, the PLL needs to
	  be reconfigured, and USB block needs tn be reset and reconnect. */ /* P1.16..23 defined as Outputs */ /* turn off all the LEDs */ /* Wake up first time, now, blink 10 times. */ /* Once the LED blink number of times, the MCU will go to sleep
	  or power down mode again. Another incoming CAN message will wake up
	  the MCU again. */ /* Set SLEEPDEEP bit in SCR in Cortex M3 core. */