int main() { HANDLE hDevice = GetDeviceViaInterface((LPGUID)&GUID_DEVINTERFACE_SDIO_DEVICE,0); if (hDevice == INVALID_HANDLE_VALUE) { printf("Failed to obtain file handle to device: " "%s with Win32 error code: %d\n", "MyWDMDevice", GetLastError() ); return 1; } EnableInt(hDevice); Sleep(2000); DWORD dwRead; ReadFile(hDevice,buffer,BUFFER_SIZE,&dwRead,NULL); printf("read %x\n",dwRead); DisableInt(hDevice); CloseHandle(hDevice); return 0; }
/* ButtonTask: Checks if the button is still pressed and if not re-enables the button's ** ISR. (Also toggles a GPIO pin for debugging purposes.) */ void ButtonTask(void *argument) { UINT32 i; TaskParametersDef *TaskParameters = (TaskParametersDef *)argument; ToggleBit(TaskParameters->Flag_Pin); for (i = 0; i < TaskParameters->Delay; i += 1); ToggleBit(TaskParameters->Flag_Pin); if (IsPressed(TaskParameters->Button_Pin)) // Is button still pressed? OSScheduleSuspendedTask(TaskParameters->event); // Yes, reschedule the task else { // No, clear interrupt flag to prevent button rebounds ClearInt(TaskParameters->Button_Pin); EnableInt(TaskParameters->Button_Pin); } OSSuspendSynchronousTask(); } /* end of ButtonTask */
/* * Target system-dependent initialization */ EXPORT ER tkdev_initialize( void ) { static UINT giob[4] = { _L, _H, _HH, _HHH }; UINT gb; INT i; /* initialize GPIO interrupt */ for ( i = 0; i < 4; ++i ) { gb = giob[i]; out_w(GIO_IDS(gb), 0xffffffff); /* disable interrupt */ out_w(GIO_IIA(gb), 0x00000000); /* disassert interrupt pin */ out_w(GIO_GSW(gb), 0x00000000); /* disassert FIQ pin */ } /* initialize interrupt controller (AINT) */ out_w(IT0_IDSS0, 0xffffffff); /* disassert interrupt pin */ out_w(IT0_IDSS1, 0xffffffff); out_w(IT0_IDSS2, 0xffffffff); out_w(IT0_IDS0, 0xffffffff); /* disable interrupt */ out_w(IT0_IDS1, 0xffffffff); out_w(IT0_IDS2, 0xffffffff); out_w(IT_PINV_CLR0, 0xffffffff); /* reset inverted logic */ out_w(IT_PINV_CLR1, 0xffffffff); out_w(IT_PINV_CLR2, 0xffffffff); out_w(IT_LIIR, 0xffffffff); /* clear interrupt */ out_w(IT0_IIR, 0xffffffff); out_w(IT0_FIE, 0x00000001); /* enable FIQ */ /* enable GPIO interrupt on AINT */ out_w(IT0_IENS0, IRQM(26)|IRQM(27)); /* assert interrupt pin */ out_w(IT0_IENS1, IRQM(50)|IRQM(51)|IRQM(52)|IRQM(53)); out_w(IT0_IENS2, IRQM(79)|IRQM(80)); out_w(IT0_IEN0, IRQM(26)|IRQM(27)); /* enable interrupt */ out_w(IT0_IEN1, IRQM(50)|IRQM(51)|IRQM(52)|IRQM(53)); out_w(IT0_IEN2, IRQM(79)|IRQM(80)); /* enable abort switch(SW1) */ SetIntMode(IV_GPIO(8), IM_ENA|IM_LEVEL|IM_HI); EnableInt(IV_GPIO(8)); return E_OK; }
static int rio_open (struct net_device *dev) { struct netdev_private *np = netdev_priv(dev); long ioaddr = dev->base_addr; int i; u16 macctrl; i = request_irq (dev->irq, &rio_interrupt, IRQF_SHARED, dev->name, dev); if (i) return i; /* Reset all logic functions */ writew (GlobalReset | DMAReset | FIFOReset | NetworkReset | HostReset, ioaddr + ASICCtrl + 2); mdelay(10); /* DebugCtrl bit 4, 5, 9 must set */ writel (readl (ioaddr + DebugCtrl) | 0x0230, ioaddr + DebugCtrl); /* Jumbo frame */ if (np->jumbo != 0) writew (MAX_JUMBO+14, ioaddr + MaxFrameSize); alloc_list (dev); /* Get station address */ for (i = 0; i < 6; i++) writeb (dev->dev_addr[i], ioaddr + StationAddr0 + i); set_multicast (dev); if (np->coalesce) { writel (np->rx_coalesce | np->rx_timeout << 16, ioaddr + RxDMAIntCtrl); } /* Set RIO to poll every N*320nsec. */ writeb (0x20, ioaddr + RxDMAPollPeriod); writeb (0xff, ioaddr + TxDMAPollPeriod); writeb (0x30, ioaddr + RxDMABurstThresh); writeb (0x30, ioaddr + RxDMAUrgentThresh); writel (0x0007ffff, ioaddr + RmonStatMask); /* clear statistics */ clear_stats (dev); /* VLAN supported */ if (np->vlan) { /* priority field in RxDMAIntCtrl */ writel (readl(ioaddr + RxDMAIntCtrl) | 0x7 << 10, ioaddr + RxDMAIntCtrl); /* VLANId */ writew (np->vlan, ioaddr + VLANId); /* Length/Type should be 0x8100 */ writel (0x8100 << 16 | np->vlan, ioaddr + VLANTag); /* Enable AutoVLANuntagging, but disable AutoVLANtagging. VLAN information tagged by TFC' VID, CFI fields. */ writel (readl (ioaddr + MACCtrl) | AutoVLANuntagging, ioaddr + MACCtrl); } init_timer (&np->timer); np->timer.expires = jiffies + 1*HZ; np->timer.data = (unsigned long) dev; np->timer.function = &rio_timer; add_timer (&np->timer); /* Start Tx/Rx */ writel (readl (ioaddr + MACCtrl) | StatsEnable | RxEnable | TxEnable, ioaddr + MACCtrl); macctrl = 0; macctrl |= (np->vlan) ? AutoVLANuntagging : 0; macctrl |= (np->full_duplex) ? DuplexSelect : 0; macctrl |= (np->tx_flow) ? TxFlowControlEnable : 0; macctrl |= (np->rx_flow) ? RxFlowControlEnable : 0; writew(macctrl, ioaddr + MACCtrl); netif_start_queue (dev); /* Enable default interrupts */ EnableInt (); return 0; }
void Ventilation (void) { register int flagvvm = 0; register int ncol, nlin, escala, y0, y1, y2; int y_ini0, y_ini1; int cor; float far *apt; float far *aptaux; register float flux, sum_flux; float sum[4]; #ifdef BYPASS_VVM int step = 0; int offset = 0; #endif BYPASS_VVM LeData (); getviewsettings (&vp); VentVolMax = sum_flux = 0.0; NumeroSinal = 0; escala = DELTA_Y(14); coluna = DELTA_X( 6); y0 = y_ini0 = DELTA_Y(74); y2 = y1 = y_ini1 = DELTA_Y(90); apt = inicVVM1; aptaux = inicVVM1Int; Atendeu = FALSE; sum[0] = sum[1] = sum[2] = sum[3] = 0.0; LinBaseVVM1 = LinBaseVVM2 =0.0; #ifndef BYPASS_HADWARE #ifndef BYPASS_VVM IniAquisition(); EnableInt(); #endif BYPASS_VVM #endif BYPASS_HADWARE do { #ifndef BYPASS_VVM DisableInt(); #endif BYPASS_VVM Help = kbhit() && (ESC == getch()); #ifndef BYPASS_VVM EnableInt(); #endif BYPASS_VVM if (Help) Abortou = TRUE; else { #ifndef BYPASS_VVM while(!Atendeu); Sinal -= (int)Zero; #else BYPASS_VVM Sinal = 14; #endif BYPASS_VVM Atendeu = FALSE; } } while( (abs(Sinal) < 10) && (!Abortou) ); if (!Abortou) { #ifdef GRAVACAO_DE_DADOS fprintf ( PDados, "\n\n\t %%%%%%%%%%% VENTVOL: %%%%%%%%%%%"); #endif GRAVACAO_DE_DADOS do { #ifndef BYPASS_VVM DisableInt(); #endif BYPASS_VVM Help = kbhit() && (ESC == getch()); #ifndef BYPASS_VVM EnableInt(); #endif BYPASS_VVM if (Help) Abortou = TRUE; else { #ifndef BYPASS_VVM while(!Atendeu); *aptaux = flux = (Sinal > Zero) ? VDxFluxo ( Sinal , GanhoExp ): VDxFluxo ( Sinal , GanhoIns ); #else BYPASS_VVM /* ----------------------------- */ /* Simulacao de um Alcaponamento */ /* ----------------------------- */ if (!(NumeroSinal % 15)) { offset = -1; } else { offset = 0; } if ( NumeroSinal > 1200 ) { offset = -2; } if ( NumeroSinal > 1300 ) { offset = 0; } *aptaux = flux = 10 * cos ( (M_PI * step++) /60) + offset; #endif BYPASS_VVM #ifdef GRAVACAO_DE_DADOS fprintf ( PDados, "\n\t%04X", Sinal); #endif GRAVACAO_DE_DADOS if (*aptaux > 0.0) { VentVolMax += flux / SampleRatio; flagvvm = 1; } #ifdef VVM_ALCAP_ sum_flux += flux / SampleRatio; sum[0] = (.01 * sum_flux) + (.19 * sum[1]) + (.30 * sum[2]) + (.50 * sum[3]); sum[3] = sum[2]; sum[2] = sum[1]; sum[1] = sum[0]; /* --------------------------- */ /* Calculo das Linhas de Base */ /* para obtencao do valor do */ /* volume Alcaponado. */ /* */ /* Convecionou-se: */ /* LBASE1 -> Volume Medio Entre*/ /* 2 e 3 segundos. */ /* */ /* LBASE2 -> Volume Medio Entre*/ /* 10 e 11 segundos. */ /* */ /* Volume Acapondado Extrapola-*/ /* do a um minuto sera a dife- */ /* das das linhas de Base vezes*/ /* 7.5 (que e'60/8) */ /* --------------------------- */ if ( (NumeroSinal >= 200) && (NumeroSinal < 400) ) /* ------- */ /* LBASE_1 */ /* ------- */ { LinBaseVVM1 += sum[0]; } else if ( (NumeroSinal >= 2000) && (NumeroSinal < 2200) ) /* ------- */ /* LBASE_2 */ /* ------- */ { LinBaseVVM2 += sum[0]; } #else VVM_ALCAP_ sum_flux = sum_flux; y_ini1 = y_ini1; y0 = y0; y1 = y1; y2 = y2; #endif VVM_ALCAP_ if (flagvvm) { *apt = VentVolMax; /* --------------------------- */ /* Um ponto chega a cada 5ms */ /* Totalizando 2400 ptos em 12s*/ /* Os 12s medem DELTA_X(88), */ /* logo a coluna atual depende */ /* de NumSinal segundo a formu-*/ /* la abaixo: */ /* --------------------------- */ ncol = (int) ( (((long) NumeroSinal) * DELTA_X(88))/2400 + DELTA_X( 6) ); if ( ncol != coluna ) { cor = getcolor(); /* -------------------------- */ /* Tracado do Volume Expirado */ /* -------------------------- */ nlin = (int) ((y_ini0 - (((long) escala ) * VentVolMax)/10)); moveto(coluna, y0); lineto( coluna, nlin ); y0 = nlin; #ifdef VVM_ALCAP_ setcolor (bea_color[ 7]); /* ----------------------------- */ /* Tracado do Volume (Invertido) */ /* ----------------------------- */ nlin = (int) ((y_ini1 + (((long) escala ) * (sum_flux))/2)); moveto(coluna, y1); lineto( coluna, nlin ); y1 = nlin; setcolor (bea_color[11]); /* -------------------------------------------------- */ /* Tracado Valor Medio Filtrado do Volume (Invertido) */ /* -------------------------------------------------- */ nlin = (int) ((y_ini1 + (((long) escala ) * (sum[0]))/2)); moveto(coluna, y2); lineto( coluna, nlin ); y2 = nlin; #endif VVM_ALCAP_ setcolor (cor); coluna = ncol; } ++NumeroSinal; } ++apt; ++aptaux; Atendeu = FALSE; } } while ( (NumeroSinal != NUMMAXPONTOSINF-1) && (coluna != DELTA_X(88) + DELTA_X( 6)) && (!Abortou) ); #ifndef BYPASS_VVM DisableInt(); #endif BYPASS_VVM for (; apt<inicVVM1+NUMMAXPONTOSINF; apt++) { *apt = FIM_1; } *aptaux = END; *(aptaux+1) = TempAmb; *(aptaux+2) = UmidRel; *(aptaux+3) = PresBar; if (!Abortou) { if (FlagIntegridade) ReCalcula(); CalculaParamVVM(); CalculaVVMpercent(); outtextxy(DELTA_X(25) , DELTA_Y( 5), "Param Teorico Calculado %"); cor = getcolor(); setcolor(bea_color[15]); gprintf (DELTA_X(25) , DELTA_Y( 6) + CharH, "VVM %6.2f %6.2f %4.0f", VentVolMaxteorico, VentVolMax, (VentVolMaxpercent+0.5)); #ifdef VVM_ALCAP_ gprintf (DELTA_X(25) , DELTA_Y( 7) + 2 * CharH, "ALCAP -- %7.2f - ", VolAlcaponado); #endif VVM_ALCAP_ setcolor(cor); if (teste1VVM) { teste2VVM = TRUE; teste1VVM = FALSE; } else teste1VVM = TRUE; } } #ifndef BYPASS_VVM else DisableInt(); #endif BYPASS_VVM } /* Ventilation */
static int rio_open (struct net_device *dev) { struct netdev_private *np = netdev_priv(dev); long ioaddr = dev->base_addr; int i; u16 macctrl; i = request_irq (dev->irq, rio_interrupt, IRQF_SHARED, dev->name, dev); if (i) return i; /* */ writew (GlobalReset | DMAReset | FIFOReset | NetworkReset | HostReset, ioaddr + ASICCtrl + 2); mdelay(10); /* */ writel (readl (ioaddr + DebugCtrl) | 0x0230, ioaddr + DebugCtrl); /* */ if (np->jumbo != 0) writew (MAX_JUMBO+14, ioaddr + MaxFrameSize); alloc_list (dev); /* */ for (i = 0; i < 6; i++) writeb (dev->dev_addr[i], ioaddr + StationAddr0 + i); set_multicast (dev); if (np->coalesce) { writel (np->rx_coalesce | np->rx_timeout << 16, ioaddr + RxDMAIntCtrl); } /* */ writeb (0x20, ioaddr + RxDMAPollPeriod); writeb (0xff, ioaddr + TxDMAPollPeriod); writeb (0x30, ioaddr + RxDMABurstThresh); writeb (0x30, ioaddr + RxDMAUrgentThresh); writel (0x0007ffff, ioaddr + RmonStatMask); /* */ clear_stats (dev); /* */ if (np->vlan) { /* */ writel (readl(ioaddr + RxDMAIntCtrl) | 0x7 << 10, ioaddr + RxDMAIntCtrl); /* */ writew (np->vlan, ioaddr + VLANId); /* */ writel (0x8100 << 16 | np->vlan, ioaddr + VLANTag); /* */ writel (readl (ioaddr + MACCtrl) | AutoVLANuntagging, ioaddr + MACCtrl); } init_timer (&np->timer); np->timer.expires = jiffies + 1*HZ; np->timer.data = (unsigned long) dev; np->timer.function = rio_timer; add_timer (&np->timer); /* */ writel (readl (ioaddr + MACCtrl) | StatsEnable | RxEnable | TxEnable, ioaddr + MACCtrl); macctrl = 0; macctrl |= (np->vlan) ? AutoVLANuntagging : 0; macctrl |= (np->full_duplex) ? DuplexSelect : 0; macctrl |= (np->tx_flow) ? TxFlowControlEnable : 0; macctrl |= (np->rx_flow) ? RxFlowControlEnable : 0; writew(macctrl, ioaddr + MACCtrl); netif_start_queue (dev); /* */ EnableInt (); return 0; }