Beispiel #1
0
int main()
{
    UINT32 val;
    char c, forceClearCfg = 0;
    /* enable watchdog */
    wdt_enable(WDTO_8S);
#ifdef INCLUDE_KTANK_UART
    /* init UART */
    init_uart(9600);
    printk("\n\n\n!!!!!!!!!!ktank start!!!!!!!!!!!!!!\n\n\n");
#endif
    /* init PWM, local time */
    pwm_init();
    /* enable i2c bus, rtc need it  */
    I2C_init();
    /* init timer */
    timer_init();
    val = timebase_get();
#ifdef INCLUDE_KTANK_UART
    do{
        if(uart_poll_c((UINT8*)&c) > 0 && c == 'c'){
            forceClearCfg++;
        }
    }while(time_diff_ms(val) < 2000);
#endif
    if(forceClearCfg > 10){
        DBG_PRINT("slave force clear cfg..\n");
        EEPROM_put(EEPROM_OFS_RFAVAIL, 0xff);
    }
    local_device_info_load();
    local_device_info_show();
    if(RF_CFG_AVAL()){
        rf_init(NULL, SLAVE_MODE_NORMAL);

        rf_config(EEPROM_get(EEPROM_OFS_HOSTID), EEPROM_get(EEPROM_OFS_DEVID));
        DBG_PRINT("slave start hostid 0x%x devid 0x%x\n", 
               EEPROM_get(EEPROM_OFS_HOSTID), EEPROM_get(EEPROM_OFS_DEVID));
        nrf_enter_rx_mode();
    }else{
#if 0
        rf_init(NULL, SLAVE_MODE_WAIT_SYNC);
        DBG_PRINT("no cfg, force device id 1, host id 0xef\n");
        rf_config(0xef, 1);
        nrf_enter_rx_mode();
#else

        rf_init(NULL, SLAVE_MODE_WAIT_DISCOVER);
        rf_config(0xc0, 0x80);
        DBG_PRINT("slave start without rf cfg\n");
#endif
    }
    sei();
    while(1){
        wdt_reset();
        rf_process();
	local_device_update();
    }
}
Beispiel #2
0
int main( void )
{
	stop_watchdog();
	setup_finish_ports();
	setup_clock();
	setup_uart();
	rf_init(sizeof(struct packet));
	configure_timer_38k();
	timer_38k_enable(1);
	configure_watchdog();

	__enable_interrupt();

	// Show battery voltage on start
	display_vcc();

	// Setup RF channel
	setup_channel();

	set_state(st_stopped);

	// Start/stop loop
	for (;;) {
		wait_start();
		set_state(st_started);
		beep(SHORT_DELAY_TICKS);
		detect_finish();
		set_state(st_stopped);
		report_finish();
	}
}
Beispiel #3
0
void rf_cmd(const struct carl9170_cmd *cmd, struct carl9170_rsp *resp)
{
	uint32_t ret;

	fw.phy.ht_settings = cmd->rf_init.ht_settings;
	fw.phy.frequency = cmd->rf_init.freq;

	/*
	 * Is the clock controlled by the PHY?
	 */
	if ((fw.phy.ht_settings & EIGHTY_FLAG) == EIGHTY_FLAG)
		clock_set(AHB_80_88MHZ, true);
	else
		clock_set(AHB_40_44MHZ, true);

	ret = rf_init(le32_to_cpu(cmd->rf_init.delta_slope_coeff_exp),
		      le32_to_cpu(cmd->rf_init.delta_slope_coeff_man),
		      le32_to_cpu(cmd->rf_init.delta_slope_coeff_exp_shgi),
		      le32_to_cpu(cmd->rf_init.delta_slope_coeff_man_shgi),
		      le32_to_cpu(cmd->rf_init.finiteLoopCount),
		      cmd->hdr.cmd == CARL9170_CMD_RF_INIT);

	resp->hdr.len = sizeof(struct carl9170_rf_init_result);
	resp->rf_init_res.ret = cpu_to_le32(ret);
}
int main()
{
uart_init();
rf_init();
DDRD=0xF0;
while(1)
 {

	switch(uart_read())
	{
	case 'F':
	    rf_transmit_B(5,2,0x50);
	    break;
	case 'B':
	    rf_transmit_B(5,2,0xA0);
	    break;
	case 'R':
	    rf_transmit_B(5,2,0x40);
	    break;
	case 'L':
	    rf_transmit_B(5,2,0x10);
	    break;
	case 'S':
	    rf_transmit_B(5,2,0x00);
	    break;
	}
	 delayms(10);	
 }
}
Beispiel #5
0
int main(void)
{
  __disable_interrupt();
  sys_init();
  __delay_cycles(8000000);//Защита от коротких нажатий
  P1OUT |= BIT6; //защелкиваем питание
  led(1);
  ADC10_Init();
  AFE_Init();
  rf_init();
  TACCR0 = 0xFFFF;// запуск таймера
  __enable_interrupt();

 while (1)
 {
   if(rf_rx_data_ready_fg) {
     onRF_MessageReceived();
     rf_rx_data_ready_fg = 0;
   }
   if (packetDataReady){       
     uchar packetSize = assemblePacket();
     rf_send((uchar*)&packet_buf[0], packetSize);
     packetDataReady = 0;      
   }
   if(rf_rx_data_ready_fg || packetDataReady){
  // идем по циклу снова
   }else{
   __bis_SR_register(CPUOFF + GIE); // Уходим в спящий режим 
   }
 }
} 
Beispiel #6
0
int8_t bmac_set_channel(uint8_t chan)
{
    if(chan>26) return NRK_ERROR;
    g_chan=chan;
    rf_init (&bmac_rfRxInfo, chan, 0xFFFF, 0x00000);
    return NRK_OK;
}
Beispiel #7
0
//=======================================
void main(void)
{   
  uint8_t remote_id1_packet[NRFR_LENGTH_REPORT_1], remote_id2_packet[NRFR_LENGTH_REPORT_2];
  uint8_t i;
//=======================================
  CLKCTL=0;
  RFCE=0;
  RFCTL=0x10;
  rf_init();									// RF初始化
//=======================================
  hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb);   
  hal_usb_endpoint_config(0x81, 32, ep_1_in_cb); // Configure 32 byte IN endpoint 1
  EA=1;
  app_keep_alive_cnt=0;
  RX_Mode();									//进入接收模式
  while(true)                                                                               
  {
     	  if(RX_DR)
     	  {
			sta=0;
			for(i=0;i<5;i++)
			{
			   remote_id1_packet[i]=rx_buf[i];
			}
			for(i=0;i<9;i++)
			{
			   remote_id2_packet[i]=rx_buf[i+5];
			}
			app_transfer_to_usb(remote_id1_packet, remote_id2_packet);
			app_keep_alive_cnt=1;
			delay(100);
          }
		  app_maintain_keep_alive();        
  }
}                          
Beispiel #8
0
void setup_textfile_tests()
{
    rf_init(LOG_TARGET_STDOUT, NULL, LOG_DEBUG,
            RF_DEFAULT_TS_MBUFF_INITIAL_SIZE,
            RF_DEFAULT_TS_SBUFF_INITIAL_SIZE);
    ck_assert(rf_stringx_init_buff(&g_buff, 512, ""));
    ck_assert(rf_stringx_init_buff(&g_fname, 64, ""));
}
Beispiel #9
0
void setup_textfile_invalid_args_tests()
{
    rf_init(LOG_TARGET_FILE, "refuclib.log", LOG_DEBUG,
            RF_DEFAULT_TS_MBUFF_INITIAL_SIZE,
            RF_DEFAULT_TS_SBUFF_INITIAL_SIZE);
    ck_assert(rf_stringx_init_buff(&g_buff, 512, ""));
    ck_assert(rf_stringx_init_buff(&g_fname, 64, ""));
}
Beispiel #10
0
} END_TEST

void setup_realloc_tests()
{
    rf_init(LOG_TARGET_STDOUT, NULL, LOG_DEBUG,
            128,
            RF_DEFAULT_TS_SBUFF_INITIAL_SIZE);
}
Beispiel #11
0
/******************************************************************************\
 * See msg.h for documentation of these functions.
\******************************************************************************/
void msg_init(msgType* rxBuffer)
{
    uart_init();
    rf_init(RF_CHANNEL_CENTRE, RF_PWR_MAX);
    msgBuffer = rxBuffer;
    rf_msgBuffer.data = (volatile uint8_t*)rxBuffer;
    rf_setReceiveBuffer(&rf_msgBuffer);
    rf_setMode(RF_MODE_RECEIVING);
}
Beispiel #12
0
int8_t tdma_set_channel (uint8_t chan)
{
  if (chan > 26)
    return NRK_ERROR;
  tdma_chan = chan;
//rf_init (&tdma_rfRxInfo, chan, 0xFFFF, 0x00000);
  rf_init (&tdma_rfRxInfo, chan, 0x2420, 0x1214);
  return NRK_OK;
}
Beispiel #13
0
//------------------------------------------------------------------------------
//      void main (void)
//
//      DESCRIPTION:
//              Startup routine and main loop
//------------------------------------------------------------------------------
int main (void)
{
    uint8_t i,length;
    uint32_t cnt;

    nrk_setup_ports(); 
    nrk_setup_uart (UART_BAUDRATE_115K2);
 
    printf( "Basic TX...\r\n" ); 
    nrk_led_set(0); 
    nrk_led_set(1); 
    nrk_led_clr(2); 
    nrk_led_clr(3); 
/*
	    while(1) {
		   
				for(i=0; i<40; i++ )
					halWait(10000);
		    nrk_led_toggle(1);

	    }

*/

    rfRxInfo.pPayload = rx_buf;
    rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
		nrk_int_enable();
    rf_init (&rfRxInfo, 26, 0x2420, 0x1214);
    cnt=0;
    while(1){
	  		DPDS1 |= 0x3;
			DDRG |= 0x1;
			PORTG |= 0x1;
			DDRE|=0xE0;
			PORTE|=0xE0;
    		rfTxInfo.pPayload=tx_buf;
    		sprintf( tx_buf, "%lu", cnt); 
    		rfTxInfo.length= strlen(tx_buf) + 1;
				rfTxInfo.destAddr = 0x1215;
				rfTxInfo.cca = 0;
				rfTxInfo.ackRequest = 0;
				
				printf( "Sending\r\n" );
	//			nrk_gpio_set(NRK_DEBUG_0);
				if(rf_tx_packet(&rfTxInfo) != 1)
					printf("--- RF_TX ERROR ---\r\n");
	//			nrk_gpio_clr(NRK_DEBUG_0);
				cnt++;
		
				for(i=0; i<10; i++ )
					halWait(10000);
				nrk_led_toggle(RED_LED);
		}

}
Beispiel #14
0
int8_t tdma_init (uint8_t mode, uint8_t chan, uint16_t my_mac)
{
  tx_reserve = -1;
  tdma_rx_failure_cnt = 0;
  tdma_mode = mode;
  tdma_tx_slots = 0;

  sync_status=0;

  tdma_slots_per_cycle = TDMA_DEFAULT_SLOTS_PER_CYCLE;


  tdma_rx_pkt_signal = nrk_signal_create ();
  if (tdma_rx_pkt_signal == NRK_ERROR) {
    nrk_kprintf (PSTR ("TDMA ERROR: creating rx signal failed\r\n"));
    nrk_kernel_error_add (NRK_SIGNAL_CREATE_ERROR, nrk_cur_task_TCB->task_ID);
    return NRK_ERROR;
  }
  tdma_tx_pkt_done_signal = nrk_signal_create ();
  if (tdma_tx_pkt_done_signal == NRK_ERROR) {
    nrk_kprintf (PSTR ("TDMA ERROR: creating tx signal failed\r\n"));
    nrk_kernel_error_add (NRK_SIGNAL_CREATE_ERROR, nrk_cur_task_TCB->task_ID);
    return NRK_ERROR;
  }
  tdma_enable_signal = nrk_signal_create ();
  if (tdma_enable_signal == NRK_ERROR) {
    nrk_kprintf (PSTR ("TDMA ERROR: creating enable signal failed\r\n"));
    nrk_kernel_error_add (NRK_SIGNAL_CREATE_ERROR, nrk_cur_task_TCB->task_ID);
    return NRK_ERROR;
  }


  // Set the one main rx buffer
  tdma_rx_pkt_set_buffer (tdma_rx_buf, TDMA_MAX_PKT_SIZE);
  tdma_rx_buf_empty = 1;
  tx_data_ready = 0;


  // Setup the radio 
  rf_init (&tdma_rfRxInfo, chan, 0xffff, my_mac);
  tdma_chan = chan;
  tdma_my_mac = my_mac;

  //FASTSPI_SETREG (CC2420_RSSI, 0xE580); // CCA THR=-25
  //FASTSPI_SETREG (CC2420_TXCTRL, 0x80FF);       // TX TURNAROUND = 128 us
  //FASTSPI_SETREG (CC2420_RXCTRL1, 0x0A56);
  // default cca thresh of -45
  rf_set_cca_thresh (-45);

  asm volatile ("":::"memory");
  tdma_running = 1;
  tdma_is_enabled = 1;
  return NRK_OK;
}
Beispiel #15
0
//------------------------------------------------------------------------------
//      void main (void)
//
//      DESCRIPTION:
//              Startup routine and main loop
//------------------------------------------------------------------------------
int main (void)
{
    uint8_t cnt,i,length;

    nrk_setup_ports(); 
    nrk_setup_uart (UART_BAUDRATE_115K2);
 
    printf( "Basic TX...\r\n" ); 
    nrk_led_set(0); 
    nrk_led_set(1); 
    nrk_led_clr(2); 
    nrk_led_clr(3); 
/*
	    while(1) {
		   
				for(i=0; i<40; i++ )
					halWait(10000);
		    nrk_led_toggle(1);

	    }

*/

    rfRxInfo.pPayload = rx_buf;
    rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
		nrk_int_enable();
    rf_init (&rfRxInfo, 13, 0x2420, 0x1214);
    cnt=0;
    while(1){
				nrk_led_set(GREEN_LED);
    		rfTxInfo.pPayload=tx_buf;
    		sprintf( tx_buf, "This is my string counter %d", cnt); 
    		rfTxInfo.length= strlen(tx_buf) + 1;
				rfTxInfo.destAddr = 0x1215;
				rfTxInfo.cca = 0;
				rfTxInfo.ackRequest = 0;
				
				printf( "Sending\r\n" );
				nrk_gpio_set(NRK_DEBUG_0);
				if(rf_tx_packet(&rfTxInfo) != 1)
					printf("--- RF_TX ERROR ---\r\n");
				nrk_gpio_clr(NRK_DEBUG_0);
				cnt++;
		
				for(i=0; i<80; i++ )
					halWait(10000);
				nrk_led_clr(GREEN_LED);
				for(i=0; i<20; i++ )
					halWait(10000);
		}

}
Beispiel #16
0
/**
 * Re-init the rf chip
 */
void rfhelp_restart(void) {
	chMtxLock(&rf_mutex);

	rf_init();
	rf_set_tx_addr(tx_addr, address_length);
	for (int i = 0;i < 6;i++) {
		if (rx_addr_set[i]) {
			rf_set_rx_addr(i, rx_addr[i], address_length);
		}
	}

	chMtxUnlock();
}
Beispiel #17
0
int main(void) {
	char message[] = "hello _+_re!";
	if(!rf_init())
		return 1;
	_delay_ms(1990);
	PORTD = 0x01;
	_delay_ms(10);
	PORTD = 0x00;
	_delay_ms(10);
	PORTD = 0x01;
	_delay_us(100);
	rf_send_block(message, strlen(message));
	return 0;
}
Beispiel #18
0
int main() 
{
	//! Инициализация портов для светодиодов.
	DDRF |= (1 << DDF0 | 1 << DDF1 | 1 << DDF2 | 1 << DDF3);
	uart_init();						//!< Инициализируем UART.
	// Устанавливаем функцию обратного вызова на прием байта по UART.
	uart_set_input_cb(uart_rx_cb);

	printf("%s\r\n", __TIME__);
	printf("LESO6 ATMEGA128RFA1\r\n");

	// Инициализация радио трансивера.
	rf_init();

	while(1);

	return 0;
}
Beispiel #19
0
int main()
{
	unsigned char idx;
	unsigned int i = 0;
	store_cpu_rate(16);
	P0_DIR &= ~0x28;
	P0_ALT &= ~0x28;

	rf_init();
	rf_configure(cfg);
	serial_init(19200);	
	eco_page_init();
	
	//long_function(4,6,8,4);

	msg[0] = 0x0A;
	msg[1] = 0x00;
	/* ADDR */
	msg[2] = 0x02;
	msg[3] = 0xA0;
	/* LEN */
	msg[4] = 0x02;
	msg[5] = 0xDD;
	msg[6] = 0xCC;
	
	for(idx = 4; idx > 0; idx--)
	{
		blink_led();		
		mdelay(300);
	}

	mdelay(1000);

	while(1)
	{
		blink4();
		rf_send(dst_addr, 3, msg, 7);
		blink2();
		mdelay(200);	
		blink6();
	}

	return 0;
}
/*
 * \brief Function initialises and registers the RF driver.
 *
 * \param none
 *
 * \return rf_radio_driver_id Driver ID given by NET library
 */
int8_t rf_device_register(void)
{
    rf_trx_part_e radio_type;

    if (0 != at24mac_read_eui64(atmel_MAC))
        return -1; //No MAC

    rf_init();

    radio_type = rf_radio_type_read();
    if(radio_type != ATMEL_UNKNOW_DEV)
    {
        /*Set pointer to MAC address*/
        device_driver.PHY_MAC = atmel_MAC;
        device_driver.driver_description = "ATMEL_MAC";
        //Create setup Used Radio chips
        if(radio_type == ATMEL_AT86RF212)
        {
            device_driver.link_type = PHY_LINK_15_4_SUBGHZ_TYPE;
        }
        else
        {
            device_driver.link_type = PHY_LINK_15_4_2_4GHZ_TYPE;
        }
        device_driver.phy_channel_pages = phy_channel_pages;
        /*Maximum size of payload is 127*/
        device_driver.phy_MTU = 127;
        /*No header in PHY*/
        device_driver.phy_header_length = 0;
        /*No tail in PHY*/
        device_driver.phy_tail_length = 0;
        /*Set address write function*/
        device_driver.address_write = &rf_address_write;
        /*Set RF extension function*/
        device_driver.extension = &rf_extension;
        /*Set RF state control function*/
        device_driver.state_control = &rf_interface_state_control;
        /*Set transmit function*/
        device_driver.tx = &rf_start_cca;
        /*Register device driver*/
        rf_radio_driver_id = arm_net_phy_register(&device_driver);
    }
    return rf_radio_driver_id;
}
Beispiel #21
0
int main (void) {

    board_init();
	#ifdef SIMULATE
	init_socket();
	#endif

    printf("JoyOS v"JOYOS_VERSION"\n");

	#ifndef SIMULATE
    init_thread();
    create_thread(&robot_monitor, STACK_DEFAULT, 0, "main");
    rf_init();
    schedule();
	#else 
	robot_monitor();
	#endif

}
Beispiel #22
0
//------------------------------------------------------------------------------
//      void main (void)
//
//      DESCRIPTION:
//              Startup routine and main loop
//------------------------------------------------------------------------------
int main (void)
{
    uint8_t cnt,i,length;

    nrk_setup_ports(); 
    nrk_setup_uart (UART_BAUDRATE_115K2);
 
    printf( "Basic TX...\r\n" ); 
    nrk_led_clr(0); 
    nrk_led_clr(1); 
    nrk_led_clr(2); 
    nrk_led_clr(3); 

    nrk_gpio_set(NRK_DEBUG_0);
    nrk_gpio_set(NRK_DEBUG_1);

    rfRxInfo.pPayload = rx_buf;
    rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
    rf_init (&rfRxInfo, 25, 0x2420, 0x1215);
    cnt=0;
    while(1)
	{
		nrk_led_set(1);
    		rfTxInfo.pPayload=tx_buf;
    		sprintf( tx_buf, "This is my string counter %d", cnt); 
    		rfTxInfo.length=strlen(&tx_buf);
    		rfTxInfo.cca=0;
		nrk_gpio_set(NRK_DEBUG_0);
		printf( "Sending\r\n" );
		rf_tx_packet (&rfTxInfo);
		nrk_gpio_clr(NRK_DEBUG_0);
		cnt++;
		for(i=0; i<10; i++ )
			halWait(10000);
		nrk_led_clr(1);
		for(i=0; i<10; i++ )
			halWait(10000);
	}


}
Beispiel #23
0
void main(void)
{
  disable_interrupt();
  
  clock_init();

  /* workaround to wait for LSM9DS0 ready */
  clock_delay_usec(60000);

  /* serial port */
  serial_init();

  /* one wire UART based LIN (ULIN) */
  ulin_init();

  /* real time timer */
  rtimer_init();

  /* radio configuration */
  rf_init(RADIO_CHANNEL);

  /* comment this line out to prevent bluetooth board from crashing */
  printf("\nSMAC2.0 - [%x:%x]\n", rf_get_short_addr1(), rf_get_short_addr0());
  
  enable_interrupt();

  /* module specific initialization - modules.h */
  module_init();

  /* flash bank used as storage */
  flash_bank_select(FLASH_BANK_7);

  /* looping services */
  while(1)
  {
    json_service();
    serial_service();
    ulin_service();
  }
}
Beispiel #24
0
void Task1 ()
{
  uint16_t cnt;
  uint8_t len,i;
  //printf ("My node's address is %d\r\n", NODE_ADDR);

  //printf ("Task1 PID=%d\r\n", nrk_get_pid ());


  rfRxInfo.pPayload = rx_buf;
  rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
  nrk_int_enable();
  rf_init (&rfRxInfo, 13, 0x2420, 0x1214);

  cnt = 0;
  slip_init (stdin, stdout, 0, 0);
	rf_rx_on();
  while (1) {
    


    while (rf_rx_packet_nonblock () != NRK_OK) {
      nrk_wait_until_next_period();

    }
		
		
    rx_packet_len = rfRxInfo.length;
    for(i=0; i<rfRxInfo.length; i++ ) slip_tx_buf[i]=rfRxInfo.pPayload[i];
		slip_tx_buf[10] = rfRxInfo.rssi;
		
    while(uart_tx_busy==1) nrk_wait_until_next_period();
    uart_tx_busy=1;
    slip_tx (slip_tx_buf, rx_packet_len);
    uart_tx_busy=0;
		

  }
}
Beispiel #25
0
int main(void)
{
  __disable_interrupt();
  sys_init();
  led(1);
  ADC10_Init();
  AFE_Init();
  rf_init();
  TACCR0 = 0xFFFF;  // запуск таймера
  __enable_interrupt();

  while (1)
  {
    if (rf_rx_data_ready_fg)
    {
      onRF_MessageReceived();
      rf_rx_data_ready_fg = 0;
    }

    if (packetDataReady)
    {
      uchar packetSize = assemblePacket();
      rf_send((uchar*) &packet_buf[0], packetSize);
      packetDataReady = 0;
    }

    if (rf_rx_data_ready_fg || packetDataReady)
    {
      ; // идем по циклу снова
    }
    else
    {
      __bis_SR_register(CPUOFF + GIE); // Уходим в спящий режим 
    }
  }
}
Beispiel #26
0
int8_t bmac_init (uint8_t chan)
{
    bmac_running=0;
    tx_reserve=-1;
    cca_active=true;
    rx_failure_cnt=0;
	
#ifdef NRK_SW_WDT
#ifdef BMAC_SW_WDT_ID

    _bmac_check_period.secs=30;
    _bmac_check_period.nano_secs=0;
    nrk_sw_wdt_init(BMAC_SW_WDT_ID, &_bmac_check_period, NULL );
    nrk_sw_wdt_start(BMAC_SW_WDT_ID);
#endif
#endif



    _bmac_check_period.secs=0;
    _bmac_check_period.nano_secs=BMAC_DEFAULT_CHECK_RATE_MS*NANOS_PER_MS;
	
	// SIGNAL
/*  bmac_rx_pkt_signal=nrk_signal_create();
    if(bmac_rx_pkt_signal==NRK_ERROR)
    {
        printf("BMAC ERROR: creating rx signal failed\r\n");
       // nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID); // commented out by madhur: error implementation has not been checked yet
        return NRK_ERROR;
    }
*/    bmac_tx_pkt_done_signal=nrk_signal_create();
    if(bmac_tx_pkt_done_signal==NRK_ERROR)
    {
        printf("BMAC ERROR: creating tx signal failed\r\n");
        //nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID);
        return NRK_ERROR;
    }
    bmac_enable_signal=nrk_signal_create();
    if(bmac_enable_signal==NRK_ERROR)
    {
        printf("BMAC ERROR: creating enable signal failed\r\n");
       // nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID);
        return NRK_ERROR;
    }
	

    tx_data_ready=0;
		
    // Set the one main rx buffer
    rx_buf_empty=0;
    bmac_rfRxInfo.pPayload = NULL;
    bmac_rfRxInfo.max_length = 0;

    // Setup the MRF24J40 chip
    rf_init (&bmac_rfRxInfo, chan, 0xffff, 0);
    g_chan=chan;

		/*
    FASTSPI_SETREG(CC2420_RSSI, 0xE580); // CCA THR=-25
    FASTSPI_SETREG(CC2420_TXCTRL, 0x80FF); // TX TURNAROUND = 128 us
    FASTSPI_SETREG(CC2420_RXCTRL1, 0x0A56);
    */
		
		// default cca thresh of -45
    //rf_set_cca_thresh(-45);
    rf_set_cca_thresh(-45);
		
		// Disable checking address field
		rf_addr_decode_disable();
		
    bmac_running=1;
    is_enabled=1;
    return NRK_OK;
}
Beispiel #27
0
/**
 * isa_init()
 *
 * This function sets up the low level link layer parameters.
 * This starts the main timer routine that will then automatically
 * trigger whenever a packet might be sent or received.
 * This should be called before ANY scheduling information is set
 * since it will clear some default values.
 *
 */
uint8_t isa_init (isa_node_mode_t mode, uint8_t id)
{
    uint8_t i;

    /* Generate signals */
    isa_rx_pkt_signal=nrk_signal_create();
    if(isa_rx_pkt_signal==NRK_ERROR){
	nrk_kprintf(PSTR("ISA ERROR: creating rx signal failed\r\n"));
	nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID);
	return NRK_ERROR;
    }
    isa_tx_done_signal=nrk_signal_create();
    if(isa_tx_done_signal==NRK_ERROR){
	nrk_kprintf(PSTR("ISA ERROR: creating tx signal failed\r\n"));
	nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID);
	return NRK_ERROR;
    }

    // No buffer to start with
    isa_rfRxInfo.pPayload = NULL;
    isa_rfRxInfo.max_length = 0;

    /*FIXME Actually we dont need to always run the high speed timer */
    _nrk_high_speed_timer_start();  

    /* clear everything out */
    global_cycle = 0;
    global_slot = MAX_ISA_GLOBAL_SLOTS;
    _isa_sync_ok = 0;
    slot_expired = 0;
    isa_node_mode = mode;
    isa_id = id;//change
    isa_rx_data_ready = 0;
    isa_tx_data_ready = 0;


    isa_param.mobile_sync_timeout = 100;
    isa_param.rx_timeout = 8000;   // 8000 *.125us = 1ms
    isa_param.tx_guard_time = TX_GUARD_TIME;
    isa_param.channel = 12;
    isa_param.mac_addr = 0x1980;

for (i = 0; i < ISA_SLOTS_PER_FRAME; i++) {
        isa_sched[i] = 0;
    }
    isa_tdma_rx_mask = 0;
    isa_tdma_tx_mask = 0;

    /* Setup the cc2420 chip */
    rf_init (&isa_rfRxInfo, isa_param.channel, 0x2420, isa_param.mac_addr);

    AFTER_FIRST_SYNC = 1;

    /* Setup fisrt hopping channel */
    #ifdef CHANNEL_HOPPING
	if(id!=0){
	    channelIndex = id-1;
	    currentChannel = channelPattern[channelIndex];    
	}else{
	    channelIndex = 0;
	    currentChannel = channelPattern[channelIndex];
	}
    #endif

    return NRK_OK;
}
Beispiel #28
0
int main(void)
{   
	int test_mode;
	int vm_present;
	int i;
	unsigned int seed;

	// Needs to be called ASAP as rf need a looooooong time to wake up.
	// This function is just sending a pulse over the SCL line.
	rf_wakeup();
	
	clock_set_speed(16000000UL,16);	
	
	setup_pps();
	setup_io();
	
	leds_init();

	CHARGE_500MA = 0; // Switch back to 100mA charge.
	
	// Switch on one led to say we are powered on
	leds_set(LED_BATTERY_0, 32);

	// Enable the poweroff softirq.
	_INT3IF = 0;
	_INT3IP = 1;
	_INT3IE = 1;

	// Sound must be enabled before analog, as 
	// The analog interrupt callback into sound processing ... 
	// But must be initialised _after_ leds as it use one led IO for enabling amp.
	sound_init();
	tone_init(); // Init tone generator
	
	pwm_motor_init();
	pid_motor_init();

	// We need the settings for the horizontal prox.
	load_settings_from_flash();


	for (i = 0; i < 2; i++) {
		// Settings is definitely wrong....
		if(settings.mot256[i] <= 0)
			settings.mot256[i] = 256;

		// 1024 (AD resolution is 10 bits) * 256 / 9 fits in signed 16 bits.
		if (settings.mot256[i] < 9)
			settings.mot256[i] = 9;
	}
	
	// This is the horizontal prox. Vertical one are handled by the ADC
	// but ADC sync the motor mesurment with the prox, so we don't pullute it with noise ...
	
	timer_init(TIMER_IR_COMM, 0,-1); // The period will be changed later.
	prox_init(PRIO_SENSORS);  // Same priority as analog (maybe should be at 7 ...)
	
	// Warning: We cannot use the SD before the analog init as some pin are on the analog port.
	analog_init(TIMER_ANALOG, PRIO_SENSORS);

        wait_valid_vbat();
        
	log_init(); // We will need to read vbat to be sure we can flash.

	ntc_init(ntc_callback, PRIO_1KHZ);

//	i2c_init(I2C_3);

	i2c_init_master(I2C_3, 400000, PRIO_I2C);
	I2C3CON = 0x9000;

	
	mma7660_init(I2C_3, MMA7660_DEFAULT_ADDRESS, acc_cb, 0);
	mma7660_set_mode(MMA7660_120HZ, 1);
	
	rc5_init(TIMER_RC5, rc5_callback, PRIO_RC5);
	
	sd_init();

	timer_init(TIMER_1KHZ, 1000, 6);
	timer_enable_interrupt(TIMER_1KHZ, timer_1khz, PRIO_1KHZ);
	
	rf_init(I2C_3);
	
	timer_enable(TIMER_1KHZ);
	
	sd_log_file();
	
	vm_present = init_aseba_and_fifo();
	
	if(vm_present) 
		log_analyse_bytecode();

	vmVariables.fwversion[0] = FW_VERSION;
	vmVariables.fwversion[1] = FW_VARIANT;
	
	// SD file is more important than internal flash
	if(!sd_load_aseba_code()) {
		log_set_flag(LOG_FLAG_VMCODESD);
		vm_present = 1;
		log_analyse_bytecode();
	}

	// Behavior is on INT4 (softirq trigged by 1khz timer).
	behavior_init(PRIO_BEHAVIOR);
	
	
	test_mode = sd_test_file_present();
	
	if(!test_mode)
		mode_init(vm_present);

	
	
	// Enable the LVD interrupt
	_LVDIE = 1;
	
	play_sound(SOUND_POWERON);
	
	if(test_mode) {	
		test_mode_start();
		while(1) 
			idle_without_aseba();
	}
	
	while(behavior_enabled(B_MODE)) 
		idle_without_aseba();
	
	// If usb did not put us out of behavior mode, then start the rf link
	if(!usb_uart_serial_port_open() && (rf_get_status() & RF_PRESENT)) {
		rf_set_link(RF_UP);
	}

	// get the random seed
	seed = 0;
	for(i = 0; i < 5; i++) {
		seed += vmVariables.buttons_mean[i];
		seed += vmVariables.buttons_noise[i];
	}
	seed += vmVariables.vbat[0];
	seed += vmVariables.vbat[1];
	
	for(i = 0; i < 3; i++) 
		seed += vmVariables.acc[i];
	
	AsebaSetRandomSeed(seed);
	
	for(i = 0; i < 3; i++)
		AsebaGetRandom();
	
	// Give full control to aseba. No way out (except reset).
	run_aseba_main_loop();
}
Beispiel #29
0
void rwip_init(uint32_t error)
{
    #if (NVDS_SUPPORT && DEEP_SLEEP)
    uint8_t length = 1;
    uint8_t sleep_enable;
    uint8_t ext_wakeup_enable;
    #endif //NVDS_SUPPORT && DEEP_SLEEP

    // Reset RW environment
    memset(&rwip_env, 0, sizeof(rwip_env));
	
	ke_mem_heaps_used = KE_MEM_BLOCK_MAX;

    #if (KE_SUPPORT)
    // Initialize kernel
    ke_init();
    // Initialize memory heap used by kernel.
    #if (KE_MEM_RW)
    // Memory allocated for environment variables

    //ke_mem_init(KE_MEM_ENV,           (uint8_t*)rwip_heap_env,     RWIP_HEAP_ENV_SIZE);
    ke_mem_init(KE_MEM_ENV,(uint8_t*)(jump_table_struct[rwip_heap_env_pos]),     jump_table_struct[rwip_heap_env_size]);	
    #if 1//(BLE_HOST_PRESENT)
    // Memory allocated for Attribute database
    //ke_mem_init(KE_MEM_ATT_DB,        (uint8_t*)rwip_heap_db,      RWIP_HEAP_DB_SIZE);
    ke_mem_init(KE_MEM_ATT_DB,(uint8_t*)(jump_table_struct[rwip_heap_db_pos]),      jump_table_struct[rwip_heap_db_size]);	
    #endif // (BLE_HOST_PRESENT)
    // Memory allocated for kernel messages
    //ke_mem_init(KE_MEM_KE_MSG,        (uint8_t*)rwip_heap_msg,     RWIP_HEAP_MSG_SIZE);
    ke_mem_init(KE_MEM_KE_MSG,(uint8_t*)(jump_table_struct[rwip_heap_msg_pos]),     jump_table_struct[rwip_heap_msg_size]);
    // Non Retention memory block
    //ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)rwip_heap_non_ret, RWIP_HEAP_NON_RET_SIZE);
    ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)(jump_table_struct[rwip_heap_non_ret_pos]), jump_table_struct[rwip_heap_non_ret_size]);


    #endif // (KE_MEM_RW)
    #endif //KE_SUPPORT

    #if (GTL_ITF)
    // Initialize the Generic Transport Layer
    gtl_init(rwip_eif_get(RWIP_EIF_AHI));
    #endif //GTL_ITF

    // Initialize RF
    #if (BT_EMB_PRESENT || BLE_EMB_PRESENT)
    rf_init(&rwip_rf);
    SetBits32(BLE_RADIOCNTL1_REG, XRFSEL, 3);

    #endif //BT_EMB_PRESENT || BLE_EMB_PRESENT

    #if (BT_EMB_PRESENT)
    // Initialize BT
    rwbt_init();
    #endif //BT_EMB_PRESENT

    #if (BLE_EMB_PRESENT)
    // Initialize BLE
    rwble_init();
    #endif //BLE_EMB_PRESENT

    #if (BLE_HOST_PRESENT)
    // Initialize BLE Host stack
    rwble_hl_init();
    #endif //BLE_HOST_PRESENT

    #if (DISPLAY_SUPPORT)
    // Initialize display module
    display_init();

    // Add some configuration information to display
    display_add_config();
    #endif //DISPLAY_SUPPORT

    #if (NVDS_SUPPORT && DEEP_SLEEP)
    // Activate deep sleep feature if enabled in NVDS
    if(nvds_get(NVDS_TAG_SLEEP_ENABLE, &length, &sleep_enable) == NVDS_OK)
    {
        if(sleep_enable != 0)
        {
            rwip_env.sleep_enable = true;

            // Set max sleep duration depending on wake-up mode
            if(nvds_get(NVDS_TAG_EXT_WAKEUP_ENABLE, &length, &ext_wakeup_enable) == NVDS_OK)
            {
                if(ext_wakeup_enable != 0)
                {
                    //vm  rwip_env.ext_wakeup_enable = true;
                    rwip_env.ext_wakeup_enable = ext_wakeup_enable;
                }
            }
        }
    }
    #endif //NVDS_SUPPORT && DEEP_SLEEP

    // If FW initializes due to FW reset, send the message to Host
    if(error != RESET_NO_ERROR)
    {
        #if (BT_EMB_PRESENT && HCIC_ITF)
        rwbt_send_message(error);
        #elif (BLE_EMB_PRESENT && HCIC_ITF)
        rwble_send_message(error);
        #elif (BLE_HOST_PRESENT && GTL_ITF)
        rwble_hl_send_message(error);
        #endif //BT_EMB_PRESENT / BLE_EMB_PRESENT
    }

    /*
     ************************************************************************************
     * Application initialization
     ************************************************************************************
     */
    // vm moved to main
    //    if(jump_table_struct[0]==TASK_APP)
    // Initialize APP
    //    app_init();

    func_check_mem_flag = 0;//false;
}
Beispiel #30
0
/**
 * isa_init()
 *
 * This function sets up the low level link layer parameters.
 * This starts the main timer routine that will then automatically
 * trigger whenever a packet might be sent or received.
 * This should be called before ANY scheduling information is set
 * since it will clear some default values.
 *
 */
uint8_t isa_init (isa_node_mode_t mode, uint8_t id, uint8_t src_id)
{
    uint8_t i;

    /* Generate signals */
    isa_rx_pkt_signal=nrk_signal_create();
    if(isa_rx_pkt_signal==NRK_ERROR){
	nrk_kprintf(PSTR("ISA ERROR: creating rx signal failed\r\n"));
	nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID);
	return NRK_ERROR;
    }
    isa_tx_done_signal=nrk_signal_create();
    if(isa_tx_done_signal==NRK_ERROR){
	nrk_kprintf(PSTR("ISA ERROR: creating tx signal failed\r\n"));
	nrk_kernel_error_add(NRK_SIGNAL_CREATE_ERROR,nrk_cur_task_TCB->task_ID);
	return NRK_ERROR;
    }

    // No buffer to start with
    isa_rfRxInfo.pPayload = NULL;
    isa_rfRxInfo.max_length = 0;

    /*FIXME Actually we dont need to always run the high speed timer */
    _nrk_high_speed_timer_start();  

    /* clear everything out */
    global_cycle = 0;
    global_slot = MAX_ISA_GLOBAL_SLOTS;
    _isa_sync_ok = 0;
    _isa_join_ok = 0;
    slot_expired = 0;
    isa_node_mode = mode;
    isa_id = id;//change
    isa_clk_src_id=src_id; //change
    isa_rx_data_ready = 0;
    isa_tx_data_ready = 0;


    isa_param.mobile_sync_timeout = 100;
    isa_param.rx_timeout = 8000;   // 8000 *.125us = 1ms
    isa_param.tx_guard_time = TX_GUARD_TIME;
    isa_param.channel = 15;
    isa_param.mac_addr = 0x1980;

for (i = 0; i < ISA_SLOTS_PER_FRAME; i++) {
        isa_sched[i] = 0;
    }
    isa_tdma_rx_mask = 0;
    isa_tdma_tx_mask = 0;

    /* Setup the cc2420 chip */
    rf_init (&isa_rfRxInfo, isa_param.channel, 0x2420, isa_param.mac_addr);

    AFTER_FIRST_SYNC = 1;

    /* Setup fisrt hopping channel */
    #ifdef CHANNEL_HOPPING
	slowIndex=0; 
	if(id!=0){
	    channelIndex = src_id;
	    currentChannel = slottedPattern[channelIndex];   
	}else{
	    channelIndex = 0;
	    currentChannel = slottedPattern[channelIndex];
	}
	isa_set_channel(currentChannel);
    #endif

    #ifdef JOIN_PROCESS
	if(mode==ISA_GATEWAY){
	   for(i=22;i<=24;i++){
		isa_tx_info[i].pPayload = join_pkt_buf;
    		isa_tx_info[i].length = PKT_DATA_START+1;    // pass le pointer
    		isa_tx_info[i].DHDR = configDHDR();
    		isa_tx_data_ready |= ((uint32_t) 1 << i);        // set the flag
	   }
        }
    #endif

    return NRK_OK;
}