void RFSend (unsigned char *str)
// transmit function, it only transmit a string, so make sure the input is a pointer to a string
// or we can come up with a way to change a variable into a string
{
    txptr = str;
    enable_tx();
}
Beispiel #2
0
 //conditionally disable and enable tx
 bool disable_tx(void) {
     if (_tx_enabled) {
         enable_tx(false);
         return true;
     }
     return false;
 }
Beispiel #3
0
static void handle_response(GObex *obex, GError *err, GObexPacket *rsp)
{
	struct pending_pkt *p = obex->pending_req;
	gboolean disconn = err ? TRUE : FALSE, final_rsp = TRUE;

	if (rsp != NULL)
		final_rsp = parse_response(obex, rsp);

	if (p->cancelled)
		err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED,
					"The operation was cancelled");

	if (err)
		g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);

	if (p->rsp_func) {
		p->rsp_func(obex, err, rsp, p->rsp_data);

		/* Check if user callback removed the request */
		if (p != obex->pending_req)
			return;
	}

	if (p->cancelled)
		g_error_free(err);

	if (final_rsp) {
		pending_pkt_free(p);
		obex->pending_req = NULL;
	}

	if (!disconn && g_queue_get_length(obex->tx_queue) > 0)
		enable_tx(obex);
}
Beispiel #4
0
void switch_to_tx(void)
{
    //turn on tx
    enable_tx();
    //turn on UDRE interrupt
    enable_udre_interrupt();
}
Beispiel #5
0
void g_obex_resume(GObex *obex)
{
	g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u", obex->conn_id);

	obex->suspended = FALSE;

	if (g_queue_get_length(obex->tx_queue) > 0 || obex->tx_data > 0)
		enable_tx(obex);
}
Beispiel #6
0
void send_rx_buffer() {
  rx.val.pID = SERVO_ADDR;
  uint8_t cs1 = calculate_cs1();
  rx.val.cs1 = (cs1 & 0xFE);
  rx.val.cs2 = ((cs1 ^ 0xFF) & 0xFE);

  enable_tx();
  hwuart_tx(0xff); // sync
  hwuart_tx(0xff);
  uint8_t tosend = rx.val.size - 2;
  for (uint8_t i=0; i < tosend; i++) {
    hwuart_tx(rx.rawdata[i]);
  }
  hwuart_tx(0); // junk, just in case
  disable_tx();
}
Beispiel #7
0
static gboolean g_obex_send_internal(GObex *obex, struct pending_pkt *p,
								GError **err)
{

	if (obex->io == NULL) {
		g_set_error(err, G_OBEX_ERROR, G_OBEX_ERROR_DISCONNECTED,
					"The transport is not connected");
		g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", (*err)->message);
		return FALSE;
	}

	if (g_obex_packet_get_operation(p->pkt, NULL) == G_OBEX_OP_ABORT)
		g_queue_push_head(obex->tx_queue, p);
	else
		g_queue_push_tail(obex->tx_queue, p);

	if (obex->pending_req == NULL || p->id == 0)
		enable_tx(obex);

	return TRUE;
}
void main ( void )
{
	ADI_ETHER_HANDLE   hEthernet;
	ADI_ETHER_RESULT   etherResult;
	ADI_ETHER_DEV_INIT EtherInitData[MAX_NETWORK_IF] = { { true, &memtable[0] }, { true, &memtable[1] }}; // data-cache,driver memory
	uint32_t reg_data;
	int i, nEtherDevUsed;
	char *ether_stack_block;

	ADI_GPIO_RESULT gpio_result;
	uint32_t gpioMaxCallbacks;
	int nRet;


	/**
	 * Initialize managed drivers and/or services that have been added to
	 * the project.
	 * @return zero on success
	 */
	adi_initComponents();
	
	/**
	 * The default startup code does not include any functionality to allow
	 * core 0 to enable core 1. A convenient way to enable core 1 is to use the
	 * 'adi_core_1_enable' function.
	 */
	adi_core_1_enable();
	
	/* Begin adding your custom code here */
	g_AuxiTMIsFirstUpdated = 1;
	
	/* init CGU first time */
	CGU_Init ( MULTIPLIER_SEL, CCLK_SEL, DDRCLK_SEL );				/* CCLK=16.384*iMultiplier /1 Mhz, 16.384*iMultiplier/iDDCLKSel Mhz DDR2 CLK */
	
#if defined(__DEBUG_FILE__)
    /* open the debug file */
    pDebugFile = fopen(__DEBUG_FILE_NAME__, "w");
    if (pDebugFile == 0)
    {
    	fclose(pDebugFile);
    	return;
    }
#elif defined(__DEBUG_UART__)
    Init_UART();
#endif

    Init_PTPAuxin();

	/* configures the switches */
#if BF609_EZ_BRD
	
	DEBUG_STATEMENT ( "Configuring switches for the ethernet operation \n\n" );
	ConfigSoftSwitches();
	
#endif
	
	/* open ethernet device */
	nEtherDevUsed = ( user_net_num_ifces > MAX_NETWORK_IF ) ? MAX_NETWORK_IF : user_net_num_ifces;

#if BF609_EZ_BRD
	nEtherDevUsed = 1;
#endif

	DEBUG_STATEMENT ( " init EMAC\n\n" );

	for ( i = 0; i < nEtherDevUsed; i++ )
	{
		etherResult = adi_ether_Open ( g_pDevEntry[i], &EtherInitData[i], g_pEthCallBack[i], &hEthernet );
		if ( etherResult != ADI_ETHER_RESULT_SUCCESS )
		{
			DEBUG_STATEMENT ( "adi_ether_Open: failed to open ethernet driver\n\n" );
			return ;
		}
		
		g_hDev[i] = hEthernet;
		
		/* get the mac address */
		memcpy ( ( ( ADI_EMAC_DEVICE * ) hEthernet )->MacAddress, user_net_config_info[i].hwaddr, 6 );

		/* allocate memory  */
		ether_stack_block = heap_malloc ( i+1, g_contEthHeapSize[i] );
		if ( ether_stack_block == NULL )
		{
			DEBUG_PRINT ( " heap_malloc: in heap %d, failed to allocate memory to the stack \n\n" , i+1);
			return ;
		}
		
		/* init buf mem */
		nRet = InitBuff ( g_contEthHeapSize[i],
				ether_stack_block, hEthernet,
				&user_net_config_info[i] );
		if( nRet<0 )
		{
			DEBUG_STATEMENT ( " InitBuff: failed to enable Init Buffs\n\n" );
			return ;
		}

		/* Enable the MAC */
		etherResult = adi_ether_EnableMAC ( hEthernet );
		if ( etherResult != ADI_ETHER_RESULT_SUCCESS )
		{
			DEBUG_STATEMENT ( " adi_ether_EnableMAC: failed to enable EMAC\n\n" );
			return ;
		}
	}
	
	//enable EMAC INT
	adi_int_EnableInt ( ( (ADI_EMAC_DEVICE *)g_hDev[0])->Interrupt, true);
	adi_int_EnableInt ( ( (ADI_EMAC_DEVICE *)g_hDev[1])->Interrupt, true);

	/* activate rx channel DMA */
	enable_rx ( g_hDev[0] );
	enable_rx ( g_hDev[1] );
	/* activate tx channel DMA */
	enable_tx ( g_hDev[0] );
	enable_tx ( g_hDev[1] );

	//enable emac0 tx,rx
	enable_emac_tx_rx (  g_hDev[0] );

	//enable emac1 tx,rx
	enable_emac_tx_rx (  g_hDev[1] );

	//enable
	Enable_Time_Stamp_Auxin_Interrupt();

	//
	HandleLoop();

	return ;

}//main
Beispiel #9
0
static ssize_t bladerf_write(struct file *file, const char *user_buf, size_t count, loff_t *ppos)
{
    bladerf_device_t *dev;
    unsigned long flags;
    char *buf = NULL;
    struct data_buffer *db = NULL;
    unsigned int idx;
    int reread;
    int status = 0;

    /* TODO truncate count to be within range of ssize_t here? */

    dev = (bladerf_device_t *)file->private_data;

    if (dev->intnum == 0) {
        int llen;
        buf = (char *)kmalloc(count, GFP_KERNEL);
        if (buf) {
            if (copy_from_user(buf, user_buf, count)) {
                status = -EFAULT;
            } else {
                status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2), buf, count, &llen, BLADE_USB_TIMEOUT_MS);
            }
            kfree(buf);
        } else {
            dev_err(&dev->interface->dev, "Failed to allocate write buffer\n");
            status = -ENOMEM;
        }

        if (status < 0)
            return status;
        else
            return llen;
    }

    if (dev->writer) {
        if (file != dev->writer) {
            return -EPERM;
        }
    } else
        dev->writer = file;

    reread = atomic_read(&dev->data_out_used);
    if (reread >= NUM_DATA_URB) {
        status = wait_event_interruptible_timeout(dev->data_out_wait, atomic_read(&dev->data_out_used) < NUM_DATA_URB, 2 * HZ);

        if (status < 0) {
            return status;
        } else if (status == 0) {
            return -ETIMEDOUT;
        }
    }

    spin_lock_irqsave(&dev->data_out_lock, flags);

    idx = dev->data_out_producer_idx++;
    dev->data_out_producer_idx &= (NUM_DATA_URB - 1);
    db = &dev->data_out_bufs[idx];
    atomic_inc(&dev->data_out_cnt);
    atomic_inc(&dev->data_out_used);

    spin_unlock_irqrestore(&dev->data_out_lock, flags);

    if (copy_from_user(db->addr, user_buf, count)) {
        return -EFAULT;
    }

    db->valid = 1; // mark this TX packet as having valid data

    __submit_tx_urb(dev);
    if (!dev->tx_en)
        enable_tx(dev);

    return count;
}
Beispiel #10
0
 void restore_tx(bool last) {
     if (last != _tx_enabled) {
         enable_tx(last);
     }
 }