Exemplo n.º 1
0
/****************************************************************************
 *
 * NAME: vInitSystem
 *
 * DESCRIPTION: Initialise the radio system
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vInitSystem(void)
{
	// Setup interface to MAC
	(void) u32AHI_Init();
	(void) u32AppQApiInit(NULL,mcpsCallback , NULL);


	loadSettings();


	if (useHighPowerModule == TRUE)
	{
		//max power for europe including antenna gain is 10dBm
		// TODO see if we can use more power as rx antenna is lower gain
		//??? boost is +2.5 ant is 1 and power set to 4 = 7.5 ????
		vAHI_HighPowerModuleEnable(TRUE, TRUE);
#ifdef JN5168
		eAppApiPlmeSet(PHY_PIB_ATTR_TX_POWER, 34+10*2);
#else
		bAHI_PhyRadioSetPower(2);
#endif
	}
	// Initialise end device state
	sEndDeviceData.eState = E_STATE_IDLE;
	sEndDeviceData.u8TxPacketSeqNb = 0;
	sEndDeviceData.u8RxPacketSeqNb = 0;
	sEndDeviceData.u8ChannelSeqNo = 0;

	// Set up the MAC handles. Must be called AFTER u32AppQApiInit()
	s_pvMac = pvAppApiGetMacHandle();
	s_psMacPib = MAC_psPibGetHandle(s_pvMac);

	// Set Pan ID in PIB (also sets match register in hardware)
	MAC_vPibSetPanId(s_pvMac, PAN_ID);

	// Enable receiver to be on when idle
	MAC_vPibSetRxOnWhenIdle(s_pvMac, TRUE, FALSE);

	// sometimes useful during development
	// all messages are passed up from lower levels
	// MAC_vPibSetPromiscuousMode(s_pvMac, TRUE, FALSE);


	module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation();

	//moved to after u32AHI_Init() for jn5148
	randomizeHopSequence(((uint32) macptr->u32H) ^ ((uint32) macptr->u32L));

#if (defined JN5148 || defined JN5168)
	/* Enable TOF ranging. */
//	vAppApiTofInit(TRUE);
#endif

}
Exemplo n.º 2
0
PUBLIC void vJenie_CbInit(bool_t bWarmStart)
{

    vUtils_Init();

    if(bWarmStart==FALSE)
    {
        (void)u32AHI_Init();
        sHomeData.bStackReady=FALSE;
        /* Initialise buttons, LEDs and program variables */
        vInitEndpoint();
        /* Set DIO for buttons and LEDs */
        vLedControl(LED1, FALSE);
        vLedControl(LED2, FALSE);
        vLedInitRfd();
        vButtonInitRfd();

        #ifdef NO_SLEEP
            vAHI_WakeTimerEnable(E_AHI_WAKE_TIMER_1, TRUE);
        #endif

        /* Set SW1(dio9) to input */
        vAHI_DioSetDirection(E_AHI_DIO9_INT, 0);
        /* set interrupt for DIO9 to occur on button release - rising edge */
        vAHI_DioInterruptEdge(E_AHI_DIO9_INT, 0);
        /* enable interrupt for DIO9 */
        vAHI_DioInterruptEnable(E_AHI_DIO9_INT, 0);

        /* Set SW2(dio10) to input */
        vAHI_DioSetDirection(E_AHI_DIO10_INT, 0);
        /* set interrupt for DIO9 to occur on button release - rising edge */
        vAHI_DioInterruptEdge(E_AHI_DIO10_INT, 0);
        /* enable interrupt for DIO9 */
        vAHI_DioInterruptEnable(E_AHI_DIO10_INT, 0);

        /* Set up peripheral hardware */
        vALSreset();
        vHTSreset();

        /* Start ALS now: it automatically keeps re-sampling after this */
        vALSstartReadChannel(0);

        sHomeData.eAppState = E_STATE_REGISTER;
        switch(eJenie_Start(E_JENIE_END_DEVICE))        /* Start network as end device */
        {
        case E_JENIE_SUCCESS:
            #ifdef DEBUG
                vUtils_Debug("Jenie Started");
            #endif
            #ifdef HIGH_POWER
                /* Set high power mode */
                eJenie_RadioPower(18, TRUE);
            #endif
            break;

        case E_JENIE_ERR_UNKNOWN:
        case E_JENIE_ERR_INVLD_PARAM:
        case E_JENIE_ERR_STACK_RSRC:
        case E_JENIE_ERR_STACK_BUSY:

        default:
            /* Do something on failure?? */
            break;
        }
    }else{

        /* Set up peripheral hardware */
        vALSreset();
        vHTSreset();

        /* Start ALS now: it automatically keeps re-sampling after this */
        vALSstartReadChannel(0);

        switch(eJenie_Start(E_JENIE_END_DEVICE))        /* Start network as end device */
        {
        case E_JENIE_SUCCESS:
            #ifdef HIGH_POWER
                /* Set high power mode */
                eJenie_RadioPower(18, TRUE);
            #endif
            break;

        case E_JENIE_ERR_UNKNOWN:
        case E_JENIE_ERR_INVLD_PARAM:
        case E_JENIE_ERR_STACK_RSRC:
        case E_JENIE_ERR_STACK_BUSY:

        default:
            /* Do something on failure?? */
            break;
        }

    }
    /* set watchdog to long timeout - override setting in JenNet startup */
    #ifdef WATCHDOG_ENABLED
       vAHI_WatchdogStart(254);
    #endif

}
Exemplo n.º 3
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;
}