예제 #1
0
파일: buf.c 프로젝트: andreimironenko/bios
/*
 *  ======== BUF_create ========
 */
BUF_Handle BUF_create(Uns numbuff, MEM_sizep size, Uns align, BUF_Attrs *attrs)
{
    HeapBuf_Params params;
    BUF_Handle buf = NULL;
    Error_Block eb;

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

    Error_init(&eb);

    HeapBuf_Params_init(&params);

    params.buf = MEM_alloc(attrs->segid, size * numbuff, align);
    params.numBlocks = numbuff;
    params.blockSize = size;
    params.align = align;
    params.bufSize = size * numbuff;
    
    if (params.buf != NULL) {
        buf = (BUF_Handle)HeapBuf_create(&params, &eb);
    }

    return (buf);
}
Int SystemCfg_createResources(SystemCfg_Object *obj)
{
    Error_Block         eb;
    Int                 status = 0;
    HeapBuf_Params      heapBufP;
    IHeap_Handle        heapH;


    Log_print1(Diags_ENTRY | Diags_INFO, "--> "FXNN": (obj=0x%x)",(IArg)obj);
    Error_init(&eb);

    /* allocate heap backing store from SR_0 heap */
    heapH = (IHeap_Handle)SharedRegion_getHeap(0);
    obj->rcmHeapBufSize = 5 * 128;
    obj->rcmHeapBufBase = Memory_alloc(heapH, obj->rcmHeapBufSize, 128, &eb);

    if (Error_check(&eb)) {
        Log_error1(FXNN": out of memory: size=%u", obj->rcmHeapBufSize);
        status = -1;
        goto leave;
    }

    /* create heap for messages */
    HeapBuf_Params_init(&heapBufP);
    heapBufP.blockSize = 128;       // header = 52 B, payload = 76 B
    heapBufP.numBlocks = 5;         // 5 messages, total heap storage = 640 B
    heapBufP.align = 128;           // align on cache line boundary
    heapBufP.buf = obj->rcmHeapBufBase;     // heap storage base address
    heapBufP.bufSize = obj->rcmHeapBufSize; // heap storage size

    obj->rcmHeapH = HeapBuf_create(&heapBufP, &eb);

    if (Error_check(&eb)) {
        Log_error0(FXNN": HeapBuf_create() failed");
        status = -1;
        goto leave;
    }

    /* register this heap with MessageQ */
    Log_print2(Diags_INFO,
        FXNN": MessageQ_registerHeap: (rcmHeapH: 0x%x, heapId: %d)",
        (IArg)(obj->rcmHeapH), (IArg)SystemCfg_RcmMsgHeapId_CompDev);

    MessageQ_registerHeap((Ptr)(obj->rcmHeapH), SystemCfg_RcmMsgHeapId_CompDev);

leave:
    Log_print1(Diags_EXIT, "<-- "FXNN": %d", (IArg)status);
    return(status);
}
예제 #3
0
파일: memory.c 프로젝트: tomaszmat/simulate
/*
 *  ======== main ========
 */
Int main()
{
    /* Call board init functions */
    Board_initGeneral();

    /* Construct BIOS objects */
    Task_Params taskParams;
    HeapBuf_Params heapBufParams;
    HeapMem_Params heapMemParams;

    /* Construct writer/reader Task threads */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)task0Fxn, &taskParams, NULL);

    taskParams.stack = &task1Stack;
    Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL);

    /* Construct two heaps to be used by two separate tasks for alloc and free. */
    HeapBuf_Params_init(&heapBufParams);
    heapBufParams.blockSize = HEAPBUFSIZE / 2;
    heapBufParams.numBlocks = 2;
    heapBufParams.align = 8;
    heapBufParams.buf = heapBufBuffer;
    heapBufParams.bufSize = HEAPBUFSIZE;
    HeapBuf_construct(&heapBufStruct, &heapBufParams, NULL);
    task0Heap = HeapBuf_handle(&heapBufStruct);

    HeapMem_Params_init(&heapMemParams);

    heapMemParams.size = HEAPMEMSIZE;
    heapMemParams.minBlockAlign = 8;
    heapMemParams.buf = heapMemBuffer;
    HeapMem_construct(&heapMemStruct, &heapMemParams);
    task1Heap = HeapMem_handle(&heapMemStruct);

    System_printf("Memory example started.\n");

    BIOS_start();    /* Does not return */
    return(0);
}
예제 #4
0
/*
 *  ======== tsk0_func ========
 *  Allocates a message and ping-pongs the message around the processors.
 *  A local message queue is created and a remote message queue is opened.
 *  Messages are sent to the remote message queue and retrieved from the
 *  local MessageQ.
 */
Void tsk0_func(UArg arg0, UArg arg1)
{
    MessageQ_Msg     msg;    
    MessageQ_Handle  messageQ;
    MessageQ_QueueId remoteQueueId;    
    Int              status;
    UInt16           msgId = 0;
    Ptr              buf;
    HeapBuf_Handle   heapHandle;
    HeapBuf_Params   hbparams;
    SizeT            blockSize;
    UInt             numBlocks;

    /* Compute the blockSize & numBlocks for the HeapBuf */
    numBlocks = 2;
    blockSize = sizeof(MessageQ_MsgHeader);

    /* Alloc a buffer from the default heap */
    buf = Memory_alloc(0, numBlocks * blockSize, 0, NULL);
    
    /* 
     *  Create the heap that is used for allocating MessageQ messages.
     */     
    HeapBuf_Params_init(&hbparams);
    hbparams.align          = 0;
    hbparams.numBlocks      = numBlocks;
    hbparams.blockSize      = blockSize;
    hbparams.bufSize        = numBlocks * blockSize;
    hbparams.buf            = buf;
    heapHandle = HeapBuf_create(&hbparams, NULL);
    if (heapHandle == NULL) {
        System_abort("HeapBuf_create failed\n" );
    }
        
    /* Register default system heap with MessageQ */
    MessageQ_registerHeap((IHeap_Handle)(heapHandle), HEAPID);

    /* Create the local message queue */
    messageQ = MessageQ_create(localQueueName, NULL);    
    if (messageQ == NULL) {
        System_abort("MessageQ_create failed\n" );
    }
    
    /* Open the remote message queue. Spin until it is ready. */
    do {
        status = MessageQ_open(remoteQueueName, &remoteQueueId); 
        /* 
         *  Sleep for 1 clock tick to avoid inundating remote processor
         *  with interrupts if open failed
         */
        if (status < 0) { 
            Task_sleep(1);
        }
    } while (status < 0);
    
    if (MultiProc_self() == 0) {
        /* Allocate a message to be ping-ponged around the processors */
        msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader));
        if (msg == NULL) {
           System_abort("MessageQ_alloc failed\n" );
        }
        
        /* 
         *  Send the message to the remote processor and wait for a message
         *  from the previous processor.
         */
        System_printf("Start the main loop\n");
        while (msgId < NUMLOOPS) {
            /* Increment...the remote side will check this */
            msgId++;
            MessageQ_setMsgId(msg, msgId);
            
            System_printf("Sending a message #%d to %s\n", msgId, remoteQueueName);
            
            /* send the message to the remote processor */
            status = MessageQ_put(remoteQueueId, msg);
            if (status < 0) {
               System_abort("MessageQ_put had a failure/error\n");        
            }
            
            /* Get a message */
            status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
            if (status < 0) {
               System_abort("This should not happen since timeout is forever\n");
            }
        }
    }
    else {
        /*
         *  Wait for a message from the previous processor and
         *  send it to the remote processor
         */
        System_printf("Start the main loop\n");
        while (TRUE) {
            /* Get a message */
            status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
            if (status < 0) {
               System_abort("This should not happen since timeout is forever\n");
            }

            System_printf("Sending a message #%d to %s\n", MessageQ_getMsgId(msg),
                remoteQueueName);

            /* Get the message id */
            msgId = MessageQ_getMsgId(msg);

            /* send the message to the remote processor */
            status = MessageQ_put(remoteQueueId, msg);
            if (status < 0) {
               System_abort("MessageQ_put had a failure/error\n");
            }
            
            /* test done */
            if (msgId >= NUMLOOPS) {
                break;
            }
        }
    }
    
    System_printf("The test is complete\n");

    BIOS_exit(0);
}