예제 #1
0
void init_state_init(void *arg)
{
	sw_timer_init();

	/* Set the node information base */
	config_node_ib();

	/* Initialize the TAL layer */
	if (tal_init() != MAC_SUCCESS) {
		/* something went wrong during initialization */
		app_alert();
	}

	app_timers_init();

	/* Initilaize sio rx state */
	init_sio();

	/* select the configurtion mode */
	configuration_mode_selection();

#if (TAL_TYPE == AT86RF233) && (ANTENNA_DIVERSITY == 1)
	/* In order to demonstrate RPC the antenna diversity is disabled. */
	tal_ant_div_config(ANT_DIVERSITY_DISABLE, ANT_CTRL_1); /* Enable A1/X2 */
#endif

	/* Keep compiler happy */
	arg = arg;
}
예제 #2
0
/*! \brief Main function.
 */
int main(void)
{
	irq_initialize_vectors();
#if SAMD20
	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();
	serial_interface_init();

	if (MAC_SUCCESS != wpan_init()) {
		app_alert();
	}

	LED_On(LED_POWER);
	cpu_irq_enable();
	

	while (1) {
		wpan_task();
		serial_data_handler();
	}
}
예제 #3
0
 /**
 * @brief zid_set_attribute_confirm ZID Set attribute confirm callback allows to 
 *        check whether attributes are sent to the ZID Adaptor.
 *
 * @param Status  status from the network layer corresponds to the zid_set_attribute_request
 * @param PairingRef current pairing ref
 * @param ZIDAttribute attribute name
 * @param ZIDAttributeIndex attribute index
 */
static void zid_set_attribute_confirm(nwk_enum_t status,uint8_t PairingRef, zid_attribute_t ZIDAttribute, uint8_t ZIDAttributeIndex)
{
   if(status == NWK_SUCCESS)
   {
       if(ZIDAttribute == aplHIDStdDescCompsList)
       {
          if(ZIDAttributeIndex >= (ZID_ATTRIBUTE_REQ_SIZE - 1))
          {
              set_attribute_index = 0;
              LED_Off(ZID_APP_LED);
              

              node_status = CONNECTING;

              dev_type_t OrgDevTypeList[1];;
              profile_id_t OrgProfileIdList[1];
              profile_id_t DiscProfileIdList[1];

              OrgDevTypeList[0] = DEV_TYPE_REMOTE_CONTROL;
              OrgProfileIdList[0] = PROFILE_ID_ZID;
              DiscProfileIdList[0] = PROFILE_ID_ZID;

              zid_org_connect_request(APP_CAPABILITIES, OrgDevTypeList, OrgProfileIdList,
                                   DEV_TYPE_WILDCARD, NUM_SUPPORTED_PROFILES, DiscProfileIdList
#ifdef RF4CE_CALLBACK_PARAM
                                    ,(FUNC_PTR)zid_connect_confirm
#endif
                                     );
          }
          else
          {
              set_attribute_index++;
          }
       }
   }
   else
   {
        if(node_status == COLD_START)
		{
			app_alert();
		}
		else
		{
		  indicate_fault_behavior();
		  /* Reset the network and start again */
		  /* Warm start */
			node_status = WARM_START;
			nlme_reset_request(false
#ifdef RF4CE_CALLBACK_PARAM
                          ,(FUNC_PTR)nlme_reset_confirm
#endif
                           );
		}
   }
   PairingRef = PairingRef;
   ZIDAttribute = ZIDAttribute;
   ZIDAttributeIndex =ZIDAttributeIndex;
}
예제 #4
0
/**
 * Main function, initialization and main message loop
 *
 */
int main(void)
{
    irq_initialize_vectors();

    /* Initialize the board.*/	
    board_init();    

	/* Initialize the Software timer */
    sw_timer_init();       
    
	/* Init the RF4CE Network layer */
    if (nwk_init()!= NWK_SUCCESS)
    {
        app_alert();
    }

#ifdef RF4CE_CALLBACK_PARAM
	/* Register the ZID Callback indication */
    zid_ind.zid_report_data_indication_cb = zid_report_data_indication;
    zid_ind.zid_get_report_indication_cb = zid_get_report_indication;
    register_zid_indication_callback(&zid_ind);
#endif
    /*
     * The stack is initialized above,
     * hence the global interrupts are enabled here.
     */
     cpu_irq_enable();
	 sw_timer_get_id(&APP_TIMER_ACC_READ);
    if (get_zid_keyrc_button(button_scan()) == ZID_COLD_START)
    {        
        /* Cold start */
        LED_On(ZID_APP_LED);
        node_status = COLD_START;
        nlme_reset_request(true
#ifdef RF4CE_CALLBACK_PARAM
                          ,(FUNC_PTR)nlme_reset_confirm
#endif
                           );
    }
    else
    {
        /* Warm start */
        node_status = WARM_START;
        nlme_reset_request(false
#ifdef RF4CE_CALLBACK_PARAM
                          ,(FUNC_PTR)nlme_reset_confirm
#endif
                           );
    }

    /* Endless while loop */
    while (1)
    {
        app_task(); /* Application task */
        nwk_task(); /* RF4CE network layer task */
    }
}
예제 #5
0
/**
 * @brief Main function of the Terminal Target application
 */
int main(void)
{
    irq_initialize_vectors();
	sysclk_init();

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

    sw_timer_init();

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

    zrc_ind.vendor_data_ind_cb = vendor_data_ind;

#ifdef ZRC_CMD_DISCOVERY
	zrc_ind.zrc_cmd_disc_indication_cb =  zrc_cmd_disc_indication;
#endif
	zrc_ind.zrc_cmd_indication_cb = zrc_cmd_indication;

	register_zrc_indication_callback(&zrc_ind);

	nwk_ind.nwk_ch_agility_indication_cb = nwk_ch_agility_indication;
	nwk_ind.nlme_unpair_indication_cb = nlme_unpair_indication;
	register_nwk_indication_callback(&nwk_ind);

	/* Initialize LEDs. */
	LED_On(LED_START);     /* indicating application is started */
	LED_Off(LED_NWK_SETUP); /* indicating network is started */
	LED_Off(LED_DATA);     /* indicating data reception */

	/*
	 * The stack is initialized above, hence the global interrupts are
	 *enabled
	 * here.
	 */
	cpu_irq_enable();

#ifdef SIO_HUB
	/* Initialize the serial interface used for communication with terminal
	 *program. */

	sio2host_init();
#endif

	sw_timer_get_id(&led_timer);

	/* Endless while loop */
	while (1) {
		app_task(); /* Application task */
		nwk_task(); /* RF4CE network layer task */
	}
}
예제 #6
0
static void app_timers_init(void)
{

if(STATUS_OK != sw_timer_get_id(&T_APP_TIMER))
{
        app_alert();
}
if(STATUS_OK != sw_timer_get_id(&APP_TIMER_TO_TX))
{
        app_alert();
}
if(STATUS_OK != sw_timer_get_id(&APP_TIMER_TO_TX_LED_OFF))
{
        app_alert();
}
if(STATUS_OK != sw_timer_get_id(&APP_TIMER_TO_RX_LED_OFF))
{
        app_alert();
}

}
예제 #7
0
static void app_timers_init(void)
{
if(STATUS_OK != (status_code_genare_t)sw_timer_get_id(&T_APP_TIMER))
{
        app_alert();
}
if(STATUS_OK != (status_code_genare_t)sw_timer_get_id(&APP_TIMER_TO_TX))
{
        app_alert();
}
if(STATUS_OK != (status_code_genare_t)sw_timer_get_id(&APP_TIMER_TO_TX_LED_OFF))
{
        app_alert();
}
if(STATUS_OK != (status_code_genare_t)sw_timer_get_id(&APP_TIMER_TO_RX_LED_OFF))
{
        app_alert();
}

	if (STATUS_OK != (status_code_genare_t)sw_timer_get_id(&T_APP_TIMER_RANGE)) {
		app_alert();
	}
}
예제 #8
0
/*! \brief Main function.
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	irq_initialize_vectors();
	board_init();
	sysclk_init();

	sw_timer_init();

	if(MAC_SUCCESS != wpan_init())
	{
        /*
         * Stay here; we need a valid IEEE address.
         * Check kit documentation how to create an IEEE address
         * and to store it into the EEPROM.
         */
		app_alert();
	}

    /* Initialize LEDs. */
    LED_On(LED_START);         // indicating application is started
    LED_Off(LED_NWK_SETUP);    // indicating node is associated
    LED_Off(LED_DATA);         // indicating successfull data transmission

	cpu_irq_enable();

	sw_timer_get_id(&TIMER_LED_OFF);
	sw_timer_get_id(&WAKE_TIMER);

	node_status = COLD_START_RESET;

    /*
     * Reset the MAC layer to the default values
     * This request will cause a mlme reset confirm message ->
     * usr_mlme_reset_conf
     */
    wpan_mlme_reset_req(true);

    /* Main loop */
	while (true)
	{
		wpan_task();
        app_task(); /* Application task */
	}
}
예제 #9
0
파일: main.c 프로젝트: AndreyMostovov/asf
/**
 * 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 */
}
예제 #10
0
/**
 * @brief Main function of the device application
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	irq_initialize_vectors();
	board_init();
	sysclk_init();

	sw_timer_init();

	if(MAC_SUCCESS != wpan_init())
	{
		app_alert();
	}

    /* Initialize LEDs. */
    LED_On(LED_START);         // indicating application is started
    LED_Off(LED_NWK_SETUP);    // indicating node is associated
    LED_Off(LED_DATA);         // indicating successfull data transmission

	cpu_irq_enable();

#ifdef SIO_HUB
    /* Initialize the serial interface used for communication with terminal program. */
   sio2host_init();

    /* To make sure the hyper terminal gets connected to the system */
    sio2host_getchar();

    printf("\nNobeacon_Application\r\n\n");
    printf("\nDevice\r\n\n");
#endif /* SIO_HUB */

	sw_timer_get_id(&APP_TIMER_LED_OFF);
	sw_timer_get_id(&APP_TIMER_POLL_DATA);

	wpan_mlme_reset_req(true);

	while (true)
	{
		wpan_task();
	}
}
예제 #11
0
static
#endif
void zid_connect_confirm(nwk_enum_t Status, uint8_t PairingRef)
{
    if (Status != NWK_SUCCESS)
    {
        if(node_status == COLD_START)
		{
			app_alert();
		}
		else
		{
		  indicate_fault_behavior();
		  /* Reset the network and start again */
		  /* Warm start */
			node_status = WARM_START;
			nlme_reset_request(false
#ifdef RF4CE_CALLBACK_PARAM
                          ,(FUNC_PTR)nlme_reset_confirm
#endif
                           );
		}
    }

    pairing_ref = PairingRef;

    /* Set power save mode */

    if (node_status == CONNECTING)
    {
        node_status = IDLE;
        zid_state = ZID_STATE_IDLE;

       /* LED handling */
	   LED_On(ZID_APP_LED);
	   delay_ms(1000);
	   LED_Off(ZID_APP_LED);
       LED_On(LED_1); 
       LED_Off(LED_2);
       LED_Off(LED_3);
       LED_Off(LED_4);
       LED_On(LED_5);       
    }
}
예제 #12
0
파일: main.c 프로젝트: Realtime-7/asf
/**
 * Main function, initialization and main message loop
 *
 */
int main (void)
{
    irq_initialize_vectors();

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

    sw_timer_init();

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

    zid_indication_callback_init();
    /*
     * The stack is initialized above, hence the global interrupts are enabled
     * here.
     */
    cpu_irq_enable();
    /* Initializing udc stack as HID composite device*/
    udc_start();

    sw_timer_get_id(&APP_TIMER);

    /* Endless while loop */
    //udi_hid_gpd_up(16);
    while (1)
    {


        app_task(); /* Application task */
        nwk_task(); /* RF4CE network layer task */


    }
}
예제 #13
0
파일: tal.c 프로젝트: AndreyMostovov/asf
/**
 * \brief Switches the PLL on
 * \ingroup group_tal_state_machine_rfa1
 */
static void switch_pll_on(void)
{
	trx_irq_reason_t irq_status;
	uint8_t poll_counter = 0;

	/* Check if trx is in TRX_OFF; only from PLL_ON the following procedure
	 *is applicable */
	if (trx_bit_read(SR_TRX_STATUS) != TRX_OFF) {
		Assert(
				"Switch PLL_ON failed, because trx is not in TRX_OFF" ==
				0);
		return;
	}

	IRQ_STATUS = _BV(PLL_LOCK); /* clear PLL lock bit */
	/* Switch PLL on */
	trx_reg_write(RG_TRX_STATE, CMD_PLL_ON);

	/* Check if PLL has been locked. */
	do {
		irq_status = (trx_irq_reason_t)trx_reg_read(RG_IRQ_STATUS);

		if (irq_status & TRX_IRQ_PLL_LOCK) {
			return; /* PLL is locked now */
		}

		/* Wait a time interval of typical value for timer TR4. */
		pal_timer_delay(TRX_OFF_TO_PLL_ON_TIME_US);

		poll_counter++;
	} while (poll_counter < PLL_LOCK_ATTEMPTS);

#if (_DEBUG_ > 0)
	Assert("PLL switch failed" == 0);
	app_alert();
#endif
}
예제 #14
0
/**
 * Main function, initialization and main message loop
 *
 * @return error code
 */
int main (void)
{
    irq_initialize_vectors();

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

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

    zid_indication_callback_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
     */
   
    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 */
}
예제 #15
0
static
#endif
void nlme_start_confirm(nwk_enum_t Status)
{
    if (Status != NWK_SUCCESS)
    {
		if(node_status == COLD_START)
		{
			app_alert();
		}
		else
		{
		  indicate_fault_behavior();
		  /* Reset the network and start again */
		  /* Warm start */
			node_status = WARM_START;
			nlme_reset_request(false
#ifdef RF4CE_CALLBACK_PARAM
                          ,(FUNC_PTR)nlme_reset_confirm
#endif
                           );
		}
    }

    if(node_status == COLD_START)
    {
        uint8_t value = ZID_ATTRIBUTE_REQ_SIZE;
        zid_set_attribute_request(0xFF, aplHIDNumStdDescComps, 0, &value
#ifdef RF4CE_CALLBACK_PARAM
                               , (FUNC_PTR)zid_set_attribute_confirm
#endif
                              );
        node_status = CONFIGURING_ATTRIBUTES;
    }

}
예제 #16
0
/**
 * @brief Main function of the device application
 */
int main(void)
{
    irq_initialize_vectors();
#if SAMD || 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
#ifdef SIO_HUB
    sio2host_init();
#endif
    sw_timer_init();

    if (MAC_SUCCESS != wpan_init()) {
        app_alert();
    }

    /* Initialize LEDs. */
    LED_On(LED_START);     /* indicating application is started */
    LED_Off(LED_NWK_SETUP); /* indicating network is started */
    LED_Off(LED_DATA);     /* indicating data transmission */
    cpu_irq_enable();
#ifdef SIO_HUB

    /* Initialize the serial interface used for communication with terminal
     * program. */

    /* To Make sure the Hyper Terminal to the System */
    sio2host_getchar();

    printf("\nBeacon_Application\r\n\n");
    printf("\nDevice\r\n\n");
    print_stack_app_build_features();
#endif

    sw_timer_get_id(&APP_TIMER);

    wpan_mlme_reset_req(true);
#ifdef ENABLE_SLEEP
    sw_timer_get_id(&APP_TIMER_SLEEP);
#endif
    LED_Off(LED_NWK_SETUP);
    while (true) {
        wpan_task();
#if (defined ENABLE_SLEEP || defined RTC_SLEEP)
        /* Requesting MAC for Sleep Duration*/
        sleep_time = mac_ready_to_sleep();
        if ((sleep_time > (uint32_t)APP_GUARD_TIME_US)) {
            /*Entering Power save Mode when the sleep duration is
             * above the guard time*/
            enter_sleep(sleep_time);
        }
#endif
    }
}
예제 #17
0
/**
 * @brief Main function of the coordinator application
 *
 * This function initializes the MAC, initiates a MLME reset request
 * (@ref wpan_mlme_reset_req()), and implements a the main loop.
 */
int main(void)
{	
	irq_initialize_vectors();
	#if SAMD20
	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
	#ifdef SIO_HUB
		sio2host_init();
	#endif
	sw_timer_init();

	if (MAC_SUCCESS != wpan_init()) {
		app_alert();
	}

	/* Initialize LEDs. */
	LED_On(LED_START);     /* indicating application is started */
	LED_Off(LED_NWK_SETUP); /* indicating network is started */
	LED_Off(LED_DATA);     /* indicating data transmission */

	cpu_irq_enable();

#ifdef SIO_HUB
	/* Initialize the serial interface used for communication with terminal
	 *program. */

	/* To make sure the Hyper Terminal Connected to the system*/
	sio2host_getchar();

#ifdef BEACON_SUPPORT
printf("\nBeacon_Application\r\n\n");
#else
printf("\nNO Beacon_Application\r\n\n");
#endif
	printf("\nCoordinator\r\n\n");
	print_stack_app_build_features();
#endif /* SIO_HUB */

	sw_timer_get_id(&APP_TIMER_INDIRECT_DATA);
	sw_timer_get_id(&APP_TIMER_BCN_PAYLOAD_UPDATE);
	sw_timer_get_id(&APP_TIMER_BC_DATA);
	#ifdef GTS_SUPPORT
	sw_timer_get_id(&APP_TIMER_GTS_DATA);
    #endif
	/*
	 * Reset the MAC layer to the default values.
	 * This request will cause a mlme reset confirm message ->
	 * usr_mlme_reset_conf
	 */
	wpan_mlme_reset_req(true);

#ifdef GPIO_PUSH_BUTTON_0
	dst_addr.AddrMode = 2;
	dst_addr.PANId = DEFAULT_PAN_ID;
#endif /* GPIO_PUSH_BUTTON_0 */

	while (true) {
		wpan_task();
#ifdef GPIO_PUSH_BUTTON_0
		if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) {
			delay_ms(DEBOUNCE_DELAY_MS);
			if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) {
				dst_addr.Addr.short_address = BROADCAST;
				wpan_mcps_data_req(FCF_SHORT_ADDR, &dst_addr,
						strlen(broadcast_payload),
						(uint8_t *)&broadcast_payload, 1,
						WPAN_TXOPT_OFF);
			}
		}

#endif /* GPIO_PUSH_BUTTON_0 */
	}
}