Esempio n. 1
0
void Components_Init(void)
{
    /*! DMA_controller Auto initialization start */
    EDMA_DRV_Init(&DMA_controller_State,&DMA_controller_InitConfig0);
    /*! DMA_controller Auto initialization end */


    /*! OLED_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_OLED_SPI, &OLED_SPI_MasterState, &OLED_SPI_MasterConfig, &OLED_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_OLED_SPI, &OLED_SPI_BusConfig, &OLED_SPI_calculatedBaudRate);
    /*! OLED_SPI Auto initialization end */

    /*! FLASH_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_FLASH_SPI, &FLASH_SPI_MasterState, &FLASH_SPI_MasterConfig, &FLASH_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_FLASH_SPI, &FLASH_SPI_BusConfig, &FLASH_SPI_calculatedBaudRate);
    /*! FLASH_SPI Auto initialization end */

    /*! GPIO Auto initialization start */
    GPIO_DRV_Init(NULL,NULL);
    /*! GPIO Auto initialization end */

    /*! KW40_UART Auto initialization start */
    UART_DRV_Init(FSL_KW40_UART,&KW40_UART_State,&KW40_UART_InitConfig0);
    /*! KW40_UART Auto initialization end */
    /*! DEBUG_UART Auto initialization start */
    UART_DRV_Init(FSL_DEBUG_UART,&DEBUG_UART_State,&DEBUG_UART_InitConfig0);
    /*! DEBUG_UART Auto initialization end */
    /*! FS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_FS_I2C, &FS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_FS_I2C, &FS_I2C_MasterConfig);
    /*! FS_I2C Auto initialization end */

    /*! NFS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_NFS_I2C, &NFS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_NFS_I2C, &NFS_I2C_MasterConfig);
    /*! NFS_I2C Auto initialization end */

    /*! PWR_Manager Auto initialization start */
//  POWER_SYS_Init(powerConfigsArr, 2U, NULL , 0U);
    INT_SYS_EnableIRQ(LLWU_IRQn);
    /*! PWR_Manager Auto initialization end */
    /*! CLOCK Auto initialization start */
    RTC_DRV_Init(FSL_CLOCK);
    /*! CLOCK Auto initialization end */

    /*! BATTERY_ADC Auto initialization start */
    ADC16_DRV_Init(FSL_BATTERY_ADC, &BATTERY_ADC_InitConfig);
    ADC16_DRV_ConfigConvChn(FSL_BATTERY_ADC, 0U, &BATTERY_ADC_ChnConfig);
    /*! BATTERY_ADC Auto initialization end */

    /*! sensor_timer Auto initialization start */
    LPTMR_DRV_Init(FSL_SENSOR_TIMER,&sensor_timer_State,&sensor_timer_cfg);
    /*! sensor_timer Auto initialization end */

}
Esempio n. 2
0
void Components_Init(void)
{

  /*! DbgCs1 Auto initialization start */
  /* Debug console initialization */
  DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, DEBUG_UART_BAUD, DEBUG_UART_TYPE);
  /*! DbgCs1 Auto initialization end */
  /*! gpio1 Auto initialization start */
  GPIO_DRV_Init(NULL,gpio1_OutConfig0);
  /*! gpio1 Auto initialization end */
  
}
/*!
 * @brief main function
 */
int main(void)
{
#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    adc16_calibration_param_t tempSnseCalibraitionParam;
#endif

    hardware_init();
    GPIO_DRV_Init(NULL, ledPins);

    // Configure the power mode protection
    SMC_HAL_SetProtection(SMC_BASE_PTR, kAllowPowerModeVlp);

    ADC16_DRV_StructInitUserConfigDefault(&tempSnseAdcConfig);
#if (FSL_FEATURE_ADC16_MAX_RESOLUTION >= 16)
    tempSnseAdcConfig.resolution = kAdc16ResolutionBitOf16;
#endif

#if BOARD_ADC_USE_ALT_VREF
    tempSnseAdcConfig.refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    // Init ADC
    ADC16_DRV_Init(ADC_INSTANCE, &tempSnseAdcConfig);
    // Calibrate VDD and ADCR_TEMP25
#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    // Auto calibraion
    ADC16_DRV_GetAutoCalibrationParam(ADC_INSTANCE, &tempSnseCalibraitionParam);
    ADC16_DRV_SetCalibrationParam(ADC_INSTANCE, &tempSnseCalibraitionParam);
#endif // FSL_FEATURE_ADC16_HAS_CALIBRATION
    calibrateParams();

    // get cpu uid low value for slave
    gSlaveId = SIM_UIDL_UID(SIM_BASE_PTR);

    PRINTF("i2c_rtos_slave_bm demo\r\n");

    // task list initialize
    OSA_Init();

    // create task(in BM: only the first registered task can be executed)
    OSA_TaskCreate(task_slave,
                   (uint8_t *)"slave",
                   512,
                   task_slave_stack,
                   0,
                   (void *)0,
                   false,
                   &task_slave_task_handler);

    OSA_Start();

    return 0;
}
int  main (void)
{
    OS_ERR   err;

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_ERR  cpu_err;
#endif
    hardware_init();
    GPIO_DRV_Init(switchPins, ledPins);


#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_NameSet((CPU_CHAR *)"MK64FN1M0VMD12",
                (CPU_ERR  *)&cpu_err);
#endif

    OSA_Init();                                                 /* Init uC/OS-III.                                      */

   OSSemCreate(&MySem1,           /* Create Semaphore 1         */
                "sem 1",
                 0,
                &err);

   OSSemCreate(&MySem2,           /* Create Semaphore 2         */
                "sem 2",
                 0,
                &err);

    INT_SYS_InstallHandler(PORTC_IRQn, SW1_Intr_Handler);       // associate ISR with sw1 intr source
    INT_SYS_InstallHandler(PORTA_IRQn, SW2_Intr_Handler);       // associate ISR with sw2 intr source

    OSTaskCreate(&AppTaskStartTCB,                              /* Create the start task                                */
                 "App Task Start",
                  AppTaskStart,
                  0u,
                  APP_CFG_TASK_START_PRIO,
                 &AppTaskStartStk[0u],
                 (APP_CFG_TASK_START_STK_SIZE / 10u),
                  APP_CFG_TASK_START_STK_SIZE,
                  0u,
                  0u,
                  0u,
                 (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR | OS_OPT_TASK_SAVE_FP),
                 &err);

    OSA_Start();                                                /* Start multitasking (i.e. give control to uC/OS-III). */

    while (DEF_ON) {                                            /* Should Never Get Here                                */
        ;
    }
}
Esempio n. 5
0
File: Cpu.c Progetto: bobby1879/K64
void Components_Init(void)
{

  /*! LED Auto initialization start */
  GPIO_DRV_Init(LED_Config,LED_OutConfig0);
  /*! LED Auto initialization end */
  
  /*! i2c_compS Auto initialization start */
  OSA_InstallIntHandler(I2C0_IRQn, i2c_compS_IRQHandler);
  I2C_DRV_MasterInit(FSL_I2C_COMPS, &i2c_compS_MasterState);
  I2C_DRV_MasterSetBaudRate(FSL_I2C_COMPS, &i2c_gmeter);
  /*! i2c_compS Auto initialization end */
  
}
Esempio n. 6
0
void hardware_init(void) {

  /* enable clock for PORTs */
  CLOCK_SYS_EnablePortClock(PORTA_IDX);
  CLOCK_SYS_EnablePortClock(PORTB_IDX);
  CLOCK_SYS_EnablePortClock(PORTC_IDX);
  CLOCK_SYS_EnablePortClock(PORTD_IDX);
  CLOCK_SYS_EnablePortClock(PORTE_IDX);

  /* Init board clock */
  BOARD_ClockInit();
  dbg_uart_init();
  GPIO_DRV_Init(switchPins, ledPins);
}
Esempio n. 7
0
void hardware_init(void) {

  /* enable clock for PORTs */
  CLOCK_SYS_EnablePortClock(PORTA_IDX);
  CLOCK_SYS_EnablePortClock(PORTB_IDX);
  CLOCK_SYS_EnablePortClock(PORTC_IDX);
  CLOCK_SYS_EnablePortClock(PORTE_IDX);

#ifdef BOARD_XTAL0_CLK_FREQUENCY
#endif

  configure_sdcard_spi_pins(1U);
  GPIO_DRV_Init(sdcardCardDectionPin, NULL);
  /* Init board clock */
  BOARD_ClockInit();
  dbg_uart_init();
}
int  main (void)
{
    OS_ERR   err;

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_ERR  cpu_err;
#endif

    hardware_init();

    GPIO_DRV_Init(switchPins, ledPins);

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_NameSet((CPU_CHAR *)"MK64FN1M0VMD12",
                (CPU_ERR  *)&cpu_err);
#endif

    OSA_Init();                                                 /* Init uC/OS-III.                                      */

    OSTaskCreate(&AppTaskStartTCB,                              /* Create the start task                                */
                 "App Task Start",
                  AppTaskStart,
                  0u,
                  APP_CFG_TASK_START_PRIO,
                 &AppTaskStartStk[0u],
                 (APP_CFG_TASK_START_STK_SIZE / 10u),
                  APP_CFG_TASK_START_STK_SIZE,
                  0u,
                  0u,
                  0u,
                 (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR | OS_OPT_TASK_SAVE_FP),
                 &err);

    OSA_Start();                                                /* Start multitasking (i.e. give control to uC/OS-III). */

    while (DEF_ON) {                                            /* Should Never Get Here                                */
        ;
    }
}
Esempio n. 9
0
/*******************************************************************************
 * Main function for application.
 ******************************************************************************/
void lab2_power(void)
{
    demo_power_modes_t testVal = kDemoRun;
    volatile uint8_t powerMode;
    uint8_t clockManagerMode = CLOCK_RUN;
    uint32_t freq = 0;

    //*******************************************************
	//* Step 1: Initialize the Clock Manager  configurations.
	//*******************************************************

    // Create list of supported clock configurations.  These are taken from the
    // board.c file and will be passed into CLOCK_SYS_Init().
    clock_manager_user_config_t const *clockConfigs[] =
    {
        NULL,
        &g_defaultClockConfigVlpr,
        &g_defaultClockConfigRun,
        &g_defaultClockConfigHsrun,
    };

    //*****************************************************
	//* Step 2: Configure Clock Manager callback function.
	//*****************************************************

    // Clock Manager callback function.
    clock_manager_callback_user_config_t clockManagerCallbackCfg =
    {
        .callback     = clockManagerCallback,
        .callbackType = kClockManagerCallbackBeforeAfter,
        .callbackData = NULL
    };

    clock_manager_callback_user_config_t *clockCallbacks[] =
    {
        &clockManagerCallbackCfg
    };

    //*****************************************************
	//* Step 3: Initialize the Clock Manager.
	//*****************************************************

    // Pass in configuration and callback data to Clock Manager.
	CLOCK_SYS_Init(clockConfigs,
				   CLOCK_NUMBER_OF_CONFIGURATIONS,
				   clockCallbacks,
				   ARRAY_SIZE(clockCallbacks));

	// Set to RUN mode.
	CLOCK_SYS_UpdateConfiguration(CLOCK_RUN, kClockManagerPolicyForcible);

    //*****************************************************
    //* Step 4: Set up supported power mode structures.
    //*****************************************************

    const power_manager_user_config_t runConfig =
    {
        .mode = kPowerManagerRun,
        .sleepOnExitValue = false,
    };

    power_manager_user_config_t hsrunConfig = runConfig;
    hsrunConfig.mode = kPowerManagerHsrun;

    power_manager_user_config_t waitConfig  = runConfig;
    waitConfig.mode = kPowerManagerWait;

    power_manager_user_config_t stopConfig  = runConfig;
    stopConfig.mode = kPowerManagerStop;

    power_manager_user_config_t vlprConfig   = runConfig;
    vlprConfig.mode = kPowerManagerVlpr;

    power_manager_user_config_t vlpwConfig	= runConfig;
    vlpwConfig.mode = kPowerManagerVlpw;

    power_manager_user_config_t vlpsConfig  = runConfig;
    vlpsConfig.mode = kPowerManagerVlps;

    power_manager_user_config_t lls3Config   = runConfig;
    lls3Config.mode = kPowerManagerLls3;

    power_manager_user_config_t vlls0Config   = runConfig;
    vlls0Config.mode = kPowerManagerVlls0;

    //***********************************************************
    //* Step 5: Configure managed power configurations structure.
    //***********************************************************

    // Create the list of supported modes to pass into the Power Manager.
    power_manager_user_config_t const *powerConfigs[] =
    {
    	&runConfig,
		&hsrunConfig,
		&waitConfig,
		&stopConfig,
		&vlprConfig,
		&vlpwConfig,
		&vlpsConfig,
		&lls3Config,
		&vlls0Config
    };

    //*****************************************************
	//* Step 6: Configure Power Manager callback function.
	//*****************************************************

    // Initializes callback configuration structure for the Power Manager.
    power_manager_callback_user_config_t powerManagerCallbackCfg =
    {
		.callback  	  = powerManagerCallback,
		.callbackType = kPowerManagerCallbackBeforeAfter,
		.callbackData = NULL
    };

    // Initializes array of pointers to power manager callbacks.
    power_manager_callback_user_config_t *powerCallbacks[] =
    {
    	&powerManagerCallbackCfg
    };

    //*****************************************************
    //* Step 7: Initialize the Power Manager.
    //*****************************************************

    // Pass power configurations and callback info to Power Manager.
    POWER_SYS_Init(powerConfigs,
    			   sizeof(powerConfigs) / sizeof(power_manager_user_config_t *),
				   powerCallbacks,
				   ARRAY_SIZE(powerCallbacks));

    // Initialize system to RUN mode.
    powerMode = kDemoRun - kDemoMin - 1;
    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

    //**************************************************************
    //* Step 8: Configure the rest of the chip for this application.
    //**************************************************************

    // Configure pin mux for UART functionality.
    configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);

    // Initializes GPIO driver for LEDs and buttons
    GPIO_DRV_Init(switchPins, ledPins);

    // Initialize the debug UART console.
    DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_LOW_POWER_UART_BAUD,
    				kDebugConsoleUART);

    // Enable PORTC clock for GPIO/LLWU interrupt.
    CLOCK_SYS_EnablePortClock(2);

    // Enables falling edge interrupt for switch SW2.
    PORT_HAL_SetMuxMode(BOARD_SW_LLWU_BASE, BOARD_SW_LLWU_PIN, kPortMuxAsGpio);
    PORT_HAL_SetPinIntMode(BOARD_SW_LLWU_BASE, BOARD_SW_LLWU_PIN, kPortIntFallingEdge);

    // Enable GPIO interrupt.
    INT_SYS_EnableIRQ(PORTC_IRQn);

    // Configure the LLWU.
    LLWU_HAL_ClearExternalPinWakeupFlag(LLWU, BOARD_SW_LLWU_EXT_PIN);
    LLWU_HAL_SetExternalInputPinMode(LLWU, kLlwuExternalPinFallingEdge, BOARD_SW_LLWU_EXT_PIN);

    // Enable LLWU interrupt.
    INT_SYS_EnableIRQ(LLWU_IRQn);

    // Main loop.
    while (1)
    {
    	// Get the system clock frequency and current clock configuration to print out.
        CLOCK_SYS_GetFreq(kCoreClock, &freq);
        clockManagerMode = CLOCK_SYS_GetCurrentConfiguration();

        PRINTF("\n\r####################  Power Manager Demo ####################\n\n\r");
        PRINTF("    Core Clock   = %d MHz \n\r", freq / 1000000);
        PRINTF("    Current Mode = ");

        switch(clockManagerMode)
        {
			case CLOCK_RUN:
				PRINTF("RUN\n\r");
				break;
			case CLOCK_VLPR:
				PRINTF("VLPR\n\r");
				break;
			case CLOCK_HSRUN:
				PRINTF("HSRUN\n\r");
				break;
        }

        PRINTF("\n\rSelect the desired operation \n\n\r");
        PRINTF("Press  %c for enter: RUN   - Normal RUN mode\n\r", kDemoRun);
        PRINTF("Press  %c for enter: HSRUN - High Speed RUN mode\n\r", kDemoHsRun);
        PRINTF("Press  %c for enter: Wait  - Wait mode\n\r", kDemoWait);
        PRINTF("Press  %c for enter: Stop  - Stop mode\n\r", kDemoStop);
        PRINTF("Press  %c for enter: VLPR  - Very Low Power Run mode\n\r", kDemoVlpr);
        PRINTF("Press  %c for enter: VLPW  - Very Low Power Wait mode\n\r", kDemoVlpw);
        PRINTF("Press  %c for enter: VLPS  - Very Low Power Stop mode\n\r", kDemoVlps);
        PRINTF("Press  %c for enter: LLS3  - Low Leakage Stop mode\n\r", kDemoLls3);
        PRINTF("Press  %c for enter: VLLS0 - Very Low Leakage Stop mode 0\n\r", kDemoVlls0);
        //PRINTF("Press  %c for enter: VLLS3 - Very Low Leakage Stop mode 3\n\r", kDemoVlls3);

        PRINTF("\n\rWaiting for key press...\n\r\n\r");

        // Wait for user input.
        testVal = (demo_power_modes_t)GETCHAR();

        if ((testVal >= 'a') && (testVal <= 'z'))
        {
            testVal -= 'a' - 'A';
        }

        if (testVal > kDemoMin && testVal < kDemoMax)
        {
        	// Obtain Power Manager readable version of the value passed in.
        	powerMode = testVal - kDemoMin - 1;

        	// Switch to selected mode.
            switch (testVal)
            {
				case kDemoRun:

					if (POWER_SYS_GetCurrentMode() == kPowerManagerRun)
					{
						PRINTF("Run mode already active.\n\r");
						break;
					}

					// Update the power configuration.
					POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

					// Update the clock configuration.
					CLOCK_SYS_UpdateConfiguration(CLOCK_RUN, kClockManagerPolicyAgreement);

					break;

				case kDemoHsRun:

					if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
					{
						PRINTF("High Speed Run mode already active.\n\r");
						break;
					}

					// Update the power configuration.
					POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

					// Update the clock configuration.
					CLOCK_SYS_UpdateConfiguration(CLOCK_HSRUN, kClockManagerPolicyAgreement);

					break;

                case kDemoWait:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr)
                    {
                        PRINTF("Cannot go from VLPR to WAIT directly...\n\r");
                        break;
                    }
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to WAIT directly...\n\r");
                        break;
                    }

                    PRINTF("Entering WAIT mode. Press SW2 to wake...\n\r");

                    // Update the power configuration.
                    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

                    break;

                case kDemoStop:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr)
                    {
                        PRINTF("Cannot go from VLPR to STOP directly...\n\r");
                        break;
                    }
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to STOP directly...\n\r");
                        break;
                    }

                    PRINTF("Entering STOP mode. Press SW2 to wake...\n\r");

                    // Update the power configuration.
                    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

                    // Update the clock configuration.
                    CLOCK_SYS_UpdateConfiguration(clockManagerMode, kClockManagerPolicyAgreement);

                    break;

                case kDemoVlpr:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to VLPR directly...\n\r");
                        break;
                    }

                    if(POWER_SYS_GetCurrentMode() != kPowerManagerVlpr)
                    {
                    	// Update the clock configuration PRIOR to entering VLPR.
                    	CLOCK_SYS_UpdateConfiguration(CLOCK_VLPR, kClockManagerPolicyAgreement);

                    	// Update the power configuration.
                        POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);
                    }
                    else
                    {
                        PRINTF("Very Low Power Run mode already active.\n\r");
                    }

                    break;

                case kDemoVlpw:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerRun)
                    {
                        PRINTF("Cannot go from RUN to VLPW directly...\n\r");
                        break;
                    }

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to VLPW directly...\n\r");
                        break;
                    }

                    PRINTF("Entering VLPW mode. Press SW2 to wake...\n\r");

                    // Update the power configuration.
                    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

                    break;

                case kDemoVlps:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to VLPS directly...\n\r");
                        break;
                    }

                    PRINTF("Entering VLPS mode. Press SW2 to wake...\n\r");

                    // Update the power configuration.
                    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

                    // If we entered via RUN mode, restore clock settings.
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerRun)
					{
                    	CLOCK_SYS_UpdateConfiguration(clockManagerMode, kClockManagerPolicyAgreement);
					}

                    break;

                case kDemoLls3:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to LLSx directly...\n\r");
                        break;
                    }

                    PRINTF("Entering LLS3 mode. Press SW2 to wake...\n\r");

                    // Update the power configuration.
                    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

                    // Check the mode active mode prior to LLS3 entry.
                    if(POWER_SYS_GetCurrentMode() != kPowerManagerVlpr)
                    {
                        CLOCK_SYS_UpdateConfiguration(clockManagerMode, kClockManagerPolicyAgreement);
                    }

                    break;

                case kDemoVlls0:

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Cannot go from HSRUN to VLLSx directly...\n\r");
                        break;
                    }

                    PRINTF("Press SW2 to wake. VLLSx wake goes through RESET sequence.\n\r");

                    // Update the power configuration.
                    POWER_SYS_SetMode(powerMode, kPowerManagerPolicyAgreement);

                    break;

                default:
                    PRINTF("Bad value.");
                    break;
            }

            PRINTF("\n\rNext loop\n\r");
        }
    }
}
/*FUNCTION**********************************************************************
 *
 * Function Name : SMARTCARD_DRV_NCN8025Init
 * Description   : This function iniitializes SMARTCARD PHY/Interface. The function will
 * initialize PHY speciic state, card/slot specific state, PHY's control interface 
 * parameters, initialize card clock etc.
 *
 *END**************************************************************************/
smartcard_status_t SMARTCARD_DRV_NCN8025Init(uint32_t interfaceInstance, 
                               smartcard_state_t * smartcardStatePtr,
                               const smartcard_interface_config_t * interfaceUserConfig)
{
#if defined(EMVSIM_INSTANCE_COUNT)
    uint32_t instance = interfaceUserConfig->clockModuleInstance;
    EMVSIM_Type * base = g_emvsimBase[instance];
#endif

    if (!g_smartcardInterfaceStatePtr[interfaceInstance])
    {
        /* Clear the state structure for this instance. */
        memset((void *)(&gInterfaceState[interfaceInstance]) , 0, sizeof(smartcard_interface_state_t));
        
        /* Save runtime structure pointer.*/
        g_smartcardInterfaceStatePtr[interfaceInstance] = &gInterfaceState[interfaceInstance];
    }

    /* Store interface IC state pointer */
    smartcardStatePtr->interfaceState = &gInterfaceState[interfaceInstance];

    /* Check if this slot already in use */
    if(smartcardStatePtr->interfaceState->slot[interfaceUserConfig->cardSoltNo])
    {
        return kStatus_SMARTCARD_PhyInitialized;
    }
    
    /* Store slot pointer */
    smartcardStatePtr->interfaceState->slot[interfaceUserConfig->cardSoltNo] = &gInterfaceSlot[interfaceUserConfig->interfaceInstance][interfaceUserConfig->cardSoltNo];
    
    /* Clear the state structure for this instance. */
    memset((void *)(smartcardStatePtr->interfaceState->slot[interfaceUserConfig->cardSoltNo]) , 0, sizeof(smartcard_interface_slot_t));
    
    /* Set Clock apply to Reset delay to EMV specific value */
    ((smartcard_interface_slot_t *)(smartcardStatePtr->interfaceState->slot[interfaceUserConfig->cardSoltNo]))->clockToResetDelay = 42000;
    
    /*************** Initialize PHY/Interface interface ********************/
    /* Clock */
    SMARTCARD_DRV_InterfaceClockInit(smartcardStatePtr->interfaceConfig.clockModuleInstance,  smartcardStatePtr->interfaceConfig.clockModuleChannel, smartcardStatePtr->interfaceConfig.sCClock);
  
    /* Define gpio input pin config Interrupt structure.*/
    gpio_input_pin_user_config_t intPin[] = {
        {
             GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.irqPort, (uint32_t)smartcardStatePtr->interfaceConfig.irqPin),
             {
#if FSL_FEATURE_PORT_HAS_PULL_ENABLE
              false,
#endif
#if FSL_FEATURE_PORT_HAS_PULL_SELECTION
              kPortPullDown,
#endif
#if FSL_FEATURE_PORT_HAS_PASSIVE_FILTER  
              false,
#endif
#if FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
              false,
#endif
#if FSL_FEATURE_GPIO_HAS_INTERRUPT_VECTOR
              kPortIntEitherEdge
#endif
             }
        },
        {
             GPIO_PINS_OUT_OF_RANGE,
             {
#if FSL_FEATURE_PORT_HAS_PULL_ENABLE
              false,
#endif
#if FSL_FEATURE_PORT_HAS_PULL_SELECTION
              kPortPullDown,
#endif
#if FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
              false,
#endif
#if FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
              false,
#endif
#if FSL_FEATURE_GPIO_HAS_INTERRUPT_VECTOR
              kPortIntDisabled
#endif
             }
        }
    };

    gpio_output_pin_user_config_t controlPins[] = {

#if !defined(EMVSIM_INSTANCE_COUNT)
        /* Define gpio output pin CMDVCC config structure.*/
        {
            GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.controlPort, (uint32_t)smartcardStatePtr->interfaceConfig.controlPin),
            {
                1,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
                kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
                kPortHighDriveStrength,
#endif
#if FSL_FEATURE_PORT_HAS_OPEN_DRAIN
                false
#endif
            }
        },
#endif
        /* Define gpio output pin VSEL0 config structure.*/
        {
            GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.vsel0Port, (uint32_t)smartcardStatePtr->interfaceConfig.vsel0Pin),
            {
                0,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
                kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
                kPortHighDriveStrength,
#endif
#if FSL_FEATURE_PORT_HAS_OPEN_DRAIN
                false
#endif
            }
        },
        /* Define gpio output pin VSEL1 config structure.*/
        {
            GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.vsel1Port, (uint32_t)smartcardStatePtr->interfaceConfig.vsel1Pin),
            {
                0,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
                kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
                kPortHighDriveStrength,
#endif
#if FSL_FEATURE_PORT_HAS_OPEN_DRAIN
                false
#endif
            }
        },
#if !defined(EMVSIM_INSTANCE_COUNT)
        /* Define gpio output pin RESET config structure.*/
        {
            GPIO_MAKE_PIN((uint32_t)smartcardStatePtr->interfaceConfig.resetPort, (uint32_t)smartcardStatePtr->interfaceConfig.resetPin),
            {
                0,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
                kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
                kPortHighDriveStrength,
#endif
#if FSL_FEATURE_PORT_HAS_OPEN_DRAIN
                false
#endif
            }
        },
#endif
        {
            GPIO_PINS_OUT_OF_RANGE,
            {
                0,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
                kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
                kPortLowDriveStrength,
#endif
#if FSL_FEATURE_PORT_HAS_OPEN_DRAIN
                false
#endif
            }
        }
    };

    /*Init Input pin, Output pin.*/
    GPIO_DRV_Init(intPin, controlPins);
#if defined(EMVSIM_INSTANCE_COUNT)
    /* Set CMD_VCC pin to logic level '1', to allow card detection interrupt from NCN8025 */
    EMVSIM_HAL_SetVCCEnable(base, true);
    EMVSIM_HAL_SetCardVCCEnablePolarity(base, kEmvsimVccEnIsHigh);
#endif
    
    return kStatus_SMARTCARD_Success;
}
Esempio n. 11
0
/*!
 * @brief Watchdog main routine
 * Run a simple application which enables watchdog, then
 * continuously refreshes the watchdog to prevent CPU reset
 * Upon SW1 button push, the watchdog will expire after
 * approximately 2 seconds and issue reset
 */
void main(void)
{
    // Configure watchdog.
    const wdog_user_config_t wdogConfig =
    {
        .timeoutValue          = 2048U,// Watchdog overflow time is about 2s
        .windowValue           = 0,    // Watchdog window value, 0-disable window function
        .clockPrescalerValue   = kWdogClockPrescalerValueDevide1, // Watchdog clock prescaler
        .updateRegisterEnable  = true, // Update register enabled
        .clockSource           = kClockWdogSrcLpoClk, // Watchdog clock source is LPO 1KHz
        .workInWaitModeEnable  = true, // Enable watchdog in wait mode
        .workInStopModeEnable  = true, // Enable watchdog in stop mode
        .workInDebugModeEnable = false,// Disable watchdog in debug mode
    };

    // Init hardware.
    hardware_init();

    // Init OSA layer.
    OSA_Init();

    // Call this function to initialize the console UART.  This function
    // enables the use of STDIO functions (printf, scanf, etc.)
    dbg_uart_init();
    // Init pinsfor switch and led.

    GPIO_DRV_Init(switchPins, ledPins);
    // Initialize wdog before the WDOG timer has a chance
    //to reset the device

    // Turn LED1 on;
    LED1_ON;

    WDOG_DRV_Init(&wdogConfig);

    // If not wdog reset, clear reset count
    if (!(RCM->SRS0 & RCM_SRS0_WDOG_MASK))
    {
        WDOG_DRV_ClearResetCount();
        printf("\r\n WDOG example \r\n");
    }

    // Check if WDOG reset occurred , disable WDOG and turn off LED1.
    if (WDOG_DRV_GetResetCount())
    {
        printf("\r\n WDOG reset count %ld",WDOG_DRV_GetResetCount());
    }

    printf("\r\n Press SW1 to expire watchdog ");

    // Continue to run in loop to refresh watchdog until SW1 is pushed
    while (1)
    {
        // Check for SW1 button push.Pin is grounded when button is pushed.
        if (0 != is_key_pressed())
        {
            while (1)
            {
                // Button has been pushed,blink LED
                // showing that the watchdog is about to expire.
                LED1_TOGGLE;
                OSA_TimeDelay(BLINK_TIME);
            }
        }

        // Restart the watchdog so it doesn't reset.
        WDOG_DRV_Refresh();
        OSA_TimeDelay(100u);
    }

}
/*!
 * @brief main function
 */
int main(void)
{
    uint8_t i;
    uint8_t index, indexChar, value;
    uint8_t cmdBuff[1] = {0xFF};
    uint8_t sendBuff[1] = {0xFF};       // save data sent to i2c slave
    uint8_t receiveBuff[1] = {0xFF};    // save data received from i2c slave

    i2c_master_state_t master;
    i2c_status_t returnValue;

    i2c_device_t slave =
    {
        .address = 0x3A,
        .baudRate_kbps = 100
    };

    hardware_init();

    dbg_uart_init();

    // Configure I2C pins
    configure_i2c_pins(BOARD_I2C_COMM_INSTANCE);

    OSA_Init();

    GPIO_DRV_Init(0, ledPins);

    // Init I2C module
    I2C_DRV_MasterInit(BOARD_I2C_COMM_INSTANCE, &master);

    printf("\r\n====== I2C Master ======\r\n\r\n");

    OSA_TimeDelay(500);
    LED_toggle_master();
    OSA_TimeDelay(500);
    LED_toggle_master();
    OSA_TimeDelay(500);
    LED_toggle_master();
    OSA_TimeDelay(500);
    LED_toggle_master();

    while (1)
    {
        printf("\r\nI2C Master reads values from I2C Slave sub address:\r\n");
        printf("\r\n------------------------------------");
        printf("\r\nSlave Sub Address   |    Character         ");
        printf("\r\n------------------------------------");
        for (i=Subaddress_Index_0; i<Invalid_Subaddress_Index; i++)
        {
            cmdBuff[0] = i;
            returnValue = I2C_DRV_MasterReceiveDataBlocking(
                                                       BOARD_I2C_COMM_INSTANCE,
                                                       &slave,
                                                       cmdBuff,
                                                       1,
                                                       receiveBuff,
                                                       sizeof(receiveBuff),
                                                       500);
            if (returnValue == kStatus_I2C_Success)
            {
                printf("\r\n[%d]                      %c", i, receiveBuff[0]);
            }
            else
            {
                printf("\r\nI2C communication failed, error code: %d", returnValue);
            }

        }
        printf("\r\n------------------------------------");
        printf("\r\n");

        printf("\r\nPlease input Slave sub address and the new character.");

        do
        {
            printf("\r\nSlave Sub Address: ");
            indexChar = getchar();
            putchar(indexChar);

            printf("\r\nInput New Character: ");
            value = getchar();
            putchar(value);

            printf("\n");

            index = (uint8_t)(indexChar - '0');

            if (index >= Invalid_Subaddress_Index)
            {
                printf("\r\nInvalid Sub Address.");
            }
        } while (index >= Invalid_Subaddress_Index);

        cmdBuff[0]  = index;
        sendBuff[0] = value;

        returnValue = I2C_DRV_MasterSendDataBlocking(
                                                    BOARD_I2C_COMM_INSTANCE,
                                                    &slave,
                                                    cmdBuff,
                                                    1,
                                                    sendBuff,
                                                    sizeof(sendBuff),
                                                    500);
        if (returnValue != kStatus_I2C_Success)
        {
            printf("\r\nI2C communication failed, error code: %d", returnValue);
        }
    }
}
Esempio n. 13
0
void HEXIWEAR_startup( task_param_t param )
{
  uint8_t
    status = 0;

  /** output GPIO configuration */

  GPIO_DRV_Init( NULL, OLED_cfg );
  GPIO_DRV_Init( NULL, FLASH_cfg );
  GPIO_DRV_Init( NULL, PWR_cfg );
  GPIO_DRV_Init( NULL, VIBRO_cfg );
  GPIO_DRV_Init( NULL, RGB_cfg );
  GPIO_DRV_Init( NULL, KW40_GPIO_cfg );


  /** input GPIO configuration */

  GPIO_DRV_Init( BAT_CHG_cfg, NULL );
  GPIO_DRV_Init( TAP_cfg, NULL );

#if defined( HEXIWEAR_DEBUG )
  GPIO_DRV_Init( NULL, DEBUG_cfg );
#endif

  power_ResetKW40();
  timer_Init( HEXIWEAR_TIMER_SENSOR );

  status |= RTC_Init();
  status |= FLASH_Init( &flashModule, &flashSettings );

  // intern flash initialization
  INTFLASH_Init();

  // RGB off
  FLASH_SetOFF();

  /** create basic tasks */
  status |= Notification_Init();
  status |= HostInterface_Init();
  status |= sensor_Init();
  status |= GuiDriver_Init();

  haptic_MutexCreate();

  sensor_InitAcc();

  /** set GPIO interrupt for the tap function */
  PORT_HAL_SetPinIntMode( PORTC, 1, kPortIntFallingEdge );

  /** set charging battery interrupt */
  PORT_HAL_SetPinIntMode( PORTC, 12, kPortIntEitherEdge );
  NVIC_SetPriority( PORTC_IRQn, HEXIWEAR_CHG_IRQ_PRIO );
  INT_SYS_EnableIRQ( PORTC_IRQn );

  if ( HEXIWEAR_STATUS_SUCCESS != status )
  {
    catch( CATCH_INIT );
  }

  /** check for settings in flash at startup */
  gui_sensorTag_CheckAtStartup();
  haptic_CheckAtStartup();

  CLOCK_SYS_Init( g_clockManConfigsArr, FSL_CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, FSL_CLOCK_MANAGER_CALLBACK_CNT );
  POWER_SYS_Init( powerConfigsArr, 2U, powerStaticCallbacksConfigsArr , 2U );

  // turn on regular battery readings
  sensor_SetPacketTargets( PACKET_BAT, sensor_GetPacketTargets( PACKET_BAT) | PACKET_PUSH_POWER_MGMT, true );

  while (1)
  {
    power_Init();
    OSA_TaskDestroy( NULL );
  }
}
/*!
 * @brief main function
 */
int main(void)
{
    i2c_slave_state_t slave;

    i2cData_t i2cData =
    {
      .subAddress = Invalid_Subaddress_Index,
      .data = 0,
      .state = CMD_MODE
    };

    i2c_slave_user_config_t userConfig =
    {
        .address = 0x3A,
        .slaveListening = true,
        .slaveCallback  = i2c_slave_event_callback_passive,
        .callbackParam  = &i2cData,
#if FSL_FEATURE_I2C_HAS_START_STOP_DETECT
        .startStopDetect  = false,
#endif
#if FSL_FEATURE_I2C_HAS_STOP_DETECT
        .stopDetect       = false,
#endif
    };

    // Low Power Configuration
    smc_power_mode_config_t smcConfig;

    // Init struct
    memset(&smcConfig, 0, sizeof(smcConfig));

    hardware_init();
    OSA_Init();
    GPIO_DRV_Init(0, ledPins);

    // Initiate I2C instance module
    I2C_DRV_SlaveInit(BOARD_I2C_INSTANCE, &userConfig, &slave);

    PRINTF("\r\n====== I2C Slave ======\r\n\r\n");

    // turn LED_slave on to indicate I2C slave status is waiting for date receiving
    LED_turnon_slave();
    LED_turnoff_master();
    OSA_TimeDelay(50);

    PRINTF("\r\n I2C slave enters low power mode...\r\n");

    // set to allow entering specific modes
    SMC_HAL_SetProtection(SMC, kAllowPowerModeVlp);

    // set power mode to specific Run mode
#if FSL_FEATURE_SMC_HAS_LPWUI
    smcConfig.lpwuiOptionValue = kSmcLpwuiEnabled;
#endif
#if FSL_FEATURE_SMC_HAS_PORPO
    smcConfig.porOptionValue = kSmcPorEnabled;
#endif

#if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
    smcConfig.powerModeName = kPowerModeRun;
    // If current status is HSRUN mode, change to RUN mode first.
    if (kStatHsrun == SMC_HAL_GetStat(SMC_BASE_PTR))
    {
        SMC_HAL_SetMode(SMC_BASE_PTR, &smcConfig);
    }
#endif

    smcConfig.powerModeName = kPowerModeWait;
    // Entry to Low Power Mode
    SMC_HAL_SetMode(SMC_BASE_PTR, &smcConfig);

    // LED_slave is still on during low power mode until I2C master send data to slave.
    // Turn off LED_slave to indicate MCU wake up by I2C address matching interrupt
    LED_turnoff_slave();
    PRINTF("\r\n I2C slave wakes up from low power mode by I2C address matching.\r\n");

    while(1);
}
Esempio n. 15
0
/*!
 * @brief main demo function.
 */
int main(void) {
    demo_power_modes_t testVal = kDemoRun;
    uint8_t mode;
    power_manager_error_code_t ret = kPowerManagerSuccess;
    uint32_t freq = 0;
    rtc_datetime_t date =
    {
        .year = 2014U,
        .month = 4U,
        .day = 30U,
        .hour = 14U,
        .minute = 0U,
        .second = 0U,
    };

    // Example of constant configuration
    // It may save the space in RAM
    const power_manager_user_config_t vlprConfig = {
        .mode = kPowerManagerVlpr,
        .sleepOnExitValue = false,
    };
    power_manager_user_config_t vlpwConfig     =    vlprConfig;
    power_manager_user_config_t vlls0Config    =    vlprConfig;
    power_manager_user_config_t vlls1Config    =    vlprConfig;
    power_manager_user_config_t vlls2Config    =    vlprConfig;
    power_manager_user_config_t vlls3Config    =    vlprConfig;
    power_manager_user_config_t llsConfig      =    vlprConfig;
    power_manager_user_config_t vlpsConfig     =    vlprConfig;
    power_manager_user_config_t waitConfig     =    vlprConfig;
    power_manager_user_config_t stopConfig     =    vlprConfig;
    power_manager_user_config_t runConfig      =    vlprConfig;
    power_manager_user_config_t hsrunConfig    =
    {
        .mode = kPowerManagerHsrun,
    };

    // Initializes array of pointers to power manager configurations
    power_manager_user_config_t const *powerConfigs[] =
    {
      &runConfig,
      &waitConfig,
      &stopConfig,
      &vlprConfig,
      &vlpwConfig,
      &vlpsConfig,
      &llsConfig,
      &vlls0Config,
      &vlls1Config,
      &vlls2Config,
      &vlls3Config,
      &hsrunConfig
    };

    // User callback data
    user_callback_data_t callbackData0;

    // Initializes callback configuration structure for power manager
    power_manager_callback_user_config_t callbackCfg0 = { callback0,
        kPowerManagerCallbackBeforeAfter,
        (power_manager_callback_data_t*) &callbackData0 };

    // Initializes array of pointers to power manager callbacks
    power_manager_callback_user_config_t * callbacks[] =
    { &callbackCfg0 };

    // Initializes hardware
    hardware_init();

    // Make the current Clock Manager mode configuration 1 (default configuration)
    /* Set clock configurations to clock manager. */
    CLOCK_SYS_Init(g_defaultClockConfigurations, CLOCK_NUMBER_OF_CONFIGURATIONS,
                   clockCallbackTable, ARRAY_SIZE(clockCallbackTable));

    CLOCK_SYS_UpdateConfiguration(CLOCK_RUN, kClockManagerPolicyForcible);

    // select the 1Hz for RTC_CLKOUT
    CLOCK_SYS_SetRtcOutSrc(kClockRtcoutSrc1Hz);

    /* Enable clock gate to RTC module */
    CLOCK_SYS_EnableRtcClock( 0U);

    /* Initialize the general configuration for RTC module.*/
    RTC_HAL_Init(RTC_BASE_PTR);

    /* Need to check this here as the RTC_HAL_Init() may have issued a software reset on the
     * module clearing all prior RTC OSC related setup */
    if (!(RTC_HAL_IsOscillatorEnabled(RTC_BASE_PTR)))
    {
        BOARD_InitRtcOsc();
    }
    /* Enable the RTC Clock output */
    RTC_HAL_SetClockOutCmd(RTC_BASE_PTR, true);

    NVIC_ClearPendingIRQ(RTC_IRQn);
    INT_SYS_EnableIRQ(RTC_IRQn);

    //RTC_DRV_SetDatetime(0, &date);
    RTC_HAL_SetDatetime(RTC_BASE_PTR, &date);
   // Initializes GPIO driver for LEDs and buttons
    GPIO_DRV_Init(switchPins, ledPins);
    memset(&callbackData0, 0, sizeof(user_callback_data_t));

    // initializes configuration structures
    vlpwConfig.mode  = kPowerManagerVlpw;
    // VLLS0 mode is supported only by some SOCs.
    vlls0Config.mode = kPowerManagerVlls0;
    vlls1Config.mode = kPowerManagerVlls1;
    vlls2Config.mode = kPowerManagerVlls2;
    vlls3Config.mode = kPowerManagerVlls3;
    // LLS3 mode retains all ram content so CPU wake up doesn't go through restart sequence
    llsConfig.mode   = kPowerManagerLls3;
    vlpsConfig.mode  = kPowerManagerVlps;
    waitConfig.mode  = kPowerManagerWait;
    stopConfig.mode  = kPowerManagerStop;
    runConfig.mode   = kPowerManagerRun;
    hsrunConfig.mode = kPowerManagerHsrun;

    // initialize power manager driver
    POWER_SYS_Init(powerConfigs,
    sizeof(powerConfigs)/sizeof(power_manager_user_config_t *),
    callbacks,
    sizeof(callbacks)/sizeof(power_manager_callback_user_config_t *));

    // Enables LLWU interrupt
    INT_SYS_EnableIRQ(LLWU_IRQn);

    mode = kDemoRun - kDemoMin - 1;
    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
    if (ret != kPowerManagerSuccess)
    {
        PRINTF("POWER_SYS_SetMode(%u) returned unexpected status : %u\r\n",mode,ret);
    }

    while (1)
    {
        mode = 0;
        CLOCK_SYS_GetFreq(kCoreClock, &freq);
        PRINTF("\r\n####################  Power Manager Demo ####################\r\n\r\n");
        PRINTF("    Core Clock = %dHz \r\n", freq);
        displayPowerMode();
        PRINTF("\r\nSelect the desired operation \r\n\r\n");
        PRINTF("Press  %c for enter: RUN   - Normal RUN mode\r\n",kDemoRun);
        PRINTF("Press  %c for enter: Wait  - Wait mode\r\n",kDemoWait);
        PRINTF("Press  %c for enter: Stop  - Stop mode\r\n",kDemoStop);
        PRINTF("Press  %c for enter: VLPR  - Very Low Power Run mode\r\n",kDemoVlpr);
        PRINTF("Press  %c for enter: VLPW  - Very Low Power Wait mode\r\n",kDemoVlpw);
        PRINTF("Press  %c for enter: VLPS  - Very Low Power Stop mode\r\n",kDemoVlps);
        PRINTF("Press  %c for enter: LLS3  - Low Leakage Stop mode\r\n",kDemoLls);
        PRINTF("Press  %c for enter: VLLS0 - Very Low Leakage Stop 0 mode\r\n",kDemoVlls0);
        PRINTF("Press  %c for enter: VLLS1 - Very Low Leakage Stop 1 mode\r\n",kDemoVlls1);
        PRINTF("Press  %c for enter: VLLS2 - Very Low Leakage Stop 2 mode\r\n",kDemoVlls2);
        PRINTF("Press  %c for enter: VLLS3 - Very Low Leakage Stop 3 mode\r\n",kDemoVlls3);
        PRINTF("Press  %c for enter: HSRUN   - High Speed RUN mode\r\n",kDemoHsRun);
        PRINTF("\r\nWaiting for key press..\r\n\r\n");

        // Wait for user response
        testVal = (demo_power_modes_t)GETCHAR();

        if ((testVal >= 'a') && (testVal <= 'z'))
        {
            testVal -= 'a' - 'A';
        }

        if (testVal > kDemoMin && testVal < kDemoMax)
        {

            mode = testVal - kDemoMin - 1;
            switch (testVal)
            {
                case kDemoWait:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr)
                    {
                        PRINTF("Can not go from VLPR to WAIT directly\r\n");
                        break;
                    }
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to WAIT directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Wait mode");

                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);

                    break;

                case kDemoStop:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr)
                    {
                        PRINTF("Can not go from VLPR to STOP directly\r\n");
                        break;
                    }
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to STOP directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Stop mode");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);
                    // update Clock Mode
                    update_clock_mode(CLOCK_RUN);
                    break;

                case kDemoVlpr:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLPR directly\r\n");
                        break;
                    }
                    if(kPowerManagerVlpr != POWER_SYS_GetCurrentMode())
                    {
                        /*
                         If apps default CM config mode is not VLPR, but needs to enter VLPR, and real CM config
                         is not VLPR, then we need to update it to VLPR mode here. Otherwise pass through.
                         */
                        update_clock_mode(CLOCK_VLPR);
                        PRINTF("Entering Very Low Power Run mode\r\n");
                        ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                        CHECK_RET_VAL(ret, mode);
                    }
                    else
                    {
                        PRINTF("Very Low Power Run mode already active\r\n");
                    }
                    break;

                case kDemoVlpw:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerRun)
                    {
                        PRINTF("Can not go from RUN to VLPW directly\r\n");
                        break;
                    }

                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLPW directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Very Low Wait mode");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoVlps:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLPS directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Very Low Power Stop mode");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerRun)
                    {
                        // update Clock Mode to Run
                        update_clock_mode(CLOCK_RUN);
                    }
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoLls:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to LLSx directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Low Leakage Stop mode 3");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    // Check the mode LLS was entered
                    if(kPowerManagerVlpr != POWER_SYS_GetCurrentMode())
                    {
                        update_clock_mode(CLOCK_RUN);
                    }
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoVlls0:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLLS0 directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Very Low Leakage Stop 0 mode");
                    PRINTF("Wake up goes through Reset sequence.\r\n");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoVlls1:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLLS1 directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Very Low Leakage Stop 1 mode");
                    PRINTF("Wake up goes through Reset sequence.\r\n");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoVlls2:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLLS2 directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Very Low Leakage Stop 2 mode");
                    PRINTF("Wake up goes through Reset sequence.\r\n");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoVlls3:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        PRINTF("Can not go from HSRUN to VLLS3 directly\r\n");
                        break;
                    }
                    setWakeUpSource(selectWakeUpSource(testVal),"Very Low Leakage Stop 3 mode");
                    PRINTF("Wake up goes through Reset sequence.\r\n");
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    CHECK_RET_VAL(ret, mode);
                    break;

                case kDemoRun:
                    /* Need to decrease clock frequence before back RUN mode from HSRUN */
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerHsrun)
                    {
                        update_clock_mode(CLOCK_RUN);
                    }
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);

                    if (ret != kPowerManagerSuccess)
                    {
                        PRINTF("POWER_SYS_SetMode(%u) returned unexpected status : %u\r\n",mode,ret);
                    }
                    else
                    {
                        update_clock_mode(CLOCK_RUN);
                    }
                    break;

                case kDemoHsRun:
                    if (POWER_SYS_GetCurrentMode() == kPowerManagerVlpr)
                    {
                        PRINTF("Can not go from HSRUN to VLPR directly\r\n");
                        break;
                    }
                    ret = POWER_SYS_SetMode(mode, kPowerManagerPolicyAgreement);
                    if (ret != kPowerManagerSuccess)
                    {
                        PRINTF("POWER_SYS_SetMode(%u) returned unexpected status : %u\r\n",mode,ret);
                    }
                    else
                    {
                        update_clock_mode(CLOCK_HSRUN);
                    }
                    break;
                default:
                    PRINTF("Wrong value");
                    break;
            }
            PRINTF("\r\nNext loop\r\n");
        }
    }
}
Esempio n. 16
0
void HEXIWEAR_startup( task_param_t param )
{
    uint8_t
    status = 0;

    /** output GPIO config */

    GPIO_DRV_Init( NULL, OLED_cfg );
    GPIO_DRV_Init( NULL, FLASH_cfg );
    GPIO_DRV_Init( NULL, PWR_cfg );
    GPIO_DRV_Init( NULL, VIBRO_cfg );
    GPIO_DRV_Init( NULL, RGB_cfg );
    GPIO_DRV_Init( NULL, KW40_GPIO_cfg );
    GPIO_DRV_Init( NULL, REL_GPIO_cfg );


    /** input GPIO config */

    GPIO_DRV_Init( BAT_CHG_cfg, NULL );
    GPIO_DRV_Init( TAP_cfg, NULL );

    // lajkatest
    // GPIO_DRV_Init( GPIO_TEST_CFG, NULL );

#if defined( HEXIWEAR_DEBUG )
    GPIO_DRV_Init( NULL, DEBUG_cfg );
#endif

    power_ResetKW40();
    timer_Init( HEXIWEAR_TIMER_SENSOR );

    status |= RTC_Init();
    status |= FLASH_Init( &flashModule, &flashSettings );

    // intern flash initialization
    INTFLASH_Init();

    // enable power save by default
    // power_EnablePowerSave();
    power_DisablePowerSave();

    // set to deep sleep by default
    // power_SetSleepMode( POWER_SLEEP_TYPE_DEEP );

    // RGB off
    FLASH_SetOFF();

    // visual indication for testing HR sensor
//  MAXIM_Test();

    /** create basic tasks */
    status |= Notification_Init();
    status |= HostInterface_Init();
    status |= sensor_Init();
    status |= power_Init();
    status |= GuiDriver_Init();

    haptic_MutexCreate();

    sensor_InitAcc();

    /** set GPIO interrupt for the tap function */
    PORT_HAL_SetPinIntMode( PORTC, 1, kPortIntFallingEdge );

    /** set charging battery interrupt */
    PORT_HAL_SetPinIntMode( PORTC, 12, kPortIntEitherEdge );
    NVIC_SetPriority( PORTC_IRQn, HEXIWEAR_CHG_IRQ_PRIO );
    INT_SYS_EnableIRQ( PORTC_IRQn );

    // status |= Run_USB_Task();

    if ( HEXIWEAR_STATUS_SUCCESS != status )
    {
        catch( CATCH_INIT );
    }

    /** check for settings in flash at startup */
    gui_sensorTag_CheckAtStartup();
    haptic_CheckAtStartup();

    CLOCK_SYS_Init( g_clockManConfigsArr, FSL_CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, FSL_CLOCK_MANAGER_CALLBACK_CNT );
    POWER_SYS_Init( powerConfigsArr, 2U, powerStaticCallbacksConfigsArr , 2U );

    // make battery readings regular
    sensor_SetPacketTargets( PACKET_BAT, sensor_GetPacketTargets( PACKET_BAT) | PACKET_PUSH_POWER_MGMT, true );

    volatile uint32_t
    foo = CLOCK_SYS_GetSystemClockFreq();

    while (1)
    {
        OSA_TaskDestroy( NULL );
    }
}
Esempio n. 17
0
/************************* Configure for MQX************************************/
#if (defined FSL_RTOS_MQX)&&(MQX_COMMON_CONFIG == MQX_LITE_CONFIG)
#if MQX_STDIO
#error "MQX Lite configuration is designed to work with tool provided STD Library.\
Remove reference to MQX STD library from your build tool project options:\
IAR:\
    Linker->Library->aditional_libraries                             - remove lib_mqx_stdlib.a path \
    C/C++ Compiler->Preprocessor->Additional include directories:    - remove mqx_stdlib \
\
KEIL: \
    Linker->Misc controls   - remove lib_mqx_stdlib.lib path \
    C/C++->Include Paths    - remove mqx_stdlib \
\
KDS: \
    C/C++ Build\Settings->Cross ARM C Linker\Miscellaneous    - remove lib_mqx_stdlib.a path\
    C/C++ Build\Settings->Cross ARM C Compiler\Includes       - remove mqx_stdlib (on 4th line)\
\
Atollic: \
    C/C++ Build\Settings->C Linker/Libraries->Librarie search path    - remove lib_mqx_stdlib \
    C/C++ Build\Settings->C Compiler/Directories->Include Paths       - remove mqx_stdlib \
CMAKE : \
    Remove following lines from CMakeList.txt: \
    INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../rtos/mqx/lib/twrk22f120m.armgcc/debug/mqx_stdlib) \
    INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../rtos/mqx/lib/twrk22f120m.armgcc/release/mqx_stdlib) \
    \
    TARGET_LINK_LIBRARIES(lpm_rtos_mqx ${ProjDirPath}/../../../../../rtos/mqx/lib/twrk22f120m.armgcc/debug/mqx_stdlib/lib_mqx_stdlib.a) \
    TARGET_LINK_LIBRARIES(lpm_rtos_mqx ${ProjDirPath}/../../../../../rtos/mqx/lib/twrk22f120m.armgcc/release/mqx_stdlib/lib_mqx_stdlib.a) \
."
#endif /* MQX_STDIO */
#elif (defined FSL_RTOS_MQX)&&(MQX_COMMON_CONFIG != MQX_LITE_CONFIG)
#define MAIN_TASK        8
void main_task(uint32_t param);
const TASK_TEMPLATE_STRUCT  MQX_template_list[] =
{
   { MAIN_TASK, main_task, 0xC00, 20, "main_task", MQX_AUTO_START_TASK},
   { 0L,        0L,        0L,    0L,  0L,         0L }
};
#endif /* (FSL_RTOS_MQX)&&(MQX_COMMON_CONFIG != MQX_LITE_CONFIG) */

///////////////////////////////////////////////////////////////////////////////
// Code
///////////////////////////////////////////////////////////////////////////////

#if (defined FSL_RTOS_MQX) && (MQX_COMMON_CONFIG != MQX_LITE_CONFIG)
    void main_task(uint32_t param)
#else /* (FSL_RTOS_MQX) && (MQX_COMMON_CONFIG != MQX_LITE_CONFIG) */
    int main(void)
#endif /* (FSL_RTOS_MQX) && (MQX_COMMON_CONFIG != MQX_LITE_CONFIG) */
{

#if (defined FSL_RTOS_MQX)
    // In deffault, MQX enables echo flag for stdin.
    // For power manager demo, disable MQX flag to doesn't echo character.
    ioctl( 0, IOCTL_NIO_TTY_SET_FLAGS, NIO_TTY_FLAGS_EOL_RN); // 0 - stdin
#endif

    memset(&s_dbgState, 0, sizeof(s_dbgState));

    hardware_init();
    OSA_Init();

#if (!defined FSL_RTOS_MQX)
    //init the uart module with base address and config structure
    g_uartStatePtr[BOARD_DEBUG_UART_INSTANCE] = &s_dbgState;
    /* Init the interrupt sync object. */
    OSA_SemaCreate(&s_dbgState.txIrqSync, 0);
    OSA_SemaCreate(&s_dbgState.rxIrqSync, 0);
    NVIC_EnableIRQ(g_uartRxTxIrqId[BOARD_DEBUG_UART_INSTANCE]);
#endif

    // Initializes GPIO driver for LEDs and buttons
#if (defined FSL_RTOS_BM)
    GPIO_DRV_Init(switchPins, 0);
#else
    GPIO_DRV_Init(switchPins, ledPins);
#endif

    NVIC_SetPriority(PM_DBG_UART_IRQn, 6U);

    NVIC_SetPriority(RTC_IRQn, 6U);
    NVIC_SetPriority(LPTMR0_IRQn, 6U);
    NVIC_SetPriority(ADC_IRQ_N, 6U);
    NVIC_SetPriority(LLWU_IRQn, 6U);

#if (defined FSL_RTOS_MQX)
    OSA_InstallIntHandler(PM_DBG_UART_IRQn, PM_MQX_DBG_UART_IRQ_HANDLER);
#endif

    adc16Init(&adcUserConfig, &adcChnConfig, &adcCalibraitionParam);

    // Low power manager task.
    s_result = OSA_TaskCreate(task_lpm,
                (uint8_t *)"lpm",
                TASK_LPM_STACK_SIZE,
                task_lpm_stack,
                TASK_LPM_PRIO,
                (task_param_t)0,
                false,
                &task_lpm_task_handler);
    if (s_result != kStatus_OSA_Success)
    {
         PRINTF("Failed to create lpm task\r\n");
    }

    // These tasks will not start in BM.
#if (!defined FSL_RTOS_BM)
    s_result = OSA_TaskCreate(task_led_rtos,
                (uint8_t *)"led_rtos",
                TASK_LED_RTOS_STACK_SIZE,
                task_led_rtos_stack,
                TASK_LED_RTOS_PRIO,
                (task_param_t)0,
                false,
                &task_led_rtos_task_handler);
    if (s_result != kStatus_OSA_Success)
    {
        PRINTF("Failed to create led_rtos task\r\n");
    }
    s_result = OSA_TaskCreate(task_led_clock,
                (uint8_t *)"led_clock",
                TASK_LED_CLOCK_STACK_SIZE,
                task_led_clock_stack,
                TASK_LED_CLOCK_PRIO,
                (task_param_t)0,
                false,
                &task_led_clock_task_handler);
    if (s_result != kStatus_OSA_Success)
    {
        PRINTF("Failed to create led_clock task\r\n");
    }
#endif

    OSA_Start();

    for(;;) {}                    // Should not achieve here
}
//PTD2_UART_rx, PTD3_UART_tx
//PTC1,2,3,4
int main (void)
{
    memcpy(packet_upper_PC.trans_header, trans_header_table, sizeof(trans_header_table));
    // RX buffers
    //! @param receiveBuff Buffer used to hold received data
    uint8_t receiveBuff;

    // Initialize standard SDK demo application pins
    hardware_init();
    OSA_Init();
    // Call this function to initialize the console UART. This function
    // enables the use of STDIO functions (printf, scanf, etc.)
    dbg_uart_init();

/*Start***FTM Init*************************************************************/
    memset(&ftmInfo, 0, sizeof(ftmInfo));
    ftmInfo.syncMethod = kFtmUseSoftwareTrig;
    FTM_DRV_Init(0, &ftmInfo);
/*End*****FTM Init*************************************************************/

    // Print the initial banner
    PRINTF("\r\nHello World!\n\n\r");

    LED2_EN;    LED3_EN;    LED4_EN;    LED5_EN;
    LED2_OFF;   LED3_OFF;   LED4_OFF;   LED5_OFF;

    I2C_fxos8700Init();
    I2C_l3g4200dInit();

    FTM_DRV_PwmStart(0, &ftmParam0, 0);
    FTM_DRV_PwmStart(0, &ftmParam1, 1);
    FTM_DRV_PwmStart(0, &ftmParam2, 2);
    FTM_DRV_PwmStart(0, &ftmParam3, 3);
    FTM_HAL_SetSoftwareTriggerCmd(g_ftmBaseAddr[0], true);

        // Hwtimer initialization
    if (kHwtimerSuccess != HWTIMER_SYS_Init(&hwtimer, &HWTIMER_LL_DEVIF, HWTIMER_LL_ID, 5, NULL))
    {
        PRINTF("\r\nError: hwtimer initialization.\r\n");
    }
    if (kHwtimerSuccess != HWTIMER_SYS_SetPeriod(&hwtimer, HWTIMER_LL_SRCCLK, HWTIMER_PERIOD))
    {
        PRINTF("\r\nError: hwtimer set period.\r\n");
    }
//    if (kHwtimerSuccess != HWTIMER_SYS_RegisterCallback(&hwtimer, hwtimer_callback, NULL))
//    {
//        PRINTF("\r\nError: hwtimer callback registration.\r\n");
//    }
//    if (kHwtimerSuccess != HWTIMER_SYS_Start(&hwtimer))
//    {
//        PRINTF("\r\nError: hwtimer start.\r\n");
//    }
    
    /* A write of any value to current value register clears the field to 0, and also clears the SYST_CSR COUNTFLAG bit to 0. */
    SysTick->VAL = 0U;
    /* Run timer and disable interrupt */
    SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk ;//| SysTick_CTRL_TICKINT_Msk;

    GPIO_DRV_Init(remoteControlPins,NULL);
//    GPIO_DRV_Init(fxos8700IntPins,NULL);
//    I2C_fxos8700AutoCalibration(); //cannot work , shit!
    
/*Start PIT init***************/    
    // Structure of initialize PIT channel No.0
    pit_user_config_t chn0Confg = {
      .isInterruptEnabled = true,
      .isTimerChained = false,
      .periodUs = 20000u //1000000 us
    };
    
    // Structure of initialize PIT channel No.1
    pit_user_config_t chn1Confg = {
      .isInterruptEnabled = true,
      .isTimerChained = false,
      .periodUs = 2000000u
    };  
    
    // Init pit module and enable run in debug
    PIT_DRV_Init(BOARD_PIT_INSTANCE, false);
    
    // Initialize PIT timer instance for channel 0 and 1
    PIT_DRV_InitChannel(BOARD_PIT_INSTANCE, 0, &chn0Confg);
//    PIT_DRV_InitChannel(BOARD_PIT_INSTANCE, 1, &chn1Confg);
    
    // Start channel 0
//    printf ("\n\rStarting channel No.0 ...");
    PIT_DRV_StartTimer(BOARD_PIT_INSTANCE, 0);
    
    // Start channel 1
//    printf ("\n\rStarting channel No.1 ...");
//    PIT_DRV_StartTimer(BOARD_PIT_INSTANCE, 1);
    
/*End PIT init***************/   

//    NVIC_SetPriority(SysTick_IRQn, 3);
//    NVIC_SetPriority(PORTB_IRQn,0);
    while(1)
    {
///*Start************Remote Controller Unlock *************/      
//      if(isRCunlock == true)
//      {    
//        LED3_ON;
//      }
//      else
//      {    
//        LED3_OFF;
//      }
//      static uint32_t unlock_times = 0;
//      static uint32_t lock_times = 0;
//      PRINTF("ThrottleValue = %6d ,YawValue = %6d \r\n" ,remoteControlValue[kThrottle],remoteControlValue[kYaw]);
//      if(isRCunlock == false)
//      {
//        if((remoteControlValue[kThrottle] < RC_THRESHOLD_L) && (remoteControlValue[kYaw] > RC_THRESHOLD_H))
//        {
//          unlock_times++;
//        }
//        else
//        {
//          unlock_times = 0;
//        }
//        if(unlock_times > 6)
//        {
//          isRCunlock = true; 
//        }
//      }
//      else
//      {
//        if((remoteControlValue[kThrottle] < RC_THRESHOLD_L) && (remoteControlValue[kYaw] < RC_THRESHOLD_L))
//        {
//          lock_times++;
//        }
//        else
//        {
//          lock_times = 0;
//        }
//        if(lock_times > 4)
//        {
//          isRCunlock = false;
//        }
//      }
///*End************Remote Controller Unlock *************/          

//      LED2_ON;
//      OSA_TimeDelay(200);
//      LED3_ON;
//      OSA_TimeDelay(200);
//      LED4_ON;
//      OSA_TimeDelay(200);
      LED5_ON;
      OSA_TimeDelay(100);

//      LED2_OFF;
//      OSA_TimeDelay(200);
//      LED3_OFF;
//      OSA_TimeDelay(200);
//      LED4_OFF;
//      OSA_TimeDelay(200);
      LED5_OFF;
      OSA_TimeDelay(100);
    }
}

volatile bool isRCunlock = false;
//below define value is in quad_common.h
//#define RC_THRESHOLD_H (220000U)
//#define RC_THRESHOLD_L (140000U)
//#define RC_THRESHOLD_ERROR (300000U)//由于IO采两个边沿中断,有可能算成低电平的时间,所以做一个剔除算法。
//#define HW_DIVIDER (2400000U) 
////120M core clock , 2400000 / 120 000 000 = 0.02 s , 50Hz , 
////遥控器信号 50Hz , 范围1~2ms,周期20ms,1.5ms中值.对应 120 000 - 240 000
void PORTB_IRQHandler(void)
{
  uint32_t intFlag = PORT_HAL_GetPortIntFlag(PORTB_BASE);
  uint32_t i =  0;
  uint32_t value = 0;
  static  uint32_t remoteControlValue1st[8] = {0};
  static  uint32_t remoteControlValue2nd[8] = {0};
  static  uint32_t remoteControlValueFlag[8] = {0};
  for(i=0 ; i<8;i++)
  {
    if (intFlag & (1 << remoteControlPinNum[i]))
    {
      if (remoteControlValueFlag[i] == 0)
      {
        remoteControlValue1st[i] = (SysTick->VAL);
        remoteControlValueFlag[i] = 1;
      }
      else
      {
        remoteControlValueFlag[i] = 0;
        remoteControlValue2nd[i] = (SysTick->VAL);
        if ( remoteControlValue1st[i] > remoteControlValue2nd[i] )
        { 
          value = remoteControlValue1st[i] - remoteControlValue2nd[i];
        }
        else
        {
          value = remoteControlValue1st[i] + HW_DIVIDER - remoteControlValue2nd[i];//hwtimer.divider
        }
        if( value > RC_THRESHOLD_ERROR)
        {
          remoteControlValueFlag[i] = 1;
          remoteControlValue1st[i] = (SysTick->VAL);
        }
        else
        {
          remoteControlValue[i] = value;
//          if(((remoteControlValue[3] <180000) ||(remoteControlValue[3] > 190000))&&remoteControlValue[3]> 100)
//            LED4_ON;
        }
      }
    }
    PORT_HAL_ClearPinIntFlag(PORTB_BASE,remoteControlPinNum[i]);
  }
  /* Clear interrupt flag.*/
 //   PORT_HAL_ClearPortIntFlag(PORTB_BASE);
}


void PORTE_IRQHandler(void)
{
  uint32_t intFlag = PORT_HAL_GetPortIntFlag(PORTE_BASE);
  if (intFlag & (1 << 11))
  {
    isFXOS8700Int1Trigger = true;
      PRINTF("\r\n PTE11 irq");
  }

  /* Clear interrupt flag.*/
  PORT_HAL_ClearPortIntFlag(PORTE_BASE);
}