Example #1
0
void ledFlash() {
	uint8_t i;
	for (i = 0; i < 4; i++) {
        ledToggle(0);
        ledToggle(1);
        ledToggle(2);
        if (i != 3) {
            _delay_ms(333);
        }
    }
}
//---------------------------------------------------------------------------
// main()
//---------------------------------------------------------------------------
void main(void)
{

   char i=1,l=2;
   hardware_init();							// init hardware via Xware

   while(1)									// forever loop
   {
	   if((GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4)==0))
	   {
		   if(i<4)
			   i=i<<1;
		   else
			   i=1;
	   }
	   while((GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4)==0));

	   if((GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0))
	   	   {
	   		   if(l<8)
	   			   l=l<<1;
	   		   else
	   			   l=2;
	   	   }
	   while((GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0));


	   ledToggle(l);
	   delay(i);

	}

}
Example #3
0
static void appTaskConnect(void *pdata) {
  
  while (true) {
    OSTimeDlyHMSM(0,0,0,500);
    ledToggle(USB_CONNECT_LED);
  } 
}
Example #4
0
void mainTimerTick()
{
	if (s_started)
	{
		if (s_timerCounter++ >= 244)
		{
			s_timerCounter = 0;
			ledToggle();
		}

		if (buttonIsPressed())
		{
			if (!s_buttonLock)
			{
				s_buttonPressed = 1;
				s_buttonLock = 1;
			}
		}
		else
		{
			s_buttonPressed = 0;
			s_buttonLock = 0;
		}
	}
}
Example #5
0
/*
 ===========================================================================================================================================================================
																																			
													ERROR FUNCTION(That function is executed when error occurs)

  ===========================================================================================================================================================================
*/ 
void error_function(void){

		while(1){
			ledToggle();	
			HAL_Delay(100);
		}
}
Example #6
0
/*
 * appTaskEmergencyStop - Emergency stop task
 * This task handles the emergency stop and stop tasks in
 * the robot 2 subsystem.
 */
static void appTaskEmergencyStop(void *pdata)
{
    /* Start the OS ticker
    * (must be done in the highest priority task)
    */
    osStartTick();
    canRxInterrupt(canHandler);
    while(true)
    {
        if(emergencyStop)
        {
            ledToggle(USB_LINK_LED);
        } else if (stopped) {
            ledToggle(USB_CONNECT_LED);
        } else {
            OSTimeDlyHMSM(0,0,0,500);
        }
    }
}
Example #7
0
static bool appDataInd(NWK_DataInd_t *ind)
{
  AppMessage_t *msg = (AppMessage_t *)ind->data;

  ledToggle(LED_DATA);

  msg->lqi = ind->lqi;
  msg->rssi = ind->rssi;

  appSendMessage(ind->data, ind->size);
  return true;
}
Example #8
0
static void appTaskLink(void *pdata) {
  /* Start the OS ticker 
   * Must be done in the highest priority task
   */
  osStartTick();
  
  /* Task main loop */
  while (true) {
    ledToggle(USB_LINK_LED);
    OSTimeDlyHMSM(0,0,0,500);
  }
}
Example #9
0
/* Emergency Stop Task
 * This task handles the pause, stop and emergency stop functions
 * in the system.
 */
static void appTaskEmergencyStop(void *pdata)
{
   // Start the OS ticker
  osStartTick();
  canRxInterrupt(canHandler);
  while(true)
  {
    if(emergencyStop)
    {
      ledToggle(USB_LINK_LED);
      conveyorSetState(CONVEYOR_OFF);
    } else if(paused){ 
      pausedState = conveyorGetState();
      conveyorSetState(CONVEYOR_OFF);
    } else if (stopped){
      ledToggle(USB_CONNECT_LED);
    }
    else{
      OSTimeDlyHMSM(0,0,0,500);
    }
  }
}
Example #10
0
void appMain(void)
{
    uint16_t i;
    for (i = 0; ; i++) {
        i %= 64;
        PRINTF("calibrate potentiometer to %u\n", i);
        if (!ad5258Write(i)) {
            PRINTF("write failed!\n");
        }
        mdelay(PERIOD);
        PRINTF("read adc: %u\n", adcRead(0));
        ledToggle();
    }
}
Example #11
0
File: main.c Project: IECS/MansOS
//-------------------------------------------
//      Entry point for the application
//-------------------------------------------
void appMain(void)
{
    // Set packet reception handler (callback function)
    serialSetPacketReceiveHandle(PRINTF_SERIAL_ID, serialPacketReceived, buf, BUF_SIZE);
    ledOff();

    // Send Ping every second
    static uint_t counter = 1;
    while (1) {
        PRINTF("Ping #%i\n", counter++);
        ledToggle();
        mdelay(1000);
    }
}
Example #12
0
//------------------------------------------------------------------------------
int main(void)
{
    ledConfig(LED_GREEN);
    
    SysTick_Config(BOARD_MCK / 1000);
    
    ledOn(LED_GREEN);
    while(1)
    {
        Wait(500);
        ledToggle(LED_GREEN);
    }

	return 0;
}
Example #13
0
__interrupt void timerA0ISR( void )
{
	timerCount = ( timerCount + 1 ) % 16;
	if ( timerCount == 0 ) {
		if( getFreeMessage( &mainMessage ) == queue_ok ){
			mainMessage->source = main_user;
			mainMessage->destination = led_user;
			mainMessage->id = MSG_ID_LED_GREEN;
			mainMessage->event = toggle_event;
			putMessage( mainMessage );
		} else {
			ledToggle( MSG_ID_LED_RED );
		}

	}
	scheduler();
}
Example #14
0
/**
 * Application entry point.
 */
int simpleTx(void)
{
    /* Reset and initialise DW1000.
     * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
     * performance. */
    reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */
    //spi_set_rate_low();
    dwt_initialise(DWT_LOADNONE);
    //spi_set_rate_high();

    /* Configure DW1000. See NOTE 2 below. */
    dwt_configure(&config);

    /* Loop forever sending frames periodically. */
    while(1)
    {
        /* Write frame data to DW1000 and prepare transmission. See NOTE 3 below.*/
        dwt_writetxdata(sizeof(tx_msg), tx_msg, 0);
        dwt_writetxfctrl(sizeof(tx_msg), 0);

        /* Start transmission. */
        dwt_starttx(DWT_START_TX_IMMEDIATE);

        /* Poll DW1000 until TX frame sent event set. See NOTE 4 below.
         * STATUS register is 5 bytes long but, as the event we are looking at is in the first byte of the register, we can use this simplest API
         * function to access it.*/
        while (!(status_reg = dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
        { };
        printf("Status reg now 0x%x\r\n",status_reg);

        /* Clear TX frame sent event. */
        dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);

        /* Execute a delay between transmissions. */
        deca_sleep(TX_DELAY_MS);

        // toggle led
		ledToggle();

        /* Increment the blink frame sequence number (modulo 256). */
        tx_msg[BLINK_FRAME_SN_IDX]++;
    }
}
static void testMode() {
   // In case disabled by boot-loader
   __enable_irq();

   initPorts();
   initTimers();
   bdm_interfaceOff();
   initUSB();
   ledEnable();
   testEnable();
   bootInputEnable();
   for(;;) {
      WAIT_MS(100);
      ledToggle();
      testToggle();
      if (bootInputActive() == 0) {
         reboot();
      }
   }
}
Example #16
0
void appMain(void)
{
    // initialize the alarm
    alarmInit(&alarm, alarmCallback, NULL);
    // schedule the alarm after specific interval
    alarmSchedule(&alarm, ALARM_INTERVAL);

    for (;;) {
        ledToggle();

        // lock the mutex in user context
        uint32_t start, end;
        start = getJiffies();
        mutexLock(&testMutex);
        end = getJiffies();
        PRINTF("in user main, mutex lock time=%lu\n", end - start);
        mdelay(1000);
        mutexUnlock(&testMutex);
    }
}
Example #17
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    uint32_t currentTime;

    /*!< At this stage the microcontroller clock setting is already configured,
         this is done through SystemInit() function which is called from startup
         file (startup_stm32f3xx.s) before to branch to application main.
         To reconfigure the default setting of SystemInit() function, refer to
          system_stm32f4xx.c file
    */

    systemReady = false;

    systemInit();

    systemReady = true;

    //evrPush(EVR_StartingMain, 0);

    /* Setup SysTick Timer for 1 msec interrupts.
       ------------------------------------------
      1. The SysTick_Config() function is a CMSIS function which configure:
         - The SysTick Reload register with value passed as function parameter.
         - Configure the SysTick IRQ priority to the lowest value (0x0F).
         - Reset the SysTick Counter register.
         - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
         - Enable the SysTick Interrupt.
         - Start the SysTick Counter.

      2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
         SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
         SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
         inside the misc.c file.

      3. You can change the SysTick IRQ priority by calling the
         NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
         call. The NVIC_SetPriority() is defined inside the core_cm4.h file.

      4. To adjust the SysTick time base, use the following formula:

           Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)

         - Reload Value is the parameter to be passed for SysTick_Config() function
         - Reload Value should not exceed 0xFFFFFF
     */

#if 1
    if (APRS_SLOT >= 0)
    {
        do
        {
/*
            while (!uartAvailable())
                sleep();
*/
        } while (!gpsDecode((char)uartRead()));

        next_aprs = millis() + 1000 * (APRS_PERIOD - (gps_seconds + APRS_PERIOD - APRS_SLOT) % APRS_PERIOD);
    }
    else
    {
        next_aprs = millis();
    }
#endif

    while (1)
    {
        //evrCheck();

        // Wait for sampling clock to overflow
        if (TIM_GetFlagStatus(TIM2, TIM_FLAG_Update) != RESET)
        {
            ;
        }

#if 1
        if ((int32_t)(millis() - next_aprs) >= 0)
        {
            getPos();
            aprsSend();
            next_aprs += APRS_PERIOD * 1000L;

            while(afskBusy())
                ;

            //sleep();
#if DEBUG_MODEM
            afskDebug();
#endif
        }

        //sleep();
#else

        ///////////////////////////////

        if (frame_500Hz)
        {
            frame_500Hz = false;

            currentTime       = micros();
            deltaTime500Hz    = currentTime - previous500HzTime;
            previous500HzTime = currentTime;

            executionTime500Hz = micros() - currentTime;
        }

        ///////////////////////////////

        if (frame_100Hz)
        {
            frame_100Hz = false;

            currentTime       = micros();
            deltaTime100Hz    = currentTime - previous100HzTime;
            previous100HzTime = currentTime;

            executionTime100Hz = micros() - currentTime;
        }

        ///////////////////////////////

        if (frame_50Hz)
        {
            frame_50Hz = false;

            currentTime      = micros();
            deltaTime50Hz    = currentTime - previous50HzTime;
            previous50HzTime = currentTime;

#if 1
            while (uartAvailable())
            {
                gpsDecode((char)uartRead());
            }
#endif

            executionTime50Hz = micros() - currentTime;
        }

        ///////////////////////////////

        if (frame_10Hz)
        {
            frame_10Hz = false;

            currentTime      = micros();
            deltaTime10Hz    = currentTime - previous10HzTime;
            previous10HzTime = currentTime;

            cliCom();

            executionTime10Hz = micros() - currentTime;
        }

        ///////////////////////////////

        if (frame_5Hz)
        {
            frame_5Hz = false;

            currentTime     = micros();
            deltaTime5Hz    = currentTime - previous5HzTime;
            previous5HzTime = currentTime;

            executionTime5Hz = micros() - currentTime;
        }

        ///////////////////////////////

        if (frame_1Hz)
        {
            frame_1Hz = false;

            currentTime     = micros();
            deltaTime1Hz    = currentTime - previous1HzTime;
            previous1HzTime = currentTime;

            if (execUp == true) {
                ledToggle(LED0);
#ifdef DEBUG_MODEM
                afskDebug();
#endif
            }

            if (execUp == false)
                execUpCount++;

            if ((execUpCount == 5) && (execUp == false))
            {
                execUp = true;
                ledOFF(LED0);
            }

            executionTime1Hz = micros() - currentTime;
        }
#endif
    }
}
Example #18
0
//-------------------------------------------
//      Entry point for the application
//-------------------------------------------
void appMain(void)
{
#if 0 // no effect
    UCTL0 = SWRST;
    ME1 &= ~(URXE0 | UTXE0 | USPIE0);
    UCTL0 &= ~SWRST;

    UCTL1 = SWRST;
    ME2 &= ~(URXE1 | UTXE1 | USPIE1);
    UCTL1 &= ~SWRST;
#endif

#if 1
    ADC12IE = 0;
    ADC12IFG = 0;
    ADC12CTL0 &= ~ENC;
    ADC12CTL0 &= ~REFON;
    ADC12CTL0 &= ~ADC12ON;

    DMA0CTL = 0;
    DMA1CTL = 0;
#endif

#if 0
    pinAsData(1, 0);
    pinAsData(1, 1);
    pinAsData(1, 2);
    pinAsData(1, 3);
    pinAsData(1, 4);
    pinAsData(1, 5);
    pinAsData(1, 6);
    pinAsData(1, 7); // radio data indicate

    pinAsData(2, 0); // ADS interrupts (unused)
    pinAsData(2, 1);
    pinAsData(2, 2);
    pinAsData(2, 3); // SHT SDA + I2C soft SDA
    pinAsData(2, 4); // SHT SCL + I2C soft SCL
    pinAsData(2, 5); // sensors enable
    pinAsData(2, 6);
    pinAsData(2, 7); // uart0 rx

    pinAsData(3, 0); // SD card CS
    pinAsData(3, 1);
    pinAsData(3, 2);
    pinAsData(3, 3);
    pinAsData(3, 4); // uart0 hw tx
    pinAsData(3, 5); // uart0 hw rx
    pinAsData(3, 6); // uart1 hw tx
    pinAsData(3, 7); // uart1 hw tx

    pinAsData(4, 0); // radio data request
    pinAsData(4, 1); // radio rts
    pinAsData(4, 2); // radio config
    pinAsData(4, 3); // radio trx disable
    pinAsData(4, 4); // radio reset
    pinAsData(4, 5); // radio sleep
    // pinAsData(4, 6); // uart0 tx
    // pinAsData(4, 7);

    pinAsData(5, 0);
    pinAsData(5, 1);
    pinAsData(5, 2);
    pinAsData(5, 3);
    pinAsData(5, 4); // red LED
    pinAsData(5, 5); // green LED
    pinAsData(5, 6); // blue LED
    pinAsData(5, 7);

    pinAsData(6, 0);
    pinAsData(6, 1);
    pinAsData(6, 2);
    pinAsData(6, 3);
    pinAsData(6, 4);
    pinAsData(6, 5);
    pinAsData(6, 6);
    pinAsData(6, 7);
#endif

    pinAsInput(1, 0);
    pinAsInput(1, 1);
    pinAsInput(1, 2);
    pinAsInput(1, 3);
    pinAsInput(1, 4);
    pinAsInput(1, 5);
    pinAsInput(1, 6);
    pinAsInput(1, 7); // radio data indicate

    pinAsInput(2, 0); // ADS interrupts (unused)
    pinAsInput(2, 1);
    pinAsInput(2, 2);
    pinAsInput(2, 3); // SHT SDA + I2C soft SDA
//    pinAsInput(2, 4); // SHT SCL + I2C soft SCL
//    pinAsInput(2, 5); // sensors enable
    pinAsInput(2, 6);
    pinAsInput(2, 7); // uart0 rx

    pinAsInput(3, 0); // SD card CS
    pinAsInput(3, 1);
    pinAsInput(3, 2);
    pinAsInput(3, 3);
    pinAsInput(3, 4); // uart0 hw tx
    pinAsInput(3, 5); // uart0 hw rx
    pinAsInput(3, 6); // uart1 hw tx
    pinAsInput(3, 7); // uart1 hw tx

    pinAsInput(4, 0); // radio data request
    pinAsInput(4, 1); // radio rts
    pinAsInput(4, 2); // radio config
    // pinAsInput(4, 3); // radio trx disable
    pinAsInput(4, 4); // radio reset
    // pinAsInput(4, 5); // radio sleep
    pinAsInput(4, 6); // uart0 tx
    pinAsInput(4, 7);

    pinAsInput(5, 0);
    pinAsInput(5, 1);
    pinAsInput(5, 2);
    pinAsInput(5, 3);
//    pinAsInput(5, 4); // red LED
    pinAsInput(5, 5); // green LED
    pinAsInput(5, 6); // blue LED
    pinAsInput(5, 7);

    pinAsInput(6, 0);
    pinAsInput(6, 1);
    pinAsInput(6, 2);
    pinAsInput(6, 3);
    pinAsInput(6, 4);
    pinAsInput(6, 5);
    pinAsInput(6, 6);
    pinAsInput(6, 7);


    // --  required for better efficiency 
    // make sure I2C clock is high
    I2C_SCL_HI();
    // make sure sensors are disabled
    pinClear(SM3_SENSORS_ENABLE_PORT, SM3_SENSORS_ENABLE_PIN);
    // --


    while (1) {
        msleep(PAUSE); // sleep PAUSE seconds
        // PRINTF("%lu: hello world\n", (uint32_t) getJiffies());
        ledToggle();
    }
}
Example #19
0
// ------------------- flashes LED
void HIDbase::ledFlash( uint8_t nLED ) {
  ledToggle( nLED );
  delay( 5 );
  ledToggle( nLED );
}
Example #20
0
void toggle_led1() {ledToggle(1);}
Example #21
0
void toggle_led2() {ledToggle(2);}
Example #22
0
void HAL_UartBytesReceived(uint16_t bytes)
{
  for (uint16_t i = 0; i < bytes; i++)
    HAL_UartReadByte();
  ledToggle(2);
}
Example #23
0
/*! ------------------------------------------------------------------------------------------------------------------
 * @fn main()
 *
 * @brief Application entry point.
 *
 * @param  none
 *
 * @return none
 */
int ssTwrInit(void)
{

    /* Reset and initialise DW1000.
     * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
     * performance. */
	int status;

	reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */
    //spi_set_rate_low();
    status = dwt_initialise(DWT_LOADUCODE);
    if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);
    //spi_set_rate_high();

    /* Configure DW1000. See NOTE 6 below. */
    status = dwt_configure(&config);
    if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);

    // read otp
    uint32_t otpVal[0x20];
    dwt_otpread(0,otpVal,0x20);
    printf("OTP   6: 0x%x\r\n",otpVal[6]);
    printf("OTP   7: 0x%x\r\n",otpVal[7]);
    printf("OTP x16: 0x%x\r\n",otpVal[0x16]);
    printf("OTP x17: 0x%x\r\n",otpVal[0x17]);

    /* Apply default antenna delay value. See NOTE 2 below. */
    printf("antenna delays: default TX: %d, default RX: %d, evk 16m: %d, evk 64m: %d\r\n",TX_ANT_DLY,RX_ANT_DLY,DWT_RF_DELAY_16M,DWT_RF_DELAY_64M);
    tx_delay = TX_ANT_DLY;
    rx_delay = RX_ANT_DLY;
    dwt_setrxantennadelay(rx_delay);
    dwt_settxantennadelay(tx_delay);

    /* Set expected response's delay and timeout. See NOTE 1 and 5 below.
     * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */
    dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);
    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);

    btn = buttons();

    printf("%s entering main loop\r\n",__FUNCTION__);

    /* Loop forever initiating ranging exchanges. */
    while (1)
    {
        /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
        tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
        status = dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);
        status = dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);
        status = dwt_writetxfctrl(sizeof(tx_poll_msg), 0);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);

        /* Start transmission, indicating that a response is expected so that reception is enabled automatically after the frame is sent and the delay
         * set by dwt_setrxaftertxdelay() has elapsed. */
        status = dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);
        if (DWT_SUCCESS != status) printf("API error line %d\r\n",__LINE__);

        /* We assume that the transmission is achieved correctly, poll for reception of a frame or error/timeout. See NOTE 8 below. */
        while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))
        { } ; // printf("Waiting. status reg 0x%x\r\n",status_reg); };
        //printf("Status reg now 0x%x\r\n",status_reg);

        if (SYS_STATUS_RXRFTO & status_reg)
            printf("RX timeout\r\n");

        /* Increment frame sequence number after transmission of the poll message (modulo 256). */
        frame_seq_nb++;

        if (status_reg & SYS_STATUS_RXFCG)
        {
            uint32 frame_len;

            //printf("Check RX\r\n");
            /* Clear good RX frame event in the DW1000 status register. */
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);

            /* A frame has been received, read it into the local buffer. */
            frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK;
            if (frame_len <= RX_BUF_LEN)
            {
                dwt_readrxdata(rx_buffer, frame_len, 0);
            }

            /* Check that the frame is the expected response from the companion "SS TWR responder" example.
             * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
            rx_buffer[ALL_MSG_SN_IDX] = 0;
            if (memcmp(rx_buffer, rx_resp_msg, ALL_MSG_COMMON_LEN) == 0)
            {
                uint32 poll_tx_ts, resp_rx_ts, poll_rx_ts, resp_tx_ts;
                int32 rtd_init, rtd_resp;

                /* Retrieve poll transmission and response reception timestamps. See NOTE 9 below. */
                poll_tx_ts = dwt_readtxtimestamplo32();
                resp_rx_ts = dwt_readrxtimestamplo32();

                /* Get timestamps embedded in response message. */
                resp_msg_get_ts(&rx_buffer[RESP_MSG_POLL_RX_TS_IDX], &poll_rx_ts);
                resp_msg_get_ts(&rx_buffer[RESP_MSG_RESP_TX_TS_IDX], &resp_tx_ts);

                /* Compute time of flight and distance. */
                rtd_init = resp_rx_ts - poll_tx_ts;
                rtd_resp = resp_tx_ts - poll_rx_ts;

                tof = ((rtd_init - rtd_resp) / 2.0) * DWT_TIME_UNITS;
                distance = tof * SPEED_OF_LIGHT;

                /* Display computed distance on LCD. */
                //sprintf(dist_str, "DIST: %3.2f m", distance);
                sprintf(dist_str, "%3.2f", distance);
                printf("%s\r\n",dist_str);
                //lcd_display_str(dist_str);

            }
        }
        else
        {
            /* Clear RX error events in the DW1000 status register. */
            printf("Errors occured. Clearing up\r\n");
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
        }

        /* Execute a delay between ranging exchanges. */
        //printf("Delay %dms\r\n",RNG_DELAY_MS);
        deca_sleep(RNG_DELAY_MS);

        // toggle led
		ledToggle();
		// update antenna
		if (buttons() & 1) {
		    tx_delay -= 10; // >>= 1;
		    rx_delay -= 10; //>>= 1;
		    dwt_setrxantennadelay(rx_delay);
		    dwt_settxantennadelay(tx_delay);
		    printf("Decreased antenna delay to 0x%x\r\n",tx_delay);
		}
		if (buttons() & 2) {
			tx_delay += 10;
			rx_delay += 10;
		    dwt_setrxantennadelay(rx_delay);
		    dwt_settxantennadelay(tx_delay);
		    printf("Increased antenna delay to 0x%x\r\n",tx_delay);
		}

    }
}
// led timer expire kicks in about ~100ms and perform the led operation according to the ledState and
// restart the timer according to ledState
static void ledTimerExpire(void)
{
    int i;
    PLED_CTRL pCurLed;
    unsigned long flags;

    BCM_ASSERT_NOT_HAS_SPINLOCK_V(&brcm_ledlock);

    for (i = 0, pCurLed = gLedCtrl; i < kLedEnd; i++, pCurLed++)
    {
#if defined(DEBUG_LED)
        printk("led[%d]: Mask=0x%04x, State = %d, blcd=%d\n", i, pCurLed->ledGreenGpio, pCurLed->ledState, pCurLed->blinkCountDown);
#endif
        spin_lock_irqsave(&brcm_ledlock, flags);        // LEDs can be changed from ISR
        switch (pCurLed->ledState)
        {
        case kLedStateOn:
        case kLedStateOff:
        case kLedStateFail:
            pCurLed->blinkCountDown = 0;            // reset the blink count down
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;

        case kLedStateSlowBlinkContinues:
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = kSlowBlinkCount;
                ledToggle(pCurLed);
            }
            gTimerOnRequests++;
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;

        case kLedStateFastBlinkContinues:
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = kFastBlinkCount;
                ledToggle(pCurLed);
            }
            gTimerOnRequests++;
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;

        case kLedStateUserWpsInProgress:          /* 200ms on, 100ms off */
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = (((gLedRunningCounter++)&1)? kFastBlinkCount: kSlowBlinkCount);
                ledToggle(pCurLed);
            }
            gTimerOnRequests++;
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;             

        case kLedStateUserWpsError:               /* 100ms on, 100ms off */
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = kFastBlinkCount;
                ledToggle(pCurLed);
            }
            gTimerOnRequests++;
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;        

        case kLedStateUserWpsSessionOverLap:      /* 100ms on, 100ms off, 5 times, off for 500ms */        
            if (pCurLed->blinkCountDown-- == 0)
            {
                if(((++gLedRunningCounter)%10) == 0) {
                    pCurLed->blinkCountDown = 4;
                    setLed(pCurLed, kLedOff, kLedGreen);
                    pCurLed->ledState = kLedStateUserWpsSessionOverLap;
                }
                else
                {
                    pCurLed->blinkCountDown = kFastBlinkCount;
                    ledToggle(pCurLed);
                }
            }
            gTimerOnRequests++;
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;        

        default:
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            printk("Invalid state = %d\n", pCurLed->ledState);
        }
    }

    // Restart the timer if any of our previous LED operations required
    // us to restart the timer, or if any other threads requested a timer
    // restart.  Note that throughout this function, gTimerOn == TRUE, so
    // any other thread which want to restart the timer would only
    // increment the gTimerOnRequests and not call ledTimerStart.
    spin_lock_irqsave(&brcm_ledlock, flags);
    if (gTimerOnRequests > 0)
    {
        ledTimerStart();
        gTimerOnRequests = 0;
    }
    else
    {
        gTimerOn = FALSE;
    }
    spin_unlock_irqrestore(&brcm_ledlock, flags);
}
Example #25
0
int main(void)
{
	int ch;
	int8_t res;
	
	systemInit();
	gpioInit();
	
	uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
		
	uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n");
	uart1Puts("efsl LPC2000-port and this Demo-Application\r\n");
	uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n");
	
	/* init efsl debug-output */
	lpc2000_debug_devopen(uart1Putch);
		
	ledToggle();
	
	rprintf("CARD init...");
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		rprintf("failed with %i\n",res);
	}
	else {
		rprintf("ok\n");
		rprintf("Directory of 'root':\n");
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			rprintf( "%s ( %li bytes )\n" ,
				list.currentEntry.FileName,
				list.currentEntry.FileSize ) ;
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) {
			rprintf("File %s open for append. Appending...", LogFileName);
			strcpy((char*)buf, "Martin hat's angehaengt\r\n");
			if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) {
				rprintf("ok\n");
			}
			else {
				rprintf("fail\n");
			}
			file_fclose( &filew );
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		fs_umount( &efs.myFs ) ;
	}
	
	while(1) {
		if ((ch = uart1Getch()) >= 0) {
			uart1Puts("You pressed : ");
			uart1Putch(ch);
			uart1Puts("\r\n");
			if ( ch == 'M' ) {
				rprintf("Creating FS\n");
				mkfs_makevfat(&efs.myPart);
			}
			ledToggle();
		}
	}
	
	return 0; /* never reached */
}
Example #26
0
static void appNetworkStatusTimerHandler(SYS_Timer_t *timer)
{
  ledToggle(LED_NETWORK);
  (void)timer;
}
Example #27
0
// led timer expire kicks in about ~100ms and perform the led operation according to the ledState and
// restart the timer according to ledState
static void ledTimerExpire(void)
{
    int i;
    PLED_CTRL pCurLed;
    unsigned long flags;

    gTimerOn = FALSE;

    for (i = 0, pCurLed = gLedCtrl; i < kLedEnd; i++, pCurLed++)
    {
#if defined(DEBUG_LED)
        printk("led[%d]: Mask=0x%04x, State = %d, blcd=%d\n", i, pCurLed->ledGreenGpio, pCurLed->ledState, pCurLed->blinkCountDown);
#endif
        spin_lock_irqsave(&brcm_ledlock, flags);        // LEDs can be changed from ISR
        switch (pCurLed->ledState)
        {
        case kLedStateOn:
        case kLedStateOff:
        case kLedStateFail:
            pCurLed->blinkCountDown = 0;            // reset the blink count down
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            break;

        case kLedStateSlowBlinkContinues:
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = kSlowBlinkCount;
                ledToggle(pCurLed);
            }
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            ledTimerStart();
            break;

        case kLedStateFastBlinkContinues:
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = kFastBlinkCount;
                ledToggle(pCurLed);
            }
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            ledTimerStart();
            break;

        case kLedStateUserWpsInProgress:          /* 200ms on, 100ms off */
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = (((gLedRunningCounter++)&1)? kFastBlinkCount: kSlowBlinkCount);
                ledToggle(pCurLed);
            }
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            ledTimerStart(); 
            break;             

        case kLedStateUserWpsError:               /* 100ms on, 100ms off */
            if (pCurLed->blinkCountDown-- == 0)
            {
                pCurLed->blinkCountDown = kFastBlinkCount;
                ledToggle(pCurLed);
            }
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            ledTimerStart();
            break;        

        case kLedStateUserWpsSessionOverLap:      /* 100ms on, 100ms off, 5 times, off for 500ms */        
            if (pCurLed->blinkCountDown-- == 0)
            {
                if(((++gLedRunningCounter)%10) == 0) {
                    pCurLed->blinkCountDown = 4;
                    setLed(pCurLed, kLedOff, kLedGreen);
                    pCurLed->ledState = kLedStateUserWpsSessionOverLap;
                }
                else
                {
                    pCurLed->blinkCountDown = kFastBlinkCount;
                    ledToggle(pCurLed);
                }
            }
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            ledTimerStart();                 
            break;        

        default:
            spin_unlock_irqrestore(&brcm_ledlock, flags);
            printk("Invalid state = %d\n", pCurLed->ledState);
        }
    }
}