コード例 #1
0
int pictimerInstall(unsigned timer_no, int pri, int freq, void (*isr)(void*))
{
unsigned              tmp;

	if ( timer_no >= NumberOf(timerConnected) ) {
		fprintf(stderr,"Invalid timer instance %i; (0..3 allowed)\n", timer_no);
		return -1;
	}

	if ( timerConnected[timer_no] ) {
		fprintf(stderr,"OpenPIC Timer #%i already connected\n", timer_no);
		return -1;
	}

	if ( pri > 15 || pri < 1 ) {
		fprintf(stderr,"Invalid timer IRQ priority %i (1..15 allowed)\n",pri);
		return -1;
	}

	printf("Using OpenPIC Timer #%i at %p\n", timer_no, &OpenPIC->Global.Timer[timer_no]);

	timer_period_ns = 1000000000 / in_le32( &OpenPIC->Global.Timer_Frequency );

	/* freq < 0 means they want to specify a period in ticks directly */
	if ( freq < 0 )
		tmp = -freq;
	else
		tmp = in_le32( &OpenPIC->Global.Timer_Frequency ) / freq;

	out_le32( &OpenPIC->Global.Timer[timer_no].Base_Count, OPENPIC_MASK | tmp );
	out_le32( &OpenPIC->Global.Timer[timer_no].Base_Count, tmp );
	/* map to 1st CPU */
	openpic_maptimer(timer_no, 1);
	if ( 0 == bspExtInstallSharedISR( TIMER_IVEC + timer_no, isr, (void*)timer_no, BSPEXT_ISR_NONSHARED ) ) {
		openpic_inittimer( timer_no, pri, TIMER_IVEC + timer_no );
		timerConnected[timer_no] = isr;
		return 0;
	}
	fprintf(stderr,"Unable to install shared ISR for OpenPIC Timer #%i\n",timer_no);
	return -1;
}
コード例 #2
0
ファイル: if_xxx_rtems.c プロジェクト: epicsdeb/rtems
int
NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_attach)
	(struct rtems_bsdnet_ifconfig *config, int attaching)
{
	int error     = 0;
	device_t dev = net_dev_get(config);
	struct	NET_SOFTC *sc;
	struct  ifnet     *ifp;
#ifndef HAVE_LIBBSPEXT
	rtems_irq_connect_data irq_data = {
				0,
				the_net_isr,
#if ISMINVERSION(4,6,99)
				0,
#endif
				noop,
				noop,
				noop1 };
#endif

	if ( !dev )
		return 1;

	if ( !dev->d_softc.NET_SOFTC_BHANDLE_FIELD ) {
#if defined(NETDRIVER_PCI)
		device_printf(dev,NETDRIVER" unit not configured; executing setup...");
		/* setup should really be performed prior to attaching.
		 * Wipe the device; setup and re-obtain the device...
		 */
		memset(dev,0,sizeof(*dev));
		error = NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_pci_setup)(-1);
		/* re-obtain the device */
		dev   = net_dev_get(config);
		if ( !dev ) {
			printk("Unable to re-assign device structure???\n");
			return 1;
		}
		if (error <= 0) {
			device_printf(dev,NETDRIVER" FAILED; unable to attach interface, sorry\n");
			return 1;
		}
		device_printf(dev,"success\n");
#else
		device_printf(dev,NETDRIVER" unit not configured; use 'rtems_"NETDRIVER"_setup()'\n");
		return 1;
#endif
	}

	if ( !net_driver_ticks_per_sec )
		rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &net_driver_ticks_per_sec );

	sc  = device_get_softc( dev );
	ifp = &sc->arpcom.ac_if;

#ifdef DEBUG_MODULAR
	if (!METHODSPTR) {
		device_printf(dev,NETDRIVER": method pointer not set\n");
		return -1;
	}
#endif

	if ( attaching ) {
		if ( ifp->if_init ) {
			device_printf(dev,NETDRIVER" Driver already attached.\n");
			return -1;
		}
		if ( config->hardware_address ) {
			/* use configured MAC address */
			memcpy(sc->arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN);
		} else {
#ifdef NET_READ_MAC_ADDR
			NET_READ_MAC_ADDR(sc);
#endif
		}
		if ( METHODSPTR->n_attach(dev) ) {
			device_printf(dev,NETDRIVER"_attach() failed\n");
			return -1;
		}
	} else {
		if ( !ifp->if_init ) {
			device_printf(dev,NETDRIVER" Driver not attached.\n");
			return -1;
		}
		if ( METHODSPTR->n_detach ) {
			if ( METHODSPTR->n_detach(dev) ) {
				device_printf(dev,NETDRIVER"_detach() failed\n");
				return -1;
			}
		} else {
			device_printf(dev,NETDRIVER"_detach() not implemented\n");
			return -1;
		}
	}


	if ( !sc->tid )
		sc->tid = rtems_bsdnet_newproc(NETDRIVER"d", 4096, net_daemon, sc);

	if (attaching) {
#ifdef DEBUG
		printf("Installing IRQ # %i\n",sc->irq_no);
#endif
#ifdef HAVE_LIBBSPEXT
		if ( bspExtInstallSharedISR(sc->irq_no, the_net_isr, sc, 0) )
#else
		/* BSP dependent :-( */
		irq_data.name   = sc->irq_no;
#if ISMINVERSION(4,6,99)
		irq_data.handle = (rtems_irq_hdl_param)sc;
#else
		thesc = sc;
#endif
		if ( ! BSP_install_rtems_irq_handler( &irq_data ) )
#endif
		{
			fprintf(stderr,NETDRIVER": unable to install ISR\n");
			error = -1;
		}
	} else {
		if ( sc->irq_no ) {
#ifdef DEBUG
		printf("Removing IRQ # %i\n",sc->irq_no);
#endif
#ifdef HAVE_LIBBSPEXT
		if (bspExtRemoveSharedISR(sc->irq_no, the_net_isr, sc))
#else
		/* BSP dependent :-( */
		irq_data.name   = sc->irq_no;
#if ISMINVERSION(4,6,99)
		irq_data.handle = (rtems_irq_hdl_param)sc;
#endif
		if ( ! BSP_remove_rtems_irq_handler( &irq_data ) )
#endif
		{
			fprintf(stderr,NETDRIVER": unable to uninstall ISR\n");
			error = -1;
		}
		}
	}
	return error;
}