Exemple #1
0
/* the clearing of the flags cannot be done in the idle loop because
 * it may be interrupted
 */
void TaskCheckIn(etTaskCheckInId TaskId)
{
  portENTER_CRITICAL();  
  
  TaskCheckInFlags |= (1 << (unsigned char)TaskId);

#if WATCHDOG_TEST_MODE == 0
  if ( TaskCheckInFlags == ALL_TASKS_HAVE_CHECKED_IN )
  {
    /* all tasks have checked in - so the flags can be cleared
     * and the watchdog can be kicked
     */
    TaskCheckInFlags = 0;
    RestartWatchdog();
  }
#endif
  
  portEXIT_CRITICAL();
//  PrintStringAndHexByte("- ChkIn:0x", TaskCheckInFlags);
}
Exemple #2
0
void main(void)
{
    ENABLE_LCD_LED();

#if ENABLE_WATCHDOG
    RestartWatchdog();
#else
    WDTCTL = WDTPW + WDTHOLD;
#endif

    /* clear shipping mode, if set to allow configuration */
    PMMCTL0_H = PMMPW_H;
    PM5CTL0 &= ~LOCKLPM5;

    /* disable DMA during read-modify-write cycles */
    DMACTL4 = DMARMWDIS;

    DetermineErrata();

#ifdef BOOTLOADER

    /*
     * enable RAM alternate interrupt vectors
     * these are defined in AltVect.s43 and copied to RAM by cstartup
     */
    SYSCTL |= SYSRIVECT;

    ClearBootloaderSignature();

#endif

    /* calibration data is used for clock setup */
    InitializeCalibrationData();

#ifndef BOOTLOADER
    SaveResetSource();
#endif

    SetupClockAndPowerManagementModule();

    OsalNvInit(0);

    /* change the mux settings according to presense of the charging clip */
    InitializeMuxMode();
    ChangeMuxMode();

    InitDebugUart();
    TestModeControl();

    /* adc is required to get the board configuration */
    InitializeAdc();
    ConfigureDefaultIO(GetBoardConfiguration());

    InitializeDebugFlags();

//  InitButton();

    InitializeVibration();
    InitializeOneSecondTimers();

    InitializeBufferPool();
    InitializeWrapperTask();
    InitializeRealTimeClock();

    InitializeDisplayTask();

    DISABLE_LCD_LED();

#if CHECK_FOR_PMM15
    /* make sure error pmm15 does not exist */
    while ( PMM15Check() );
#endif

    /* Errata PMM17 - automatic prolongation mechanism
     * SVSLOW is disabled
     */
    *(unsigned int*)(0x0110) = 0x9602;
    *(unsigned int*)(0x0112) |= 0x0800;

    WhoAmI();
    PrintResetSource();

    /* if a watchdog occurred then print and save information about the source */
    WatchdogTimeoutHandler(GetResetSource());

    PrintString("Starting Task Scheduler\r\n");
    SetUartNormalMode();

    vTaskStartScheduler();

    /* if vTaskStartScheduler exits an error occured. */
    PrintString("Program Error\r\n");
    ForceWatchdogReset();
}
Exemple #3
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" ) ) {