示例#1
0
static int bma250_set_power(bool enable)
{
    int err = 0;
    if(enable != power_state) {
        pr_info(KERN_INFO"%s: [%d] \r\n", __func__, enable);
        err = set_power(pm8038_l9, 0, enable);
        if(err) 
            goto err1;
        err = set_power(pm8038_lvs2, 0, enable);
        if(err) 
            goto err2;

        power_state = enable;
        if (enable) {
            msleep(5);
        }
    }

    return 0;

err2:
    printk(KERN_ERR"%s: err2 \n", __func__);
err1:
    printk(KERN_ERR"%s: err1 \n", __func__);

    return -1;
}
示例#2
0
// write '1' to turn on power, '0' to turn it off
// write 'w' to set BT WAKE to 0,  'W' to set BT WAKE to 1
// write 'a' to trigger A2DP mode transition to send broadcom VSC for BT prioritization [disabled, built-in to FroYo]
int bt_power_write_proc(struct file *file, const char *buffer, unsigned long count, void *data)
{
  //  extern int A2DP_prioritization_trigger;
  
  if(copy_from_user(proc_buf, buffer, 1)) {return(-EFAULT);}
  
  //  if('a' == *proc_buf)
  //    {
  //      printk(KERN_INFO "BLUETOOTH: A2DP VSC for BT prioritization triggered (was %d)\n",
  //	     A2DP_prioritization_trigger);
  //      A2DP_prioritization_trigger = 2;
  //      return(0);
  //    }
  
  if('w' == *proc_buf)
    {
      set_bt_wake(0);
      printk(KERN_INFO "BLUETOOTH: BT_WAKE: low\n");
      return(0);
    }
  
  if('W' == *proc_buf)
    {
      set_bt_wake(1);
      printk(KERN_INFO "BLUETOOTH: BT_WAKE: high\n");
      return(0);
    }
  
  if('1' == *proc_buf)
    {
      if(!power_is_on)
	{
	  set_power(1);  // turn power on to BT module
	  set_reset(1);  // take BT out of reset
	  
	  power_is_on = 1;
	  printk(KERN_INFO "BLUETOOTH: bt_power: ON\n");
	}
    }
  else
    {
      if(power_is_on)
	{
	  set_reset(0);  // put BT into reset
	  set_power(0);  // turn off internal BT VREG
	  
	  power_is_on = 0;
	  printk(KERN_INFO "BLUETOOTH: bt_power: OFF\n");
	}
    }

  return(0);
}
示例#3
0
void
fujitsu_control::poweron()
{
  set_power(true);
  m_powermem = true;
  send_data();
}
示例#4
0
文件: maca.c 项目: retfie/mist
void maca_init(void) {
    reset_maca();
    radio_init();
    flyback_init();
    init_phy();
    set_channel(0); /* things get weird if you never set a channel */
    set_power(0);   /* set the power too --- who knows what happens if you don't */
    free_head = 0;
    tx_head = 0;
    rx_head = 0;
    rx_end = 0;
    tx_end = 0;
    dma_tx = 0;
    dma_rx = 0;
    free_all_packets();

#if DEBUG_MACA
    Print_Packets("maca_init");
#endif

    /* initial radio command */
    /* nop, promiscuous, no cca */
    *MACA_CONTROL =
        (prm_mode << PRM) |
        (NO_CCA << MACA_MODE);

    enable_irq(MACA);
    *INTFRC = (1 << INT_NUM_MACA);
}
示例#5
0
文件: usb.c 项目: entropia/usblockd
static int control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
		uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)) {
	(void)buf;
	(void)len;
	(void)complete;
	(void)usbd_dev;

	if(req->bRequest == USB_REQ_STATUS) {
		if(req->wValue & 1)
			set_state(OPEN);
		else
			set_state(CLOSED);

		return 1;
	} else if(req->bRequest == USB_REQ_LOCK) {
		if(req->wValue & 1)
			lock();
		else
			unlock();

		return 1;
	} else if(req->bRequest == USB_REQ_POWER) {
		set_power(req->wValue == 1);

		return 1;
	}

	return 0;
}
示例#6
0
int set_wlan_advance(int radio)
{
    int ret;
    int wlan_mode = -1;
    nvram_get_wlan_mode(radio, &wlan_mode);
    radio_up_down(radio, RADIO_DOWN, wlan_mode);
    /*dtim*/
    ret = set_dtim(radio);
    if(T_FAILURE == ret)
        {
            printf("ERRO:Set DTIM failure!\n");
            return T_FAILURE;
        }
    /*bcn*/
    ret = set_beacon_interval(radio);
    if(T_FAILURE == ret)
        {
            printf("ERRO:Set BCN Interval failure!\n");
            return T_FAILURE;
        }

    radio_up_down(radio, RADIO_UP, wlan_mode);

    /*txpower*/
    ret = set_power(radio);
    if(T_FAILURE == ret)
        {
            printf("ERRO:Set POWER failure!\n");
            return T_FAILURE;
        }

	//Deleted by Mario Huang 2014-08-12
	//set_ap_wmm(radio, 0);
    return T_SUCCESS;
}
示例#7
0
void main(void) {
	volatile packet_t *p;
	volatile uint8_t t=20;
	uint8_t chan;
	char c;

	gpio_data(0);
	
	gpio_pad_dir_set( 1ULL << LED );
        /* read from the data register instead of the pad */
	/* this is needed because the led clamps the voltage low */
	gpio_data_sel( 1ULL << LED);

	/* trim the reference osc. to 24MHz */
	trim_xtal();

	uart_init(UART1, 115200);

	vreg_init();

	maca_init();

        /* sets up tx_on, should be a board specific item */
        *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
	gpio_pad_dir_set( 1ULL << 44 );

	set_power(0x0f); /* 0dbm */
	chan = 0;
	set_channel(chan); /* channel 11 */

	*MACA_MACPANID = 0xaaaa;
	*MACA_MAC16ADDR = 0x1111;
	*MACA_TXACKDELAY = 68; /* 68 puts the tx ack at about the correct spot */
	set_prm_mode(AUTOACK);

	print_welcome("rftest-rx");
	while(1) {		

		/* call check_maca() periodically --- this works around */
		/* a few lockup conditions */
		check_maca();

		if((p = rx_packet())) {
			/* print and free the packet */
			printf("autoack-rx --- ");
			print_packet(p);
			maca_free_packet(p);
		}

		if(uart1_can_get()) {
			c = uart1_getc();
			if(c == 'z') t++;
			if(c == 'x') t--;
			*MACA_TXACKDELAY = t;
			printf("tx ack delay: %d\n\r", t);
		}

	}
}
示例#8
0
void minus(void) {
  if(state > 0) {
    state--;
    set_power();
  };
  if(state == 0) power_off();
  full_power_leds();
};
示例#9
0
void plus(void) {
  if(state < MAX_STATE) {
    state++;
    set_power();
  };
  if(state == 1) power_on();
  full_power_leds();
};
示例#10
0
void restore_state(void) {
  unsigned char init_state = read();
  if (init_state < 0 || init_state > 6) {
    state = 1;
  } else {
    state = init_state;
  };
  set_power();
};
示例#11
0
static inline void mms_pwr_on_reset(void)
{
	touch_i2c_to_gpio(true);

	set_power(false);
	gpio_direction_output(GPIO_SDA, 1);
	gpio_direction_output(GPIO_SCL, 1);
	gpio_direction_output(GPIO_IRQ, 1);
	msleep(50);
	set_power(true);
	msleep(50);

	touch_i2c_to_gpio(false);

	/* TODO: Seems long enough for the firmware to boot.
	 * Find the right value */
	msleep(250);
}
示例#12
0
/**
 * acquire_hp_resource
 *
 * @param drc
 * @param of_path
 * @returns 0 on success, !0 otherwise
 */
static int
acquire_hp_resource(struct dr_connector *drc, char *of_path)
{
	struct of_node *new_nodes;
	int progress = ACQUIRE_HP_START;
	int state;
	int rc;

	state = dr_entity_sense(drc->index);
	if (state == PRESENT || state == NEED_POWER || state == PWR_ONLY) {
		rc = set_power(drc->powerdomain, POWER_ON);
		if (rc) {
			say(ERROR, "set power failed for 0x%x\n",
			    drc->powerdomain);
			return progress;
		}

		progress = ACQUIRE_HP_SPL;
		if (state == PWR_ONLY)
			state = dr_entity_sense(drc->index);
	}

	if (state == PRESENT || state == NEED_POWER) {
		rc = rtas_set_indicator(ISOLATION_STATE, drc->index,
				UNISOLATE);
		if (rc) {
			say(ERROR, "set ind failed for 0x%x\n", drc->index);
			return progress;
		}

		progress = ACQUIRE_HP_UNISO;
		if (state == NEED_POWER)
			state = dr_entity_sense(drc->index);
	}

	if (state < 0) {
		say(ERROR, "invalid state %d\n", state);
		return progress;
	}

	if (state == PRESENT) {
		new_nodes = configure_connector(drc->index);
		if (new_nodes == NULL)
			return progress;

		progress = ACQUIRE_HP_CFGCONN;

		rc = add_device_tree_nodes(of_path, new_nodes);
		if (rc) {
			say(ERROR, "add nodes failed for 0x%x\n", drc->index);
			return progress;
		}
	}

	return 0;
}
示例#13
0
static int __init bt_power_init(void)
{
  bluetooth_gpio_init();

  //  if (create_proc_read_entry("bt_power", 0, NULL, bt_power_read_proc,NULL) == 0) 
  proc_entry = create_proc_entry("bt_power", 0666, NULL);
  if(!proc_entry)
    {
      printk(KERN_ERR "BLUETOOTH: Registration of proc \"bt_power\" file failed\n");
      return(-ENOMEM);
    }

  proc_entry->read_proc  = bt_power_read_proc;
  proc_entry->write_proc = bt_power_write_proc;

  printk(KERN_INFO "BLUETOOTH: /proc/bt_power created\n");

  {
    proc_entry = create_proc_entry("bt_stat", 0666, NULL);
    if(!proc_entry)
      {
	printk(KERN_ERR "BLUETOOTH: Registration of proc \"bt_stat\" file failed\n");
	return(-ENOMEM);
      }
    
    proc_entry->read_proc  = bt_stat_read_proc;
    proc_entry->write_proc = 0;
    
    printk(KERN_INFO "BLUETOOTH: /proc/bt_stat created\n");
  }

  {
    proc_entry = create_proc_entry("bt_status", 0666, NULL);
    if(!proc_entry)
      {
	printk(KERN_ERR "BLUETOOTH: Registration of proc \"bt_status\" file failed\n");
	return(-ENOMEM);
      }
    
    proc_entry->read_proc  = bt_status_read_proc;
    proc_entry->write_proc = 0;
    
    printk(KERN_INFO "BLUETOOTH: /proc/bt_status created\n");
  }

  { // turn off power to BT and hold it in reset
    set_reset(0);  // put BT into reset
    set_power(0);  // turn off internal BT VREG
    printk(KERN_INFO "BLUETOOTH: bt_power: Bluetooth power is off, and BT module is in reset.\n");
    
    power_is_on = 0;
  }
  
  return 0;
}
示例#14
0
static void hw_reboot(bool bootloader)
{
	set_power(false);
	gpio_direction_output(GPIO_SDA, bootloader ? 0 : 1);
	gpio_direction_output(GPIO_SCL, bootloader ? 0 : 1);
	gpio_direction_output(GPIO_IRQ, 0);
	msleep(30);
	set_power(true);
	msleep(30);

	if (bootloader) {
		gpio_set_value(GPIO_SCL, 0);
		gpio_set_value(GPIO_SDA, 1);
	} else {
		gpio_set_value(GPIO_IRQ, 1);
		gpio_direction_input(GPIO_IRQ);
		gpio_direction_input(GPIO_SCL);
		gpio_direction_input(GPIO_SDA);
	}
	msleep(40);
}
void
init_lowlevel(void)
{
	/* button init */
	/* set up kbi */
	enable_irq_kbi(4);
	kbi_edge(4);
	enable_ext_wu(4);
//	kbi_pol_neg(7);
//	kbi_pol_pos(7);
//	gpio_sel0_pullup(29);
//	gpio_pu0_disable(29);

	trim_xtal();
	
	/* uart init */
	uart_init(BRINC, BRMOD, SAMP);
	
	default_vreg_init();

	maca_init();

	set_channel(RF_CHANNEL - 11); /* channel 11 */
	set_power(0x12); /* 0x12 is the highest, not documented */

	enable_irq(CRM);

#if USE_32KHZ_XTAL
	enable_32khz_xtal();
#else
	cal_ring_osc();
#endif

#if USE_32KHZ_XTAL
	*CRM_RTC_TIMEOUT = 32768 * 10; 
#else 
	*CRM_RTC_TIMEOUT = cal_rtc_secs * 10;
#endif

#if (USE_WDT == 1)
	/* set the watchdog timer timeout to 1 sec */
	cop_timeout_ms(WDT_TIMEOUT);
	/* enable the watchdog timer */
	CRM->COP_CNTLbits.COP_EN = 1;
#endif

	/* XXX debug */
	/* trigger periodic rtc int */
//	clear_rtc_wu_evt();
//	enable_rtc_wu();
//	enable_rtc_wu_irq();
}
示例#16
0
文件: phy.c 项目: BeeeOn/sensors
void PHY_init(PHY_init_t params){
    
    HW_init();
    
    HW_disableConfig();
    HW_disableData();
    
    PHY_STORAGE.send_done = false;
    PHY_STORAGE.cca_noise_treshold = params.cca_noise_treshold;


    //----  configuring the RF link --------------------------------    
    for (uint8_t i = 0; i <= 31; i++) {
        //setup freq
        if((i << 1)== R1CNTREG ){
          set_chanel_freq_rate (params.channel, params.band, params.bitrate);
          //jump over R1CNTREG, P1CNTREG, S1CNTREG
          i+=3;
        }
        
        if((i << 1)== TXPARAMREG ){
          set_power(params.power);
          //jump over TXPARAMREG
          i+=1;
        }

        if((i << 1)== FDEVREG){
          set_bitrate(params.bitrate);
          //jump over FDEVREG, BRREG
          i+=2;
        }
        if((i << 1)== FILCONREG){
          // already done in previous call of set_bitrate(params.bitrate);
          i+=1;
        }
        set_register(i<<1, InitConfigRegs[i]);
    }
    
    for (uint8_t i = 0; i <= 31; i++) {
      uint8_t reg_val = get_register(i<<1);
    }
    
    send_reload_radio();

    HW_clearIRQ0();
    HW_enableIRQ0();

    HW_clearIRQ1();
    HW_enableIRQ1();
}
示例#17
0
int16_t parse_cmd_set_power (char *cmd, char *output, uint16_t len)
{
   //char value[10];
   uint8_t value;
   uint8_t ret  = 0;

   //ret = sscanf_P(cmd, PSTR("%s"), &value);
   ret = sscanf_P(cmd, PSTR("%u"), &value);
   
   if (ret == 1) {
      set_power(value);
      return ECMD_FINAL_OK;
   } else
      return ECMD_ERR_PARSE_ERROR;
}
// Closes the interface.
// This routine is not thread safe.
static void cleanup(void)
{
    if (has_cleaned_up) {
        ALOGW("%s Already cleaned up for this session\n", __func__);
        return;
    }

    BTHCDBG("cleanup");

    if (hc_cb.worker_thread)
    {
        if (fwcfg_acked)
        {
            epilog_wait_timer();
            // Stop reading thread
            userial_close_reader();

            thread_post(hc_cb.worker_thread, event_epilog, NULL);
        }
        thread_free(hc_cb.worker_thread);

        pthread_mutex_lock(&hc_cb.worker_thread_lock);
        hc_cb.worker_thread = NULL;
        pthread_mutex_unlock(&hc_cb.worker_thread_lock);

        if (hc_cb.epilog_timer_created)
        {
            timer_delete(hc_cb.epilog_timer_id);
            hc_cb.epilog_timer_created = false;
        }
    }
    BTHCDBG("%s Finalizing cleanup\n", __func__);

    lpm_cleanup();
    userial_close();
    p_hci_if->cleanup();
    utils_cleanup();

    set_power(BT_VND_PWR_OFF);
    vendor_close();

    pthread_mutex_destroy(&hc_cb.worker_thread_lock);

    fwcfg_acked = false;
    bt_hc_cbacks = NULL;
    has_cleaned_up = true;
}
示例#19
0
/**
 * release_hp_resource
 *
 * @param drc_index
 * @param power_domain
 * @returns 0 on success, !0 otherwise
 */
static int
release_hp_resource(struct dr_node *node)
{
	int rc;

	rc = remove_device_tree_nodes(node->ofdt_path);
	if (rc) {
		say(ERROR, "failed to remove kernel nodes for index 0x%x\n",
		    node->drc_index);
		return -EIO;
	}

	if (pci_hotplug_only)
		return 0;

	rc = rtas_set_indicator(DR_INDICATOR, node->drc_index, LED_OFF);
	if (rc) {
		say(ERROR, "failed to set led off for index 0x%x\n",
		    node->drc_index);
		return -EIO;
	}

	rc = rtas_set_indicator(ISOLATION_STATE, node->drc_index, ISOLATE);
	if (rc) {
		say(ERROR, "failed to isolate for index 0x%x\n",
		    node->drc_index);
		return -EIO;
	}

	rc = set_power(node->drc_power, POWER_OFF);
	if (rc) {
		struct stat sb;

		say(ERROR, "failed to power off for index 0x%x\n",
		    node->drc_index);

		if (!stat(IGNORE_HP_PO_PROP, &sb))
			say(ERROR, "Ignoring hot-plug power off failure.\n");
		else
			return -EIO;
	}

	return 0;
}
示例#20
0
/****************************************************************************
 * Command handler
 * Parameters : Standard ioctl params
 * Returns : 0 == success, otherwise error code
 ****************************************************************************/
static int
reciva_ioctl ( struct inode *inode, struct file *file,
               unsigned int cmd, unsigned long arg)
{
  int i;
  switch(cmd)
  {
    case IOC_USB_POWER:
      if (copy_from_user(&i, (void *)arg, sizeof(i)))
        return -EFAULT;

      set_power(i);
      break;

    default:
      return -ENODEV;
  }

  return 0;
}
示例#21
0
void
fujitsu_control::poweroff()
{
  set_power(false);
  m_powermem = false;
  char bytes[7], i;
  bytes[0] = 0x14;
  bytes[1] = 0x63;
  bytes[2] = 0x00;
  bytes[3] = 0x10;
  bytes[4] = 0x10;
  bytes[5] = 0x02;
  bytes[6] = 0xFD;

  send_leader();

  for (i = 0; i < 7; ++i) {
    send_byte(bytes[i]);
  }

  send_trailer();
}
示例#22
0
void NRF24L01::set_rx_mode()
{
    ce->reset();
    
    set_addr_width(5);
    set_local_addr(0,rx_addr_0);//写RX节点地址
    
   	set_chanal_ack(0,ENABLE);    //使能通道0的自动应答    
  	set_chanal(0,ENABLE);//使能通道0的接收地址  
    
  	set_rf_frq(40);	     //设置RF通信频率	
    
  	set_pload_width(0,4);//选择通道0的有效数据宽度 	    

  	set_gain(RF_N_0DB);//设置TX发射参数,0db增益,低噪声增益开启   
    set_baudrate(_2MBPS);//2Mbps
    
    set_power(1);//PWR_UP
    set_tx_rx_mode(RX_MODE);//接收模式 
    set_crc(1,1);//EN_CRC,16BIT_CRC
    
    ce->set();
}
示例#23
0
int main(int argc, char **argv)
{
	if (argc < 2) {
		usage();
		return 0;
	}
	if (strcmp(argv[1], "chat") == 0) {
		chat();
	} else if (strcmp(argv[1], "reg") == 0) {
		if (argc < 4) {
			usage();
			return 0;
		}
		uint8_t reg, value;
		reg = strtol(argv[2], NULL, 10);
		value = strtol(argv[3], NULL, 10);
		reg_write(reg, value);
	} else if (strcmp(argv[1], "reset") == 0) {
		reset();
	} else if (strcmp(argv[1], "power") == 0) {
		if (argc < 3) {
			usage();
			return 0;
		}
		int8_t power = strtol(argv[2], NULL, 10);
		set_power(power);
	} else if (strcmp(argv[1], "mode") == 0) {
		if (argc < 3) {
			usage();
			return 0;
		}
		int mode = strtol(argv[2], NULL, 10);
		set_mode(mode);
	}
  
    return 0;
}
示例#24
0
文件: autoack-tx.c 项目: 1uk3/contiki
void main(void) {
	volatile packet_t *p;
	char c;
	uint16_t r=30; /* start reception 100us before ack should arrive */
	uint16_t end=180; /* 750 us receive window*/

	/* trim the reference osc. to 24MHz */
	trim_xtal();

	uart_init(UART1, 115200);

	vreg_init();

	maca_init();

	set_channel(0); /* channel 11 */
//	set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
//	set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
	set_power(0x12); /* 0x12 is the highest, not documented */

        /* sets up tx_on, should be a board specific item */
	GPIO->FUNC_SEL_44 = 1;	 
	GPIO->PAD_DIR_SET_44 = 1;	 

	GPIO->FUNC_SEL_45 = 2;	 
	GPIO->PAD_DIR_SET_45 = 1;	 

	*MACA_RXACKDELAY = r;
	
	printf("rx warmup: %d\n\r", (int)(*MACA_WARMUP & 0xfff));

	*MACA_RXEND = end;

	printf("rx end: %d\n\r", (int)(*MACA_RXEND & 0xfff));

	set_prm_mode(AUTOACK);

	print_welcome("rftest-tx");

	while(1) {		
	    		
		/* call check_maca() periodically --- this works around */
		/* a few lockup conditions */
		check_maca();

		while((p = rx_packet())) {
			if(p) {
				printf("RX: ");
				print_packet(p);
				free_packet(p);
			}
		}

		if(uart1_can_get()) {
			c = uart1_getc();

			switch(c) {
			case 'z':
				r++;
				if(r > 4095) { r = 0; }
				*MACA_RXACKDELAY = r;
				printf("rx ack delay: %d\n\r", r);
				break;
			case 'x':
				if(r == 0) { r = 4095; } else { r--; }
				*MACA_RXACKDELAY = r;
				printf("rx ack delay: %d\n\r", r);
				break;
			case 'q':
				end++;
				if(r > 4095) { r = 0; }
				*MACA_RXEND = end;
				printf("rx end: %d\n\r", end);
				break;
			case 'w':
				end--;
				if(r == 0) { r = 4095; } else { r--; }
				*MACA_RXEND = end;
				printf("rx end: %d\n\r", end);
				break;
			default:
				p = get_free_packet();
				if(p) {
					fill_packet(p);
					
					printf("autoack-tx --- ");
					print_packet(p);
					
					tx_packet(p);				
				}
				break;
			}
		}
		
	}

}
示例#25
0
/**
 * do_add
 *
 * Prepares a PCI hot plug slot for adding an adapter, then
 * configures the adapter and any PCI adapters below into
 * the Open Firmware device tree.
 *
 * Verifies that a given hot plug PCI slot does not have an adapter
 * already connected, identifies the slot to the user unless requested not
 * to with the -i flag, prompts the user to connect the adapter, powers
 * the slot on, and calls configure connector. When configure connector
 * completes and returns the new node(s) for the new PCI adapter and any
 * attached devices then the Open Firmware device tree is
 * updated to reflect the new devices.
 */
static int
do_add(struct options *opts, struct dr_node *all_nodes)
{
	struct dr_node *node;
	int usr_key = USER_CONT;
	int rc;

	node = find_slot(opts->usr_drc_name, all_nodes);
	if (node == NULL)
		return -1;

	/* Prompt user only if in interactive mode. */
	if (0 == opts->noprompt) {
		if (!opts->no_ident)
			usr_key = identify_slot(node);

		if (usr_key == USER_QUIT) {
			if (node->children == NULL)
				process_led(node, LED_OFF);
			else
				process_led(node, LED_ON);
			return 0;
		}
	}

	if (node->children != NULL) {
		/* If there's already something here, turn the
		 * LED on and exit with user error.
		 */
		process_led(node, LED_ON);
		say(ERROR, "The specified PCI slot is already occupied.\n");
		return -1;
	}


	/* Now it's time to isolate, power off, set the
	 * action LED, and prompt the user to put the
	 * card in.
	 */

	say(DEBUG, "is calling rtas_set_indicator(ISOLATE index 0x%x)\n",
	    node->drc_index);

	rc = rtas_set_indicator(ISOLATION_STATE, node->drc_index, ISOLATE);
	if (rc) {
		if (rc == HW_ERROR)
			say(ERROR, "%s", hw_error);
		else
			say(ERROR, "%s", sw_error);

		set_power(node->drc_power, POWER_OFF);
		return -1;
	}

	say(DEBUG, "is calling set_power(POWER_OFF index 0x%x, "
	    "power_domain 0x%x) \n", node->drc_index, node->drc_power);

	rc = set_power(node->drc_power, POWER_OFF);
	if (rc) {
		if (rc == HW_ERROR)
			say(ERROR, "%s", hw_error);
		else
			say(ERROR, "%s", sw_error);

		return -1;
	}

	if (0 == opts->noprompt) {
		/* Prompt user to put in card and to press
		 * Enter to continue or other key to exit.
		 */
		if (process_led(node, LED_ACTION))
			return -1;

		printf("The visual indicator for the specified PCI slot has\n"
			"been set to the action state. Insert the PCI card\n"
			"into the identified slot, connect any devices to be\n"
			"configured and press Enter to continue. Enter x to "
			"exit.\n");

		if (!(getchar() == '\n')) {
			process_led(node, LED_OFF);
			return 0;
		}
	}

	/* Call the routine which determines
	 * what the user wants and does it.
	 */
	rc = add_work(opts, node);
	if (rc)
		return rc;

	say(DEBUG, "is calling enable_slot to config adapter\n");

	/* Try to config the adapter */
	set_hp_adapter_status(PHP_CONFIG_ADAPTER, node->drc_name);

	return 0;
}
示例#26
0
/**
 * remove_work
 *
 * Removes nodes associated a PCI slot from the
 * Open Firmware device tree and isolates and powers off the PCI slot.
 *
 * A remove may be specified by the location code of the  PCI slot.
 * Unless the user specifies the -I flag, the slot is identified to
 * the user.
 * Nodes representing the device(s) are removed from the
 * Open Firmware device tree. The slot is isolated and powered off,
 * and the LED is turned off.
 *
 * @returns pointer slot on success, NULL on failure
 */
static struct dr_node *
remove_work(struct options *opts, struct dr_node *all_nodes)
{
	struct dr_node *node;
	struct dr_node *child;
	int rc;
	int usr_key = USER_CONT;

	node = find_slot(opts->usr_drc_name, all_nodes);
	if (node == NULL)
		return NULL;

	say(DEBUG, "found node: drc name=%s, index=0x%x, path=%s\n",
	     node->drc_name, node->drc_index, node->ofdt_path);

	/* Prompt user only if not in noprompt mode */
	if (0 == opts->noprompt) {
		if (!opts->no_ident)
			usr_key = identify_slot(node);

		if (usr_key == USER_QUIT) {
			if (node->children == NULL)
				process_led(node, LED_OFF);
			else
				process_led(node, LED_ON);
			return NULL;
		}
	}

	/* Turn on the LED while we go do some work. */
	if (process_led(node, LED_ON))
		return NULL;

	/* Make sure there's something there to remove. */
	if (node->children == NULL) {
		process_led(node, LED_OFF);
		say(ERROR, "There is no configured card to remove from the "
		    "specified PCI slot.\n");
		return NULL;
	}

	/* Make sure all the devices are
	 * not configured before proceeding
	 */
	if (get_hp_adapter_status(node->drc_name) == CONFIG) {
		say(DEBUG, "unconfiguring adapter in slot[%s]\n",
		    node->drc_name);
		set_hp_adapter_status(PHP_UNCONFIG_ADAPTER, node->drc_name);

		int rc = get_hp_adapter_status(node->drc_name);
		if (rc != NOT_CONFIG) {
			say(ERROR, "Unconfig adapter failed.\n");
			return NULL;
		}
	} else {
		/* In certain cases such as a complete failure of the
		 * adapter there may not have been the possibility to clean
		 * up everything. Mark these adapaters for additional
		 * processing later.
		 */
		node->post_replace_processing = 1;
	}

	/* Call subroutine to remove node(s) from
	 * the device tree.
	 */
	for (child = node->children; child; child = child->next) {
		rc = remove_device_tree_nodes(child->ofdt_path);
		if (rc) {
			say(ERROR, "%s", sw_error);
			rtas_set_indicator(ISOLATION_STATE, node->drc_index,
					   ISOLATE);
			set_power(node->drc_power, POWER_OFF);
			return NULL;
		}
	}

	/* We have to isolate and power off before
	 * allowing the user to physically remove
	 * the card.
	 */
	say(DEBUG, "is calling rtas_set_indicator(ISOLATE index 0x%x)\n",
	    node->drc_index);

	rc = rtas_set_indicator(ISOLATION_STATE, node->drc_index, ISOLATE);
	if (rc) {
		if (rc == HW_ERROR)
			say(ERROR, "%s", hw_error);
		else
			say(ERROR, "%s", sw_error);

		set_power(node->drc_power, POWER_OFF);
		return NULL;
	}

	say(DEBUG, "is calling set_power(POWER_OFF index 0x%x, power_domain "
	    "0x%x)\n", node->drc_index, node->drc_power);

	rc = set_power(node->drc_power, POWER_OFF);
	if (rc) {
		if (rc == HW_ERROR)
			say(ERROR, "%s", hw_error);
		else
			say(ERROR, "%s", sw_error);

		set_power(node->drc_power, POWER_OFF);
		return NULL;
	}

	return node;
}
void main(void) {
  volatile packet_t *p;
#ifdef CARRIER_SENSE
  volatile uint32_t i;
#endif
  uint16_t r=30; /* start reception 100us before ack should arrive */
  uint16_t end=180; /* 750 us receive window*/

  /* trim the reference osc. to 24MHz */
  trim_xtal();
  uart_init(INC, MOD, SAMP);
  vreg_init();
  maca_init();

  ///* Setup the timer */
  *TMR_ENBL = 0;                     /* tmrs reset to enabled */
  *TMR0_SCTRL = 0;
  *TMR0_LOAD = 0;                    /* reload to zero */
  *TMR0_COMP_UP = 18750;             /* trigger a reload at the end */
  *TMR0_CMPLD1 = 18750;              /* compare 1 triggered reload level, 10HZ maybe? */
  *TMR0_CNTR = 0;                    /* reset count register */
  *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE);
  *TMR_ENBL = 0xf;                   /* enable all the timers --- why not? */

  set_channel(CHANNEL); /* channel 11 */
  set_power(0x12); /* 0x12 is the highest, not documented */

  /* sets up tx_on, should be a board specific item */
  GPIO->FUNC_SEL_44 = 1;	 
  GPIO->PAD_DIR_SET_44 = 1;	 
  GPIO->FUNC_SEL_45 = 2;	 
  GPIO->PAD_DIR_SET_45 = 1;	 
  *MACA_RXACKDELAY = r;
  *MACA_RXEND = end;

  set_prm_mode(AUTOACK);

  while(1) {		

    if((*TMR0_SCTRL >> 15) != 0) 
      tick();

    /* call check_maca() periodically --- this works around */
    /* a few lockup conditions */
    check_maca();

    while((p = rx_packet())) {
      if(p) free_packet(p);
    }

    p = get_free_packet();
    if(p) {
      fill_packet(p);

#ifdef CARRIER_SENSE
      for(i=0; i<POWER_DELAY; i++) {continue;}
      while(get_power()>74) {}
#endif

#ifdef BLOCKING_TX
      blocking_tx_packet(p);
#else
      tx_packet(p);
#endif

      current_pkts++;

#if defined(RANDOM_WAIT_TIME) || defined(FIXED_WAIT)
      random_wait();
#endif
    }
  }
}
示例#28
0
文件: cuci.c 项目: lonegoli/R7000
void _setConfigurations(cJSON *root, s_config *config, char *http_packet)
{
	cJSON *valueSetObj= cJSON_CreateObject();
	cJSON *attribute;
	cJSON *key;
	cJSON *item;
	int array_size;
	int i;
	char cmd[MAX_BUF];
	char result[MAX_BUF];
	char ErrMesg[B_5_BUF];
	cJSON *transaction_id = cJSON_GetObjectItem(root, "transaction_id");
	char *conf_version;
	char *radio_index;
	char *profile_index;
	char *status;
	int flag =0;
	if(!transaction_id) {
		debug(LOG_ERR, "Can not find transaction_id parameter: %s", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, NULL, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{transaction_id}", config->sn, http_packet);
		return;

	}
	cJSON *valueSet = cJSON_GetObjectItem(root, "valueSet");
	if(!valueSet) {
		debug(LOG_ERR, "Get valueSet faild[%s]", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{valueSet}", config->sn, http_packet);
		return;
	}
	/*
	if((key = cJSON_GetObjectItem(valueSet, "conf_version")) == NULL || (conf_version = key->valuestring) == NULL) {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{conf_version}", config->sn, http_packet);
		return;
	}
	*/
	ErrMesg[0]=0;
	//setDeviceInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setDeviceInfo")) != NULL) {
			if((key = cJSON_GetObjectItem(attribute, "apname")) != NULL && key->valuestring != NULL) {
					/*snprintf(cmd, MAX_BUF, "config apname %s\n", key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_apname(key->valuestring, result, sizeof(result)/sizeof(result[0]));
				}
		}
	}
	//setRadioInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setRadioInfo")) != NULL) {
			array_size = cJSON_GetArraySize(attribute);
			debug(LOG_DEBUG, "Array size of paras is %d",array_size);
 			for(i=0; i< array_size; i++) {
				item = cJSON_GetArrayItem(attribute, i);
				//debug(LOG_DEBUG, "%s\n",item->valuestring);
				if((key = cJSON_GetObjectItem(item, "radio_index")) == NULL || (radio_index = radio_keywords[parse_radio_keywords(key->valuestring)].value) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{radio_index}", config->sn, http_packet);
					return;
				}
				/*
				if((key = cJSON_GetObjectItem(item, "radio")) != NULL && key->valuestring != NULL) {
					snprintf(cmd, MAX_BUF, "config interface wlan %s radio %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					//debug(LOG_INFO, "result is %d", strlen(result));
				}
				*/
				if((key = cJSON_GetObjectItem(item, "mode")) != NULL && key->valuestring != NULL) {
					/*snprintf(cmd, MAX_BUF, "config interface wlan %s mode %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
			
					set_mode(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "power")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s power %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_power(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "channel")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s channel %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_channel(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				if((key = cJSON_GetObjectItem(item, "channelwidth")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s channelwidth %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_channelwidth(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
	
				}
				if((key = cJSON_GetObjectItem(item, "max-wireless-clients")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s max-wireless-clients %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_max_assoc(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "client-isolation")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s client-isolation %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_ap_isolate(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
					
				}
				/*
				if((key = cJSON_GetObjectItem(item, "rate")) != NULL && key->valuestring != NULL) {
					snprintf(cmd, MAX_BUF, "config interface wlan %s rate %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
				}	
				*/
 			}
		}
	}
	//setSSIDInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setSSIDInfo")) != NULL) {
			array_size = cJSON_GetArraySize(attribute);
			debug(LOG_DEBUG, "Array size of paras is %d",array_size);
 			for(i=0; i< array_size; i++) {
				item = cJSON_GetArrayItem(attribute, i);
				if((key = cJSON_GetObjectItem(item, "radio_index")) == NULL || (radio_index = radio_keywords[parse_radio_keywords(key->valuestring)].value) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{radio_index}", config->sn, http_packet);
					return;
				}
				if((key = cJSON_GetObjectItem(item, "profile_index")) == NULL || (profile_index = key->valuestring) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{profile_index}", config->sn, http_packet);
					return;
				}
				if((key = cJSON_GetObjectItem(item, "status")) == NULL || (status = key->valuestring) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{status}", config->sn, http_packet);
					return;
				}
				if(atoi(profile_index)>0) {
					char vifs[128];
					char viname[32];
					sprintf(viname, "wl%d.%d", atoi(radio_index), atoi(profile_index));
					read_vifs(atoi(radio_index), vifs, sizeof(vifs)/sizeof(vifs[0]));
	
					if(strstr(vifs, viname) && atoi(status)==0) {
						del_virtual_interface(atoi(radio_index), atoi(profile_index));
					}
					else if(!strstr(vifs, viname) && atoi(status)==1) {
						add_virtual_interface(atoi(radio_index), atoi(profile_index));
					}
					else if((!strstr(vifs, viname) && atoi(status)==0) || atoi(profile_index)>3) {
						continue;
					}
					
				}
				if((key = cJSON_GetObjectItem(item, "hide-network-name")) != NULL && key->valuestring != NULL) {
					set_status(atoi(radio_index), atoi(profile_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);	
				}
				if((key = cJSON_GetObjectItem(item, "ssid")) != NULL && key->valuestring != NULL) {
					set_ssid(atoi(radio_index), atoi(profile_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
						
				}
				if((key = cJSON_GetObjectItem(item, "authentication")) != NULL && key->valuestring != NULL) {
					
					set_security_mode(atoi(radio_index), atoi(profile_index), authentication_keywords[parse_authentication_keywords(key->valuestring)].value, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "encryption")) != NULL && key->valuestring != NULL) {
					set_crypto(atoi(radio_index), atoi(profile_index), encryption_keywords[parse_encryption_keywords(key->valuestring)].value, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}

				if((key = cJSON_GetObjectItem(item, "presharedkey")) != NULL && key->valuestring != NULL) {
					set_wpa_psk(atoi(radio_index), atoi(profile_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				flag =1;
 			}
			
		}
		
 	}
 	{
 		//apply_setting();
 		/*
 		int result;
		pthread_t tid_init_service = 0;
		config->upgrade_lock = 1;
 		debug(LOG_INFO, "create a new thread (thread_init_service)");
		result = pthread_create(&tid_init_service, NULL, (void *)thread_init_service, NULL);
		if (result != 0) {
			debug(LOG_ERR, "FATAL: Failed to create a new thread (init_service) - exiting");
			exit(1);
		}*/
		system("nvram commit");
		
 	}
 
	if(strlen(ErrMesg)) {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "1000", ErrMesg, config->sn, http_packet);
	}
	else {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "success", "0", NULL, config->sn, http_packet);
	}
	if(flag) {
		safe_encrypt_http_send(config->httpfd, http_packet, strlen(http_packet), 0); 
		shutdown(config->httpfd, SHUT_RDWR);
		system("reboot");
	}
		
			
}
示例#29
0
文件: main.c 项目: jkent/hexbright
int main(void)
{
	uint8_t button;
	mode_t mode = MODE_OFF;
	mode_t next_mode = MODE_OFF;
	
	uint8_t up_time = 0;
	uint8_t down_time = 0;
	uint8_t time = 0;

	init_hardware();

	leds[GREEN_LED].state = LED_OFF;
	leds[GREEN_LED].on_time = 31;
	leds[GREEN_LED].off_time = 31;

	leds[RED_LED].state = LED_HIZ;


	while (1) {
		button = poll_button();

		if (button & 2) {
			if (down_time < 255) {
				down_time++;
			}
			up_time = 0;
		} else {
			if (up_time < 255) {
				up_time++;
			}
			down_time = 0;
		}

		if (time < 255) {
			time++;
		}

		// Button pressed
		if (button == 1) {
			if (mode != MODE_OFF && up_time >= 62) {
				next_mode = MODE_OFF;
			} else if (mode < MODE_CYCLE_END) {
				next_mode = mode + 1;
				if (next_mode == MODE_CYCLE_END) {
					next_mode = MODE_OFF;
				}
			} else {
				next_mode = MODE_OFF;
			}
		}

		// Button held
		if (down_time >= 37) {
			switch (mode) {
			case MODE_CYCLE_LEVEL1:
				next_mode = MODE_HOLD_BLINKY;
				break;
			case MODE_CYCLE_LEVEL2:
				next_mode = MODE_PERSIST_BLINKY;
				break;
			default:
				break;
			}
		}

		// Button released
		if (button == 2 && mode > MODE_PERSIST_END) {
			next_mode = MODE_OFF;
		}

		if (poll_temp() >= OVERTEMP) {
			if (mode > MODE_CYCLE_LEVEL2) {
				next_mode = MODE_CYCLE_LEVEL2;
			} else if (next_mode > MODE_CYCLE_LEVEL2) {
				next_mode = MODE_OFF;
			}
		}

		if (next_mode != mode) {
			mode = next_mode;

			set_power(mode);

			switch (mode) {
			case MODE_OFF:
				set_light(0);
				break;
			case MODE_CYCLE_LEVEL1:
				set_light(50);
				break;
			case MODE_CYCLE_LEVEL2:
				set_light(250);
				break;
			case MODE_CYCLE_LEVEL3:
				set_light(1000);
				break;
			case MODE_CYCLE_LEVEL4:
				set_light(1500);
				break;
			case MODE_CYCLE_LEVEL5:
				set_light(2000);
				break;
			case MODE_PERSIST_BLINKY:
			case MODE_HOLD_BLINKY:
				time = 0;
				set_light(2000);
				break;
			default:
				mode = MODE_OFF;
				break;
			}
		}

		switch (mode) {
		case MODE_PERSIST_BLINKY:
		case MODE_HOLD_BLINKY:
			if (time >= 24) {
				set_light(2000);
				time = 0;
			} else if (time >= 8) {
				set_light(0);
			}
			break;
		default:
			break;
		}

		switch (poll_charger()) {
		case CHARGE_SHUTDOWN:
			leds[GREEN_LED].state = LED_OFF;
			break;
		case CHARGE_CHARGING:
			leds[GREEN_LED].state |= LED_FLASH;
			break;
		case CHARGE_FINISHED:
			leds[GREEN_LED].state = LED_ON;
			break;
		}

		update_leds();
		sleep();
	}

	return 0;
}
示例#30
0
文件: phy.c 项目: BeeeOn/sensors
bool PHY_set_power(uint8_t power){
    if (power == PHY_STORAGE.power) return true;
    return set_power(power);
}