Пример #1
0
/*-----------*/
int main(void) {
	uint8_t x;

	_INIT();

	wdt_enable(WDTO_1S);

    usbInit();
    usbDeviceDisconnect();	// enforce re-enumeration, do this while interrupts are disabled!
    x = 25;
    while(--x) {             // fake USB disconnect for > 250 ms
        wdt_reset();
        _delay_ms(10);
    }
    usbDeviceConnect();

	pulse_counter = 0;
	sei();

    DisplayRefresh(1);
    x = 100;
    while(--x) {
        wdt_reset();
        _delay_ms(10);
    }
	ClearLine(SecondLine);
	DisplayRefresh(1);

    uart_init(__UBRR);
    uart_putstr("\r\n");
    uart_putstr("Radioactive@Home V2.60\r\n");
    uart_putstr("Firmware 1.0 (27.03.14)\r\n");

    while(1) {
    	wdt_reset();
        usbPoll();

        HV_Supply_EVENT();
        BeepIfChange_EVENT();
        Switch_EVENT();
        RadCalc_EVENT();
        DisplayRefresh_EVENT();
    }
    return 0;
}
Пример #2
0
__myevic__ void Plantouille( int xpsr, int* stack )
{
	int i, k;

	k = 0;

	SYS_UnlockReg();
	WDT_Close();
	SYS_LockReg();

	InitDisplay();

	while ( 1 )
	{
		ClearScreenBuffer();

		DrawImage( 0, 0, 'X'+0x27 );
		DrawHexLong( 16, 0, xpsr, 0 );

		DrawHexDigit( 0, 16, k );

		for ( i = 0; i < 14 ; ++i )
		{
			DrawHexLong( 16, 16+i*8, stack[i+k*14], 0 );
		}

		DisplayRefresh();

		while ( !PE0 || !PD2 || !PD3 )
			CLK_SysTickDelay( 10000 );

		while ( PE0 && PD2 && PD3 )
			CLK_SysTickDelay( 10000 );

		if ( !PE0 )
		{
		  SYS_UnlockReg();
		  SYS_ResetChip();
		  while ( 1 )
			;
		}

		if ( !PD2 ) ++k;
		if ( !PD3 ) --k;

		if ( k < 0 ) k = 0;
		else if ( k > 15 ) k = 15;
	}
}
Пример #3
0
void UpdateGraph( void )
{
    if ((tick - previousTick ) > graphUpdateRate)
    {
        previousTick = tick;

        // Remove the old graph and vertical grid lines
        SetColor( BLACK );
        DrawGraphLine();
        DrawGridVerticals();

        // Get the latest potentiometer reading.
        graphData[graphDataTail++] = graphNextSample ;

        if (graphDataTail == GRAPH_DATA_BUFFER_SIZE)
        {
            graphDataTail = 0;
        }

        // When the graph is full, update the head pointer to wrap and the display offset
        if (graphDataHead == graphDataTail)
        {
            graphDataHead ++;
            if (graphDataHead == GRAPH_DATA_BUFFER_SIZE)
            {
                graphDataHead = 0;
            }

            graphOffset ++;
            if (graphOffset >= GRID_SPACING_HORIZONTAL)
            {
                graphOffset = 0;
            }
        }

        // Draw the new graph
        SetColor( WHITE );
        DrawGraphLine();

        // Draw the updated grid
        //SetColor( WHITE );
        //DrawGridVerticals();
        //DrawGridHorizontals();
		DisplayRefresh(GDbuffer,DISPLAY_WIDTH);
    }
}
Пример #4
0
__myevic__ void GameIClick()
{
	UpdateDataFlash();
	if ( dfFBSpeed <= 2 )
	{
		gFlags.playing_fb = 1;
		Screen = 0;
		gFlags.user_idle = 1;
		gFlags.refresh_display = 1;
		BatRefreshTmr = 0;
		SleepTimer = 3000;
		fbInitTimeouts();
		ClearScreenBuffer();
		DisplayRefresh();
		fbBirdAnim( 24 );
		fbCreateTimeout( fbStartScreen + 1 );
	}
}
Пример #5
0
//****************************************************************************
//
//! Task function implementing the gettime functionality using an NTP server
//!
//! \param none
//!
//! This function
//!    1. Initializes the required peripherals
//!    2. Initializes network driver and connects to the default AP
//!    3. Creates a UDP socket, gets the NTP server IP address using DNS
//!    4. Periodically gets the NTP time and displays the time
//!
//! \return Returns \b TASK_RET_IN_PROG.
//
//****************************************************************************
int GetNTPTimeTask(void *pvParameters)
{
    SlSecParams_t SecurityParams;
    long lRetVal = -1;
    struct SlTimeval_t timeVal;
    static char cTaskOwnState = GET_TIME_TASK_STATE_INIT;
    static tGetTime sGetTime;
    long OptionLen;
    int SetCommitInt;
    unsigned char OptionVal;

    switch(cTaskOwnState)
    {

    case GET_TIME_TASK_STATE_INIT:
        //
        // Start networking service in default STA_MODE state
        //
        lRetVal = NetStartDefaultState();
        if(lRetVal < 0)
        {
          return TASK_RET_DONE;
        }

        //
        // Set the status as stated
        //
        sDisplayInfo.ucNetStat = NET_STAT_STARTED;

        //
        // Set the time zone
        //
        sGetTime.ucGmtDiffHr   = GMT_DIFF_TIME_HRS;
        sGetTime.ucGmtDiffMins = GMT_DIFF_TIME_MINS;

        //
        // Set conneting status
        //
        sDisplayInfo.ucNetStat = NET_STAT_CONN;

        //
        // Get the Version Info
        //
        NetFwInfoGet(&sDisplayInfo.sNwpVersion);

        //
        // Make the formated string for firmware version
        //
        sprintf(sDisplayInfo.ucNwpVersion,
                "%d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d",
                sDisplayInfo.sNwpVersion.NwpVersion[0],
                sDisplayInfo.sNwpVersion.NwpVersion[1],
                sDisplayInfo.sNwpVersion.NwpVersion[2],
                sDisplayInfo.sNwpVersion.NwpVersion[3],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[0],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[1],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[2],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.FwVersion[3],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[0],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[1],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[2],
                sDisplayInfo.sNwpVersion.ChipFwAndPhyVersion.PhyVersion[3]);

        //
        // Set next task state
        //
        cTaskOwnState = GET_TIME_TASK_STATE_CONN;

        //
        // Signal display refresh
        //
        DisplayRefresh();
        break;

    case GET_TIME_TASK_STATE_CONN:

        //
        // Initialize AP security params
        //
        SecurityParams.Key = (signed char *)SECURITY_KEY;
        SecurityParams.KeyLen = strlen(SECURITY_KEY);
        SecurityParams.Type = SECURITY_TYPE;

        //
        // Connect to Access Point
        //
        lRetVal = NetWlanConnect(SSID_NAME,&SecurityParams);

        //
        // Failed to connect to AP, kill the task
        //
        if(lRetVal != 0)
        {
          return TASK_RET_DONE;
        }

        //
	// Check if this image is booted in test mode
	//
	sl_extLib_OtaGet(pvOtaApp,EXTLIB_OTA_GET_OPT_IS_PENDING_COMMIT,
                         &OptionLen,&OptionVal);

	if(OptionVal == true)
	{


            SetCommitInt = OTA_ACTION_IMAGE_COMMITED;
            sl_extLib_OtaSet(pvOtaApp, EXTLIB_OTA_SET_OPT_IMAGE_COMMIT,
                             sizeof(int), (_u8 *)&SetCommitInt);

            //
            // Set status
            //
            g_ulSysState = SYS_STATE_TEST_REBOOT;
            DisplayRefresh();

            //
            // Reboot the MCU
            //
            cTaskOwnState = GET_TIME_TASK_STATE_DONE;
            break;
	}

        //
        // Set the status
        //
        sDisplayInfo.ucNetStat = NET_STAT_CONNED;
        DisplayRefresh();

        //
        // Signal the network start
        //
        TaskSyncObjSignal(&g_NetStatSyncObj);

        //
        // Set next task state
        //
        cTaskOwnState = GET_TIME_TASK_STATE_OPEN_SOCK;

        break;

    case GET_TIME_TASK_STATE_OPEN_SOCK:

        //
        // Create UDP socket
        //
        sGetTime.iSocket = sl_Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

        //
        // Failed to create a socket, kill the task
        //
        while(sGetTime.iSocket < 0)
        {
          return TASK_RET_DONE;
        }

        //
        // Set socket time option
        //
        timeVal.tv_sec =  20;
        timeVal.tv_usec = 0;
        sl_SetSockOpt(sGetTime.iSocket,SOL_SOCKET,SL_SO_RCVTIMEO, &timeVal,
                      sizeof(timeVal));

        //
        // Initialize Server Index
        //
        sDisplayInfo.ucServerIndex = 0;
        DisplayRefresh();

        //
        // Set next task state
        //
        cTaskOwnState = GET_TIME_TASK_STATE_GET_IP;
        break;


    case GET_TIME_TASK_STATE_GET_IP:

        //
        // Get the NTP server host IP address using the DNS lookup
        //
        lRetVal = NetGetHostIP((char*)g_acSNTPserver[sDisplayInfo.ucServerIndex],
                         &sGetTime.ulNtpServerIP);

        sDisplayInfo.ulServerIP = sGetTime.ulNtpServerIP;
        DisplayRefresh();

        //
        // Set the net task state based on return value
        //
        if(lRetVal >= 0)
        {
          //
          // Go to get time
          //
          cTaskOwnState = GET_TIME_TASK_STATE_GET_TIME;
        }
        else
        {
          //
          // Go back and try a new NTP server
          //
          cTaskOwnState = GET_TIME_TASK_STATE_SET_SERVER;
        }
        break;

    case GET_TIME_TASK_STATE_GET_TIME:

        //
        // Get the NTP time and display the time
        //
        lRetVal = GetSNTPTime(&sGetTime);
        DisplayRefresh();

        //
        // On failure go back and try a new NTP server
        //
        if(lRetVal != 0)
        {
          //
          // Chech and wait if we are disconnected
          //
          while( !NetIsConnectedToAP() )
          {

          }

          cTaskOwnState = GET_TIME_TASK_STATE_SET_SERVER;
        }

        //
        // End the task if Reboot was requested
        //
        if(g_ulSysState == SYS_STATE_REBOOT)
        {
          cTaskOwnState = GET_TIME_TASK_STATE_DONE;
        }

        //
        // Set some sleep
        //
        TaskSleep(5*1000);
        break;

    case GET_TIME_TASK_STATE_SET_SERVER:

          strcpy((char *)sDisplayInfo.ucUTCTime,"NTP Server Error. Retrying...");
          sDisplayInfo.ucLocalTime[0]='-';
          sDisplayInfo.ucLocalTime[1]='\0';

          sDisplayInfo.ucServerIndex
            = ((sDisplayInfo.ucServerIndex + 1)%NOF_NTP_SERVER);

          cTaskOwnState = GET_TIME_TASK_STATE_GET_IP;
          DisplayRefresh();
          break;

    default:

        //
        // Disconnect and stop networking service
        //
        NetStop();

        sDisplayInfo.ucNetStat = NET_STAT_OFF;
        DisplayRefresh();

        //
        // Reboot nonw
        //
        RebootMCU();

        //
        // Return task done
        //
        return TASK_RET_DONE;
    }

    //
    // Return task in progress
    //
    return TASK_RET_IN_PROG;
}
Пример #6
0
//****************************************************************************
//
//! Task function implementing the OTA update functionality
//!
//! \param none
//!
//! \return None.
//
//****************************************************************************
int OTAUpdateTask(void *pvParameters)
{
    int iRet;
    int SetCommitInt = 1;
    unsigned char ucVendorStr[50];
    unsigned long ulVendorStrLen;
    static char cTaskOwnState = OTA_UPDATE_STATE_WAIT_START;

    switch(cTaskOwnState)
    {

    case OTA_UPDATE_STATE_WAIT_START:

        cTaskOwnState = OTA_UPDATE_STATE_WAIT_BTN;

        //
        // Wait for sl_Start and wlan connect to complete
        //
        TaskSyncObjWait(&g_NetStatSyncObj);
        break;

    case OTA_UPDATE_STATE_WAIT_BTN:

        cTaskOwnState = OTA_UPDATE_STATE_INIT;

        //
        // Wait for button press
        //
        TaskSyncObjWait(&g_OTAStatSyncObj);
        Button_IF_EnableInterrupt(SW3);
        break;

    case OTA_UPDATE_STATE_INIT:

        //
	// Create vendor string from NWP version and Vendor Prefix
	//
        strcpy((char *)ucVendorStr,OTA_VENDOR_STRING);

        ulVendorStrLen = strlen(OTA_VENDOR_STRING);

        sprintf((char *)&ucVendorStr[ulVendorStrLen],"%02lu",
        sDisplayInfo.sNwpVersion.NwpVersion[3]);

        //
        // Initializa OTA service
        //
        OTAServerInfoSet(&pvOtaApp,(char *)ucVendorStr);

        //
        // Set the OTA status and system state to RUN
        //
        sDisplayInfo.iOTAStatus = OTA_INPROGRESS;
        g_ulSysState	        = SYS_STATE_RUN;
        cTaskOwnState           = OTA_UPDATE_STATE_RUN;
        DisplayRefresh();
        break;

    case OTA_UPDATE_STATE_RUN:

        iRet = sl_extLib_OtaRun(pvOtaApp);

        if ( iRet < 0 )
        {

            if( RUN_STAT_ERROR_CONTINUOUS_ACCESS_FAILURES == iRet )
            {
              //
              // Schelude a restart.
              //
              sDisplayInfo.iOTAStatus = OTA_ERROR;
              g_ulSysState =  SYS_STATE_REBOOT;

            }
            else
            {
              sDisplayInfo.iOTAStatus = OTA_ERROR_RETRY;
            }

        }
        else if( iRet == RUN_STAT_NO_UPDATES )
        {

            sDisplayInfo.iOTAStatus = OTA_NO_UPDATES;
            g_ulSysState =  SYS_STATE_WAIT;
            cTaskOwnState = OTA_UPDATE_STATE_WAIT_BTN;
            //
            // Enable button Interrupt
            //
            Button_IF_EnableInterrupt(SW3);
            DisplayRefresh();
        }
        else if ((iRet & RUN_STAT_DOWNLOAD_DONE))
        {
            //
            // Set OTA File for testing
            //
            iRet = sl_extLib_OtaSet(pvOtaApp, EXTLIB_OTA_SET_OPT_IMAGE_TEST,
                                    sizeof(int), (_u8 *)&SetCommitInt);

            sDisplayInfo.iOTAStatus = OTA_DONE;

            if (iRet & (OTA_ACTION_RESET_MCU| OTA_ACTION_RESET_NWP) )
            {
                g_ulSysState  = SYS_STATE_REBOOT;
                cTaskOwnState = OTA_UPDATE_STATE_DONE;
            }
            else
            {
                g_ulSysState =  SYS_STATE_WAIT;
                cTaskOwnState = OTA_UPDATE_STATE_WAIT_BTN;
                //
                // Enable button Interrupt
                //
                Button_IF_EnableInterrupt(SW3);
            }
        }
        else if(sDisplayInfo.iOTAStatus == OTA_ERROR_RETRY)
        {
          sDisplayInfo.iOTAStatus = OTA_INPROGRESS;

        }

        DisplayRefresh();
        break;

    default:
      return TASK_RET_DONE;

    }

    return TASK_RET_IN_PROG;
}
Пример #7
0
__myevic__ void DrawScreen()
{
	if ( Screen == 2 && FireDuration && FireDuration != CurrentFD )
	{
		CurrentFD = FireDuration;
		ScreenDuration = 1;
		ShowFDTimer = 0;
		gFlags.refresh_display = 1;
	}

	if ( gFlags.refresh_display )
	{
		gFlags.refresh_display = 0;
		ClearScreenBuffer();

		switch ( Screen )
		{
			case  0: // Black
				break;

			case  1: // Main view
			case  3: // Main view (?)
			case  4: // (unused?)
				ShowMainView();
				break;

			case  2: // Firing
				if ( !dfStealthOn )
				{
					ShowMainView();
				}
				break;

			case  5: // Black w/ Battery
				ShowBatCharging();
				break;

			case 20: // No Atomizer Found
				ShowNoAtoFound();
				break;

			case 21: // Atomizer Short
				ShowAtoShort();
				break;

				case 22: // Atomizer Low
				ShowAtoLow();
				break;

			case 23: // 10s Protection
				Show10sProtec();
				break;

			case 24: // Battery Low
				ShowBatLow();
				break;

			case 25: // Battery Low Lock
				ShowBatLowLock();
				break;

			case 28: // Key Lock
				ShowKeyLock();
				break;

			case 29: // Device too hot
				ShowDevTooHot();
				break;

			case 31: // Key UnLock
				ShowKeyUnLock();
				break;

			case 37: // Board Temp
				ShowBoardTemp();
				break;

			case 40: // Stealth ON/OFF
				ShowStealthMode();
				break;

			case 41: // Ti ON/OFF
				ShowTiOnOff();
				break;

			case 50: // FW Version
				ShowVersion();
				break;

			case 51: // New Coil
				ShowNewCoil();
				break;

			case 54: // Battery Voltage
				ShowBattVolts();
				break;

			case 59: // TCR Set Menu
				ShowTCRSet();
				break;

			case 82: // LOGO Menu
				ShowLOGOMenu();
				break;

			case 83: // Game Menu
				ShowGameMenu();
				break;

			case 100:
				ShowInfos();
				break;

			case 101:
				ShowContrast();
				break;

			case 102:
				ShowMenus();
				break;

			case 103:
				ShowRTCSpeed();
				break;

			case 104:
				ShowRTCAdjust();
				break;

			default:
				break;
		}

		if ( myDbgFlag & 1 )
		{
			int nd = (Screen<100?Screen<10?1:2:3);
			DrawValue( 64-6*nd, 120, Screen, 0, 0x01, nd );
			DrawValue( 0, 120, ScreenDuration, 0, 0x01, 0 );
		}
		
		DisplayRefresh();
	}

	if (( gFlags.firing ) && ISMODETC(dfMode))
	{
		ShowFDTimer += 5;
	}
	else
	{
		ShowFDTimer += 1;
	}

	if ( ShowFDTimer < 10 )
		return;

	ShowFDTimer = 0;

	if ( ScreenDuration && --ScreenDuration )
		return;

	switch ( Screen )
	{
		case   0: // Black
			if ( dfStatus.off )
			{
				SleepTimer = 0;
			}
			break;

		case   2: // Firing
			if ( dfStealthOn )
			{
				gFlags.refresh_display = 1;
				if ( !(gFlags.battery_charging) )
				{
					Screen = 0;
					SleepTimer = 18000;
				}
				else
				{
					Screen = 5;
				}
			}
			else
			{
				MainView();
			}
			break;

		case   5: // Black w/ Battery
			break;

		case  20: // No Atomizer Found
		case  21: // Atomizer Short
			MainView();
			break;

		case  22: // Atomizer Low
		case  23: // 10s Protection
		case  24: // Battery Low
		case  25: // Battery Low Lock
			break;

		case  29: // Device too hot
			MainView();
			break;

		case 101: // Contrast Menu
		case 102: // Menus
		case 103: // RTC Speed
			gFlags.edit_capture_evt = 0;
			// NOBREAK
		case  59: // TCR Set Menu
		case  82: // LOGO Menu
		case  83: // Game Menu
			UpdateDataFlash();
			// NOBREAK
		case   1: // Main view
		case  28: // Key Lock
		case  31: // Key UnLock
		case  37: // Board Temp
		case  40: // Stealth ON/OFF
		case  41: // Ti ON/OFF
		case  54: // Battery Voltage
		case 100: // Ferox's page
		case 104: // Adjust Clock
			if ( !dfScreenSave )
			{
				if ( Screen != 1 )
					MainView();
				break;
			}
			if ( !(gFlags.battery_charging) )
			{
				gFlags.refresh_display = 1;
				Screen = 0;
				SleepTimer = 18000;
			}
			else
			{
				Screen = 5;
			}
			break;

		case  50: // FW Version
			break;

		case  51: // New Coil
			MainView();
			break;

		default:
			break;
	}

	return;
}
Пример #8
0
//=========================================================================
// Additional initialisations
//-------------------------------------------------------------------------
__myevic__ void CustomStartup()
{

//-------------------------------------------------------------------------
// EADC test

	if ( 0 )
	{
		uint32_t s1, s2, s3;

		SetADCState( 0, 1 );
		SetADCState( 4, 1 );

		do
		{
			ClearScreenBuffer();

			CLK_SysTickDelay( 10 );
			s3 = ADC_Read( 4 );

			CLK_SysTickDelay( 10 );
			s1 = ADC_Read( 18 );

			CLK_SysTickDelay( 10 );
			s2 = ADC_Read( 0 );

			DrawValue( 8,  0, s1, 0, 0x29, 4 );
			DrawValue( 8, 20, s2, 0, 0x29, 4 );
			DrawValue( 8, 40, s3, 0, 0x29, 4 );

			DisplayRefresh();

			WaitOnTMR2( 1000 );
		}
		while ( PD3 );
	}


//-------------------------------------------------------------------------
// Timer test 1

	if ( 0 )
	{
		TIMER_Stop( TIMER3 );
		TIMER_Close( TIMER3 );

		MemClear( gPlayfield.uc, 256 );

		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_LIRC, 0 );

		gPlayfield.ul[1] =
		TIMER_Open( TIMER3, TIMER_PERIODIC_MODE, 10 );
		TIMER_EnableInt( TIMER3 );
		TIMER_Start( TIMER3 );
	}


//-------------------------------------------------------------------------
// Timer test 2

	if ( 0 )
	{
		TIMER_Close( TIMER2 );
		TIMER_Close( TIMER3 );

		MemClear( gPlayfield.uc, 256 );

		CLK_SetModuleClock( TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HXT, 0 );
		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_LIRC, 0 );

		CLK_EnableModuleClock( TMR2_MODULE );
		CLK_EnableModuleClock( TMR3_MODULE );

		__set_PRIMASK(1);

		TIMER3->CTL |= TIMER_CTL_RSTCNT_Msk;
		TIMER2->CTL |= TIMER_CTL_RSTCNT_Msk;

		TIMER3->CMP  = 1000;

		TIMER3->CTL  = TIMER_CTL_CNTEN_Msk | TIMER_ONESHOT_MODE;
		TIMER2->CTL  = TIMER_CTL_CNTEN_Msk | TIMER_CONTINUOUS_MODE;
		while(!(TIMER3->INTSTS & TIMER_INTSTS_TIF_Msk));
		TIMER2->CTL = 0;

		gPlayfield.ul[0] = TIMER2->CNT;

		__set_PRIMASK(0);

		TIMER_Close( TIMER2 );
		TIMER_Close( TIMER3 );

		CLK_SetModuleClock( TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HIRC, 0 );
		CLK_EnableModuleClock( TMR2_MODULE );
		TIMER_Open( TIMER2, TIMER_PERIODIC_MODE, 1000 );
		TIMER_EnableInt( TIMER2 );
		TIMER_Start( TIMER2 );

		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_HXT, 0 );
		CLK_EnableModuleClock( TMR3_MODULE );
		TIMER_Open( TIMER3, TIMER_PERIODIC_MODE, 10 );
		TIMER_EnableInt( TIMER3 );
		TIMER_Start( TIMER3 );
	}

	return;
}
Пример #9
0
static void DisplayRefresh_EVENT(void) {
	if (!Timer_100ms) {
		Timer_100ms = 100;							// Every 0.1s (10Hz)
		DisplayRefresh(1);
	}
}