byte GDClass::rd(unsigned int addr)
{
  __start(addr);
  byte r = SPI.transfer(0);
  __end();
  return r;
}
示例#2
0
void ar9170_set_state_when(struct ar9170 *ar, enum ar9170_device_state current, enum ar9170_device_state newstate)
{
	__start(&ar->state_lock);
	if (CHK_DEV_STATE(ar, current)) {
		__ar9170_set_state(ar, newstate);	
	} else {
		printf("WARNING: Device in wrong state.\n");
	}	
	__complete(&ar->state_lock);
}
unsigned int GDClass::rd16(unsigned int addr)
{
  unsigned int r;

  __start(addr);
  r = SPI.transfer(0);
  r |= (SPI.transfer(0) << 8);
  __end();
  return r;
}
示例#4
0
void up_systemswitch(uint32_t sys_addr)
{
  typedef void (FAR *__start_t)(void);
  __start_t __start;

  __start = (__start_t) *(CODE uint32_t*) (sys_addr + 4);

  setcontrol(getcontrol() & 0xfffffffc);	
  setmsp(*(CODE uint32_t*) sys_addr);
	
  __start();
}
示例#5
0
int SoftI2C_Read(const SoftI2C *i2c, uint8_t addr, uint8_t *dat, int len) {
	int i;

	__start(i2c); // start
	__onebyte(i2c, (addr << 1)  + 1); // addr + Write
	if (0 != __onebit(i2c, 1)) { // check ACK
		return 0;
	}

	for (i = 0; i < len; ++i) {
		*dat++ = __onebyte(i2c, 0xFF);
		__onebit(i2c, 0); // ACK
	}
	__stop(i2c);
	return i;
}
示例#6
0
int SoftI2C_Write(const SoftI2C *i2c, uint8_t addr, const uint8_t *dat, int len) {
	int i;

	__start(i2c); // start
	__onebyte(i2c, addr << 1); // addr + Write
	if (0 != __onebit(i2c, 1)) { // check ACK
		return 0;
	}

	for (i = 0; i < len; ++i) {
		__onebyte(i2c, *dat++);
		if (0 != __onebit(i2c, 1)) { // check ACK
			break;
		}
	}
	__stop(i2c);
	return i;
}
示例#7
0
bool ar9170_usb_send_cmd(completion_t* lock, uint8_t* cmd, uint16_t cmd_len) {
	
	/* Lock asynchronous command transfer. The flag must
	 * be released by the callback function, which is 
	 * called upon transfer completion.
	 */
	__start(lock);
	
	/* Block execution while the endpoint is not available. */
	while(!uhi_vendor_int_is_available());
	
	/* Copy the command data to the 
	 * interrupt endpoint output buffer.
	 */
	memcpy(int_out_buffer, cmd, cmd_len);
	
	/* Start transferring OUT on the interrupt endpoint. 
	 * Return the status of the transfer upon completion. 
	 */
	return (bool) uhi_vendor_int_out_run(int_out_buffer, 
		(iram_size_t) cmd_len, ar9170_interrupt_out_transfer_done);
}
示例#8
0
void NativeWrapper::compute()
{
	__start();
}
示例#9
0
void ar9170_set_state(struct ar9170 *ar, enum ar9170_device_state newstate)
{
	__start(&ar->state_lock);
	__ar9170_set_state(ar, newstate);
	__complete(&ar->state_lock);
}
示例#10
0
void CMainLoop::start()
{
	__is_run = true;
	emit __start();
}
示例#11
0
	void __wstart(unsigned int addr) // start an SPI write transaction to addr
{
		__start(0x8000|addr);
	
}
示例#12
0
 /// Start all io_service objects in nonblock model.
 void start(bool block=false)
 {
     __start(block);
 }
void GDClass::__wstartspr(unsigned int sprnum)
{
  __start((0x8000 | RAM_SPR) + (sprnum << 2));
  spr = 0;
}
示例#14
0
bool ar9170_usb_write_reg(completion_t* lock, uint8_t* cmd, uint16_t cmd_len)
{	
	int i;
	bool result;
	UNUSED(i);
		
	if (cmd_len > INTR_ENDPOINT_MAX_SIZE) {
		printf("ERROR: Command exceeds maximum length: %d.\n",cmd_len);
		return false;
	}			
	struct ar9170* ar = ar9170_get_device();
	/* Lock execution */
	__start(&ar->cmd_buf_lock);
	
	if (ar->cmd_list->buffer == NULL) {
		if(ar->cmd_list->next_send_chunk != NULL) {
			printf("ERROR: Command buffer is null while next command is not.\n");
			return false;
		}
		/*
 		 * If command buffer is ready, we place the current command in
		 * the list of pending commands, and we attempt the command 
		 * transmission down to the device.
		 */		
		ar->cmd_list->buffer = cmd;
		ar->cmd_list->send_chunk_len = cmd_len;
		
		__complete(&ar->cmd_buf_lock);
		/* Actual command transfer occurs here */
		result = ar9170_usb_send_cmd(lock, cmd, cmd_len);
		
		if(result == false) {
			printf("ERROR: CMD could not be send correctly.\n");
			return result;
		}
		
	} else {
		printf("WARNING: Non-empty command buffer.\n");
		/* If the command buffer is non-empty, put the current command in
		 * the tail of the list and return.
		 */
		int counter = 0;
		struct ar9170_send_list* next_pos = ar->cmd_list;
		while(next_pos->next_send_chunk != NULL) {
			counter++;
			next_pos = next_pos->next_send_chunk;
		}		
		if (counter > AR9170_MAX_CMD_BUFFER_LEN) {
			printf("ERROR: Command buffer reached maximum length!\n");
			return false;
		}
		
		next_pos->next_send_chunk = smalloc(sizeof(struct ar9170_send_list));
		if (next_pos->next_send_chunk == NULL) {
			
			printf("ERROR: Could not allocate memory for register write.\n");
			__complete(&ar->cmd_buf_lock);
			return false;
			
		} else {
			
			next_pos->next_send_chunk->buffer = cmd;
			next_pos->next_send_chunk->send_chunk_len = cmd_len;
			next_pos->next_send_chunk->next_send_chunk = NULL;
		}
		
		__complete(&ar->cmd_buf_lock);
	}
		
	return true;
}
示例#15
0
bool ar9170_write_data( uint8_t* data, uint16_t tx_len, bool zero_packet_flag )
{
	int i;
	bool result = true;
	UNUSED(i);
	UNUSED(zero_packet_flag); // TODO - add the option to send through a vendor API command with zero packet disabled

	if (tx_len > BULK_ENDPOINT_MAX_OUT_SIZE) {
		printf("ERROR: Data exceeds maximum length: %d.\n",tx_len);
		return false;
	}
	
	struct ar9170* ar = ar9170_get_device();
	/* Lock access to the tx buffer. */
	__start(&ar->tx_buf_lock);
	
	if (ar->tx_list->buffer == NULL) {
		/* Consistency check. */
		if(ar->tx_list->next_send_chunk != NULL) {
			printf("ERROR: TX buffer is null while next tx chunk is not.\n");
			__complete(&ar->tx_buf_lock);
			return false;
		}
		/*
		 * If the transmit buffer is empty, we place the current chunk in 
		 * the chunks list and execute the tx submit directly. TODO check
		 * how to implement atomic read and write for safer implementation.
		 */
		ar->tx_list->buffer = data;
		ar->tx_list->send_chunk_len = tx_len;
		
		__complete(&ar->tx_buf_lock);
		
		/* Lock asynchronous TX process, so no more
		 * packets can be sent down, until the current
		 * transfer finishes. 
		 */
		__start(&ar->tx_async_lock);
		/* The actual data is sent here. */
		result = ar9170_usb_send_data(data, tx_len);
		
		#if USB_CMD_WRAPPER_DEBUG_DEEP
		printf("Bulk OUT [%u]: ",(unsigned int)tx_len);
		for (i=0; i<tx_len; i++) {
			printf("%02x ", bulk_out_buffer[i]);
		}
		printf(" \n");
		#endif

		if(result == false) {
			printf("ERROR: Data could not be submitted correctly.\n");
			/* Release asynchronous TX process, because we normally 
			 * do not expect the callback to be called and release 
			 * the asynchronous transmission flag.
			 */
			__complete(&ar->tx_async_lock);
			return result;
		}
		
	} else {
		printf("WARNING: Non-empty usb packet list.\n");
		/* If the transmission buffer is non-empty, put the current command 
		 * in the tail of the list and return. 
		 */
		struct ar9170_send_list* next_pos = ar->tx_list;
		while(next_pos->next_send_chunk != NULL) {
			next_pos = next_pos->next_send_chunk;
		}
		next_pos->next_send_chunk = smalloc(sizeof(struct ar9170_send_list));
		if (next_pos->next_send_chunk == NULL) {
			printf("ERROR: Could not allocate memory for data bulk transfer.\n");
			__complete(&ar->tx_buf_lock);
			return false;
		
		} else {
			
			next_pos->next_send_chunk->buffer = data;
			next_pos->next_send_chunk->send_chunk_len = tx_len;
			next_pos->next_send_chunk->next_send_chunk = NULL;
		}
		__complete(&ar->tx_buf_lock);		
	}
	/* Note that the asynchronous transmission flag is locked, and will be
	 * released by the callback, so no more data can be transfered down to
	 * the USB line before the current transmission is over.
	 */
	return result;
}