예제 #1
0
/* This function will invoke the CPU power save sleep mode.
 *
 * Bus traffic will wake the CPU and cause execution to vector to the CAN
 * module's ISR. The ISR will detect the event as a wakeup and call the wake-up
 * handler, which simply performs a software reset.
 *
 * TODO: This function could be a centralized location for putting peripherals
 * in low power or OFF states. Right now that is done by the caller
 * (vi-firmware.cpp). This is easy to do via direct manipulation of the
 * peripheral control registers (SFRs), but skips over the peripheral libraries.
 * Using the existing C++ libraries here isn't always possible, however, since
 * they can use overloaded functions, which gcc won't allow.
 */
void openxc::power::suspend() {
    debug("Going to low power mode");

    PowerSaveSleep();

    // The only peripheral configured with wake-up events should be the CAN1
    // module. That event will trigger the CAN1 ISR, which will lead directly to
    // a software reset. Code execution should therefore never reach this point.
    // Nevertheless, a software reset would be prudent here.
    SoftReset();
}
void gotoSLEEP()
{
    if (processIRCommand)
    {
        printf("Ignore sleep, have IR to process\r\n");
        return;
    }


    printf("Sleep\r\n");
    delayMs(20);

    T2CONbits.ON = 0;
    enableCNModule(stbTVRunning);

    PowerSaveSleep();
    disableCNModule();

    prepareTimer2AfterWake();
}
예제 #3
0
void DoSerial() // Serial Processing of any input data
{
	char c;
	uint8 i;
	if(Serial2Available())
	{
		SerialConnected=1;	// Client has connected so we can now send stuff.. (Set until POR as we dont have the equivelent for a disconnect)
		c = Serial2Read();
		if(c==3)	// 3. Raw image test (focus setup etc)
		{
			while(c!=1 && c!=9)
			{
				OC_COUNT(ON);
				AquireImage();
				Serial2Write(3);
				Serial2Write(99);
				for(i=0; i<128; i++)
					Serial2Write(RawData[i]);
				Serial2Write(99);
				DelayMicroseconds(100000);
				if(Serial2Available()) c = Serial2Read();
			}
		}
		if(c==4) // 4. end processing
		{
			PowerSaveSleep(); // END!
			while(1);
		}
		if(c==5)	// 5. Send fixed (NVM) settings
		{
			Serial2Write(5);
    	Serial2Write(99);
			Serial2Write(Tmin);
			Serial2Write(algorithm);
			Serial2Write(cap);
			Serial2Write(neck);
			Serial2Write(SampleRate>>8);
			Serial2Write(SampleRate);
			Serial2Write(RejOnTime>>8);
			Serial2Write(RejOnTime);
			Serial2Write(tollerance);
		}
		if(c==6) SendCounters();// 6. Send current settings
		if(c==7)	// 7. Receive new settings temporary until reset or permanent if written to NVM
		{
			Tmin=Serial2Read();
			algorithm=Serial2Read();
			cap=Serial2Read();
			neck=Serial2Read();
			SampleRate=Serial2Read()<<8 + Serial2Read();
			RejOnTime=Serial2Read()<<8 + Serial2Read();
			tollerance=Serial2Read();
			NVMChanged=1;
			Serial2Write(7);
		}
		if(c==8 && NVMChanged)  // 8. Save to NVM
		{
			if( (void*)(NVMPtr+8) >= NVM_END)  // used all the flash page so we have to erase whole page and start again (will never happen seriously!)
			{
				NVMErasePage(NVM_START);
				NVMPtr = NVM_START;
			}
			// Each variable is stored as a 32 bit integer which is the minimum size programable to flash NVMPtr will always be set at next free FLASH slot after POR or a write
			NVMWriteWord( (void*) (NVMPtr++) , Tmin );
			NVMWriteWord( (void*) (NVMPtr++) , algorithm );
			NVMWriteWord( (void*) (NVMPtr++) , cap );
			NVMWriteWord( (void*) (NVMPtr++) , neck );
			NVMWriteWord( (void*) (NVMPtr++) , SampleRate );
			NVMWriteWord( (void*) (NVMPtr++) , RejOnTime);
			NVMWriteWord( (void*) (NVMPtr++) , tollerance);
			NVMChanged = 0; // All good so unflag change
			Serial2Write(8);
		}
		if(c==9) SoftReset();		// 9. RESET Sensor!
	}