예제 #1
0
/********************************************************************
* Function: 	main()
*
* Precondition: 
*
* Input: 		None.
*
* Output:		None.
*
* Side Effects:	None.
*
* Overview: 	Main entry function. If there is a trigger or 
*				if there is no valid application, the device 
*				stays in firmware upgrade mode.
*
*			
* Note:		 	None.
********************************************************************/
INT main(void)
{
	UINT pbClk;
        UINT bSoftResetFlag = 0;

	// Setup configuration
	pbClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
	
	InitLED();

    TRISBbits.TRISB15 = 1;//test

    bSoftResetFlag = *(unsigned int *)(NVM_DATA);
    if(bSoftResetFlag == 1)
    {
        NVMErasePage((void*)NVM_DATA);
        NVMWriteWord((void*)(NVM_DATA), (unsigned int)0x00);
    }

	// Enter firmware upgrade mode if there is a trigger or if the application is not valid
	if(bSoftResetFlag == 1 || CheckTrigger() || !ValidAppPresent())
	{
		// Initialize the transport layer - UART/USB/Ethernet
		TRANS_LAYER_Init(pbClk);
		
		while(!FRAMEWORK_ExitFirmwareUpgradeMode()) // Be in loop till framework recieves "run application" command from PC
		{
			// Enter firmware upgrade mode.
			// Be in loop, looking for commands from PC
			TRANS_LAYER_Task(); // Run Transport layer tasks
			FRAMEWORK_FrameWorkTask(); // Run frame work related tasks (Handling Rx frame, process frame and so on)
			// Blink LED (Indicates the user that bootloader is running).
			BlinkLED();	
		}
		// Close trasnport layer.
		TRANS_LAYER_Close();
	}

	
	// No trigger + valid application = run application.
	JumpToApp();
	
	return 0;
}			
/********************************************************************
* Function: 	main()
*
* Precondition:
*
* Input: 		None.
*
* Output:		None.
*
* Side Effects:	None.
*
* Overview: 	Main entry function. If there is a trigger or
*				if there is no valid application, the device
*				stays in firmware upgrade mode.
*
*
* Note:		 	None.
********************************************************************/
INT main(void)
{
	UINT pbClk;

	// Setup configuration
	pbClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

	InitLED();
    mLED = 0;

    TRISAbits.TRISA4 = 1; // TEST pin
    CNPDAbits.CNPDA4 = 1; // Pull-down
    delay_us( 10 ); // Wait a bit until the port pin got pulled down.

	// Enter firmware upgrade mode if there is a trigger or if the application is not valid
	if(CheckTrigger() || !ValidAppPresent())
	{
		// Initialize the transport layer - UART/USB/Ethernet
		TRANS_LAYER_Init(pbClk);

		while(!FRAMEWORK_ExitFirmwareUpgradeMode()) // Be in loop till framework recieves "run application" command from PC
		{
			// Enter firmware upgrade mode.
			// Be in loop, looking for commands from PC
			TRANS_LAYER_Task(); // Run Transport layer tasks
			FRAMEWORK_FrameWorkTask(); // Run frame work related tasks (Handling Rx frame, process frame and so on)
			// Blink LED (Indicates the user that bootloader is running).
			BlinkLED();
		}
		// Close trasnport layer.
		TRANS_LAYER_Close();

        mLED = 0;
        while ( CheckTrigger() ) {}; // Do not run the application while TEST is still tied to VCC.
	}

    // No trigger + valid application = run application.
    CNPDAbits.CNPDA4 = 0; // turn off Pull-down
    JumpToApp();

	return 0;
}
예제 #3
0
void main()
{
  APIRET rc;
  USBHANDLE hUSBDevice;
  ULONG ulNumDevices;
  UCHAR ucBuffer[640];

  rc = UsbQueryNumberDevices(&ulNumDevices);
  printf("Num devices = %d (rc=%d)\r\n",ulNumDevices,rc);

  rc = UsbOpen( &hUSBDevice,
                VENDOR_RAINBOW,
                PRODUCT_IKEY1000,
                USB_ANY_PRODUCTVERSION,
                USB_OPEN_FIRST_UNUSED);

  if(!rc && hUSBDevice!=0 &&
     0==OpenIKey(hUSBDevice))
  {

    BlinkLED(hUSBDevice);

    memset(ucBuffer,sizeof(ucBuffer),0);

    rc = UsbCtrlMessage( hUSBDevice,
                         0x41, 4,0,0,
                         0x02, ucBuffer,
                         0);
    if(!rc)
      ReadIKeyData( hUSBDevice, 0x0E, ucBuffer);

    UsbClose(hUSBDevice);
  }
  else
  {
    printf("USBOpen returned %d\r\n",rc);
  }

}
예제 #4
0
/**
 * @fn uint8_t WirelessOperation(unsigned int * pBuffer)
 *
 * @brief This function listens for incoming frames, qualifies the data as 
 *        being from a network member, and if so copies data to Nodes[].InData[]
 *        and returns the node IDindex that it came from
 *
 * @return an unsigned int, IDindex; >0 is valid, =0 is invalid/no data
 */
uint8_t WirelessOperation(unsigned int * pBuffer)
{
  s_AppRadio * pRadio = &appRadio[RadioLocal.currentRadio];

  // ----------- Check for the PushButton input ------------
  if (pushButtonAction)
  {
    switch (pushButtonAction)
    {
      unsigned char i;

      case FLASH_FACTORY_DEFAULT :
        for(i=0;i<MAX_NODES;i++){                                               // Remove all the nodes from paired nodes list, so that when the GUI reads the nodes list, 
          RemoveNodeFromNetwork(i);                                             // it sees the network change and updates according to it.
        }
        ChangeConfiguration(&pRadio, 0, 0, 0, 0, 0);
        // If GUI sees an application state change, it reads the nodes list and updates the network change itself. 
        // This works if the application state is sensor and is changed to hub. But if the application state is
        // already hub, the GUI does not see any state change and it does not update the network change itself. 
        // So this condition is placed to make sure that the network gets updated. (for GUI).
        if (ApplicationState == HUB)                                            
        {
          #if defined(__COMMAND_INTERFACE)
            NetworkChanged();                                                   // Report to GUI that the netowrk has been changed.
            PhysicalChanged();                                                  // Report to GUI that the RSCP settings have been changed.
          #endif
        }
        SetApplicationState(HUB);
        break;

      case ENABLE_PAIRING_HUB_TO_SENSOR :                                       // Change application state to sensor and place it in pairing mode immediately.
        SetApplicationState(SENSOR);
		// NOTE: Fall through to pair the devices.
      case ENABLE_PAIRING :
        SetPairingMask(0xFFFFFFFF);
        SoftwareTimerSetInterval(__BSP_SWTIMER[0], 1000);                       // Set 10 second timeout
        SoftwareTimerEnable(__BSP_SWTIMER[0]);
        break;

      case NEXT_APPLICATION_STATE :
        for (i=1;i<MAX_NODES;i++) {
          RemoveNodeFromNetwork(i);                                             // Remove all the nodes from paired nodes list
        }
        if (ApplicationState == HUB) SetApplicationState(SENSOR);
        else if(ApplicationState == SENSOR) SetApplicationState(HUB);
		// NOTE: Fall through to display state change with LEDs.
      case GET_APPLICATION_STATE :
        if (ApplicationState == HUB) BlinkLED(__BSP_LEDRED1, 2, 20);
        else if(ApplicationState == SENSOR) BlinkLED(__BSP_LEDRED1, 3, 20);
        break;

      default :
        break;
    }
    
    pushButtonAction = 0;
  }

  if (swTimerAction == DISABLE_PAIRING)
  {
    SoftwareTimerDisable(__BSP_SWTIMER[0]);
    swTimerAction = 0;
    if (GetPairingMask())
    {
      SetPairingMask(0x00000000);
    }
  }


  if(ApplicationState == HUB)
  {
    return HubWirelessOperation(pRadio, pBuffer);
  }
  else if(ApplicationState == SENSOR)
  {
    return SensorWirelessOperation(pRadio, pBuffer);
  }
  return 0;
}
예제 #5
0
/*************************************************************************
	module		:[指定した位置に一文字表示]
	function	:[1.表示バッファのを順次スキャンし内容をDDRAMへ書き込む
				  2.表示位置:上段ー>0〜19、下段->20〜39
	]
	return		:[]
	common		:[LcdScanPos]
	comment		:[5ms割り込み]
*************************************************************************/
void DisplayLCD(void)
{
	/* SCIリード(key入力取り込み) */
	while(!(Input(SCI_SSR0) & SSR_RDRF));	/* RDRF = 1 ? */
	NewKey = Input(SCI_RDR0);
	Output(SCI_SSR0, (Input(SCI_SSR0) & ~SSR_RDRF));

	/* LCDにデータ書き込み処理(前回の割込でシリアルに書いたデータをLCDに送る) */
	if ((LcdScanPos == LCD_HIGH_INST_POS) || (LcdScanPos == LCD_LOW_INST_POS)) {
		/* LcdScanPos = 0 or 21 */
		LcdDriverRegisterIR();
		LcdDriverClockOn();
		LcdDriverClockOff();
	} else if (((LcdScanPos >= LCD_HIGH_START_POS) && (LcdScanPos < LCD_HIGH_END_POS))
		|| ((LcdScanPos >= LCD_LOW_START_POS) && (LcdScanPos < LCD_LOW_END_POS))){	
		/* LcdScanPos = 1-20 or 22-41 */
		LcdDriverRegisterData();
		LcdDriverClockOn();
		LcdDriverClockOff();
	} else if (LcdScanPos == LED1_WRITE_POS) {	/* = 42 */
		LedPortSelect1On();
		LedPortSelect1Off();
	} else {
		LedPortSelect2On();
		LedPortSelect2Off();
	}

	if (++LcdScanPos >= LCD_WR_MAX) {
		LcdScanPos = 0;
	}

	PanelDataLoadOff();
	PanelDataLoadOn();

	/* RS -> 0 */
	LcdDriverRegisterIR();

	/* Data Write */
	while(!(Input(SCI_SSR0) & SSR_TDRE));		/* TDRE = 1 ? */
	if ((LcdScanPos == LCD_HIGH_INST_POS) || (LcdScanPos == LCD_LOW_INST_POS)) {
		/* DDRAMアドレス */
		if (LcdScanPos == LCD_HIGH_INST_POS) {
			Output(SCI_TDR0, DDRAM_FIRST_ROW_ADDRESS);
		} else {
			Output(SCI_TDR0, DDRAM_SECOND_ROW_ADDRESS);
		}
	} else if ((LcdScanPos >= LCD_HIGH_START_POS) && (LcdScanPos < LCD_HIGH_END_POS)) {	 /* 1-20 */
		/* 表示データ */
		if ((LcdScanPos == LcdCursorPos) && (CursorBlinkFlag)) {
			Output(SCI_TDR0, 0xFF);		/* 全黒をセット */
		} else {

#if (0)
** 			/* LCD表示がちらつくので、ローカル用バッファに一旦コピーしてから表示するように変更
** 			** byO.Kimoto 1999/02/06
** 			*/
** 			Output(SCI_TDR0, DisplayBufferHigh[LcdScanPos - LCD_HIGH_START_POS]);
#else
			Output(SCI_TDR0, LCD_DisplayBufferHigh[LcdScanPos - LCD_HIGH_START_POS]);
#endif

		}
	} else if ((LcdScanPos >= LCD_LOW_START_POS) && (LcdScanPos < LCD_LOW_END_POS)){	/* 22-41 */
		/* 表示データ */
		if ((LcdScanPos == LcdCursorPos) && (CursorBlinkFlag)) {
			Output(SCI_TDR0, 0xFF);		/* 全黒をセット */
		} else {

#if (0)
** 			/* LCD表示がちらつくので、ローカル用バッファに一旦コピーしてから表示するように変更
** 			** byO.Kimoto 1999/02/06
** 			*/
** 			Output(SCI_TDR0, DisplayBufferLow[LcdScanPos - LCD_LOW_START_POS]);
#else
			Output(SCI_TDR0, LCD_DisplayBufferLow[LcdScanPos - LCD_LOW_START_POS]);
#endif

		}
	} else if (LcdScanPos == LED1_WRITE_POS) {
		/* LED1の点灯/消灯 */
		Output(SCI_TDR0, ~SYS_LED1_PortStatus);
	} else {
		/* LED2の点灯/消灯 */
		Output(SCI_TDR0, ~SYS_LED2_PortStatus);
	}

	Output(SCI_SSR0, (Input(SCI_SSR0) & ~SSR_TDRE)); /* TDRE -> 0 */
	/* カーソル点滅 */
	CursorBlinkCont++;
	if (!(CursorBlinkCont % 100)) {	/* 500ms間隔 */
		CursorBlinkFlag ^= 0x01;
	}
	if (CursorBlinkCont >= 200) {	/* 1000ms間隔 */
#if (0)
		BlinkLED();			/* LED点滅 */
#endif
		CursorBlinkCont = 0;
	}
}