Example #1
0
/****************************************************************************
 *
 * NAME: NODE_vInit
 *
 * DESCRIPTION:
 * Initialises Zigbee stack, hardware and application.
 *
 ****************************************************************************/
PUBLIC void NODE_vInit(void)
{
    uint32 u32RandomSeed;

	/* Debug */
	DBG_vPrintf(NODE_TRACE, "\n%d NODE < NODE_vInit()", NODE_sData.u32Timer);

    /* Seed the pseudo random number generator using the hardware random gen */
    *((volatile uint32 *)0x02001010) |= (1 << 30); /* clear ready flag */
    vAHI_StartRandomNumberGenerator(TRUE /* single shot */, FALSE /* no ints */);
    while (!bAHI_RndNumPoll());
    u32RandomSeed = ((uint32)u16AHI_ReadRandomNumber()) << 16;

    *((volatile uint32 *)0x02001010) |= (1 << 30); /* clear ready flag */
    vAHI_StartRandomNumberGenerator(TRUE /* single shot */, FALSE /* no ints */);
    while (!bAHI_RndNumPoll());
    u32RandomSeed |= u16AHI_ReadRandomNumber();

	RND_vInit(u32RandomSeed);
    DBG_vPrintf(NODE_TRACE, " RND=%08x", u32RandomSeed);

    /* Initialise JenOS modules */
    PWRM_vInit(E_AHI_SLEEP_OSCON_RAMON);
	DBG_vPrintf(NODE_TRACE, " PWRM");

    /* Initialise persistent data */
    PDM_vInit(7, 1, 64*1024, NULL, mutexPdmMedia, NULL, NULL);
	DBG_vPrintf(NODE_TRACE, " PDM");
	/* Delete persistent data - always start over for now */
    PDM_vDelete();
	DBG_vPrintf(NODE_TRACE, "deleted");

    PDUM_vInit();
	DBG_vPrintf(NODE_TRACE, " PDUM");

    /* Initialise ZigbeePro stack */
    ZPS_eAplAfInit();
    DBG_vPrintf(NODE_TRACE, " ZPS");

	/* No state yet */
	NODE_sData.eNwkState = NODE_NWKSTATE_NONE;

	/* Initialise non-zero node structure members */
	NODE_sData.u64Address   = *(uint64 *) pvAppApiGetMacAddrLocation();	/**< Address of node */
	NODE_sData.u16Address   = 0xffff;									/**< Short address of node */
	NODE_sData.u16Parent    = 0xffff;									/**< Short address of node's parent */

	/* Initialise node structure pointer members */
	NODE_sData.pvMac = (void *) pvAppApiGetMacHandle();
	NODE_sData.psPib = MAC_psPibGetHandle(NODE_sData.pvMac);
	NODE_sData.pvNwk = ZPS_pvNwkGetHandle();
	NODE_sData.psNib = ZPS_psNwkNibGetHandle(NODE_sData.pvNwk);

	/* Note initial MinBe */
	NODE_sData.u8DefPibMinBe = NODE_sData.psPib->u8MinBe_ReadOnly;
}
Example #2
0
/*---------------------------------------------------------------------------*/
#if WITH_TINYOS_AUTO_IDS
uint16_t TOS_NODE_ID = 0x1234; /* non-zero */
uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */
#endif /* WITH_TINYOS_AUTO_IDS */
int
main(void)
{
  /* Set stack overflow address for detecting overflow in runtime */
  vAHI_SetStackOverflow(TRUE, ((uint32_t *)&heap_location)[0]);

  /* Initialize random with a seed from the SoC random generator.
   * This must be done before selecting the high-precision external oscillator.
   */
  vAHI_StartRandomNumberGenerator(E_AHI_RND_SINGLE_SHOT, E_AHI_INTS_DISABLED);
  random_init(u16AHI_ReadRandomNumber());

  clock_init();
  rtimer_init();

#if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR
  /* initialize the 32kHz crystal and wait for ready */
  xosc_init();
  /* need to reinitialize because the wait-for-ready process uses system timers */
  clock_init();
  rtimer_init();
#endif

  watchdog_init();
  leds_init();
  leds_on(LEDS_ALL);
  init_node_mac();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  node_id_restore();

#if WITH_TINYOS_AUTO_IDS
  node_id = TOS_NODE_ID;
#endif /* WITH_TINYOS_AUTO_IDS */
  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
  {
    uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
    memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
    node_mac[7] = node_id & 0xff;
  }
#endif

  process_init();
  ctimer_init();
  uart0_init(UART_BAUD_RATE); /* Must come before first PRINTF */

#if NETSTACK_CONF_WITH_IPV4
  slip_arch_init(UART_BAUD_RATE);
#endif /* NETSTACK_CONF_WITH_IPV4 */

  /* check for reset source */
  if(bAHI_WatchdogResetEvent()) {
    PRINTF("Init: Watchdog timer has reset device!\r\n");
  }
  process_start(&etimer_process, NULL);
  set_linkaddr();
  netstack_init();

#if NETSTACK_CONF_WITH_IPV6
#if UIP_CONF_IPV6_RPL
  PRINTF(CONTIKI_VERSION_STRING " started with IPV6, RPL\n");
#else
  PRINTF(CONTIKI_VERSION_STRING " started with IPV6\n");
#endif
#elif NETSTACK_CONF_WITH_IPV4
  PRINTF(CONTIKI_VERSION_STRING " started with IPV4\n");
#else
  PRINTF(CONTIKI_VERSION_STRING " started\n");
#endif

  if(node_id > 0) {
    PRINTF("Node id is set to %u.\n", node_id);
  } else {
    PRINTF("Node id is not set.\n");
  }
#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
  queuebuf_init();
#endif /* NETSTACK_CONF_WITH_IPV6 */

  PRINTF("%s %s %s\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name);

#if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
  uart0_set_input(serial_line_input_byte);
  serial_line_init();
#endif

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16);
#endif /* TIMESYNCH_CONF_ENABLED */

#if NETSTACK_CONF_WITH_IPV4
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL); /* Start IP output */
  process_start(&slip_process, NULL);

  slip_set_input_callback(set_gateway);

  {
    uip_ipaddr_t hostaddr, netmask;

    uip_init();

    uip_ipaddr(&hostaddr, 172, 16,
               linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
    uip_ipaddr(&netmask, 255, 255, 0, 0);
    uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);

    uip_sethostaddr(&hostaddr);
    uip_setnetmask(&netmask);
    uip_over_mesh_set_net(&hostaddr, &netmask);
    /*    uip_fw_register(&slipif);*/
    uip_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
    PRINTF("uIP started with IP address %d.%d.%d.%d\n",
           uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* NETSTACK_CONF_WITH_IPV4 */

  watchdog_start();
  NETSTACK_LLSEC.init();

#if NETSTACK_CONF_WITH_IPV6
  start_uip6();
#endif /* NETSTACK_CONF_WITH_IPV6 */

  /* need this to reliably generate the first rtimer callback and callbacks in other 
     auto-start processes */
  (void)u32AHI_Init();

  start_autostart_processes();

  leds_off(LEDS_ALL);

  main_loop();

  return -1;
}