Beispiel #1
0
HCD_STATUS HcdCancelTransfer(uint32_t PipeHandle)
{
    uint8_t HostID, EdIdx;

    ASSERT_STATUS_OK(PipehandleParse(PipeHandle, &HostID, &EdIdx) );

    HcdED(EdIdx)->hcED.Skip = 1;

    /* Clear SOF and wait for the next frame */
    USB_REG(HostID)->InterruptStatus = HC_INTERRUPT_StartofFrame;
    while ( !(USB_REG(HostID)->InterruptStatus & HC_INTERRUPT_StartofFrame) )/* TODO Should have timeout */

        /* ISO TD & General TD have the same offset for nextTD, we can use GTD as pointer to travel on TD list */
        while ( Align16(HcdED(EdIdx)->hcED.HeadP.HeadTD) != Align16(HcdED(EdIdx)->hcED.TailP) ) {
            uint32_t HeadTD = Align16(HcdED(EdIdx)->hcED.HeadP.HeadTD);
            if ( IsIsoEndpoint(EdIdx) ) {
                HcdED(EdIdx)->hcED.HeadP.HeadTD = ((PHCD_IsoTransferDescriptor) HeadTD)->NextTD;
                FreeItd( (PHCD_IsoTransferDescriptor) HeadTD);
            }
            else {
                HcdED(EdIdx)->hcED.HeadP.HeadTD = ((PHCD_GeneralTransferDescriptor) HeadTD)->hcGTD.NextTD;
                FreeGtd((PHCD_GeneralTransferDescriptor) HeadTD);
            }
        }
    HcdED(EdIdx)->hcED.HeadP.HeadTD = Align16(HcdED(EdIdx)->hcED.TailP);/*-- Toggle Carry/Halted are also set to 0 --*/
    HcdED(EdIdx)->hcED.HeadP.ToggleCarry = 0;

    HcdED(EdIdx)->hcED.Skip = 0;
    return HCD_STATUS_OK;
}
Beispiel #2
0
size_t
I420FrameBufferSizePadded(int32_t aWidth, int32_t aHeight)
{
  if (aWidth <= 0 || aHeight <= 0 || aWidth > MAX_VIDEO_WIDTH ||
      aHeight > MAX_VIDEO_HEIGHT) {
    return 0;
  }

  size_t ySize = Align16(aWidth) * Align16(aHeight);
  return ySize + (ySize / 4) * 2;
}
Beispiel #3
0
internal void
SDLResizeDIBSection(SDL_Window *Window, sdl_offscreen_buffer *Buffer,
                    int Width, int Height)
{
    int BytesPerPixel = 4;

    if (!Buffer->Renderer) {
        Buffer->Renderer = SDL_CreateRenderer(Window, -1,
                                              SDL_RENDERER_ACCELERATED |
                                              SDL_RENDERER_PRESENTVSYNC);
    }

    if (Buffer->Memory) {
        SDL_DestroyTexture(Buffer->Texture);
        int BitmapMemorySize = Buffer->Width * Buffer->Height * BytesPerPixel;
        munmap(Buffer->Memory, BitmapMemorySize);
    }

    Buffer->Width = Width;
    Buffer->Height = Height;
    Buffer->BytesPerPixel = BytesPerPixel;
    Buffer->Texture = SDL_CreateTexture(Buffer->Renderer,
                                        SDL_PIXELFORMAT_ARGB8888,
                                        SDL_TEXTUREACCESS_STREAMING,
                                        Buffer->Width, Buffer->Height);
    Buffer->Pitch = Align16(Width * BytesPerPixel);
    int BitmapMemorySize = Buffer->Pitch * Buffer->Height;
    Buffer->Memory = mmap(0, BitmapMemorySize, PROT_READ | PROT_WRITE,
                          MAP_PRIVATE | MAP_ANON, -1, 0);
}
Beispiel #4
0
static HCD_STATUS QueueOneITD(uint32_t EdIdx, uint8_t *dataBuff, uint32_t TDLen, uint16_t StartingFrame)
{
    uint32_t i;
    PHCD_IsoTransferDescriptor pItd = (PHCD_IsoTransferDescriptor) Align16(HcdED(EdIdx)->hcED.TailP);

    pItd->StartingFrame = StartingFrame;
    pItd->FrameCount =
        (TDLen / HcdED(EdIdx)->hcED.MaxPackageSize) + (TDLen % HcdED(EdIdx)->hcED.MaxPackageSize ? 1 : 0) - 1;
    pItd->BufferPage0 = Align4k( (uint32_t) dataBuff);
    pItd->BufferEnd = (uint32_t) (dataBuff + TDLen - 1);

    for (i = 0; TDLen > 0 && i < 8; i++) {
        uint32_t XactLen = MIN(TDLen, HcdED(EdIdx)->hcED.MaxPackageSize);

        pItd->OffsetPSW[i] =
            (HCD_STATUS_TRANSFER_NotAccessed <<
             12) | (Align4k((uint32_t) dataBuff) != Align4k(pItd->BufferPage0) ? _BIT(12) : 0) |
            Offset4k((uint32_t) dataBuff);					/*-- FIXME take into cross page account later 15-12: ConditionCode, 11-0: offset --*/

        TDLen -= XactLen;
        dataBuff += XactLen;
    }

    /* Create a new place holder TD & link setup TD to the new place holder */
    ASSERT_STATUS_OK(AllocItdForEd(EdIdx) );

    return HCD_STATUS_OK;
}
Beispiel #5
0
void NeuralNet::Alloc()
{
   if(mAllocated)
   {
      Free();
   }
   
   mNInp16 = Align16(mNInp * sizeof(float)) / sizeof(float);
   mNHid16 = Align16(mNHid * sizeof(float)) / sizeof(float);
   mNOut16 = Align16(mNOut * sizeof(float)) / sizeof(float);

   mpInputPatterns = new float[mBunchSize * mNInp16 + 0xF];
   mpHiddenPatterns = new float[mBunchSize * mNHid16 + 0xF];
   mpOutputPatterns = new float[mBunchSize * mNOut16 + 0xF];

   mpInputPatterns16 = MemAlign16(mpInputPatterns);
   mpHiddenPatterns16 = MemAlign16(mpHiddenPatterns);
   mpOutputPatterns16 = MemAlign16(mpOutputPatterns); 

   // mNInp16 * mNHid16: calculate more (imaginar) neurons in the hidden 
   // layer to bypass copping of patterns between hidden and output layer
   mpInpHidMatrix = new float [mNHid16 * mNInp16 + 0xF]; 
   mpHidOutMatrix = new float [mNOut16 * mNHid16 + 0xF];

   mpInpHidMatrix16 = MemAlign16(mpInpHidMatrix);
   mpHidOutMatrix16 = MemAlign16(mpHidOutMatrix);            

   mpHiddenBiases = new float [mNHid16 + 0xF];
   mpOutputBiases = new float [mNOut16 + 0xF];            
   
   mpHiddenBiases16 = MemAlign16(mpHiddenBiases);
   mpOutputBiases16 = MemAlign16(mpOutputBiases);           

   mpNormMeans = new float [mNInp16 + 0xF];
   mpNormDevs = new float [mNInp16 + 0xF];

   mpNormMeans16 = MemAlign16(mpNormMeans);  
   mpNormDevs16 = MemAlign16(mpNormDevs);
      
   mAllocated = true;
}
Beispiel #6
0
void test_MemoryAlloc()
{
    MemoryInit((void *)pool, POOL_SIZE);

    ERROR(g_hunk_base == pool);
    ERROR(g_hunk_total_size == POOL_SIZE);
    I32 size = Align16(DYNAMIC_ZONE_SIZE + sizeof(HunkHeader));
    ERROR(g_hunk_low_used == size);
    ERROR(g_hunk_high_used == 0);

    ERROR((U8 *)g_main_zone == pool + sizeof(HunkHeader));
    ERROR(g_main_zone->rover == (MemoryBlock *)(g_main_zone + 1));
    ERROR(g_main_zone->size == DYNAMIC_ZONE_SIZE);

    // ====================
    // test hunk allocation
    // ====================

    void *hunk0 = HunkLowAlloc(1231, "hunk0");
    HunkHeader *hunk0Header = (HunkHeader *)hunk0 - 1;
    I32 hunk0Size = Align16(1231 + sizeof(HunkHeader));
    ERROR(hunk0Header->size == hunk0Size);
    ERROR(hunk0Header->sentinel == HUNK_SENTINEL);
    ERROR(StringCompare(hunk0Header->name, "hunk0") == 0);
    ERROR(g_hunk_low_used == size + hunk0Size);

    void *hunk1 = HunkHighAlloc(3211, "hunk1");
    HunkHeader *hunk1Header = (HunkHeader *)hunk1 - 1;
    I32 hunk1Size = Align16(3211 + sizeof(HunkHeader));
    ERROR(hunk0Header->size == hunk0Size);
    ERROR(hunk0Header->sentinel == HUNK_SENTINEL);
    ERROR(StringCompare(hunk1Header->name, "hunk1") == 0);
    ERROR(g_hunk_high_used == hunk1Size);

    // ====================
    // test zone allocation
    // ====================

    void *zone0 = ZoneTagMalloc(234, 8);
    MemoryBlock *zone0Block = (MemoryBlock *)zone0 - 1;
    I32 zone0Size = Align8(234 + sizeof(MemoryBlock) + 4);
    ERROR(zone0Block->size == zone0Size);
    ERROR(zone0Block->tag == 8);
    ERROR(zone0Block->id == ZONE_ID);
    ERROR(zone0Block->prev == &g_main_zone->tailhead);
    MemoryBlock *freeBlock = zone0Block->next;
    ERROR(freeBlock->tag == 0);

    void *zone1 = ZoneTagMalloc(324, 1);
    void *zone2 = ZoneTagMalloc(432, 2);
    void *zone3 = ZoneTagMalloc(223, 3);
    void *zone4 = ZoneTagMalloc(333, 4);

    ZoneFree(zone1);
    MemoryBlock *zone1Block = (MemoryBlock *)zone1 - 1;
    I32 zone1Size = Align8(324 + sizeof(MemoryBlock) + 4);
    ERROR(zone1Block->tag == 0);
    ERROR(zone1Block->size == zone1Size);
    ERROR(zone1Block->id == ZONE_ID);
    ERROR(zone1Block->prev == (MemoryBlock *)zone0 - 1);
    ERROR(zone1Block->next == (MemoryBlock *)zone2 - 1);

    ZoneFree(zone3);
    MemoryBlock *zone3Block = (MemoryBlock *)zone3 - 1;
    I32 zone3Size = Align8(223 + sizeof(MemoryBlock) + 4);
    ERROR(zone3Block->tag == 0);
    ERROR(zone3Block->size == zone3Size);
    ERROR(zone3Block->id == ZONE_ID);
    ERROR(zone3Block->prev == (MemoryBlock *)zone2 - 1);
    ERROR(zone3Block->next == (MemoryBlock *)zone4 - 1);
    
    ZoneFree(zone2);
    I32 zone2Size = Align8(432 + sizeof(MemoryBlock) + 4);
    ERROR(zone1Block->tag == 0);
    ERROR(zone1Block->size == zone1Size + zone2Size + zone3Size);
    ERROR(zone1Block->prev == (MemoryBlock *)zone0 - 1);
    ERROR(zone1Block->next == (MemoryBlock *)zone4 - 1);

    void *tooBig = ZoneTagMalloc(DYNAMIC_ZONE_SIZE * 2, 22);
    ERROR(tooBig == NULL);

    ZoneClearAll(g_main_zone);
    ERROR(g_main_zone->tailhead.next == g_main_zone->rover);
    ERROR(g_main_zone->tailhead.prev == g_main_zone->rover);
    ERROR(g_main_zone->rover->next == &g_main_zone->tailhead);
    ERROR(g_main_zone->rover->next == &g_main_zone->tailhead);
}
Beispiel #7
0
void HcdIrqHandler(uint8_t HostID)
{
    uint32_t IntStatus;

    IntStatus = USB_REG(HostID)->InterruptStatus;
    /* Clear status after read immediately.
    	 Then it will be able to record a new status. */
    USB_REG(HostID)->InterruptStatus = IntStatus;/* Clear HcInterruptStatus */
    IntStatus &= USB_REG(HostID)->InterruptEnable;
    if (IntStatus == 0) {
        return;
    }

    /* disable all interrupt for processing */
    USB_REG(HostID)->InterruptDisable = HC_INTERRUPT_MasterInterruptEnable;

    /* Process RootHub Status Change */
    if (IntStatus & HC_INTERRUPT_RootHubStatusChange) {
        for(; USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_StatusChangeMask;) {
            /* only 1 port/host --> skip to get the number of ports */
            if (USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_ConnectStatusChange) {
                if (USB_REG(HostID)->RhStatus & HC_RH_STATUS_DeviceRemoteWakeupEnable) {	/* means a remote wakeup event */

                }
                else {}

                USB_REG(HostID)->RhPortStatus1 = HC_RH_PORT_STATUS_ConnectStatusChange;	/* clear CSC bit */
                OHciRhStatusChangeIsr(HostID, USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_CurrentConnectStatus);
            }

            if (USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_PortEnableStatusChange) {
                USB_REG(HostID)->RhPortStatus1 = HC_RH_PORT_STATUS_PortEnableStatusChange;	/* clear PESC */
            }

            if (USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_PortSuspendStatusChange) {
                USB_REG(HostID)->RhPortStatus1 = HC_RH_PORT_STATUS_PortSuspendStatusChange;			/* clear PSSC */
            }

            if (USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_OverCurrentIndicatorChange) {	/* Over-current handler to avoid physical damage */
                USB_REG(HostID)->RhPortStatus1 = HC_RH_PORT_STATUS_OverCurrentIndicatorChange;			/* clear OCIC */
            }

            if (USB_REG(HostID)->RhPortStatus1 & HC_RH_PORT_STATUS_PortResetStatusChange) {
                USB_REG(HostID)->RhPortStatus1 = HC_RH_PORT_STATUS_PortResetStatusChange;			/* clear PRSC */
            }
        }
    }

    if (IntStatus & HC_INTERRUPT_WritebackDoneHead) {
        ProcessDoneQueue(HostID, Align16(ohci_data[HostID].hcca.HccaDoneHead) );
    }

#if SCHEDULING_OVRERRUN_INTERRUPT
    if (USB_REG(HostID)->HcInterruptStatus & HC_INTERRUPT_SchedulingOverrun) {
        OHciSchedulingOverrunIsr(HostID);
    }
#endif

#if SOF_INTERRUPT
    if (USB_REG(HostID)->HcInterruptStatus & HC_INTERRUPT_StartofFrame) {
        OHciStartofFrameIsr(HostID);
    }
#endif

#if RESUME_DETECT_INTERRUPT
    if (USB_REG(HostID)->HcInterruptStatus & HC_INTERRUPT_ResumeDetected) {
        OHciResumeDetectedIsr(HostID);
    }
#endif

#if UNRECOVERABLE_ERROR_INTERRUPT
    if (USB_REG(HostID)->HcInterruptStatus & HC_INTERRUPT_UnrecoverableError) {
        OHciUnrecoverableErrorIsr(HostID);
    }
#endif

#if FRAMENUMBER_OVERFLOW_INTERRUPT
    if (USB_REG(HostID)->HcInterruptStatus & HC_INTERRUPT_FrameNumberOverflow) {
        OHciFramenumberOverflowIsr(HostID);
    }
#endif

#if OWNERSHIP_CHANGE_INTERRUPT
    if (USB_REG(HostID)->HcInterruptStatus & HC_INTERRUPT_OwnershipChange) {
        OHciOwnershipChangeIsr(HostID);
    }
#endif
    USB_REG(HostID)->InterruptEnable = HC_INTERRUPT_MasterInterruptEnable;

}