Example #1
0
/**
 *  sleep - most versatile sleep mode. SnoozeBlock configuration or any interrupt can wake the processor.
 *
 *  @param configuration SnoozeBlock class config.
 *
 *  @return wakeup source
 */
int SnoozeClass::sleep( SnoozeBlock &configuration ) { 
    SnoozeBlock *p = &configuration;
    enable_periph_irq = true;
#ifdef KINETISL
    tsi_set( &p->tsi_mask );
#endif
    cmp_set( &p->cmp_mask );
    lptmr_set( &p->lptmr_mask );
#ifdef KINETISK
    rtc_alarm_set( &p->rtc_mask );
#endif
    digital_set( &p->digital_mask );
#ifdef KINETISL
    pinMode( 17, OUTPUT );
    digitalWriteFast( 17, LOW );
#endif
    if ( mcg_mode( ) == BLPI ) {
        peripheral_disable( &p->setPeripheral.periph_off_mask );
        enter_wait( );
        peripheral_set( &p->setPeripheral.periph_off_mask );
    }
    else if ( mcg_mode( ) == BLPE ) {
        peripheral_set( &p->setPeripheral.periph_off_mask );
        blpe_blpi (   );
        enter_vlpr( 0 );// now safe to enter vlpr
        enter_wait(   );
        exit_vlpr (   );
        blpi_blpe (   );
        peripheral_set( &p->setPeripheral.periph_off_mask );
    }
    else {
        peripheral_set( &p->setPeripheral.periph_off_mask );
        usbDisable(   );
        pee_blpi  (   );
        enter_vlpr( 0 );// now safe to enter vlpr
        enter_wait(   );
        exit_vlpr (   );
        blpi_pee  (   );
        usbEnable (   );
        peripheral_set( &p->setPeripheral.periph_off_mask );
    }
    digital_disable( &p->digital_mask );
#ifdef KINETISK
    rtc_disable( &p->rtc_mask );
#endif
    lptmr_disable( &p->lptmr_mask );
    cmp_disable( &p->cmp_mask );
#ifdef KINETISL
    tsi_disable( &p->tsi_mask );
#endif
    return wakeupSource;
}
Example #2
0
static int virtioblk_write(struct dev *dev, void *buffer, size_t count, blkno_t blkno, int flags) {
  struct virtioblk *vblk = (struct virtioblk *) dev->privdata;
  struct virtioblk_request req;
  struct scatterlist sg[3];
  int rc;

  // Setup write request
  virtioblk_setup_request(&req, sg, buffer, count);
  req.hdr.type = VIRTIO_BLK_T_OUT;
  req.hdr.ioprio = 0;
  req.hdr.sector = blkno;
  
  // Issue request
  rc = virtio_enqueue(&vblk->vq, sg, 2, 1, &req);
  if (rc < 0) return rc;
  virtio_kick(&vblk->vq);
  
  // Wait for request to complete
  enter_wait(THREAD_WAIT_DEVIO);

  // Check status code
  switch (req.status) {
    case VIRTIO_BLK_S_OK: rc = req.size - 1; break;
    case VIRTIO_BLK_S_UNSUPP: rc = -ENODEV; break;
    case VIRTIO_BLK_S_IOERR: rc = -EIO; break;
    default: rc = -EUNKNOWN; break;
  }

  return rc;
}
Example #3
0
void board_sleep() {
	uint8_t op_mode;
	//flextimer_save();
	clk_monitor_0(OFF);//turn off clock monitors so the freq can be changed without causing a reset
	PORTA_PCR2 |= PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;//JTAG_TDO -- disconnect jtag before entering deep sleep.    
	//enter_lls(); //need to restart bsp_timer maybe..
	enter_wait();
	clk_monitor_0(ON);//enable it again.
	//flextimer_restore();
}
Example #4
0
File: klog.c Project: HarryR/sanos
static int wait_for_klog() {
  struct klogreq req;

  req.thread = self();
  req.next = klog_waiters;
  klog_waiters = &req;

  enter_wait(THREAD_WAIT_DEVIO);

  return req.rc;
}
Example #5
0
static int virtiocon_write(struct dev *dev, void *buffer, size_t count, blkno_t blkno, int flags) {
  struct virtiocon *vcon = (struct virtiocon *) dev->privdata;
  struct scatterlist sg[1];
  int rc;

  // Issue request
  sg[0].data = buffer;
  sg[0].size = count;
  rc = virtio_enqueue(&vcon->output_queue, sg, 1, 0, self());
  if (rc < 0) return rc;
  virtio_kick(&vcon->output_queue);
  
  // Wait for request to complete
  enter_wait(THREAD_WAIT_DEVIO);

  return count;
}
int main (void)
{
    	char ch;
        char low_power_mode = MODE_SELECT;
        
         
        SMC_PMPROT = SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_AVLP_MASK ;  
        
#ifdef CMSIS  // If we are conforming to CMSIS, we need to call start here
    start();
#endif
        print_llwu_status();
        gpio_init();
               
        rtc_init();  // driven by 32kHz external oscillator //

        vfnLCD_Init();
        vfnLCD_Write_Msg("1234");      
             
        
    
        PORTC_PCR3 = PORT_PCR_MUX(1) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
        enable_irq(INT_LLW-16);
        llwu_configure(0x0080,0x02,LLWU_ME_WUME5_MASK); //M5= RTC Alarm,  M7 RTC seconds
        
        
   //check if it comes from VLLx mode
        if (PMC_REGSC % PMC_REGSC_ACKISO_MASK)
        {
          if (last_gpio_status&0x01) LED1_ON; else LED1_OFF;  //configure GPIO pin with latest state
          PMC_REGSC |= PMC_REGSC_ACKISO_MASK; //write to release hold on I/O
          last_gpio_status ^= 0x01;  //update state for next work
        }

        
  	printf("\n\rRunning the lcd_rtc_lowpower project.\n\r");
        
        // wait 3 seconds before start entering in low power mode
        while  (rtc_seconds_isrv_count<3){};
        

	while(1)
	{
           LED2_TOGGLE;
           
           ch=  (char)RTC_TSR;
	   sprintf(gu8USB_Buffer,"%4i",ch );
           vfnLCD_Write_Msg(gu8USB_Buffer);	
           printf("\n\r llwu_isrv_counter = %i, rtc_isrv_counter=%i ",llwu_isrv_counter, rtc_isrv_counter );
           printf("                       "); //delay 
          
        
           switch (low_power_mode)
           { 
             case MODE_WAIT:
             enter_wait();
             printf("\n\r exit from WAIT"); 
             break;
             
           case MODE_STOP:
           /* 0x00 = STOP - Normal Stop Mode
              0x40 = PSTOP1 - Partial Stop with both system and bus clocks disabled
              0x80 = PSTOP2 - Partial Stop with system clock disabled and bus clock enabled
           */
             enter_stop(0x00);

             printf("\n\r exit from STOP"); 
           break;
             
           case MODE_LLS:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;  //Disable Clock Monitor before entering in low power mode LLS, VLSSx
            enter_lls();
            op_mode = what_mcg_mode();
            if(op_mode==PBE)
            {
              mcg_clk_hz = pbe_pee(CLK0_FREQ_HZ);
              MCG_C6 |= MCG_C6_CME0_MASK;
            }
            printf("\n\r exit from LLS");  
            break;
            
            case MODE_VLLS3:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;
            enter_vlls3();
            //Note:  exit from VLLSx mode is through RESET PMC_REGSC_ACKISO is set
            break;
            
          // VLLS2 mode not supported on KL46       
            
            case MODE_VLLS1:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;
            enter_vlls1();  //In VLLS1 and VLLS0 no SRAM is retained.
            //Note:  exit from VLLSx mode is through RESET PMC_REGSC_ACKISO is set            
            break;            
            
           default:
           }          
	} 
}
Example #7
0
/**
 *  idle - puts processor into wait mode until next interrupt typically systick.
 */
void SnoozeClass::idle( void ) {
    enter_wait( );
}