Beispiel #1
0
/*
 *  ======== MEM_redefine ========
 */
Void MEM_redefine(Int id, Ptr base, MEM_sizep length)
{
    IArg           key;
    HeapMem_Params params;
    HeapMem_Handle heap;

    /* Make sure the segid is valid. */    
    if ((id < 0) || (id == 0) || ((Uns)id >= MEM_tabSize)) {
        SYS_error("MEM", SYS_EINVAL);
        return;
    }
    
    key = HeapMem_enter();
    
    if (MEM_table[id] == NULL) {
        HeapMem_leave(key);
        SYS_error("MEM", SYS_EINVAL);        
        return;
    }
    
    heap = HeapMem_Handle_from_xdc_runtime_IHeap(MEM_table[id]);

    HeapMem_destruct(HeapMem_struct(heap));

    HeapMem_Params_init(&params);
    params.size = length;
    params.buf = base;

    HeapMem_construct(HeapMem_struct(heap), &params);

    HeapMem_leave(key);
}
Beispiel #2
0
/*
 *  ======== MEM_alloc ========
 */
Ptr MEM_alloc(Int id, size_t size, size_t align)
{
    Error_Block eb;
    
    Error_init(&eb);
    
    if (id < 0) {
        SYS_error( "MEM", SYS_EALLOC, id, size, align );
        return (NULL);
    }

    /*
     *  Allow non-legacy apps to use modules that use MEM (e.g. drivers).
     *  Use the default heap in xdc.runtime.Memory.
     */
    if (MEM_tabSize == 0) {
        return (xdc_runtime_Memory_alloc(NULL, size, align, &eb));
    }
   
    if ((Uns)id >= MEM_tabSize) {
        SYS_error( "MEM", SYS_EALLOC, id, size, align );
        return (NULL);
    }
   
    if (MEM_table[id] == NULL) {
        SYS_error( "MEM", SYS_EALLOC, id, size, align );
        return(FALSE);
    }

    return (xdc_runtime_Memory_alloc(MEM_table[id], size, align, &eb));
}
Beispiel #3
0
/*
 *  ======== MEM_free ========
 */
Bool MEM_free(Int id, Ptr addr, size_t size)
{
    if (id < 0) {
        SYS_error("MEM", SYS_EFREE, id, addr, size);
        return (FALSE);
    }

    /*
     *  Allow non-legacy apps to use modules that use MEM (e.g. drivers).
     *  Use the default heap in xdc.runtime.Memory.
     */
    if (MEM_tabSize == 0) {
        xdc_runtime_Memory_free(NULL, addr, size);
        return (TRUE);
    }
    
    if (((Uns)id < MEM_tabSize) && (MEM_table[id] != NULL)) {
        xdc_runtime_Memory_free(MEM_table[id], addr, size);
        return (TRUE);
    }
    else {
        SYS_error("MEM", SYS_EFREE, id, addr, size);
        return (FALSE);
    }
}
Beispiel #4
0
/*
 *  ======== MEM_stat ========
 */
Bool MEM_stat(Int id, MEM_Stat *statbuf)
{
    IArg            key;
    HeapMem_Handle  heap;
    Memory_Stats    stat;
    HeapMem_ExtendedStats extendedStats;
    
    if ((id < 0) || ((Uns)id >= MEM_tabSize) || (MEM_table[id] == NULL)) {
        SYS_error("MEM", SYS_EINVAL);        
        return (FALSE);
    }

    heap = HeapMem_Handle_from_xdc_runtime_IHeap(MEM_table[id]);

    /* Use HeapMem's gate for thread-safety */
    key = HeapMem_enter();

    HeapMem_getExtendedStats(heap, &extendedStats);
    Memory_getStats(MEM_table[id], &stat);
    statbuf->size = stat.totalSize;
    statbuf->used = stat.totalSize - stat.totalFreeSize;
    statbuf->length = stat.largestFreeSize;
    statbuf->space = 1;
    statbuf->base = extendedStats.buf;

    HeapMem_leave(key);

    return (TRUE);
}
Beispiel #5
0
/*
 *  ======== MEM_getHandle ========
 */
IHeap_Handle MEM_getHandle(Int id)
{
    if ((id < 0) || ((Uns)id >= MEM_tabSize)  || 
        (MEM_table[id] == NULL)) {
        SYS_error("MEM", SYS_EINVAL);
        return (NULL);
    }
    return (MEM_table[id]);
}
Beispiel #6
0
/*
 * DEV_deleteDevice deletes device(DEV_Device) entry in the OBJ table
 * if device by that name exist in the system.
 * This API is not reentrant
 */
Int DEV_deleteDevice (String name)
{
    DEV_TableElem *objDev;
    DEV_Device *entry;
    IOM_Fxns *iomfxns;
    Int status = SYS_OK;
    Uns key;

    /* Check if device   exists in the Device table, if not return FALSE */
    DEV_find(name, &entry);
    if (entry == NULL) {
        SYS_error("DEV", SYS_ENODEV);
        return(SYS_ENODEV);
    }

    /*
     * If device to be deleted is of type IOM call mdUnBindDev with
     * interrupts disabled
     */
    if (entry->type == DEV_IOMTYPE) {
        iomfxns = (IOM_Fxns *)entry->fxns;

        key = HWI_disable();
        status = iomfxns->mdUnBindDev(entry->devp);
        HWI_restore(key);

        if (status != IOM_COMPLETED) {
            SYS_error("DEV", SYS_EBADIO);
        }
        else {
            status = SYS_OK;
        }

    }

    /* Free Device entry in the device table */
    objDev = (DEV_TableElem *)((char *)entry - sizeof(QUE_Elem));
    QUE_remove(objDev);
    MEM_free(0, objDev, sizeof(DEV_TableElem));


    return(status);
}
Beispiel #7
0
int8_t MIDI_init(void)
 {
  
  #ifdef QSID_RPI
   return MIDI_RPi_MIDI_init();
  #else
   SYS_error("no MIDI driver compiled in.");
   return -1;
  #endif

 }
Beispiel #8
0
/*
 *  ======== MEM_getBaseAddress ========
 */
Ptr MEM_getBaseAddress(Int id)
{
    HeapMem_ExtendedStats stats;
    
    if ((id < 0) || ((Uns)id >= MEM_tabSize)  || 
        (MEM_table[id] == NULL)) {
        SYS_error("MEM", SYS_EINVAL);
        return (NULL);
    }

    HeapMem_getExtendedStats(
        HeapMem_Handle_from_xdc_runtime_IHeap(MEM_table[id]), &stats);

    return (stats.buf);
}
Beispiel #9
0
/*
 *  ======== MEM_undefine ========
 */
Void MEM_undefine(Int id)
{
    HeapMem_Handle      heap;
    
    /* Make sure the id is valid */
    if ( (id < 0) || ((Uns)id >= MEM_tabSize)  ||
        (MEM_table[id] == NULL)) {
        SYS_error("MEM", SYS_EINVAL);
        return;
    }

    heap = HeapMem_Handle_from_xdc_runtime_IHeap(MEM_table[id]);
    HeapMem_delete(&heap);

    MEM_table[id] = NULL;
}
Beispiel #10
0
/*
 *  ======== GIO_new ========
 */
GIO_Handle GIO_new(GIO_Handle gioChan, String name, Int mode, Int *status, Ptr optArgs,
        IOM_Packet packetBuf[], Ptr syncObject, GIO_Attrs *attrs)
{
    DEV_Device  *entry;
    Int         i;
    Int         tmpStat;

    if (attrs == NULL) {
        attrs = &GIO_ATTRS;
    }

    /*
     * status param is used to pass additional device status back to caller.
     */
    if (status == NULL) {
        status = &tmpStat;    /* no longer need to check if status valid ptr */
    }

    *status = IOM_COMPLETED;
    
    /*
     *  Find device structure in device table for device with name 'name'.
     *  DEV_match() returns the remaining name string for use by the
     *  mini-driver's create() function.
     */
    name = DEV_match(name, &entry);
    if (entry == NULL) {
        SYS_error(name, SYS_ENODEV); /* sys error - no device found */
        return (NULL);
    }
    
    if (entry->type != DEV_IOMTYPE) {
        SYS_error("IOM", SYS_EINVAL); /* sys error - invalid device parameter */
        return (NULL);
    }

    /* initialize queue structures */
    QUE_new(&gioChan->freeList);

    /* zero out the packet buffers */
    memset(packetBuf, 0, attrs->nPackets * sizeof(IOM_Packet));

    /* Put packets into freeList. */
    for (i=0; i < attrs->nPackets; i++) {
        QUE_put(&gioChan->freeList, &packetBuf[i]);
    }

    /*
     * Plug semaphore or other synchronization object.  'gioChan->syncObj' is
     * used to wait for I/O to complete when GIO_submit() is called with
     * NULL *appCallback parameter. 
     */
    gioChan->syncObj = syncObject;

    gioChan->fxns = (IOM_Fxns *)entry->fxns;
    gioChan->mode = mode;
    gioChan->timeout = attrs->timeout;

    *status = gioChan->fxns->mdCreateChan(&gioChan->mdChan, entry->devp,
            name, mode, optArgs, _GIO_iomCallback, gioChan);

    if (gioChan->mdChan == NULL) {
        return (NULL);
    }

    return (gioChan);
}
Beispiel #11
0
/*
 *  ======== GIO_create ========
 */
GIO_Handle GIO_create(String name, Int mode, Int *status, Ptr optArgs, \
        GIO_Attrs *attrs)
{
    GIO_Handle  gioChan;
    IOM_Packet  *packet;
    DEV_Device  *entry;
    Int         i;
    Int         tmpStat;

    if (attrs == NULL) {
        attrs = &GIO_ATTRS;
    }

    /*
     * status param is used to pass additional device status back to caller.
     */
    if (status == NULL) {
        status = &tmpStat;    /* no longer need to check if status valid ptr */
    }

    *status = IOM_COMPLETED;
    
    /*
     *  Find device structure in device table for device with name 'name'.
     *  DEV_match() returns the remaining name string for use by the
     *  mini-driver's create() function.
     */
    name = DEV_match(name, &entry);
    if (entry == NULL) {
        SYS_error(name, SYS_ENODEV); /* sys error - no device found */

        return (NULL);
    }
    
    if (entry->type != DEV_IOMTYPE) {
        SYS_error("IOM", SYS_EINVAL); /* sys error - invalid device parameter */

        return (NULL);
    }

    /*  allocate and 0-fill IOM object */
    gioChan = MEM_calloc(0, sizeof(GIO_Obj), 0);
    if (gioChan == NULL) {
        *status = IOM_EALLOC;  
       
        return (NULL);
    }

    /* initialize queue structures */
    QUE_new(&gioChan->freeList);

    /*
     * Allocate packets for asynch I/O.
     */
    for (i=0; i < attrs->nPackets; i++) {

        packet = _GIO_mkPacket();

        if (packet == NULL) {
           
            *status = IOM_EALLOC;

            GIO_delete(gioChan);
            return (NULL);
        }

        QUE_put(&gioChan->freeList, packet);
    }

    /*
     * Create semaphore or other synchronization object.  'gioChan->syncObj' is
     * used to wait for I/O to complete when GIO_submit() is called with
     * NULL *appCallback parameter. 
     */
    gioChan->syncObj = GIO->SEMCREATE(0, NULL);

    if (gioChan->syncObj == NULL) {

        *status = IOM_EALLOC;
 
        GIO_delete(gioChan);
        return (NULL);
    }

    gioChan->fxns = (IOM_Fxns *)entry->fxns;
    gioChan->mode = mode;
    gioChan->timeout = attrs->timeout;

    *status = gioChan->fxns->mdCreateChan(&gioChan->mdChan, entry->devp,
            name, mode, optArgs, _GIO_iomCallback, gioChan);

    if (gioChan->mdChan == NULL) {
        
        GIO_delete(gioChan);
        return (NULL);
    }

    return (gioChan);
}
Beispiel #12
0
/*
 * DEV_createDevice creates device(DEV_Device) entry in the OBJ table
 * if device by that name do not exist in the system.
 * This API is not reentrant
 */
Int DEV_createDevice (String name, Void *fxns,   Fxn initFxn,
        DEV_Attrs *attrs)
{
    DEV_TableElem *objDevHead = (DEV_TableElem*) &DEV_table;
    DEV_TableElem *objDev, *objEntry;
    DEV_Device *dptr, *entry;
    IOM_Fxns *iomfxns;
    Int status;
    Uns key;

    /*
     * Crate a device entry, if not successful return
     * SYS_EALLOC. 
     */

    objEntry = MEM_calloc(0, sizeof(DEV_TableElem), 0);

    if (objEntry == NULL) {
        return(SYS_EALLOC);
    }

    TSK_disable();


    /*
     * Check if device already exists in the Device table, if yes return
     * SYS_EINVAL
     */
    DEV_find(name, &entry);

    if (entry != NULL) {
        TSK_enable();
        MEM_free(0, objEntry, sizeof(DEV_TableElem));
        SYS_error("DEV", SYS_EINVAL);
        return(SYS_EINVAL);
    }

    /*
     * Initialize new device entry(DEV_Device) in the OBJ table with
     * the parameters passed to API
     */
    entry = &objEntry->device;
    entry->name = name;
    entry->fxns = fxns;

    if (attrs == NULL) {
        attrs = &DEV_ATTRS;
    }
    entry->devid  = attrs->devid;
    entry->params = attrs->params;
    entry->type   = attrs->type;
    entry->devp   = attrs->devp;

    /*
     * Call the Device init function if its not NULL, with interrupts
     * disabled.
     */
    if (initFxn != NULL) {
        key = HWI_disable();
        (*initFxn)();
        HWI_restore(key);
    }

    /*
     * If device created is of type IOM then call mini driver function
     * mdBindDev with interrupts disabled.
     */
    if (entry->type == DEV_IOMTYPE) {
        iomfxns = (IOM_Fxns *) entry->fxns;

        key = HWI_disable();
        status = iomfxns->mdBindDev(&entry->devp, entry->devid,
                                     entry->params);
        HWI_restore(key);

        if (status != IOM_COMPLETED) {
            
            TSK_enable();

            /* Delete the just created device entry in device table */
            MEM_free(0, objEntry, sizeof(DEV_TableElem));

            SYS_error("DEV", SYS_EBADIO);

            return(status);
        }

    }

    /*
     * Device is ready for addition into OBJ_Table. Check new device
     * name length against existing device name lengths. If length of
     * new device is greater than one in OBJ_table, mark the location
     * and insert device ahead of device whose name length is shorter
     * else add it to the end.
     *
     * This will keep all the devices sorted in descending order, which is
     * required to pass additional parameters along with device name in 
     * DEV_open()
     */

    objDev = (DEV_TableElem *)QUE_next((Ptr)objDevHead);
    while (objDev != objDevHead) {
        dptr = &objDev->device;
        if (strlen(name) > strlen(dptr->name)) {
            break;
        }
        objDev = (DEV_TableElem *)QUE_next((Ptr)objDev);
    }

    /* Insert objEntry ahead of objDev */
    QUE_insert(objDev, objEntry);

    TSK_enable();

    return(SYS_OK);
}
Beispiel #13
0
/*
 * ======== DEV_ebadio ========
 */
Int DEV_ebadio(DEV_Handle device)
{
    SYS_error("DEV", SYS_EBADIO);

    return SYS_EBADIO;
}