示例#1
0
文件: main.c 项目: cjc1029nice/ksdk
/*!
 * @brief main function
 */
int main(void)
{
    struct netif fsl_netif0;
    ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;

    app_low_level_init();
    OSA_Init();
    lwip_init();
	
    IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
    IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
    IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);
    netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);
    netif_set_default(&fsl_netif0);
    netif_set_up(&fsl_netif0);
    echo_init();

#if !ENET_RECEIVE_ALL_INTERRUPT
    uint32_t devNumber = 0; 
    enet_dev_if_t * enetIfPtr;
#if LWIP_HAVE_LOOPIF
    devNumber = fsl_netif0.num - 1;
#else
    devNumber = fsl_netif0.num;
#endif
    enetIfPtr = (enet_dev_if_t *)&enetDevIf[devNumber];
#endif
    while(1)
    {
#if !ENET_RECEIVE_ALL_INTERRUPT
        ENET_receive(enetIfPtr);
#endif
        sys_check_timeouts();
    }
}
示例#2
0
int main( void )
{
    // Target board initialisation
    BoardInitMcu();
    LOG_DEBUG("Mcu initialized.");
    OSA_Init();
    LOG_DEBUG("OS initialized.");
    BoardInitPeriph();
    LOG_DEBUG("Peripherals initialized.");

    // These tasks will not start in 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 ) {
        LOG_ERROR("Failed to create led_rtos task");
    }

    s_result = OSA_TaskCreate(task_fxos_rtos, (uint8_t *) "fxos_rtos", TASK_FXOS_RTOS_STACK_SIZE,
            task_fxos_rtos_stack, TASK_FXOS_RTOS_PRIO, (task_param_t) 0, false,
            &task_fxos_rtos_task_handler);
    if ( s_result != kStatus_OSA_Success ) {
        LOG_ERROR("Failed to create fxos_rtos task");
    }

    // Print the initial banner
    LOG_DEBUG("Hello World!\r\n");

    OSA_Start();

    for ( ;; ) {
    }                    // Should not achieve here
}
示例#3
0
文件: platform.c 项目: tbfly/MICO
void init_platform( void )
{
    PORT_HAL_SetMuxMode(PORTC_BASE,3u,kPortMuxAsGpio);
    PORT_HAL_SetMuxMode(PORTC_BASE,4u,kPortMuxAsGpio);
    GPIO_DRV_OutputPinInit(&ledPins[0]);
    GPIO_DRV_OutputPinInit(&ledPins[1]);
    OSA_Init();

}
示例#4
0
文件: main.c 项目: cjc1029nice/ksdk
int main(void)
{
    /* Initialize board hardware */
    hardware_init();
    OSA_Init();
	/* Initialize debug serial interface */
    dbg_uart_init();
    /* Call example task */
    ltc_example_task();

    while(1);
}
/*!
 * @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;
}
示例#6
0
/* 
    main
    
    Note:
        Program entry, do nessary initialization and lanuch scheduler, in baremetal OSA, it simplely call all tasks in sequence
*/
int main(void)
{
    OSA_Init();
    hardware_init();
    dbg_uart_init();
    comm_init();
	audio_init();
    usb_init();
    OS_Task_create(usb_user_task, NULL, 9L, 3000L, "usb task", NULL);
    OSA_Start();
    
    return 1;
}
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                                */
        ;
    }
}
示例#8
0
文件: main.c 项目: cjc1029nice/ksdk
/*!
 * @brief Check send/receive blocking with DMA
 *
 */
int main(void)
{
    uint8_t rxChar = 0, txChar = 0;
    uint32_t byteCountBuff = 0;

    dma_state_t state;
    lpsci_dma_state_t lpsciStateDma;

    lpsci_dma_user_config_t lpsciConfig = {
#if defined(KL02Z4_SERIES)
        .clockSource     = kClockLpsciSrcFll,
#else
        .clockSource     = kClockLpsciSrcPllFllSel,
#endif
        .bitCountPerChar = kLpsci8BitsPerChar,
        .parityMode      = kLpsciParityDisabled,
        .stopBitCount    = kLpsciOneStopBit,
        .baudRate        = BOARD_DEBUG_UART_BAUD
    };

    // Enable clock for PORTs, setup board clock source, config pin
    hardware_init();

    // Call OSA_Init to setup LP Timer for timeout
    OSA_Init();

    // Initialize DMA module for LPSCI
    DMA_DRV_Init(&state);
    LPSCI_DRV_DmaInit(BOARD_DEBUG_UART_INSTANCE, &lpsciStateDma, &lpsciConfig);

    // Inform to start polling example
    byteCountBuff = sizeof(buffStart);
    LPSCI_DRV_DmaSendDataBlocking(BOARD_DEBUG_UART_INSTANCE, buffStart, byteCountBuff, 1000u);

    // Inform user of what to do
    byteCountBuff = sizeof(bufferData1);
    LPSCI_DRV_DmaSendDataBlocking(BOARD_DEBUG_UART_INSTANCE, bufferData1, byteCountBuff, 1000u);

    while(true)
    {
        // Wait to receive input data
        if (kStatus_LPSCI_Success == LPSCI_DRV_DmaReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, &rxChar, 1u, OSA_WAIT_FOREVER))
        {
            // Echo received character
            txChar = rxChar;
            LPSCI_DRV_DmaSendDataBlocking(BOARD_DEBUG_UART_INSTANCE, &txChar, 1u, 1000u);
        }
    }

}
示例#9
0
/*!
* @brief The i2c slave
* The function runs i2c slave with interrupt active mode. Slave receive data from
* master and echo back to master
*/
void main(void)
{
    // Number byte data will be transfer
    uint32_t count = 0;
    // Buffer store data to transfer
    uint8_t dataBuff[100] = {0};
    // state of slave
    i2c_slave_state_t slave;
    // user configuration
    i2c_slave_user_config_t userConfig =
    {
        .address        = 0x7FU,
        .slaveCallback  = NULL,
        .callbackParam  = NULL,
        .slaveListening = false,
#if FSL_FEATURE_I2C_HAS_START_STOP_DETECT
        .startStopDetect  = false,
#endif
#if FSL_FEATURE_I2C_HAS_STOP_DETECT
        .stopDetect       = false,
#endif
    };

    // Initialize hardware
    hardware_init();
    // Configure pin for i2c slave
    configure_i2c_pins(BOARD_I2C_COMM_INSTANCE);
    // Initialize uart to debug
    dbg_uart_init();
    // Initialize OSA
    OSA_Init();

    printf("Slave is running ...");

    // Initialize slave
    I2C_DRV_SlaveInit(BOARD_I2C_COMM_INSTANCE, &userConfig, &slave);

    // Loop transfer
    while(1)
    {
        // Slave receive 1 byte from master
        I2C_DRV_SlaveReceiveDataBlocking(BOARD_I2C_COMM_INSTANCE, (uint8_t*)&count, 1, OSA_WAIT_FOREVER);

        // Slave receive buffer from master
        I2C_DRV_SlaveReceiveDataBlocking(BOARD_I2C_COMM_INSTANCE, dataBuff, count, 1000);

        // Slave send buffer received from master
        I2C_DRV_SlaveSendDataBlocking(BOARD_I2C_COMM_INSTANCE, dataBuff, count, 1000);
    }
}
示例#10
0
int main(void)
#endif
{
    hardware_init();
    OSA_Init();
    dbg_uart_init();

#if !(USE_RTOS)
    APP_init();
#endif

    OS_Task_create(Task_Start, NULL, 4L, 3000L, "task_start", NULL);
    OSA_Start();
#if !defined(FSL_RTOS_MQX)
    return 1;
#endif
}
int main(void)
{
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	long int x;

	char AT[] = "\nAT";
	char rxBuff[10];
	uint32_t byteCountBuff = 0;
    //Initialise the FRDM-KL26Z Board
	hardware_init();
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);

	//Print message to serial terminal
	PRINTF("First Embedded Systems Lab_Aonghus\r\n");
	PRINTF("Type a character and it will be echoed back\r\n\n");
	int i = 0;
	byteCountBuff = sizeof(AT);
    while(1) {
    	//UART_DRV_SendDataBlocking(1, AT, byteCountBuff, 16000u);
    	 while(UART_DRV_ReceiveDataBlocking ( 1, rxBuff, sizeof(rxBuff),16000u) == kStatus_UART_Success )
    	 {
    		 for(i=0;i<sizeof(rxBuff);i++)
    		 PRINTF("%c",rxBuff[i]);
    	 }
    	// if(UART_DRV_GetTransmitStatus (1,sizeof(rxBuff)) == kStatus_UART_Success ){

    	// }


    	for(x=0;x<10000000;x++);
    }
    /* Never leave main */
    return 0;
}
示例#12
0
文件: main.cpp 项目: rschuck/K64f
int main (void)
{
   OSA_Init();

   /* Initialize clocks, debug console interface and configure required pins */
   hardware_init();

   /* Disable Memory Protection Unit */
   MPU_HAL_Disable(MPU);

	testPin.pinName = test_pin_name;
	testPin.config.outputLogic = 0;
	testPin.config.slewRate = kPortFastSlewRate;
	testPin.config.driveStrength = kPortHighDriveStrength;
	testPin.config.isOpenDrainEnabled = false;
	GPIO_DRV_OutputPinInit(&testPin);

	// Structure of initialize PIT channel No.0
   pit_user_config_t chn0Confg;
   chn0Confg.isInterruptEnabled = true;
   chn0Confg.periodUs = 1000000u;

   // 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);

   // Start channel 0
   PRINTF("\n\rStarting channel No.0 ...");
   PIT_DRV_StartTimer(BOARD_PIT_INSTANCE, 0);

//	drv_Mpu9250.Init();
	sdCard.Init(1);

   OSA_TaskCreate((task_t)MainTask,   (uint8_t*)"Main Task",    4096, NULL, 2, NULL, true, NULL);
   //OSA_TaskCreate((task_t)FnetTask,   (uint8_t*)"FNET Task",    2048, NULL, 3, NULL, true, NULL);

   OSA_Start(); // This function will not return

   while(1);

   return(0);
}
示例#13
0
文件: main.c 项目: cjc1029nice/ksdk
/*!
 * @brief main function
 */
int main(void)
{
  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;

  app_low_level_init();
  OSA_Init();
  lwip_init();

  IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
  IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
  IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);
  netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);
  netif_set_default(&fsl_netif0);
  netif_set_up(&fsl_netif0);

  ping_init();

  return 0;
}
示例#14
0
void main(void)
#endif

#endif
{
    hardware_init();
    OSA_Init();
    dbg_uart_init();

#if !(USE_RTOS)
    APP_init();
#endif
    

    OS_Task_create(Task_Start, NULL, 4L, 1000L, "task_start", NULL);

    OSA_Start();
#if (!defined(FSL_RTOS_MQX))&(defined(__CC_ARM) || defined(__GNUC__))
    return 1;
#endif
}
示例#15
0
文件: main.c 项目: cjc1029nice/ksdk
int main(void)
#endif
{
  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;
  
  app_low_level_init();
  OSA_Init();
  
  LWIP_DEBUGF(PING_DEBUG,("TCP/IP initializing...\r\n"));  
  tcpip_init(NULL,NULL);
  LWIP_DEBUGF(PING_DEBUG,("TCP/IP initialized.\r\n"));

  IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
  IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
  IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);

  netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, tcpip_input);
  netif_set_default(&fsl_netif0);

  ping_init();
}
示例#16
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.                                      */

    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                                */
        ;
    }
}
示例#17
0
int main (void)
{
    /***************************************************************************
     *  RX buffers
     **************************************************************************/
    /*! @param receiveBuff Buffer used to hold received data */
    uint8_t receiveBuff[19] = {0};

    /* Initialize standard SDK demo application pins */
    hardware_init();

    /* Configure the UART TX/RX pins */
    configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);

#ifdef USE_STDIO_FUNCTIONS
    /* Call this function to initialize the console UART.  This function
       enables the use of STDIO functions (printf, scanf, etc.) */
    dbg_uart_init();
    
    /*  Print the initial banner */
    printf("\r\nHello World!\n\n\r");

    while(1)
    {
        /********************************************
         * Main routine that simply echoes received
         * characters forever
         *********************************************/

        /* First, get character.  */
        receiveBuff[0] = getchar();
        
        /* Now echo the received character */
        putchar(receiveBuff[0]);
    }
#else
    /***************************************************************************
     * UART configuration and state structures
     **************************************************************************/
    /*! @param uartConfig UART configuration structure */
    /*! @param uartState UARt state structure which is used internally by the*/
    /*! by the UART driver to keep track of the UART states */
    uart_user_config_t uartConfig;
    uart_state_t uartState;
    
    /***************************************************************************
     *  TX buffers
     **************************************************************************/
    /*! @param sourceBuff Buffer used to hold the string to be transmitted */
    uint8_t sourceBuff[19] = {"\r\nHello World!\n\n\r"};
    
    /* Configure the UART for 115200, 8 data bits, No parity, and one stop bit*/
    uartConfig.baudRate = 115200;
    uartConfig.bitCountPerChar = kUart8BitsPerChar;
    uartConfig.parityMode = kUartParityDisabled;
    uartConfig.stopBitCount = kUartOneStopBit;
    
    /* Must call the OSA Init function to use Communication drivers */
    OSA_Init();
    
    /* Initialize the UART module */
    UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig);
    
    /*  Print the initial banner */
    UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 17, 200);

    while(1)
    {
        /********************************************
         * Main routine that simply echoes received
         * characters forever
         *********************************************/

        /* First, get character.  */
        UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, receiveBuff, 1, 
                                     OSA_WAIT_FOREVER);

        /* Now, stuff the buffer for the TX side and send the character*/
        sourceBuff[0] = receiveBuff[0];

        /* Now echo the received character */
        UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 1, 
                                  200);
    }
#endif
}
示例#18
0
/*!
 * @brief DSPI master Polling.
 *
 * Thid function uses DSPI master to send an array to slave
 * and receive the array back from slave,
 * thencompare whether the two buffers are the same.
 */
int main(void)
{
    uint32_t i;
    uint32_t loopCount = 1;
    SPI_Type * dspiBaseAddr = (SPI_Type*)SPI0_BASE;
    uint32_t dspiSourceClock;
    uint32_t calculatedBaudRate;
    dspi_device_t masterDevice;
    dspi_command_config_t commandConfig = 
    {
        .isChipSelectContinuous = false,
        .whichCtar              = kDspiCtar0,
        .whichPcs               = kDspiPcs0,
        .clearTransferCount     = true,
        .isEndOfQueue           = false
    };

    // Init hardware
    hardware_init();
    // Init OSA layer, used in DSPI_DRV_MasterTransferBlocking.
    OSA_Init();
    // Call this function to initialize the console UART.  This function
    // enables the use of STDIO functions (printf, scanf, etc.)
    dbg_uart_init();
    // Print a note.
    printf("\r\n DSPI board to board polling example");
    printf("\r\n This example run on instance 0 ");
    printf("\r\n Be sure DSPI0-DSPI0 are connected ");

    // Configure SPI pins.
    configure_spi_pins(DSPI_MASTER_INSTANCE);

    // Enable DSPI clock.
    CLOCK_SYS_EnableSpiClock(DSPI_MASTER_INSTANCE);
    // Initialize the DSPI module registers to default value, which disables the module
    DSPI_HAL_Init(dspiBaseAddr);
    // Set to master mode.
    DSPI_HAL_SetMasterSlaveMode(dspiBaseAddr, kDspiMaster);
    // Configure for continuous SCK operation
    DSPI_HAL_SetContinuousSckCmd(dspiBaseAddr, false);
    // Configure for peripheral chip select polarity
    DSPI_HAL_SetPcsPolarityMode(dspiBaseAddr, kDspiPcs0, kDspiPcs_ActiveLow);
    // Disable FIFO operation.
    DSPI_HAL_SetFifoCmd(dspiBaseAddr, false, false);
    // Initialize the configurable delays: PCS-to-SCK, prescaler = 0, scaler = 1
    DSPI_HAL_SetDelay(dspiBaseAddr, kDspiCtar0, 0, 1, kDspiPcsToSck);
    // DSPI system enable
    DSPI_HAL_Enable(dspiBaseAddr);

    // Configure baudrate.
    masterDevice.dataBusConfig.bitsPerFrame = 8;
    masterDevice.dataBusConfig.clkPhase     = kDspiClockPhase_FirstEdge;
    masterDevice.dataBusConfig.clkPolarity  = kDspiClockPolarity_ActiveHigh;
    masterDevice.dataBusConfig.direction    = kDspiMsbFirst;

    DSPI_HAL_SetDataFormat(dspiBaseAddr, kDspiCtar0, &masterDevice.dataBusConfig);
    // Get DSPI source clock.
    dspiSourceClock = CLOCK_SYS_GetSpiFreq(DSPI_MASTER_INSTANCE);
    calculatedBaudRate = DSPI_HAL_SetBaudRate(dspiBaseAddr, kDspiCtar0, TRANSFER_BAUDRATE, dspiSourceClock);
    printf("\r\n Transfer at baudrate %lu \r\n", calculatedBaudRate);

    while(1)
    {
        // Initialize the transmit buffer.
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            sendBuffer[i] = i + loopCount;
        }

        // Print out transmit buffer.
        printf("\r\n Master transmit:");
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            // Print 16 numbers in a line.
            if ((i & 0x0F) == 0)
            {
                printf("\r\n    ");
            }
            printf(" %02X", sendBuffer[i]);
        }

        // Reset the receive buffer.
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            receiveBuffer[i] = 0;
        }

        // Restart the transfer by stop then start again, this will clear out the shift register
        DSPI_HAL_StopTransfer(dspiBaseAddr);
        // Flush the FIFOs
        DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true);
        // Clear status flags that may have been set from previous transfers.
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest);
        // Clear the transfer count.
        DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0);
        // Start the transfer process in the hardware
        DSPI_HAL_StartTransfer(dspiBaseAddr);
        // Send the data to slave.
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            // Write data to PUSHR
            DSPI_HAL_WriteDataMastermodeBlocking(dspiBaseAddr, &commandConfig, sendBuffer[i]);
            // Delay to wait slave is ready.
            OSA_TimeDelay(1);
        }

        // Delay to wait slave is ready.
        OSA_TimeDelay(10);

        // Restart the transfer by stop then start again, this will clear out the shift register
        DSPI_HAL_StopTransfer(dspiBaseAddr);
        // Flush the FIFOs
        DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true);
        //Clear status flags that may have been set from previous transfers.
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest);
        // Clear the transfer count.
        DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0);
        // Start the transfer process in the hardware
        DSPI_HAL_StartTransfer(dspiBaseAddr);
        // Receive the data from slave.
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            // Write command to PUSHR.
            DSPI_HAL_WriteDataMastermodeBlocking(dspiBaseAddr, &commandConfig, 0);
            // Check RFDR flag
            while (DSPI_HAL_GetStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest)== false)
            {}
            // Read data from POPR
            receiveBuffer[i] = DSPI_HAL_ReadData(dspiBaseAddr);
            // Clear RFDR flag
            DSPI_HAL_ClearStatusFlag(dspiBaseAddr,kDspiRxFifoDrainRequest);
            // Delay to wait slave is ready.
            OSA_TimeDelay(1);
        }

        // Print out receive buffer.
        printf("\r\n Master receive:");
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            // Print 16 numbers in a line.
            if ((i & 0x0F) == 0)
            {
                printf("\r\n    ");
            }
            printf(" %02X", receiveBuffer[i]);
        }

        // Check receiveBuffer.
        for (i = 0; i < TRANSFER_SIZE; ++i)
        {
            if (receiveBuffer[i] != sendBuffer[i])
            {
                // Master received incorrect.
                printf("\r\n ERROR: master received incorrect ");
                return -1;
            }
        }

        printf("\r\n DSPI Master Sends/ Recevies Successfully");
        // Wait for press any key.
        printf("\r\n Press any key to run again");
        getchar();
        // Increase loop count to change transmit buffer.
        loopCount++;
    }
}
示例#19
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
}
int main(void)
{
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	long int x;
	int recieve_size=0;
	char AT[] = "AT\r";
	char CMGF[] = "AT+CMGF=1\r";
	char CMGS[] = "AT+CMGS=\"+353877763894\"\r";
	char MESSAGE[] = "HELLO AONGHUS KL26Z \x1A";

	char response[200];
	enum STATES {INIT,TXT_MODE,SEND_SMS,SEND_MSG};
	enum STATES CurrentState = INIT;
	uint32_t byteCountBuff = 0;
    //Initialise the FRDM-KL26Z Board
	hardware_init();
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);
	PRINTF("Full test of send/recieve on UART1\r\n");
	int i = 0,y;
	for(y=0;y<=sizeof(response);y++)
		response[i]='c';

	byteCountBuff = sizeof(AT);
	wait_time = 16000u;
    while(1){
    	switch(CurrentState){
			case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size =4;
				byteCountBuff = sizeof(AT);
				result = send_command(1,AT,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned INIT\r\n");//"OK" was returned by MODEM
					CurrentState = TXT_MODE;
				}
				break;
			case TXT_MODE:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size =4;
				byteCountBuff = sizeof(CMGF);
				result = send_command(1,CMGF,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned TXT_MODE\r\n");//"OK" was returned by MODEM
					CurrentState = SEND_SMS;
				}
				break;
			case SEND_SMS:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size = 2;
				byteCountBuff = sizeof(CMGS);
				result = send_command(1,CMGS,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned SEND_SMS\r\n");//"OK" was returned by MODEM
					CurrentState = SEND_MSG;
				}
				break;
			case SEND_MSG:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size =8;
				byteCountBuff = sizeof(MESSAGE);
				result = send_command(1,MESSAGE,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned SEND_MSG\r\n");//"OK" was returned by MODEM
					//CurrentState = CHECK_PIN;
				}
				break;
			default:
				break;
		}//end switch-case
    }
    /* Never leave main */
    return 0;
}
示例#21
0
//void UART1_IRQHandler(void)
//{
//	UART_DRV_IRQHandler(1);
//}
int main(void)
{


	//Simple UART1

	//	 // Init hardware
	//	uart_state_t uartState1; // user provides memory for the driver state structure
	//	uart_user_config_t uartConfig1;
	//
	//	hardware_init();
	//	configure_uart_pins(0);
	//
	//
	//	 OSA_Init();
	//
	//
	//	uartConfig1.baudRate = 9600;
	//	uartConfig1.bitCountPerChar = kUart8BitsPerChar;
	//	uartConfig1.parityMode = kUartParityDisabled;
	//	uartConfig1.stopBitCount = kUartOneStopBit;
	//
	//PRINTF("Just to init Uart\r");
	//	UART_DRV_Init(1,  &uartState1, &uartConfig1);
	//	PRINTF("Uart initilized\n\r");
	//
	//	while(1){
	//		PRINTF("About to send data\n\r");
	//UART_DRV_SendDataBlocking(1, AT, sizeof(AT),16000u); // function
	////	UART_DRV_ReceiveDataBlocking(1, &TXBUFF, 2,16000); // function
	////	 PRINTF("\n\rWho am i register value is: %01X", TXBUFF[0]);
	//
	//	//PRINTF()
	//	PRINTF("Tried to sent some\n");
	//
	//	}

	//Accu init
    i2c_master_state_t master;
    i2c_device_t device =
    {
      .address = 0x1DU,
      .baudRate_kbps = 400   // 400 Kbps
    };
    hardware_init();
    UART2_config(9600);
    enable_UART2_receive_interrupt();
    i2cinitreg();

    // Initialize OSA
    OSA_Init();

    // Initialize i2c master
    I2C_DRV_MasterInit(I2C_INSTANCE_0, &master);
    PRINTF("\r\n=INIT\r\n");
    I2C_DRV_MasterReceiveDataBlocking(I2C_INSTANCE_0, &device,WHO_AM_I, 1, rxBuff, 1, 1000);
           //Prints out values in recived register
           PRINTF("\n\rWho am i register value is: %01X", rxBuff[0]);

    configureAccuAndMag(device);

    PRINTF("\r\n==================== I2C MASTER BLOCKING ===================\r\n");
    PRINTF("\r\n1. Master checks who am i register\
    \r\n2. Master configures accelerometer and magnetometer\
    \r\n3. Takes 200 samples, average them and displays results\r\n");
    PRINTF("\r\n============================================================\r\n\n");

    PRINTF("Press any key to start transfer:\r\n\n");
    GETCHAR();


     while(1){

    	 x = 0;
    	 y = 0;
    	 z = 0;
    	 for(count = 0; count < 200; count++){
    		 I2C_DRV_MasterReceiveDataBlocking(I2C_INSTANCE_0, &device,READ_DATA, 1, rxBuff, 13, 1000);

    		     	 x += (int16_t)(((rxBuff[1] << 8) | rxBuff[2]))>> 2;
    		     	 y += (int16_t)(((rxBuff[3] << 8) | rxBuff[4]))>> 2;
    		     	 z += (int16_t)(((rxBuff[5] << 8) | rxBuff[6]))>> 2;
    	 }
    	 x = x/200;
    	 y = y/200;
    	 getWhere(x,y);
     }

    PRINTF("\r\n==================== I2C MASTER FINISH =================== \r\n");

    // Deinit i2c
    I2C_DRV_MasterDeinit(0);

    return 0;
}

///////////////////////////////////////////////////////////////////////////////
// Pin configure
///////////////////////////////////////////////////////////////////////////////
void i2cinitreg(){
    PORTE_PCR24 |= (0x05u)<<8 | 0x03u;
    PORTE_PCR25 |= (0x05u)<<8 | 0x03u;
}
示例#22
0
int main (void)
{
    uint32_t j;
    spi_status_t spiResult;
    spi_slave_state_t spiSlaveState;

    spi_dma_slave_state_t spiDmaSlaveState;
    spi_slave_user_config_t slaveUserConfig;
    spi_dma_slave_user_config_t userDmaConfig =
    {
    #if FSL_FEATURE_SPI_16BIT_TRANSFERS
        .bitCount       = kSpi8BitMode,
    #endif
        .polarity       = kSpiClockPolarity_ActiveHigh,
        .phase          = kSpiClockPhase_FirstEdge,
        .direction      = kSpiMsbFirst
    };

    dma_state_t dmaState;

    // Init the DMA module
    DMA_DRV_Init(&dmaState);

    // init the hardware, this also sets up up the SPI pins for each specific SoC
    hardware_init();

    dbg_uart_init();

    OSA_Init();

    printf("\r\n SPI board to board dma non-blocking example");
    printf("\r\n This example run on instance 0 ");
    printf("\r\n Be sure master's SPI0 and slave's SPI0 are connected ");

    // USER CONFIGURABLE OPTION FOR SPI INSTANCE (if applicable)

    // Configure SPI pin
    configure_spi_pins(SPI_SLAVE_INSTANCE);

    if (SPI_DRV_DmaSlaveInit(SPI_SLAVE_INSTANCE, &spiDmaSlaveState, &userDmaConfig) != kStatus_SPI_Success)
    {
        printf("\r\nError in slave DMA init \r\n");
    }

    while(1)
    {
        printf("\r\nSlave example is running...");
        spiResult = SPI_DRV_DmaSlaveTransfer(SPI_SLAVE_INSTANCE, NULL,
                                      s_spiSinkBuffer, TRANSFER_SIZE);
        while(kStatus_SPI_Success != SPI_DRV_DmaSlaveGetTransferStatus(SPI_SLAVE_INSTANCE, NULL));
        if (spiResult != kStatus_SPI_Success)
        {
            printf("\r\nERROR: slave receives error ");
            return -1;
        }
        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            s_spiSourceBuffer[j] = s_spiSinkBuffer[j];
        }

        spiResult = SPI_DRV_DmaSlaveTransfer(SPI_SLAVE_INSTANCE, s_spiSourceBuffer,
                                          NULL, TRANSFER_SIZE);
        while(kStatus_SPI_Success != SPI_DRV_DmaSlaveGetTransferStatus(SPI_SLAVE_INSTANCE, NULL));
        if (spiResult != kStatus_SPI_Success)
        {
            printf("\r\nERROR: slave sends error ");
            return -1;
        }
        // Print out receive buffer
        printf("\r\nSlave receive:");
        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            if (j%16 == 0)
            {
                printf("\r\n    ");
            }
            printf(" %02X", s_spiSinkBuffer[j]);
        }
    }
}
/*!
 * @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);
        }
    }
}
示例#24
0
int main()
{

	char * AT = "\r\nAT\r\n";//Setting up a char variable AT for the a long string
	char * PIN_CHECK = "\r\nAT+CPIN?\r\n";//Setting up a char variable PIN_CHECK for the a long string
	char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";//Setting up a char variable ENTER_PIN for the a long string
	char * CREG = "\r\nAT+CREG?\r\n";//Setting up a char variable CREG for the a long string
	char response[20]; //A character buffer called response that can hold 20 characters
	int result = 0;	//int result to check the value of the response sent back
	int transmit_send = 0;
	volatile int CurrentTick;	//Volitile interger to hold the current tick count of the current time
	char * ptr;	//Character
	char * stat;
	enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED};
	enum STATES CurrentState = INIT;
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	buffer_init();
	hardware_init();
	//UART0_config();
	PIT_Configure_interrupt_mode(1);
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);
	//PRINTF("UART0 Test Code\n\r");
	//PRINTF("Any entered character will be echoed\r\n\n");
	while(1)
	{
		switch(CurrentState)
		{
		case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
			printf("Testing Modem Connection\n");
			result = send_command(AT, response, sizeof(response), 2000);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" was returned by MODEM
				CurrentState = CHECK_PIN;
			else	//incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		case CHECK_PIN:	//Check if SIM card is ready
			result = send_command(PIN_CHECK, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				if(strstr(response, "READY"))
				{
					CurrentState = CHECK_NETWORK_REG;
				}
				else if(strstr(response, "SIM PIN"))
				{
					CurrentState = SEND_PIN;
				}
			}
			else
				CurrentState = INIT;
			break;

		case SEND_PIN:	//Send PIN code. "OK" response if PIN is correct
			result = send_command(ENTER_PIN, response, sizeof(response),10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				CurrentState = CHECK_NETWORK_REG;
			}
			else
				CurrentState = INIT;
			break;


		case CHECK_NETWORK_REG:	//check if registered on mobile network
			result = send_command(CREG, response, sizeof(response), 20);
			if(strstr(response, "+CREG"))
			{
				stat = (char *)strstr(response,":");
				stat += 4;
				switch(*stat)
				{
				case '0':
					CurrentState = INIT;
					break;
				case '1':
					CurrentState = SEND_SMS;
					break;
				case '2':
					CurrentTick = tick_count;
					while((tick_count - CurrentTick) < 5)
					{}
					CurrentState = CHECK_NETWORK_REG;
					break;
				case '3':
					CurrentState = INIT;
					break;
				case '4':
					CurrentState = CONNECTED;
					break;
				case '5':
					CurrentState = SEND_SMS;
					break;

				}
			}


		case SEND_SMS:	//Send a text message
			transmit_send = send_sms("\"0877763894\"","\"Testing 123		\"");
			if(transmit_send == SUCCESS)
			{
				CurrentState = CONNECTED;
			}
			else if(transmit_send == FAIL)
			{
				printf("A transmission fail has been detected or you have timed out\r\n");
				CurrentState = SEND_SMS;
			}
			else if(transmit_send == ERROR)
			{
				printf("A transmission ERROR has been detected,rebooting\r\n");
				CurrentState = INIT;
			}
			break;

		case CONNECTED:
			printf("\nInside Connected \r\n");
			while(1)	//dummy loop
			{}
			break;

		default:
			break;
		}//end switch-case
	}
}
/*!
* @brief The i2c slave
* The function runs i2c slave with interrupt active mode. Slave receive data from
* master and echo back to master
*/
int main(void)
{
    // Number byte data will be transfer
    uint32_t count = 0;
    uint32_t i     = 0;
    // Buffer store data to transfer
    uint8_t dataBuff[DATA_LENGTH] = {0};
    // state of slave
    i2c_slave_state_t slave;
    // user configuration
    i2c_slave_user_config_t userConfig =
    {
        .address        = 0x7FU,
        .slaveCallback  = NULL,
        .callbackParam  = NULL,
        .slaveListening = false,
#if FSL_FEATURE_I2C_HAS_START_STOP_DETECT
        .startStopDetect  = false,
#endif
#if FSL_FEATURE_I2C_HAS_STOP_DETECT
        .stopDetect       = false,
#endif
    };

    // Initialize hardware
    hardware_init();

    // Initialize OSA
    OSA_Init();

    PRINTF("\r\n================== I2C SLAVE NON-BLOCKING =================\r\n\r\n");
    PRINTF("Slave is running ...");

    // Initialize slave
    I2C_DRV_SlaveInit(BOARD_I2C_INSTANCE, &userConfig, &slave);

    // Loop transfer
    while(1)
    {
        // Slave receive buffer from master
        I2C_DRV_SlaveReceiveData(BOARD_I2C_INSTANCE, (uint8_t*)&count, 1);

        /* Wait until transfer is successful */
        while (I2C_DRV_SlaveGetReceiveStatus(BOARD_I2C_INSTANCE, NULL) != kStatus_I2C_Success);

        // Clear receive buffer
        for(i = 0; i < count; i++)
        {
            dataBuff[i] = 0;
        }

        // Slave receive buffer from master
        I2C_DRV_SlaveReceiveData(BOARD_I2C_INSTANCE, dataBuff, count);

        /* Wait until transfer is successful */
        while (I2C_DRV_SlaveGetReceiveStatus(BOARD_I2C_INSTANCE, NULL) != kStatus_I2C_Success);

        // Print receive data
        PRINTF("\r\nSlave received:\r\n");
        for (i = 0; i < count; i++)
        {
            // Print 16 numbers in a line.
            if ((i & 0x0F) == 0)
            {
                PRINTF("\r\n    ");
            }
            PRINTF(" %02X", dataBuff[i]);
        }

        // Slave send buffer received from master
        I2C_DRV_SlaveSendData(BOARD_I2C_INSTANCE, dataBuff, count);

        /* Wait until transfer is successful */
        while (I2C_DRV_SlaveGetTransmitStatus(BOARD_I2C_INSTANCE, NULL) != kStatus_I2C_Success);

        OSA_TimeDelay(1);
    }
}
示例#26
0
文件: main.c 项目: cjc1029nice/ksdk
/*!
 * @brief SPI master DMA non-blocking.
 *
 * Thid function uses SPI master to send an array to slave
 * and receive the array back from slave,
 * then compare whether the two buffers are the same.
 */
int main (void)
{
    uint8_t loopCount = 0;
    uint32_t j;
    uint32_t failCount = 0;
    uint32_t calculatedBaudRate;
    spi_dma_master_state_t spiDmaMasterState;
    dma_state_t state;
    spi_dma_master_user_config_t userDmaConfig =
    {
#if FSL_FEATURE_SPI_16BIT_TRANSFERS
        .bitCount       = kSpi8BitMode,
#endif
        .polarity       = kSpiClockPolarity_ActiveHigh,
        .phase          = kSpiClockPhase_FirstEdge,
        .direction      = kSpiMsbFirst,
        .bitsPerSec     = TRANSFER_BAUDRATE
    };

    // init the hardware, this also sets up up the SPI pins for each specific SoC
    hardware_init();
    // Init OSA layer.
    OSA_Init();

    PRINTF("\r\nSPI board to board dma-non-blocking example");
    PRINTF("\r\nThis example run on instance %d", (uint32_t)SPI_MASTER_INSTANCE);
    PRINTF("\r\nBe sure master's SPI%d and slave's SPI%d are connected\r\n",
                    (uint32_t)SPI_MASTER_INSTANCE, (uint32_t)SPI_MASTER_INSTANCE);

    // Set up and init the master
    DMA_DRV_Init(&state);
    // Init the dspi module for eDMA operation
    SPI_DRV_DmaMasterInit(SPI_MASTER_INSTANCE, &spiDmaMasterState);
    SPI_DRV_DmaMasterConfigureBus(SPI_MASTER_INSTANCE,
                                    &userDmaConfig,
                                    &calculatedBaudRate);

    if (calculatedBaudRate > userDmaConfig.bitsPerSec)
    {
        PRINTF("\r\n**Something failed in the master bus config \r\n");
        return -1;
    }
    else
    {
        PRINTF("\r\nBaud rate in Hz is: %d\r\n", calculatedBaudRate);
    }

    while(1)
    {
        // Initialize the source buffer
        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            s_spiSourceBuffer[j] = j + loopCount;
        }

        // Reset the sink buffer
        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            s_spiSinkBuffer[j] = 0;
        }

        // Start the transfer
        SPI_DRV_DmaMasterTransferBlocking(SPI_MASTER_INSTANCE, NULL, s_spiSourceBuffer,
                                        NULL, TRANSFER_SIZE, MASTER_TRANSFER_TIMEOUT);
        while (SPI_DRV_DmaMasterGetTransferStatus(SPI_MASTER_INSTANCE, NULL) == kStatus_SPI_Busy)
        {
        }

        // Delay sometime to wait slave receive and send back data
        OSA_TimeDelay(500U);

        //Receive data from slave
        SPI_DRV_DmaMasterTransfer(SPI_MASTER_INSTANCE, NULL, NULL,
                            s_spiSinkBuffer, TRANSFER_SIZE);
        while (SPI_DRV_DmaMasterGetTransferStatus(SPI_MASTER_INSTANCE, NULL) == kStatus_SPI_Busy)
        {
        }

        // Verify the contents of the master sink buffer
        // refer to the slave driver for the expected data pattern
        failCount = 0; // reset failCount variable

        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            if (s_spiSinkBuffer[j] != s_spiSourceBuffer[j])
            {
                 failCount++;
            }
        }

        // Print out transmit buffer.
        PRINTF("\r\nMaster transmit:");
        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            // Print 16 numbers in a line.
            if ((j & 0x0F) == 0)
            {
                PRINTF("\r\n    ");
            }
            PRINTF(" %02X", s_spiSourceBuffer[j]);
        }
        // Print out receive buffer.
        PRINTF("\r\nMaster receive:");
        for (j = 0; j < TRANSFER_SIZE; j++)
        {
            // Print 16 numbers in a line.
            if ((j & 0x0F) == 0)
            {
                PRINTF("\r\n    ");
            }
            PRINTF(" %02X", s_spiSinkBuffer[j]);
        }

        if (failCount == 0)
        {
            PRINTF("\r\n Spi master transfer succeed! \r\n");
        }
        else
        {
            PRINTF("\r\n **failures detected in Spi master transfer! \r\n");
        }

        // Wait for press any key.
        PRINTF("\r\nPress any key to run again\r\n");
        GETCHAR();
        loopCount++;
    }
}
/*!
 * @brief Main demo function.
 */
int main (void)
{

    tpm_general_config_t driverInfo;
    accel_dev_t accDev;
    accel_dev_interface_t accDevice;
    accel_sensor_data_t accelData;
    accel_i2c_interface_t i2cInterface;
    tpm_pwm_param_t yAxisParams;
    tpm_pwm_param_t xAxisParams;
    int16_t xData, yData;
    int16_t xAngle, yAngle;

    xAxisParams.mode              = kTpmEdgeAlignedPWM;
    xAxisParams.edgeMode          = kTpmHighTrue;
    xAxisParams.uFrequencyHZ      = 100000u;
    xAxisParams.uDutyCyclePercent = 0u;

    yAxisParams.mode              = kTpmEdgeAlignedPWM;
    yAxisParams.edgeMode          = kTpmHighTrue;
    yAxisParams.uFrequencyHZ      = 100000u;
    yAxisParams.uDutyCyclePercent = 0u;

    // Register callback func for I2C
    i2cInterface.i2c_init       =  I2C_DRV_MasterInit;
    i2cInterface.i2c_read       =  I2C_DRV_MasterReceiveDataBlocking;
    i2cInterface.i2c_write      =  I2C_DRV_MasterSendDataBlocking;

    accDev.i2c      = &i2cInterface;
    accDev.accel    = &accDevice;

    accDev.slave.baudRate_kbps  = BOARD_ACCEL_BAUDRATE;
    accDev.slave.address        = BOARD_ACCEL_ADDR;
    accDev.bus                  = BOARD_ACCEL_I2C_INSTANCE;

    // Initialize standard SDK demo application pins.
    hardware_init();

    // Accel device driver utilizes the OSA, so initialize it.
    OSA_Init();

    // Print the initial banner.
    PRINTF("Bubble Level Demo!\r\n\r\n");

    // Initialize the Accel.
    accel_init(&accDev);

    // Prepare memory for initialization.
    memset(&driverInfo, 0, sizeof(driverInfo));

    // Init TPM.
    TPM_DRV_Init(BOARD_BUBBLE_TPM_INSTANCE, &driverInfo);

    // Set clock for TPM.
    TPM_DRV_SetClock(BOARD_BUBBLE_TPM_INSTANCE, kTpmClockSourceModuleClk, kTpmDividedBy2);

    // Main loop.  Get sensor data and update duty cycle for the TPM timer.
    while(1)
    {
        // Wait 5 ms in between samples (accelerometer updates at 200Hz).
        OSA_TimeDelay(5);

        // Get new accelerometer data.
          accDev.accel->accel_read_sensor_data(&accDev,&accelData);

        // Init PWM module with updated configuration.
        TPM_DRV_PwmStart(BOARD_BUBBLE_TPM_INSTANCE, &xAxisParams, BOARD_TPM_X_CHANNEL);
        TPM_DRV_PwmStart(BOARD_BUBBLE_TPM_INSTANCE, &yAxisParams, BOARD_TPM_Y_CHANNEL);

        // Get the X and Y data from the sensor data structure.fxos_data
        xData = (int16_t)((accelData.data.accelXMSB << 8) | accelData.data.accelXLSB);
        yData = (int16_t)((accelData.data.accelYMSB << 8) | accelData.data.accelYLSB);

        // Convert raw data to angle (normalize to 0-90 degrees).  No negative angles.
        xAngle = abs((int16_t)(xData * 0.011));
        yAngle = abs((int16_t)(yData * 0.011));

        // Update angles to turn on LEDs when angles ~ 90
        if(xAngle > 85) xAngle = 100;
        if(yAngle > 85) yAngle = 100;
        // Update angles to turn off LEDs when angles ~ 0
        if(xAngle < 5) xAngle = 0;
        if(yAngle < 5) yAngle = 0;

        // Update pwm duty cycle
        xAxisParams.uDutyCyclePercent = 100 - xAngle ;
        yAxisParams.uDutyCyclePercent = 100 - yAngle ;

        // Print out the raw accelerometer data.
        PRINTF("x= %d y = %d\r\n", xData, yData);
    }
}
示例#28
0
int main (void)
{
    uint8_t msg;
    uint32_t timeout = 0;
    uint32_t var;
    volatile uint16_t count;

    OSA_Init();

    hardware_init();
    dbg_uart_init();
    configure_spi_pins(HW_SPI0);
    
    printf("dspi_edma_test_slave\r\n");
    printf("\r\nDemo started...\r\n");

    // Initialize configuration
    edma_init();
    edma_dspi_rx_setup(kEDMAChannel2, (uint32_t)&g_slaveRxBuffer);
    dspi_slave_setup(HW_SPI0, SPI_BAUDRATE);
    
    printf("Press space bar to begin.\r\n");
    msg = 'A';
    while(msg != ' ')
    {
        msg = getchar();
    }

    printf("\r\nDemo started...\r\n");
    
    // Slave only have PCS0
    PORT_HAL_SetMuxMode(PORTC_BASE, 0u, kPortMuxAlt7);
    
    // Enable eDMA channels requests to initiate DSPI transfers.
    EDMA_HAL_SetDmaRequestCmd(DMA_BASE, kEDMAChannel2, true);
    DSPI_HAL_StartTransfer(SPI0_BASE);
    
    // Waiting transfer complete
    printf("waiting transfer complete...\r\n");
    while((bReceivedFlag == false) & (timeout < 50))
    {
        OSA_TimeDelay(100);
        timeout++;
    }
    
    if(bReceivedFlag == false)
    {
        printf("No date received, please check connections\r\n");
    }
    
    printf("received data:\r\n");
    
    for(count = 0; count < TEST_DATA_LEN; count++)
    {
        var = g_slaveRxBuffer[count];
        printf("%08X\t", (unsigned int)var);
        if((count + 1) % 4 == 0)
        {
            printf("\r\n");
        }
    }
    printf("\r\nEnd of demo.\r\n");
}
示例#29
0
/*!
 * @brief DSPI slave Polling.
 *
 * This function sends back received buffer from master through DSPI interface.
 */
int main(void)
{
    uint32_t i;
    SPI_Type * dspiBaseAddr = (SPI_Type*)SPI0_BASE;
    dspi_slave_user_config_t slaveConfig;

    // Init hardware
    hardware_init();
    // Init OSA layer, used in DSPI_DRV_MasterTransferBlocking.
    OSA_Init();
    // Call this function to initialize the console UART.  This function
    // enables the use of STDIO functions (printf, scanf, etc.)
    dbg_uart_init();
    // Configure SPI pins.
    configure_spi_pins(DSPI_SLAVE_INSTANCE);

    // Print a note.
    printf("\r\n DSPI board to board polling example");
    printf("\r\n This example run on instance 0 ");
    printf("\r\n Be sure DSPI0-DSPI0 are connected ");

    // Enable clock for DSPI
    CLOCK_SYS_EnableSpiClock(DSPI_SLAVE_INSTANCE);
    // Reset the DSPI module, which also disables the DSPI module
    DSPI_HAL_Init(dspiBaseAddr);
    // Set to slave mode.
    DSPI_HAL_SetMasterSlaveMode(dspiBaseAddr, kDspiSlave);
    // Set data format
    slaveConfig.dataConfig.clkPhase     = kDspiClockPhase_FirstEdge;
    slaveConfig.dataConfig.clkPolarity  = kDspiClockPolarity_ActiveHigh;
    slaveConfig.dataConfig.bitsPerFrame = 8;
    DSPI_HAL_SetDataFormat(dspiBaseAddr, kDspiCtar0, &(slaveConfig.dataConfig));
    // DSPI system enable
    DSPI_HAL_Enable(dspiBaseAddr);
    // Disable FIFO operation.
    DSPI_HAL_SetFifoCmd(dspiBaseAddr, false, false);

    while(1)
    {
         printf("\r\n Slave example is running...");
        // Reset the receive buffer.
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            receiveBuffer[i] = 0;
        }

        // Restart the transfer by stop then start again, this will clear out the shift register
        DSPI_HAL_StopTransfer(dspiBaseAddr);
        // Flush the FIFOs
        DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true);
        // Clear status flags that may have been set from previous transfers
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest);
        // Clear the transfer count
        DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0);
        // Start the transfer process in the hardware
        DSPI_HAL_StartTransfer(dspiBaseAddr);
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
                // Check RFDR flag
                while (DSPI_HAL_GetStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest)== false)
                {}
                // Read data from POPR
                receiveBuffer[i] = DSPI_HAL_ReadData(dspiBaseAddr);
                // Clear RFDR flag
                DSPI_HAL_ClearStatusFlag(dspiBaseAddr,kDspiRxFifoDrainRequest);
        }

        // Restart the transfer by stop then start again, this will clear out the shift register
        DSPI_HAL_StopTransfer(dspiBaseAddr);
        // Flush the FIFOs
        DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true);
        // Clear status flags that may have been set from previous transfers
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow);
        DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest);
        // Clear the transfer count
        DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0);
        // Start the transfer process in the hardware
        DSPI_HAL_StartTransfer(dspiBaseAddr);
        // Send the data to slave.
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            // Write data to PUSHR
            DSPI_HAL_WriteDataSlavemodeBlocking(dspiBaseAddr, receiveBuffer[i]);
        }

        // Print out receive buffer.
        printf("\r\n Slave receive:");
        for (i = 0; i < TRANSFER_SIZE; i++)
        {
            // Print 16 numbers in a line.
            if ((i & 0x0F) == 0)
            {
                printf("\r\n    ");
            }
            printf(" %02X", receiveBuffer[i]);
        }
    }
}
示例#30
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);
    }

}