Esempio n. 1
0
/*******************************************************************************
Function Name : InitSysclk
Engineer      : b08110
Date          : Jan-07-2011
Parameters    : NONE
Modifies      : NONE
Returns       : NONE
Notes         : initialize Fsys 64 MHz PLL with 8 MHz crystal reference
Issues        : NONE
*******************************************************************************/
static void InitSysclk(void)
{
    InitModesAndClks();
    InitPeriClkGen();
    DisableWatchdog(); 
}
Esempio n. 2
0
//=============================================================================
//
//=============================================================================
void MonitorMCU(void)
{
	BYTE ret, i, j;
	BYTE idx;
	 
	BYTE argv_num1, argv_num2; //, argv_num3;

	//if ( argc>2) {						 BKFYI: It will hurt a speed
	//	argv_num1 = a2h( argv[2] );
	//	if ( argc>3 ) {
	//		argv_num2 = a2h( argv[3] );
	//		if (argc > 4) {
	//			argv_num3 = a2h( argv[4] );
	//		}
	//	}
	//}

	//---------------------- Write SFR -----------------------
	if( !stricmp( argv[1], "Ws" ) ) {
		if( argc < 4 ) {
			Printf(" ----> Missing parameter !!!");
			return;
		}
		argv_num1 = a2h( argv[2] );
		argv_num2 = a2h( argv[3] );
		ret = WriteSFR(argv_num1, argv_num2);
		if( echo ) {
			Printf("\nMCU SFR Write: %02bx=%02bx (%02bx) ", argv_num1, argv_num2, ret);
			for(i=0; i<8; i++) {
				if( ret & 0x80 ) Puts("1"); else Puts("0");
				ret <<=1;
			}
		}
	}

	//---------------------- Read SFR ------------------------
	else if( !stricmp( argv[1], "Rs" ) ) {
		if( argc < 3 ) {
			Printf(" ----> Missing parameter !!!");
			return;
		}
		argv_num1 = a2h( argv[2] );
		ret = ReadSFR(argv_num1);
		if( echo ) {
			Printf("\nMCU SFR Read: %02bx=%02bx ", argv_num1, ret);
			for(i=0; i<8; i++) {
				if( ret & 0x80 ) Puts("1"); else Puts("0");
				ret <<=1;
			}
		}
	}

	//---------------------- Dump SFR ------------------------
	else if( !stricmp( argv[1], "Ds" ) ) {

		Printf("\nDump DP8051 SFR");
		for (j=0x8; j<=0x0f; j++) {
			Printf("\nSFR %02bx: ", j*0x10);
			for(i=0; i<8; i++) Printf("%02bx ", ReadSFR(j*0x10+i) );
			Printf("- ");
			for(; i<16; i++) Printf("%02bx ", ReadSFR(j*0x10+i) );
		}

	}
	//---------------------- Bitwise SFR control---------------------
	else if( !stricmp( argv[1], "Bs" ) ) {
		Printf("\nSorry!!");
	}
	//---------------------- Dump SFR map---------------------
	else if( !stricmp( argv[1], "SFR" ) ) {
		BYTE len;

		DWORD UsedTime;
		UsedTime = SystemClock;

		Printf("\nDump DP80390 SFR");



		for(j=0x00; j < 0x80; j++) {
			idx = j+0x80;
			for(i=0; i < 0x80; i++) {
				if(SFR_map[i].idx == idx)
					break;	//success
				if(SFR_map[i].idx == 0) {
					i = 0x80;
					break;  //fail
				}
			}
			if((j&0x07) == 0)
				Puts("\n");
			if(i != 0x80) {
				Printf("%02bx:%05s",SFR_map[i].idx, SFR_map[i].name);
				len = TWstrlen(SFR_map[i].name);
				len = 5-len;  //max 5.
				for(i=0; i < len; i++)
					Puts(" ");
				Printf(":%02bx ",ReadSFR(idx));
			}
			else {
			  //Printf("--:-----:--_");   
			  //Printf("            ");   
				Printf("   .....    ");   
			}
		}
		UsedTime = SystemClock - UsedTime;
		Printf("\nUsedTime:%ld.%ldsec", UsedTime/100, UsedTime%100 );

	}
	//---------------------- Dump xdata ----------------------
	else if( !stricmp( argv[1], "Wx" ) ) {

		WORD addr;

		if( argc < 4 ) {
			Printf(" ----> Missing parameter !!!");
			return;
		}
		addr      = a2h( argv[2] );
		argv_num2 = a2h( argv[3] );
		
		*(BYTE xdata *)(addr) = argv_num2;
		ret = *(BYTE xdata *)(addr);
		
		if( echo ) {
			Printf("\nMCU XDATA Write: %04x=%02bx (%02bx) ", addr, argv_num2, ret);
		}
	}

	//---------------------- Dump xdata ----------------------
	else if( !stricmp( argv[1], "Rx" ) ) {

		WORD addr;

		if( argc < 3 ) {
			Printf(" ----> Missing parameter !!!");
			return;
		}
		addr = a2h(argv[2]);

		ret = *(BYTE xdata *)(addr);

		if( echo ) {
			Printf("\nMCU XDATA Read: %04x=%02bx ", addr, ret);
		}
	}

	//---------------------- Dump xdata ----------------------
	else if( !stricmp( argv[1], "Dx" ) ) {

		//data BYTE xdata *osddata = (BYTE xdata *)0xc002;

		WORD addr=0x0000, len=0x100;

		if( argc>=3 ) addr = a2h(argv[2]);
		if( argc>=4 ) len  = a2h(argv[3]);

		Printf("\nDump DP8051 XDATA 0x%04x ", addr);
		for (j=0; j<len/0x10; j++) {
			Printf("\nXDATA %04x: ", (WORD)(addr+j*0x10) );
			for(i=0; i<8; i++) Printf("%02bx ", *(BYTE xdata *)(addr + j*0x10+i) );
			Printf("- ");
			for(; i<16; i++) Printf("%02bx ", *(BYTE xdata *)(addr + j*0x10+i) );
		}

	}

	//---------------------- Enable WDT ------------------------
#if defined(SUPPORT_WATCHDOG) || defined(DEBUG_WATCHDOG)
	else if( !stricmp( argv[1], "WDT" ) ) {
		if(argc > 2) {
			if( argv[2][0]=='1' ) {
				BYTE mode;
				if(argc > 3) 
					mode=a2h(argv[3]);
				else	
					mode = 0;

				EnableWatchdog(mode);
				Printf("\nWatchdog Timer is enabled. mode:%bx", mode);
			}
			else if( argv[2][0]=='2' ) {
				Puts("Watchdog test....");
				RestartWatchdog();
				Puts("start....");
				SFR_EWDI = 0;

				delay1s(1,__LINE__);
				delay1s(1,__LINE__);
				delay1s(1,__LINE__);
				delay1s(1,__LINE__);
				delay1s(1,__LINE__);
				delay1s(1,__LINE__);
				delay1s(1,__LINE__);
				//system reset before you here.
				Puts("..FAIL");
			}
			else {
				DisableWatchdog();
				Printf("\nWatchdog Timer is disabled.");
			}
		}
		else {
			Puts("\nWatchdog ");
			if(SFR_WDCON & 0x02) Puts("On");
			else                 Puts("Off");
#ifdef SUPPORT_WATCHDOG
			Puts(" with SUPPORT_WATCH");
#endif
#ifdef DEBUG_WATCHDOG
			Puts(" with DEBUG_WATCH");
#endif
		}

	}
#endif
	//---------------------- Enable INT ------------------------
	else if( !stricmp( argv[1], "IE" ) ) {
		if ( argc < 3 ) {
			Puts("\nMCU IE n 1/0 - MCU interrupt en/disable #n ");
			return;
		}
		argv_num1 = a2h( argv[2] );

		if( argv[3][0]=='1' ) {
			EnableExtInterrupt( argv_num1 );
			Printf("\nInterrupt #%d is enabled.", argv_num1);
		}
		else {
			DisableExtInterrupt( argv_num1 );
			Printf("\nInterrupt #%d is disabled.", argv_num1);
		}
	}
	//---------------------- Extended INT ------------------------
	else if( !stricmp( argv[1], "DE" ) ) {
		Printf("\nEnable DE-end Interrupt");
		SFR_IE1 = 0;	// Clear Pending Interrupt
		SFR_EX1 = 1;	// Enable Interrupt
	}
	//---------------------- Extended INT ------------------------
	else if( !stricmp( argv[1], "EI" ) ) {
	extern DWORD ExtIntCount;
		if( argc < 3 ) {
			Printf("\nMCU extend Interrupt Status: %02bx, count: %ld", EXINT_STATUS, ExtIntCount );
			ExtIntCount = 0;
#ifdef DEBUG_ISR
			Printf(" MCU %04x", MCU_INT_STATUS);
			MCU_INT_STATUS = 0;
#endif
			return;
		}
		argv_num1 = a2h( argv[2] );

		EXINT_STATUS &= argv_num1;
		
	}
	//---------------------- INTERRUPT Counter---------------------
#ifdef DEBUG_ISR
	else if( !stricmp( argv[1], "INTC" ) ) {
		BYTE i;
		WORD counter;
		for(i=0; i <= 20; i++) {
			SFR_EA=0;
			counter = INTR_counter[i];	//read
			INTR_counter[i]=0;			//clear
			SFR_EA=1;
			
			if(counter) {
				Printf("\n%02bd:%d",i,counter);
			}
		}
	}
#endif
#ifdef DEBUG_UART
	else if( !stricmp( argv[1], "UART" ) )
		DEBUG_dump_uart0();
#if 0
		 {
		BYTE i;
		if(UART0_OVERFLOW_counter) {
			Printf("\nUART0 Overflow:%bd",UART0_OVERFLOW_counter);
			UART0_OVERFLOW_counter = 0;  //clear
		}
		if(UART0_MAX_counter) {
			Printf("\nUART0 Max:%bd",UART0_MAX_counter);
			UART0_MAX_counter = 0;  //clear
		}
		Printf("\nRS_buf[%bd], RS_in:%bd RS_out:%bd",RS_BUF_MAX,RS_in,RS_out);
		for(i=0; i <  RS_BUF_MAX; i++)
			Printf(" %02bx", RS_buf[i]);
	}
#endif
#endif

	//---------------------- Interrupt Help ------------------------
	else if( !stricmp( argv[1], "INT" ) ) {
void main(void)
{

    IFR = 0x0000;
    IER = 0x0000;

    DisableWatchdog();
    InitSysParameters();                        // Initialization of system parameters
    InitSysTimer();                             // Initialization of system timer

#if (USE_TEST1_PIN)
    TEST_1_INI();
    TEST_1_OFF();
#endif
#if (USE_TEST2_PIN)
    TEST_2_INI();
    TEST_2_OFF();
#endif

    InitWatchdog();                             // Initialization of watchdog
    InitXWatchdog();                            // Initialization of extern watchdog

    InitIndicators();
//    InitSwitches();
    InitKeyboard();

    SetTimer(T_LED, T_LED_D);                   // Set Timers
    SetTimer(T_SEC, T_SEC_D);
    SetTimer(T_SWT, T_SWT_D);

    PieCtrlRegs.PIEACK.all = 0xFFFF;            // Enables PIE to drive a pulse into the CPU
    EINT;                                       // Enable Interrupts at the CPU level

    //--- Enable interrupts
    //SetDBGIER(IER);                             // Configure the DBGIER for realtime debug
    //asm(" CLRC INTM, DBGM");                    // Enable global interrupts and realtime debug

    TimeDev.second = 0;
    TimeDev.minute = 0;
    TimeDev.hour = 0;
    TimeDev.date = 0;

    EnableWatchdog();
//--------------------------------------------------------------------------------------------------
    for(;;)                                     // Main loop
    {
        ServiceWatchdog();                     // Reset Watchdog
//--------------------------------------------------------------------------------------------------
//----------------------------------------------// Time intervals
        if(CheckTimer(T_SEC))
        {
            SetTimer(T_SEC, T_SEC_D);
            if (++TimeDev.second > 59)
            {
                TimeDev.second = 0;
                if (++TimeDev.minute > 59)
                {
                    TimeDev.minute = 0;
                    if (++TimeDev.hour > 23)
                    {
                        TimeDev.hour = 0;
                        TimeDev.date++;
                    }
                }
            }
        }
//--------------------------------------------------------------------------------------------------
//----------------------------------------------// Indication
        if(CheckTimer(T_LED))
        {
            Debug[0]++;
            SetTimer(T_LED, T_LED_D);
//----------------------------------------------// Signaling the state of the system

//            ControlLedWork(TOGGLE);            // LED indicates normal work of the system
            //ControlIndicatorPower(TOGGLE);     // Indication of connection to the power line
//----------------------------------------------// Signaling presence of errors
            /*if (FlagDev.bit.ERR)
            {
                ControlLedError(TOGGLE);
                //ControlIndicatorError(TOGGLE);
            }
            else
            {
                ControlLedError(OFF);
                //ControlIndicatorError(OFF);
            }*/

#if (USE_INDICATOR1)
//----------------------------------------------// Indication of the device working
                                                // in the converter mode
            /*if (FlagDev.bit.WORK)
            {
                ControlIndicatorWork(ON);
            }
            else
            {
                ControlIndicatorWork(OFF);
            }*/
#endif

#if (USE_INDICATOR2)
//----------------------------------------------// Indication of the presence of communication
                                                // with the control device
            /*if (!ErrorDev.bit.CTR)
            {
                ControlIndicatorLink(ON);
            }
            else
            {
                ControlIndicatorLink(OFF);
            }*/
#endif
        }

        if(CheckTimer(T_SWT))
        {

#if (USE_SWT1)
            if (CheckButtonStop() && !CheckButtonStart())
            {
                FlagDev.bit.STOP = 1;
            }
#endif

#if (USE_SWT2)
            if (CheckButtonStart() && !CheckButtonStop())
            {
                FlagDev.bit.PUSK = 1;
            }
#endif

#if (USE_SWT3)
            if (CheckButtonReset())
            {
                FlagDev.bit.RESET = 1;
            }
#endif

#if (USE_ONB_BUT1)
            if (CheckButtonOnboard1())
            {
                ControlLedOnboard3(ON);
            }
            else
            {
                ControlLedOnboard3(OFF);
            }
#endif

#if (USE_KBRD)
            CheckKeyboard();
            if(KeyboardStat.bit.BUT1)
            {
                ControlLedWork(ON);
                Debug[1] = 1;
            }
            else
            {
                ControlLedWork(OFF);
                Debug[1] = 0;
            }
            if(KeyboardStat.bit.BUT2)
            {
                ControlLedError(ON);
                Debug[2] = 1;
            }
            else
            {
                ControlLedError(OFF);
                Debug[2] = 0;
            }
            if(KeyboardStat.bit.BUT4)
            {
                ControlLedOnboard3(ON);
                Debug[3] = 1;
            }
            else
            {
                ControlLedOnboard3(OFF);
                Debug[3] = 0;
            }
            if(KeyboardStat.bit.BUT5)
            {
                ControlLedOnboard4(ON);
                Debug[4] = 1;
            }
            else
            {
                ControlLedOnboard4(OFF);
                Debug[4] = 0;
            }
#endif
        }
//--------------------------------------------------------------------------------------------------
    }
}