virtual BOOL    PowerOff()
 {
     SetDTR(FALSE);
     CSerialPDD::PowerOff();
     if(m_pSysconRegs)
     {
         m_pSysconRegs->PCLK_GATE  &= ~PCLK_UART0;        // UART0
         m_pSysconRegs->SCLK_GATE  &= ~SCLK_UART;        // UART0~3
     }
     return TRUE;
 }
 virtual BOOL    PowerOn()
 {
     if(m_pSysconRegs)
     {
         m_pSysconRegs->PCLK_GATE  |= PCLK_UART0;        // UART0
         m_pSysconRegs->SCLK_GATE  |= SCLK_UART;        // UART0~3    
     }
     CSerialPDD::PowerOn();
     SetDTR(TRUE);
     return TRUE;
 }
Beispiel #3
0
/*-------------------------MAIN FUNCTION------------------------------
**********************************************************************/
int c_entry(void)
{	
	InitIR2110();  // Use for Driver PWM IC IR2110
//	EnableIR2110();
	DisableIR2110(); 

	flag_soft_start = 1;

	#ifdef RUN_OK
	Delayms(3000);
	#endif
//	InitDAC();
			//	 Initialize debug via UART0
//	  – 9600bps
//	  – 8 data bit
//	  – No parity
//	  – 1 stop bit
//	  – No flow control	 
	debug_frmwrk_init();
	SetOutputDTR();
	ClearDTR();  //data receive
	InitLedAlarmBattery();
	InitLedAlarmOverload();
	InitPWM(PWM_FREQUENCY,DEADTIME);
	SetDutyPWM(0,0); 
	InitADC(ADC_FREQUENCY); 
	
	InitTimerADCRead();
	
	InitTimerProcessSinwave();
	
	InitTimerProcessSensorRMSValue();
	InitTimerMainProcess();
	InitBuzzer(10000);
	
	#ifdef RUN_OK
	while(fist_startup)
	{
		if(f_Vin_RMS > VOLTAGE_MIN/*Vol*/)	
		{
			flag_voltage_low = 0;
			flag_current_high = 0;
			fist_startup = 0;
		}
	}
	#endif
	while (1)
	{	
		if ((LPC_UART1->LSR & UART_LSR_RDR)) 
		{
			buff[0] = UART_ReceiveByte((LPC_UART_TypeDef *)LPC_UART1);
			if(buff[0] == 'I')
			{
				Delayms(100);
				SetDTR();	  //data transmission
				printf_dbg("I,%d,\r",(uint32_t)(f_Vin_RMS*f_Iin_RMS));
				Delayms(10);
				ClearDTR();	  //data receive
				buff[0] = 0;
			}
		}
	}
    return 1;
}
 virtual BOOL    InitModem(BOOL bInit)
 {
     SetDTR(bInit);
     return CPdd6410Uart::InitModem(bInit);
 }
Beispiel #5
0
//---------------------------------------------------------------------------
bool TSTPort::Create(Str &ErrorText,Str &ErrorTitle,bool DoAlert)
{
  Close();
  bool Running=(runstate==RUNSTATE_RUNNING);
  LPPORTIOINFIRSTBYTEPROC FirstByteInProc=NULL;
  LPPORTIOOUTFINISHEDPROC LastByteOutProc=NULL;
  if (&MIDIPort==this){
    FirstByteInProc=MidiInBufNotEmpty;
  }else if (&ParallelPort==this){
    FirstByteInProc=ParallelInputNotify;
    LastByteOutProc=ParallelOutputNotify;
  }else if (&SerialPort==this){
    FirstByteInProc=SerialInBufNotEmpty;
  }
  bool Error=0;

  switch (Type){
    case PORTTYPE_FILE:
      f=fopen(File,"ab");
      return true;
    case PORTTYPE_LOOP:
      LoopBuf=new CircularBuffer(PORT_LOOPBUFSIZE);
      return true;
  }
#ifdef WIN32
  EasyStr PortName=EasyStr("COM")+(COMNum+1);
  int AllowIn=true,AllowOut=true;
  switch (Type){
    case PORTTYPE_MIDI:
    {
      bool MIDIOutErr=0,MIDIInErr=0;
      if (MIDIOutDevice>-2){
        MIDI_Out=new TMIDIOut(MIDIOutDevice,WORD(Running ? MIDI_out_volume:0));
        if (MIDI_Out->IsOpen()==0) MIDIOutErr=true;
      }
      if (MIDIInDevice>-1){
        MIDI_In=new TMIDIIn(MIDIInDevice,Running,FirstByteInProc);
        if (MIDI_In->IsOpen()==0) MIDIInErr=true;
      }
      if (MIDIInErr && MIDIOutErr){
        ErrorTitle=T("MIDI Errors");
        ErrorText=T("MIDI Output Error")+"\n"+MIDI_Out->ErrorText+"\n\n";
        ErrorText+=T("MIDI Input Error")+"\n"+MIDI_In->ErrorText;
      }else if (MIDIInErr){
        ErrorTitle=T("MIDI Input Error");
        ErrorText=MIDI_In->ErrorText;
      }else if (MIDIOutErr){
        ErrorTitle=T("MIDI Output Error");
        ErrorText=MIDI_Out->ErrorText;
      }
      if (MIDIOutErr){ delete MIDI_Out; MIDI_Out=NULL; }
      if (MIDIInErr){ delete MIDI_In; MIDI_In=NULL; }
      Error=(MIDIOutErr || MIDIInErr);
      break;
    }
    case PORTTYPE_PARALLEL:
      PortName=EasyStr("LPT")+(LPTNum+1);
      AllowIn=comline_allow_LPT_input;
    case PORTTYPE_COM:
      PCPort=new TPortIO(PortName,AllowIn,AllowOut);
      break;
  }
#elif defined(UNIX)
  int PortIOType=GetPortIOType(Type);
  if (PortIOType>=0){
    if (Type==PORTTYPE_LAN){
      PCPort=new TPortIO(PortDev[PortIOType],true,0,PortIOType);
      PCPortIn=new TPortIO(LANPipeIn,0,true,PortIOType);
    }else{
      PCPort=new TPortIO(PortDev[PortIOType],AllowIO[PortIOType][0],AllowIO[PortIOType][1],PortIOType);
    }
  }
#endif
	if (PCPort){
    if (PCPort->IsOpen()==0) Error=true;
    if (PCPortIn) if (PCPortIn->IsOpen()==0) Error=true;
    if (Error){
      ErrorTitle=T("Port Error");
#ifdef WIN32
      ErrorText=T("Could not open port ")+PortName+". "+
                T("It may not exist or it could be in use by another program.");
#else
      Str BadDev;
      ErrorText="";
      if (PCPortIn){
        if (PCPort->IsOpen()==0){
          BadDev=PortDev[PortIOType];
        }else{
          BadDev=LANPipeIn;
        }
      }else if (AllowIO[PortIOType][0] || AllowIO[PortIOType][1]){
        BadDev=PortDev[PortIOType];
      }
      if (BadDev.NotEmpty()){
        ErrorText=T("Could not open device")+" "+BadDev+"\n\n"+
                  T("It may not exist, it could be in use by another program or you may not have permission to access it.");
      }
#endif
      delete PCPort;PCPort=NULL;
      if (PCPortIn) delete PCPortIn;
      PCPortIn=NULL;
    }else{
      PCPort->lpInFirstByteProc=FirstByteInProc;
      PCPort->lpOutFinishedProc=LastByteOutProc;
      PCPort->OutPause=(Running==0);
      PCPort->InPause=(Running==0);
      if (PCPortIn){
        PCPortIn->lpInFirstByteProc=FirstByteInProc;
        PCPortIn->InPause=(Running==0);
      }
    }
  }
  if (Running){
    if (this==&ParallelPort){
      UpdateCentronicsBusyBit();
    }else if (this==&SerialPort){
      SetDTR(psg_reg[PSGR_PORT_A] & BIT_4);
      SetRTS(psg_reg[PSGR_PORT_A] & BIT_3);
    }
  }
  if (DoAlert && Error && ErrorText.NotEmpty()){
    Alert(ErrorText,ErrorTitle,MB_ICONEXCLAMATION | MB_OK);
  }
  CheckResetDisplay();
  return Error==0;
}