Exemplo n.º 1
0
/**
 * @brief Set subscription values.
 * @ingroup  QDebug-Remote
 * This function can be used directly in main to set data subscription
 * if 1way SPI interface is used
 * 
 * @param once 
 * @param change
 * @param always 
 */
void QDebug_SetSubscriptions(uint16_t once, uint16_t change, uint16_t allways)
{
   qgSubsOnce = once;
   qgSubsChange = change;
   qgSubsAllways = allways;

#ifdef _ENABLE_SLEEP_
   if(qgSubsAllways != 0x00)
   {   
   	   allow_to_sleep = 1;
   }
   else
   {
   	   allow_to_sleep = 0;
   }
#endif /* _ENABLE_SLEEP_ */  

   pal_ps_set(EE_QDEBUG_OFFSET, 2, &qgSubsOnce);
   pal_ps_set(EE_QDEBUG_OFFSET + 2, 2, &qgSubsChange);
   pal_ps_set(EE_QDEBUG_OFFSET + 4, 2, &qgSubsAllways);

#ifdef _ENABLE_SLEEP_   
   pal_ps_set(EE_QDEBUG_OFFSET + 6, 2, &allow_to_sleep);
#endif /* _ENABLE_SLEEP_ */
   
}
Exemplo n.º 2
0
/**
 * @brief Main function of the Terminal Target application
 * @ingroup App_API
 */
int main(void)
{
    /* Initialize all layers */
    if (nwk_init() != NWK_SUCCESS)
    {
        /* something went wrong during initialization */
        pal_alert();
    }
    /* disable pull-ups */
    MCUCR |= (1u << PUD);
    
#ifdef FLASH_NVRAM
    pal_ps_set(EE_IEEE_ADDR,IEEE_ADDRESS_BYTES, &tal_pib_IeeeAddress);
#endif
    
    /* Initialize LEDs. */
    pal_led_init();
    pal_led(LED_START, LED_ON);         /* indicating application is started */
    pal_led(LED_NWK_SETUP, LED_OFF);    /* indicating network is started */
    pal_led(LED_DATA, LED_OFF);         /* indicating data reception */

    /*
     * The stack is initialized above, hence the global interrupts are enabled
     * here.
     */
    
    pal_global_irq_enable();
 
    /**
    * @brief TWI and QT600 interface initialization
    */
    int i;
    twi_master_init();
    RESET_QT600_PIN_INIT();
    RESET_QT600_ON();
    for (i = 0; i < 100 ; i++)
        asm("nop");
    
    /* Endless while loop */
    while (1)
    {
        app_task(); /* Application task */
        if(rf4ce_new_msg == 1)
        {
          twi_send_message();
          TX_index = 0;
          rf4ce_new_msg = 0;
        }
 
        nwk_task(); /* RF4CE network layer task */
    }
}
Exemplo n.º 3
0
/**
 * Main function, initialization and main message loop
 *
 * @return error code
 */
int main(void)
{
	irq_initialize_vectors();
	#if SAMD21 || SAMD20 || SAMR21
	system_init();
	delay_init();
#else
	sysclk_init();

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
#endif	

	sw_timer_init();

	if (nwk_init() != NWK_SUCCESS) {
		app_alert();
	}

	stack_indication_callback_init();

#ifdef FLASH_NVRAM
	pal_ps_set(EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress);
#endif
	/* Initialize LEDs */
	/* pal_led_init(); */
	cpu_irq_enable();

	/*
	 * The global interrupt has to be enabled here as TAL uses the timer
	 * delay which in turn requires interrupt to be enabled
	 */
	/* pal_global_irq_enable(); */

	serial_interface_init();

	/* Loop forever, the interrupts are doing the rest */
	while (1) {
		nwk_task();
		serial_data_handler();
	}
	/* No return statement here, because this code is unreachable */
}
Exemplo n.º 4
0
/*
 * \brief Initializes the TAL
 *
 * This function is called to initialize the TAL. The transceiver is
 * initialized, the TAL PIBs are set to their default values, and the TAL state
 * machine is set to TAL_IDLE state.
 *
 * \return MAC_SUCCESS  if the transceiver state is changed to TRX_OFF and the
 *                 current device part number and version number are correct;
 *         FAILURE otherwise
 */
retval_t tal_init(void)
{
	/* Init the PAL and by this means also the transceiver interface */
	if (pal_init() != MAC_SUCCESS) {
		return FAILURE;
	}

	if (trx_init() != MAC_SUCCESS) {
		return FAILURE;
	}

	if (tal_timer_init() != MAC_SUCCESS) {
		return FAILURE;
	}

#ifdef ENABLE_STACK_NVM
	pal_ps_get(INTERN_EEPROM, EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress);
#endif

	/*
	 * Do the reset stuff.
	 * Set the default PIBs.
	 * Generate random seed.
	 */
	if (internal_tal_reset(true) != MAC_SUCCESS) {
		return FAILURE;
	}

#ifndef DISABLE_IEEE_ADDR_CHECK
	/* Check if a valid IEEE address is available. */

	/*
	 * This while loop is on purpose, since just in the
	 * rare case that such an address is randomly
	 * generated again, we must repeat this.
	 */
	uint64_t invalid_ieee_address;
	memset((uint8_t *)&invalid_ieee_address, 0xFF,
			sizeof(invalid_ieee_address));
	while ((tal_pib.IeeeAddress == 0x0000000000000000) ||
			(tal_pib.IeeeAddress == invalid_ieee_address)) {
		/*
		 * In case no valid IEEE address is available, a random
		 * IEEE address will be generated to be able to run the
		 * applications for demonstration purposes.
		 * In production code this can be omitted.
		 */

		/*
		 * The proper seed for function rand() has already been
		 * generated
		 * in function tal_generate_rand_seed().
		 */
		uint8_t *ptr_pib = (uint8_t *)&tal_pib.IeeeAddress;

		for (uint8_t i = 0; i < 8; i++) {
			*ptr_pib++ = (uint8_t)rand();

			/*
			 * Note:
			 * Even if casting the 16 bit rand value back to 8 bit,
			 * and running the loop 8 timers (instead of only 4
			 * times)
			 * may look cumbersome, it turns out that the code gets
			 * smaller using 8-bit here.
			 * And timing is not an issue at this place...
			 */
		}
	}
#endif  /* #ifndef DISABLE_IEEE_ADDR_CHECK */
#ifdef ENABLE_STACK_NVM
	pal_ps_set(EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress);
#endif

	/*
	 * Configure interrupt handling.
	 * Install a handler for the main transceiver interrupt.
	 */
	trx_irq_init((FUNC_PTR)trx_irq_handler_cb);
	pal_trx_irq_en(); /* Enable main transceiver interrupt. */

#if ((defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP)) && \
	(DISABLE_TSTAMP_IRQ == 0)

	/* Configure time stamp interrupt.
	 * The timestamping is only required for
	 * - beaconing networks or if timestamping is explicitly enabled,
	 * - and if the time stamp interrupt is not explicitly disabled.
	 */
	pal_trx_irq_init_tstamp((FUNC_PTR)trx_irq_timestamp_handler_cb);
	pal_trx_irq_en_tstamp(); /* Enable timestamp interrupt. */
#endif

	/* Initialize the buffer management module and get a buffer to store
	 * reveived frames. */
	bmm_buffer_init();
	tal_rx_buffer = bmm_buffer_alloc(LARGE_BUFFER_SIZE);

	/* Init incoming frame queue */
#ifdef ENABLE_QUEUE_CAPACITY
	qmm_queue_init(&tal_incoming_frame_queue,
			TAL_INCOMING_FRAME_QUEUE_CAPACITY);
#else
	qmm_queue_init(&tal_incoming_frame_queue);
#endif  /* ENABLE_QUEUE_CAPACITY */

#ifdef ENABLE_TFA
	tfa_init();
#endif

	return MAC_SUCCESS;
} /* tal_init() */