//**************************************************************************** // //! The delay function uses timer to implement the delay time in milliseconds //! //! \param time in millisecond // //! \return void //**************************************************************************** static void delay(int time_ms) { // Initialize Timer 0B as one-shot down counter. MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralReset(PRCM_TIMERA0); MAP_TimerConfigure(TIMERA0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT); MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_B, PRESCALE); //Load the value in milisecond MAP_TimerLoadSet(TIMERA0_BASE, TIMER_B, MILLISECONDS_TO_TICKS(time_ms)); // Enable the timer MAP_TimerEnable(TIMERA0_BASE, TIMER_B); //Stall during debug MAP_TimerControlStall(TIMERA0_BASE, TIMER_B, 1); // Enable interrupt upon Time-out MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_TIMEOUT); // Clear Interrupt Flag MAP_TimerIntClear(TIMERA0_BASE, MAP_TimerIntStatus(TIMERA0_BASE, true)); //Wait until timer time-out while (MAP_TimerIntStatus(TIMERA0_BASE, true) != TIMER_TIMB_TIMEOUT){} //Disable the timer MAP_TimerDisable(TIMERA0_BASE, TIMER_B); //Disable Interrupt MAP_TimerIntDisable(TIMERA0_BASE, TIMER_TIMB_TIMEOUT); MAP_TimerIntUnregister(TIMERA0_BASE, TIMER_B); }
int main(void) { SystemInit(); /*Initialize Erika related stuffs*/ EE_system_init(); /*Initialize systick */ EE_systick_set_period(MILLISECONDS_TO_TICKS(1, SystemCoreClock)); EE_systick_enable_int(); EE_systick_start(); console_init(); stop = 0; calcRawSpeed(); initState(kwips_rawspeed, initAlarms, initFreq, initKWPP); do { ch = readCharUSART(); } while (ch != 't'); ActivateTask(SuperTask); StartOS(OSDEFAULTAPPMODE); /* Forever loop: background activities (if any) should go here */ for (;;) { } }
/* Increase Autoscroll rate */ void DoAutoscrollIncr( void ) { if ( Prefs()->autoscrollInterval == AUTOSCROLL_MIN_INTERVAL_VALUE ) { if ( Prefs()->autoscrollJump < AUTOSCROLL_MAX_JUMP_VALUE ) Prefs()->autoscrollJump += AUTOSCROLL_INCR_JUMP_VALUE; } else { if ( Prefs()->autoscrollInterval <= MILLISECONDS_TO_TICKS( AUTOSCROLL_FINE_TRANSITION ) ) Prefs()->autoscrollInterval -= MILLISECONDS_TO_TICKS( AUTOSCROLL_FINE_INCR_INTERVAL_VALUE ); else Prefs()->autoscrollInterval -= MILLISECONDS_TO_TICKS( AUTOSCROLL_INCR_INTERVAL_VALUE ); } }
/* Decrease Autoscroll rate */ void DoAutoscrollDecr( void ) { if ( Prefs()->autoscrollJump == AUTOSCROLL_MIN_JUMP_VALUE ) { if ( Prefs()->autoscrollInterval < MILLISECONDS_TO_TICKS( AUTOSCROLL_FINE_TRANSITION ) ) Prefs()->autoscrollInterval += MILLISECONDS_TO_TICKS( AUTOSCROLL_FINE_INCR_INTERVAL_VALUE ); else if ( Prefs()->autoscrollInterval < MILLISECONDS_TO_TICKS( AUTOSCROLL_MAX_INTERVAL_VALUE ) ) Prefs()->autoscrollInterval += MILLISECONDS_TO_TICKS( AUTOSCROLL_INCR_INTERVAL_VALUE ); } else { Prefs()->autoscrollJump -= AUTOSCROLL_INCR_JUMP_VALUE; } }
//***************************************************************************** // //! starts the timer //! //! \param ulBase is the base address for the timer. //! \param ulTimer selects amoung the TIMER_A or TIMER_B or TIMER_BOTH. //! \param ulValue is the time delay in mSec after that run out, //! timer gives an interrupt. //! //! This function //! 1. Load the Timer with the specified value. //! 2. enables the timer. //! //! \return none //! //! \Note- HW Timer runs on 80MHz clock // //***************************************************************************** void Timer_IF_Start(unsigned long ulBase, unsigned long ulTimer, unsigned long ulValue) { MAP_TimerLoadSet(ulBase,ulTimer,MILLISECONDS_TO_TICKS(ulValue)); // // Enable the GPT // MAP_TimerEnable(ulBase,ulTimer); }
/* * MAIN TASK */ int main(void) { //GPIO_InitTypeDef GPIO_InitStructure; SystemInit(); /*Initializes Erika related stuffs*/ EE_system_init(); SWatch_state.errorStatus = errorSig; SWatch_state.ModelData.prevZCSigState = &ZCSig; SWatch_state.ModelData.dwork = &DWork; /* init state machine */ SWatch_initialize(&SWatch_state, &Bplus, &Bminus, &Btime, &Btimer, &Balarm, &Bswatch, &Bstart, &Bstop, &hours, &minutes, &seconds, &tenths, &mode, &alarm_signal, &timer_exp); /*Initialize systick */ EE_systick_set_period(MILLISECONDS_TO_TICKS(1, SystemCoreClock)); EE_systick_enable_int(); EE_systick_start(); /* Initializes LCD and touchscreen */ IOE_Config(); /* Initialize the LCD */ STM32f4_Discovery_LCD_Init(); // LCD_Clear(White); /* Set the LCD Text size */ // LCD_SetFont(&Font8x12); // Lcd_Touch_Calibration(); InitTouch(-0.102, 0.0656, -335, 10); /* Draw the background */ DrawInit(MyWatchScr); LCD_SetTextColor(Black); LCD_SetBackColor(Black); LCD_DrawFullRect(10, 80, 240, 56); WPrint(&MyWatchScr[SEP1STR], ":"); WPrint(&MyWatchScr[SEP2STR], ":"); /* Program cyclic alarms which will fire after an initial offset, * and after that periodically * */ SetRelAlarm(AlarmTaskLCD, 10, 50); SetRelAlarm(AlarmTaskClock, 10, 100); /* Forever loop: background activities (if any) should go here */ for (;;) { } }
static void delayAfterWelcomeMessageShown(void) { unsigned int milliseconds = 0, lastInterval = 0; lastInterval = NOW_IN_TICKS; while (milliseconds < 5000) { if (TICKS_ELAPSED_SINCE(lastInterval) >= MILLISECONDS_TO_TICKS(100)) { milliseconds += 100; lastInterval = NOW_IN_TICKS; } eventUpdates(); } }
//***************************************************************************** // //! main function demonstrates the use of the watchdog timer to perform system //! reset. //! //! \param None //! //! \return None // //***************************************************************************** void main(void) { tBoolean bRetcode; // // Initialize the board // BoardInit(); // // Pinmuxing for LEDs // PinMuxConfig(); // // configure RED LED // GPIO_IF_LedConfigure(LED1); GPIO_IF_LedOff(MCU_RED_LED_GPIO); // // Enable the peripherals used by this example. // MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); // // Set up the watchdog interrupt handler. // WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS)); // // Start the timer. Once the timer is started, it cannot be disable. // MAP_WatchdogEnable(WDT_BASE); bRetcode = MAP_WatchdogRunning(WDT_BASE); if(!bRetcode) { WDT_IF_DeInit(); } // // Loop forever while the LED winks as watchdog interrupts are handled. // while(FOREVER) { } }
//***************************************************************************** // //! main function demonstrates the use of the watchdog timer to perform system //! reset. //! //! \param None //! //! \return None // //***************************************************************************** void main(void) { tBoolean bRetcode; // // Initialize the board // BoardInit(); // // Pinmuxing for LEDs // PinMuxConfig(); // // configure RED LED // GPIO_IF_LedConfigure(LED1); GPIO_IF_LedOff(MCU_RED_LED_GPIO); // // Set up the watchdog interrupt handler. // WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS)); bRetcode = MAP_WatchdogRunning(WDT_BASE); if(!bRetcode) { WDT_IF_DeInit(); } // // Loop forever while the LED winks as watchdog interrupts are handled. // while(FOREVER) { } }
//***************************************************************************** // //! \brief Connecting to a WLAN Accesspoint //! This function connects to the required AP (SSID_NAME). //! This code example assumes the AP doesn't use WIFI security. //! The function will return only once we are connected //! and have acquired IP address //! //! \param[in] None //! //! \return 0 means success, -1 means failure //! //! \note //! //! \warning If the WLAN connection fails or we don't aquire an IP address, //! We will be stuck in this function forever. // //***************************************************************************** int WlanConnect() { int iRetCode = 0; int iRetVal = 0; int iConnect = 0; unsigned char ucQueueMsg = 0; SlSecParams_t secParams; secParams.Key = (signed char *)SECURITY_KEY; secParams.KeyLen = strlen((const char *)secParams.Key); secParams.Type = SECURITY_TYPE; // // Set up the watchdog interrupt handler. // WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS)); /* Enabling the Sleep clock for the Watch Dog Timer*/ MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_SLP_MODE_CLK); g_ucFeedWatchdog = 1; g_ucWdogCount = 0; while(!(ucQueueMsg & (EVENT_IP_ACQUIRED|CONNECTION_FAILED))) { UART_PRINT("Trying to connect to AP: "); UART_PRINT(SSID_NAME); UART_PRINT("\n\r"); sl_WlanConnect((signed char *)SSID_NAME, strlen((const char *)SSID_NAME), 0, &secParams, 0); iConnect = 0; do{ osi_MsgQRead(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER); switch(ucQueueMsg) { case EVENT_CONNECTION: iConnect = 1; break; case EVENT_IP_ACQUIRED: iRetVal = 0; break; case WDOG_EXPIRED: // // disconnect from the Access Point // if(iConnect) { WlanDisconnect(); } // // stop the simplelink with reqd. timeout value (30 ms) // sl_Stop(SL_STOP_TIMEOUT); UART_PRINT("sl stop\n\r"); MAP_UtilsDelay(8000); // // starting the simplelink // sl_Start(NULL, NULL, NULL); UART_PRINT("sl start\n\r"); break; case EVENT_DISCONNECTION: iConnect = 0; break; case CONNECTION_FAILED: iRetVal = -1; break; default: UART_PRINT("unexpected event\n\r"); break; } }while(ucQueueMsg == (unsigned char)EVENT_CONNECTION); } iRetCode = MAP_WatchdogRunning(WDT_BASE); if(iRetCode) { WDT_IF_DeInit(); MAP_PRCMPeripheralClkDisable(PRCM_WDT, PRCM_RUN_MODE_CLK); } ASSERT_ON_ERROR(iRetVal); return(iRetVal); }
//**************************************************************************** // MAIN FUNCTION //**************************************************************************** void main() { long lRetVal = 0; char data[BUF_SIZE]; char sent_data[BUF_SIZE]; unsigned char highByte, lowByte; int i; unsigned long tempStartTimeStamp, tempStopTimeStamp; memset(sent_data, 0, 10); // Board Initialization BoardInit(); // Configure the pinmux settings for the peripherals exercised PinMuxConfig(); // Initialize the PWM outputs on the board InitServos(); // Initialize the sensor ADC InitSensorADC(); // Configuring UART InitTerm(); // Display banner DisplayBanner(APPLICATION_NAME); // Connect to WIFI using default info //WlanConnect(NULL, NULL, NULL); WlanConnect("Nagui's Network", "SL_SEC_TYPE_WPA", "19520605"); // Setup the TCP Server Socket BsdTcpServerSetup(PORT_NUM); // Recieve Data while (lRetVal >= 0) { lRetVal = BsdTcpServerReceive(data); //SysTickPeriodSet(800000000); // test //SysTickEnable(); // test Timer_IF_Init(PRCM_TIMERA0, TIMERA0_BASE, TIMER_CFG_PERIODIC, TIMER_A, 0); Timer_IF_Start(TIMERA0_BASE, TIMER_A, MILLISECONDS_TO_TICKS(2000)); //tempStartTimeStamp = SysTickValueGet(); // test tempStartTimeStamp = Timer_IF_GetCount(TIMERA0_BASE, TIMER_A); for (i = 0; i<NUM_SERVOS; i++) { MoveServo((unsigned char)data[i], (enum Servo_Joint_Type)i); UART_PRINT("%d", (unsigned int) data[i]); } for (i = 0; i< NUM_SENSORS; i++) { //UnsignedShort_to_UnsignedChar(GetSensorReading((enum Fingertip_Sensor_Type)i), &highByte, &lowByte); UnsignedShort_to_UnsignedChar(GetSensorReading(SENSOR_FINGER_INDEX), &highByte, &lowByte); sent_data[i*2] = (char)highByte; sent_data[i*2+1] = (char)lowByte; } //tempStopTimeStamp = SysTickValueGet(); // test tempStopTimeStamp = Timer_IF_GetCount(TIMERA0_BASE, TIMER_A); lRetVal = BsdTcpServerSend(sent_data, 10); UART_PRINT("timestamp start: %lu\n\r", tempStartTimeStamp); //test UART_PRINT("timestamp stop: %lu\n\r", tempStopTimeStamp); //test UART_PRINT("Sent 10 bytes to client.\n\r"); } UART_PRINT("Exiting Application ...\n\r"); // power of the Network processor lRetVal = sl_Stop(SL_STOP_TIMEOUT); }
//***************************************************************************** // //! starts the timer //! //! \param ulBase is the base address for the timer. //! \param ulTimer selects between the TIMER A and TIMER B. //! \param ulValue is timer reload value (mSec) after which the timer will run out and gives an interrupt. //! //! This function //! 1. Reload the Timer with the specified value. //! //! \return none // //***************************************************************************** void Timer_IF_ReLoad(unsigned long ulBase, unsigned long ulTimer, unsigned long ulValue) { MAP_TimerLoadSet(ulBase,ulTimer,MILLISECONDS_TO_TICKS(ulValue)); }