Exemplo n.º 1
0
static void setupNVIC() {
#ifdef VECT_TAB_FLASH
    nvic_init(USER_ADDR_ROM, 0);
#elif defined VECT_TAB_RAM
    nvic_init(USER_ADDR_RAM, 0);
#elif defined VECT_TAB_BASE
    nvic_init((uint32)0x08000000, 0);
#else
#error "You must select a base address for the vector table."
#endif
}
Exemplo n.º 2
0
static void setupNVIC() {
#ifdef VECT_TAB_FLASH  //this define is coming from compile -D option
	//[ROBOTIS][CHANGE]support for cm-900, to excute it @0x08003000 by ROBOTIS[[email protected]]
	//0x08000000~0x08003000 -> cm-900 bootloader, 0x08003000 ~ application
	nvic_init(NVIC_VectTab_FLASH, 0x3000);//nvic_init(USER_ADDR_ROM, 0);
#elif defined VECT_TAB_RAM
    nvic_init(USER_ADDR_RAM, 0);
#elif defined VECT_TAB_BASE
    nvic_init((uint32)0x08000000, 0);
#else
#error "You must select a base address for the vector table."
#endif
}
Exemplo n.º 3
0
int main(void)
{
    uint8_t current_state = 0;				// Used to store the current state of TX state machine
    uint16_t pulse_count = 0;					// Used to store the current number of pulses

    GPIO_init();
    init_timer_0A();
    init_timer_0B();
    nvic_init();
    PWM_init();

    // IR Rx GPIO port (PB4) for asynch receive
    init_IR_rx();

    // Delay for microcontroller clock to stabilize
    delay_timer_0A(500);
    current_state = 1;  // Activate the tx_state_machine

    while(1)
    {
        // If the 562us timer expired then it is time to update state machine
        /*
        if (mod_period_flag) {
        	mod_period_flag = 0;
        	tx_state_machine(&current_state, &pulse_count, IR_address,  IR_data_GREEN);	  //<--- TX CHANGE HERE!!
        }
        */

        // If RX port senses an edge, store the timer count
        if (rx_interrupt_flag) {
            rx_interrupt_flag = 0;
            rx_handler();
        }
    }
}
Exemplo n.º 4
0
void comm_init(u32 baud)
{  	 
	float temp;
	u16 mantissa, fraction;
		   
	RCC->APB2ENR |= 1 << 4;   	//使能PORTC口时钟  OK
	RCC->APB1ENR |= 1 << 19;  	//使能串口时钟 		OK
	GPIOC->CRH &= 0XFFFF00FF; 
	GPIOC->CRH |= 0X00008B00;		//IO状态设置	 OK
		  
	RCC->APB1RSTR |= (1 << 19);   	//复位串口4		OK
	RCC->APB1RSTR &= ~(1 << 19);	//停止复位	   	OK 

	//波特率设置
	temp = (float)(PCLK1_FREQ / (baud * 16));	//得到USARTDIV
	mantissa = temp;						 	//得到整数部分
	fraction = (temp - mantissa) * 16; 			//得到小数部分	 
    mantissa <<= 4;
	mantissa += fraction; 
 	UART4->BRR = mantissa; // 波特率设置	 
	UART4->CR1 |= 0X200C;  // 1位停止,无校验位.

	//使能接收中断
	UART4->CR1 |= (1 << 8);    //PE中断使能
	UART4->CR1 |= (1 << 5);    //接收缓冲区非空中断使能	    	
	nvic_init(3, 3, UART4_IRQChannel, 2);//组2,最低优先级 
}
Exemplo n.º 5
0
void sx1276_cfg_init()
{
    gpio_init();
    spi_init();
    exti_set(ENABLE);
    nvic_init();
}
Exemplo n.º 6
0
/*
 * Initialize the interrupt processing subsystem.
 */
static void __init stm32_init_irq(void)
{
	/*
	 * Initialize NVIC. All interrupts are masked initially.
	 */
	nvic_init();
}
Exemplo n.º 7
0
static void setup_nvic(void) {
#ifdef VECT_TAB_FLASH
    nvic_init(USER_ADDR_ROM, 0);
#elif defined VECT_TAB_RAM
    nvic_init(USER_ADDR_RAM, 0);
#elif defined VECT_TAB_BASE
    nvic_init((uint32)0x08000000, 0);
#elif defined VECT_TAB_ADDR
    // A numerically supplied value
    nvic_init((uint32)VECT_TAB_ADDR, 0);
#else
    // Use the __text_start__ value from the linker script; this
    // should be the start of the vector table.
    nvic_init((uint32)&__text_start__, 0);
#endif
}
Exemplo n.º 8
0
void uart5_init(u32 baud)
{  	 
	float temp;
	u16 mantissa, fraction;
		   
	RCC->APB2ENR |= 1 << 4;   //使能PORTC口时钟    OK
	RCC->APB2ENR |= 1 << 5;   //使能PORTD口时钟    OK
	RCC->APB1ENR |= 1 << 20;  	//使能串口时钟 	   OK
	GPIOC->CRH &= 0XFFF0FFFF; 
	GPIOC->CRH |= 0X000B0000;	//IO状态设置	OK
	GPIOD->CRL &= 0XFFFFF0FF; 
	GPIOD->CRL |= 0X00000800;	//IO状态设置	OK	 
		  
	RCC->APB1RSTR |= (1 << 20);   	//复位串口5	   OK
	RCC->APB1RSTR &= ~(1 << 20);	//停止复位	   OK  

	//波特率设置
	temp = (float)(PCLK1_FREQ / (baud * 16));	//得到USARTDIV
	mantissa = temp;						 	//得到整数部分
	fraction = (temp - mantissa) * 16; 			//得到小数部分	 
    mantissa <<= 4;
	mantissa += fraction; 
 	USART5->BRR = mantissa; // 波特率设置	 
	USART5->CR1 |= 0X200C;  //1位停止,无校验位.

#ifdef EN_USART5_RX		  //如果使能了接收
	//使能接收中断
	USART5->CR1 |= (1 << 8);    //PE中断使能
	USART5->CR1 |= (1 << 5);    //接收缓冲区非空中断使能	    	
	nvic_init(3, 3, USART5_IRQChannel, 2);//组2,最低优先级 
#endif
}
Exemplo n.º 9
0
void init(void* arg)
{
	board_init();
	nvic_init();
	debug_init();
	demo_init();
	debug("init thread exit!\r\n");
}
Exemplo n.º 10
0
//实时时钟配置
//初始化RTC时钟,同时检测时钟是否工作正常
//BKP->DR1用于保存是否第一次配置的设置
//返回0:正常
//其他:错误代码
u8 rtc_init(void)
{
	//检查是不是第一次配置时钟
	u8 temp=0;
	if (BKP->DR1 != 0X5050)//第一次配置
	{	 
	  	RCC->APB1ENR |= 1<<28;     //使能电源时钟	    
		RCC->APB1ENR |= 1<<27;     //使能备份时钟	    
		PWR->CR |= 1<<8;           //取消备份区写保护
		RCC->BDCR |= 1<<16;        //备份区域软复位	   
		RCC->BDCR &= ~(1<<16);     //备份区域软复位结束	  	 
	    RCC->BDCR |= 1<<0;         //开启外部低速振荡器 
	    while ((!(RCC->BDCR&0X02)) && temp < 250)//等待外部时钟就绪	 
		{
			temp++;
			delay_ms(10);
		};
		if(temp>=250)
			return 1;//初始化时钟失败,晶振有问题	    

		RCC->BDCR |= 1<<8; 			//LSI作为RTC时钟 	    
		RCC->BDCR |= 1<<15;			//RTC时钟使能	  
	  	while (!(RTC->CRL & (1<<5)))
			;						//等待RTC寄存器操作完成	 
    	while (!(RTC->CRL & (1<<3)))
			;   					//等待RTC寄存器同步  
    	RTC->CRH |= 0X01;  		  	//允许秒中断
    	while (!(RTC->CRL & (1<<5)))
			;						//等待RTC寄存器操作完成	 
		RTC->CRL |= 1<<4;     		//允许配置	   
		RTC->PRLH = 0X0000;
		RTC->PRLL = 32767;             //时钟周期设置(有待观察,看是否跑慢了?)理论值:32767										 
		//auto_time_set();
		
		//rtc_set(2009,12,2,10,0,55);  //设置时间	  
		RTC->CRL &= ~(1<<4);           //配置更新
		while(!(RTC->CRL&(1<<5)))
			;   						//等待RTC寄存器操作完成		 									  
		BKP->DR1 = 0X5050;
		//BKP_Write(1,0X5050);;			//在寄存器1标记已经开启了 
		//printf("FIRST TIME\n");
	}else//系统继续计时
	{
    	while (!(RTC->CRL & (1 << 3)))
			;							//等待RTC寄存器同步  
			
    	RTC->CRH |= 0X01;  		  		//允许秒中断
    	while (!(RTC->CRL & (1 << 5)))
			;							//等待RTC寄存器操作完成
		//printf("OK\n");
	}		
		
	nvic_init(0,0,RTC_IRQChannel,2);	//RTC,G2,P2,S2.优先级最低     
	rtc_get();//更新时间 
	return 0; //ok
}
Exemplo n.º 11
0
void config_nvic(void) {
    nvic_config_prigroup(NVIC_PriGroup_2);
    // TIM6 中断配置
    nvic_conf_t conf;
    conf.IRQn = TIM6_IRQn;
    //conf.IRQn = TIM2_IRQn;
    conf.pre_prior = 1;
    conf.sub_prior = 2;
    conf.enale = 1;
    nvic_init(&conf);
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: hsjia/DIY
int main(void){
	usart1_init();
	can1_init();
	nvic_init();
	dma_init();
	
	while(1){
		if((obd_mode != 0xff) && (obd_pid != 0xff)){
			obd_cmd_parse(obd_mode, obd_pid);
		}
//		while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
//		while(DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET);
	}
}
Exemplo n.º 13
0
int main(void)
{
	char display_string1[] = "*Hello Amigos. Rolling Banner!*";
	char display_string2[] = "+-+-+-+-+";
	uint8_t i;
	
	init_gpio();			// Initialize GPIO	
  	init_timer_A();		// Initialize TIMER0->TIMERA as 16-bit, one-shot and counts down
	init_timer_B();		// Init TIMER0B as 16-bit, periodic and counts down
	nvic_init();			// Init NVIC for TIMER0B
	init_pushButton();	
		
	// Initialize LCD display
	LCD_init();
	PWM_init();	

	for(i=0; display_string1[i] != '\0'; i++)
	{
		send_data(display_string1[i]);
		delay_timer(100);
		
		// Since screen has enough to display 16 chars per line, if going off line, start shifting screen.
		if ( i >= 14 )
			send_command(0x18);
	}
	send_command(0x2);		// Return cursor home
	send_command(0xC0);		// Go to line 2

	for(i=0; display_string2[i] != '\0'; i++)
	{
		send_data(display_string2[i]);
		delay_timer(100);
		
		// Since screen has enough to display 16 chars per line, if going off line, start shifting screen.
		if ( i >= 14 )
			send_command(0x18);
	}
	
	interrupt_timer(scroll_delay);		// Interrupt timer handler scrolls the screen
	//send_command(0x18);		// Shift display to the right by 1
	//send_command(0x8);		// Turn display off
	//send_command(0xF);		// Turn display on, cursor ON, cursor position ON
	//GPIOF->DATA |= (1UL << 3);    //LED ON
	//GPIOF->DATA &= ~(1UL << 3);		//LED OFF
	while(1)
	{}
}
Exemplo n.º 14
0
static void setup_nvic(void) {

nvic_init((uint32)VECT_TAB_ADDR, 0);

/* Roger Clark. We now control nvic vector table in boards.txt using the build.vect paramater
#ifdef VECT_TAB_FLASH
    nvic_init(USER_ADDR_ROM, 0);
#elif defined VECT_TAB_RAM
    nvic_init(USER_ADDR_RAM, 0);
#elif defined VECT_TAB_BASE
    nvic_init((uint32)0x08000000, 0);
#elif defined VECT_TAB_ADDR
    // A numerically supplied value
    nvic_init((uint32)VECT_TAB_ADDR, 0);
#else
    // Use the __text_start__ value from the linker script; this
    // should be the start of the vector table.
    nvic_init((uint32)&__text_start__, 0);
#endif

*/
}
Exemplo n.º 15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval : None
  */
int main(void)
{
    int i;    
    stopwatch_reset(&stopwatch);
	
    /*
     * Enable peripherals
     */
    rcc_init();
    gpio_init();
    nvic_init();
    usart_init();
    tim_init();

    delay_ms(1000);
    
	iprintf(ANSI_CLRSCR ANSI_BOLD("STM32 Stopwatch") " rev %s, built on %s.\r\n", build_git_description, build_git_time);
	iprintf("(c) Sami Kujala, 2012. https://github.com/skujala/stm32-stopwatch\r\n");
    iprintf("Initialization complete.\r\n");
    LED_GPIO->BSRR = (1 << BLUE_LED_PIN);

    
    while (1) {
        if (stopwatch.counter == COUNTER_STOPPED){
            for (i = 0; i < 10; i++) {
                LED_GPIO->ODR ^= (1 << BLUE_LED_PIN);
                delay_ms(50);                
            }
            iprintf("Elapsed time: " ANSI_BOLD("%d") " ms.\r\n", TIMER_COUNTS_IN_MS(stopwatch.counts_elapsed));
                
            stopwatch_reset(&stopwatch);
        }
    }

    return 0;
}
Exemplo n.º 16
0
static void __init uwic_init_irq(void)
{
  nvic_init();
}
Exemplo n.º 17
0
/**
**===========================================================================
**
**  Abstract: main program
**
**===========================================================================
*/
int main(void)
{
#if SYS_STARTUP == 0
  SystemInit();
#endif

  nvic_init();			// настройка векторов прерываний
  led_init();			// инициализация светодиода, индицирующего работу процессора
  init_calendar();		// инициализация календаря
  _SPI_init();			// SPI для внешней FRAM

  // чтение заводских установок

  read_data(0x7B,0x00,128,(unsigned char*)&_Sys.FR.b1[0]);
  read_data(0x7B,0x80,128,(unsigned char*)&_Sys.FR.b1[0x80]);
  read_data(0x7C,0x00,128,(unsigned char*)&_Sys.FR.b1[0x100]);
  read_data(0x7C,0x80,128,(unsigned char*)&_Sys.FR.b1[0x180]);
  read_data(0x7D,0x00,128,(unsigned char*)&_Sys.FR.b1[0x200]);
  read_data(0x7D,0x80,128,(unsigned char*)&_Sys.FR.b1[0x280]);
  read_data(0x7E,0x00,128,(unsigned char*)&_Sys.FR.b1[0x300]);
  read_data(0x7E,0x80,128,(unsigned char*)&_Sys.FR.b1[0x380]);

  // чтение системных настроек контроллера

  //read_data(0x7F,0x58,1,&rf_ch);

  read_data(0x7F,0x00,6,(unsigned char*)&_Sys.Mem.b1[0]);

  _Sys.Adr=_Sys.Mem.b1[0];
  if((_Sys.Adr==0)||(_Sys.Adr==0xFF)) _Sys.Adr=0x01;

  _Sys.Can1_Baudrate=_Sys.Mem.b1[1];
  if(_Sys.Can1_Baudrate>5) _Sys.Can1_Baudrate=5;
  _Sys.Can1_Type = _Sys.Mem.b1[2];
  if(_Sys.Can1_Type>1) _Sys.Can1_Type=0;

  _Sys.Can2_Baudrate=_Sys.Mem.b1[3];
  if(_Sys.Can2_Baudrate>5) _Sys.Can2_Baudrate=5;
  _Sys.Can2_Type = _Sys.Mem.b1[4];
  if(_Sys.Can2_Type>1) _Sys.Can2_Type=0;

  emu_mode = _Sys.Mem.b1[5];
  if(emu_mode>2) emu_mode=0;

  read_data(0x7F,0x4C,4,ip_addr);set_ip(ip_addr);
  read_data(0x7F,0x50,6,mac_addr);set_mac(mac_addr);
  read_data(0x7F,0x5A,4,ip_gate);set_gate(ip_gate);
  read_data(0x7F,0x5E,1,&modbus_master_emu);
  read_data(0x7F,0x5F,4,ip_mask);set_mask(ip_mask);
  
#if FRAM_YEAR
  read_data(0x7F,0x56,1,(unsigned char*)&times.year);
  if(times.year>99) times.year=0;
#endif

  read_data(0x7F,0x57,1,(unsigned char*)&pult_dis);
  read_data(0x7F,0x59,1,(unsigned char*)&sd_dis);

/*  read_data(0x7F,0x5A,32,ssid_name);
  read_data(0x7F,0x7A,32,wifi_password);
  read_data(0x7F,0x9A,1,&wifi_type);
  read_data(0x7F,0x9B,4,wifi_ip);*/

  // начальные значения номеров строк пульта
  _Sys.S1=0x00;_Sys.S2=0x00;_Sys.S3=0x00;_Sys.S4=0x00;

  // системные миллисекундные задачи
  xTaskCreate( R1Task, ( signed portCHAR * ) "R1", configMINIMAL_STACK_SIZE*2, NULL, R1_TASK_PRIORITY, NULL );
  xTaskCreate( R5Task, ( signed portCHAR * ) "R5", configMINIMAL_STACK_SIZE*2, NULL, R5_TASK_PRIORITY, NULL );
  xTaskCreate( R10Task, ( signed portCHAR * ) "R10", configMINIMAL_STACK_SIZE*2, NULL, R10_TASK_PRIORITY, NULL );
  xTaskCreate( R100Task, ( signed portCHAR * ) "R100", configMINIMAL_STACK_SIZE*2, NULL, R100_TASK_PRIORITY, NULL );
  xTaskCreate( R1000Task, ( signed portCHAR * ) "R1000", configMINIMAL_STACK_SIZE*2, NULL, R1000_TASK_PRIORITY, NULL );
  // служебная вспомогательная задача (светодиод,фильтр ацп,...)
  xTaskCreate( prvFlashTask, (signed portCHAR *) "Flash", configMINIMAL_STACK_SIZE*2, NULL, mainFLASH_TASK_PRIORITY, NULL );
  // стандартный пульт или коммуникационный канал
  if(pult_dis!=0x31) xTaskCreate( LCDTask, ( signed portCHAR * ) "Lcd", configMINIMAL_STACK_SIZE*2, NULL, LCD_TASK_PRIORITY, NULL );
    else xTaskCreate( PultCanTask, ( signed portCHAR * ) "Lcd", configMINIMAL_STACK_SIZE*5, NULL, Canal_TASK_PRIORITY, NULL );
  // задача обработки входов/выходов включая модули расширения
  xTaskCreate( InOutTask, ( signed portCHAR * ) "InOut", configMINIMAL_STACK_SIZE*2, NULL, InOut_TASK_PRIORITY, NULL );
  // два основных коммуникационных канала RS485
  if(_Sys.Can1_Type==0) xTaskCreate( BinCanTask, ( signed portCHAR * ) "Canal", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL );
  else xTaskCreate( AsciiCanTask, ( signed portCHAR * ) "Canal", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL );
  if(_Sys.Can2_Type==0) xTaskCreate( BinCan2Task, ( signed portCHAR * ) "Canal2", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL );
  else xTaskCreate( AsciiCan2Task, ( signed portCHAR * ) "Canal2", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL );
  // WIFI задачи
/*  if(wifi_ip[0])
  {
    xTaskCreate( WIFITask, ( signed portCHAR * ) "Wifi", configMINIMAL_STACK_SIZE, NULL, WF_TASK_PRIORITY, NULL );
    xTaskCreate( SCAN_WIFITask, ( signed portCHAR * ) "SCANWifi", configMINIMAL_STACK_SIZE, NULL, WF_TASK_PRIORITY+1, NULL );
  }*/
  // проводной ethernet
  if(ip_addr[0]) xTaskCreate( EthTask, ( signed portCHAR * ) "Eth", configMINIMAL_STACK_SIZE*3, NULL, ETH_TASK_PRIORITY, NULL );
  // задача работы с sd картой
  if(sd_dis==0x31) xTaskCreate( ArchiveTask, ( signed portCHAR * ) "SD_Task", configMINIMAL_STACK_SIZE*2, NULL, SD_TASK_PRIORITY, NULL );

  Relkon_init(); // блок инициализации - формируется верхним уровнем (раздел #init релкона)

  init_timer();	// аппаратный таймер для определения загрузки процессора
  vTaskStartScheduler();  // старт планировщика задач
  while (1){}
}
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  sys_ctrl_init();
  clock_init();
  dint();
  /*Init Watchdog*/
  watchdog_init();//Need to check the watchdog on 123gxl

  rtimer_init();
  lpm_init();  
  gpio_init();
  ioc_init();

  leds_init();
  fade(LEDS_YELLOW);
  button_sensor_init();

  /*
   * Character I/O Initialisation.
   * When the UART receives a character it will call serial_line_input_byte to
   * notify the core. The same applies for the USB driver.
   *
   * If slip-arch is also linked in afterwards (e.g. if we are a border router)
   * it will overwrite one of the two peripheral input callbacks. Characters
   * received over the relevant peripheral will be handled by
   * slip_input_byte instead
   */
#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  /*Enable EA*/
  eint();
  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);
  PRINTF("=================================\r\n");
  PUTS(CONTIKI_VERSION_STRING);
  PRINTF("======================\r\n");  
  PRINTF("\r\n");
  PUTS(BOARD_STRING);
  PRINTF("\r\n");

#ifdef NODEID
  node_id = NODEID;
#ifdef BURN_NODEID
  node_id_burn(node_id);
  node_id_restore(); /* also configures node_mac[] */
#endif /* BURN_NODEID */
#else
  node_id_restore(); /* also configures node_mac[] */
#endif /* NODE_ID */

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef MAC_1
  {
    uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 };
    memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
  }
#endif

  /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&sensors_process, NULL);
  button_sensor_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  set_rime_addr();
  printf("finish addr seting\r\n");

  /* Initialise the H/W RNG engine. */
  random_init(0);

  udma_init();

  if(node_id > 0) {
    printf("Node id %u.\r\n", node_id);
  } else {
    printf("Node id not set.\r\n");
  }

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
  /* Setup nullmac-like MAC for 802.15.4 */

  queuebuf_init();

  netstack_init();
  PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID);  
  cc2538_rf_set_addr(IEEE802154_PANID);

  printf("%s/%s %lu %u\r\n",
         NETSTACK_RDC.name,
         NETSTACK_MAC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);

  printf("IPv6 ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\r\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(1) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xfc00, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\r\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  netstack_init();
  PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID);  
  cc2538_rf_set_addr(IEEE802154_PANID);
  
  printf("%s %lu %u\r\n",
         NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);
#endif /* WITH_UIP6 */

#if !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

#ifdef NETSTACK_AES_H
#ifndef NETSTACK_AES_KEY
#error Please define NETSTACK_AES_KEY!
#endif /* NETSTACK_AES_KEY */
  {
    const uint8_t key[] = NETSTACK_AES_KEY;
    netstack_aes_set_key(key);
  }
  /*printf("AES encryption is enabled: '%s'\n", NETSTACK_AES_KEY);*/
  printf("AES encryption is enabled\r\n");
#else /* NETSTACK_AES_H */
  printf("Warning: AES encryption is disabled\r\n");
#endif /* NETSTACK_AES_H */

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
#endif /* TIMESYNCH_CONF_ENABLED */  

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  simple_rpl_init();
  /*Watch dog configuration*/
  watchdog_periodic();
  watchdog_start();

  autostart_start(autostart_processes);

  //duty_cycle_scroller_start(CLOCK_SECOND * 2);
#if IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP && WITH_SLIP
  /* Start the SLIP */
  printf("Initiating SLIP: my IP is 172.16.0.2...\r\n");
  slip_arch_init(0);
  {
    uip_ip4addr_t ipv4addr, netmask;

    uip_ipaddr(&ipv4addr, 172, 16, 0, 2);
    uip_ipaddr(&netmask, 255, 255, 255, 0);
    ip64_set_ipv4_address(&ipv4addr, &netmask);
  }
  uart1_set_input(slip_input_byte);
#endif /* IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP */

  fade(LEDS_ORANGE);

  /*
   * This is the scheduler loop.
   */
  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      // printf("reset watchdog\r\n");
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
Exemplo n.º 19
0
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();

  leds_init();
  fade(LEDS_YELLOW);

  process_init();

  watchdog_init();
  button_sensor_init();

  /*
   * Character I/O Initialisation.
   * When the UART receives a character it will call serial_line_input_byte to
   * notify the core. The same applies for the USB driver.
   *
   * If slip-arch is also linked in afterwards (e.g. if we are a border router)
   * it will overwrite one of the two peripheral input callbacks. Characters
   * received over the relevant peripheral will be handled by
   * slip_input_byte instead
   */
#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);

  PRINTF(" Net: ");
  PRINTF("%s\n", NETSTACK_NETWORK.name);
  PRINTF(" MAC: ");
  PRINTF("%s\n", NETSTACK_MAC.name);
  PRINTF(" RDC: ");
  PRINTF("%s\n", NETSTACK_RDC.name);

  /* Initialise the H/W RNG engine. */
  random_init(0);

  udma_init();

  process_start(&etimer_process, NULL);
  ctimer_init();

  set_rf_params();

#if CRYPTO_CONF_INIT
  crypto_init();
  crypto_disable();
#endif

  netstack_init();

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

  adc_init();

  process_start(&sensors_process, NULL);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_ORANGE);

  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
Exemplo n.º 20
0
/**
 * \brief Main routine for the cc2538dk platform
 */
int main(void) {
	// Just for test purposes
	uint16_t temperature = 0;
	uint16_t humidity = 0;
	float* temperature_f;
	float* humidity_f;
	unsigned char* checksum;
	unsigned char status;
	unsigned char temp_data = 0xff;
	/* unsigned char err = 0;  SHT11 disabled */

	nvic_init();
	sys_ctrl_init();
	clock_init();
	lpm_init();
	rtimer_init();
	gpio_init();
	ioc_init();
	i2c_init();

	leds_init();
	fade(LEDS_YELLOW);

	process_init();

	watchdog_init();
	button_sensor_init();

	/*
	 * Character I/O Initialisation.
	 * When the UART receives a character it will call serial_line_input_byte to
	 * notify the core. The same applies for the USB driver.
	 *
	 * If slip-arch is also linked in afterwards (e.g. if we are a border router)
	 * it will overwrite one of the two peripheral input callbacks. Characters
	 * received over the relevant peripheral will be handled by
	 * slip_input_byte instead
	 */
#if UART_CONF_ENABLE
	uart_init();
	uart_set_input(serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
	usb_serial_init();
	usb_serial_set_input(serial_line_input_byte);
#endif

	serial_line_init();

	INTERRUPTS_ENABLE();
	fade(LEDS_GREEN);

	PUTS(CONTIKI_VERSION_STRING);PUTS(BOARD_STRING);

	PRINTF(" Net: ");PRINTF("%s\n", NETSTACK_NETWORK.name);PRINTF(" MAC: ");PRINTF("%s\n", NETSTACK_MAC.name);PRINTF(" RDC: ");PRINTF("%s\n", NETSTACK_RDC.name);

	/* Initialise the H/W RNG engine. */
	random_init(0);

	udma_init();

	process_start(&etimer_process, NULL);
	ctimer_init();

	set_rime_addr();
	netstack_init();
	cc2538_rf_set_addr(IEEE802154_PANID);

#if UIP_CONF_IPV6
	memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr));
	queuebuf_init();
	process_start(&tcpip_process, NULL);
#endif /* UIP_CONF_IPV6 */

	process_start(&sensors_process, NULL);

	energest_init();
	ENERGEST_ON(ENERGEST_TYPE_CPU);

	autostart_start(autostart_processes);

	watchdog_start();
	fade(LEDS_ORANGE);

	while (1) {
		uint8_t r;
		do {
			/* Reset watchdog and handle polls and events */
			watchdog_periodic();

			r = process_run();
/*
			err = s_measure(&temperature, checksum, TEMP);

			if (err == 0)
			{
				PRINTF("Temperature (ADC value) = 0x%4x\n", temperature);

				err = s_measure(&humidity, checksum, HUMI);

				if (err == 0)
				{
					PRINTF("Humidity (ADC value) = 0x%4x\n", humidity);

					float tc=sht11_TemperatureC(temperature);
					float hc=sht11_Humidity(temperature,humidity);
					printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
				}
				else
					PRINTF("SHT11 error - could not read humidity!\n");
			}
			else
				PRINTF("SHT11 error - could not read temperature!\n");
*/
			/*err = s_write_statusreg(&temp_data);
			if (err == 0)
			{
				err = s_read_statusreg(&status, checksum);
				if (err == 0)
					PRINTF("STATUS REGISTER = 0x%2x", status);
				else
					PRINTF("SHT11 error - could not read status register!\n");
			}*/

		} while (r > 0);

		/* We have serviced all pending events. Enter a Low-Power mode. */
		lpm_enter();
	}
}
Exemplo n.º 21
-1
/**
 * \brief Main routine for the OpenMote-CC2538 platforms
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();
  leds_init();
  fade(LEDS_RED);
  process_init();
  watchdog_init();

#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_BLUE);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);
#if STARTUP_CONF_VERBOSE
  soc_print_info();
#endif

  random_init(0);

  udma_init();

  process_start(&etimer_process, NULL);
  ctimer_init();

  board_init();

#if CRYPTO_CONF_INIT
  crypto_init();
  crypto_disable();
#endif

  netstack_init();
  set_rf_params();

  PRINTF("Net: ");
  PRINTF("%s\n", NETSTACK_NETWORK.name);
  PRINTF("MAC: ");
  PRINTF("%s\n", NETSTACK_MAC.name);
  PRINTF("RDC: ");
  PRINTF("%s\n", NETSTACK_RDC.name);

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

  process_start(&sensors_process, NULL);

  SENSORS_ACTIVATE(button_sensor);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_GREEN);

  while(1) {
    uint8_t r;
    do {
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    lpm_enter();
  }
}