Beispiel #1
0
void __exit embx_deinit( void )
{
    remove_proc_entry("embx", NULL /* parent dir */);

    EMBX_Deinit();

    EMBX_OS_MUTEX_DESTROY(&_embx_dvr_ctx.lock);
    _embx_dvr_ctx.isLockInitialized = EMBX_FALSE;

    EMBX_HandleManager_Destroy(&_embx_handle_manager);

    return;
}
void deinit_thread(void *param)
{
EMBX_TRANSPORT tp = (EMBX_TRANSPORT)param;
EMBX_ERROR res;

    EMBX_OS_Delay((unsigned long)param);

    res = EMBX_Deinit();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("deinit_thread(%ld) failed, res = %s\n", (unsigned long)param, error_strings[res]));
        return;
    }
}
Beispiel #3
0
int main()
{
EMBX_TRANSPORT hTrans;
EMBX_PORT bufferpool, consumer, mypoolconnection;
EMBX_ERROR err;
int i;

	embxRuntimeInit();
	err = EMBX_OpenTransport("shm", &hTrans);
	assert(EMBX_SUCCESS == err);

	/* Create the port which will hold the pool of work buffers */
	err = EMBX_CreatePort(hTrans, "bufferpool", &bufferpool);
	assert(EMBX_SUCCESS == err);

	/* Make a connection to the port we just created so we can inject
	 * empty buffers onto the port's queue as part of the initialization
	 */
	err = EMBX_Connect(hTrans, "bufferpool", &mypoolconnection);
	assert(EMBX_SUCCESS == err);

	/* Now wait for the consumer port to come into existence and 
	 * make a connection to it.
	 */
	err = EMBX_ConnectBlock(hTrans, "consumer", &consumer);
	assert(EMBX_SUCCESS == err);


	/* Inject empty buffers into the buffer pool */
	for(i=0;i<BUFFER_POOL_SIZE;i++)
	{
	EMBX_VOID *buffer;
		
		err = EMBX_Alloc(hTrans, BUFFER_SIZE, &buffer);
		assert(EMBX_SUCCESS == err);

		/* Send empty buffer to the buffer pool port */
		err = EMBX_SendMessage(mypoolconnection, buffer, 0);
		assert(EMBX_SUCCESS == err);
	}

	/* We don't need our connection to the buffer pool anymore
	 * so close it down.
	 */
	EMBX_ClosePort(mypoolconnection);

	for(i=0;i<100;i++)
	{
	EMBX_RECEIVE_EVENT ev;
	EMBX_UINT buffersize;
		
		/* Jabber ... */
		printf("producer: Issuing message %d of 100\n", i+1);


		/* Get an empty buffer from the pool */
		err = EMBX_ReceiveBlock(bufferpool, &ev);
		assert(EMBX_SUCCESS == err);

		/* The event size field does not represent the actual
		 * size of the buffer in this case, hence if you need
		 * to find that out use the following. However in this
		 * case where all the buffers are the same known size 
		 * it wouldn't be necessary expect as self checking debug.
		 */
		err = EMBX_GetBufferSize(ev.data, &buffersize);
		assert(EMBX_SUCCESS == err);

		/* Do something to fill the buffer with stuff to be used
		 * by the consumer...... use your imagination ......
		 */


		/* Now send the buffer to the consumer with the real amount
		 * of data in the buffer as the size argument (this can be
		 * less than the buffer size). For this example we assume
		 * the whole buffer contains valid data.
		 */
		err = EMBX_SendMessage(consumer, ev.data, buffersize);
		assert(EMBX_SUCCESS == err);
	}

	/* Shut the communication system down. This has the side effect
	 * of causing the consumer to also close down, almost certainly
	 * before outstanding messages have been processed.
	 */
	EMBX_ClosePort(bufferpool);
	EMBX_ClosePort(consumer);
	EMBX_CloseTransport(hTrans);
	EMBX_Deinit();

	return 0;
}
int run_test(void)
{
EMBX_ERROR     res;
EMBX_TPINFO    tpinfo1;
EMBX_BOOL      bFailed;
EMBX_TRANSPORT tp;
EMBX_PORT      localPort,remotePort;
EMBX_VOID     *buffer1,*buffer2;
EMBX_FACTORY   factory;

    bFailed = EMBX_FALSE;
    tp      = EMBX_INVALID_HANDLE_VALUE;
    buffer1 = buffer2 = 0;

    /* Test 1 */
    res = EMBX_SendMessage(EMBX_INVALID_HANDLE_VALUE, buffer1, 0);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    res = EMBX_RegisterTransport(EMBXLB_loopback_factory,&loopback_config,sizeof(EMBXLB_Config_t),&factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 2 */
    res = EMBX_Init();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 3 */
    res = EMBX_GetFirstTransport(&tpinfo1);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 4 */
    res = EMBX_OpenTransport(tpinfo1.name, &tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 5 */
    res = EMBX_CreatePort(tp, "testport", &localPort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }
    
    /* Test 6 */
    res = EMBX_Connect(tp, "testport", &remotePort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }
    
    /* Test 7 */
    res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 8 */
    res = EMBX_SendMessage(tp, buffer1, 0);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 9 */
    res = EMBX_SendMessage(localPort, buffer1, 0);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 10 */
    res = EMBX_SendMessage(remotePort, 0, 0);
    if(res != EMBX_INVALID_ARGUMENT)
    {
        EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 11 */
    res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE+1);
    if(res != EMBX_INVALID_ARGUMENT)
    {
        EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 12 */
    res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 13 - Ensure this allocation happens before buffer1 gets free'd
     * when the port is closed, so buffer1 and buffer2 will not point to
     * the same memory which is important for later tests.
     */
    res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer2);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 14 */
    res = EMBX_ClosePort(localPort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 15 - buffer1 has been freed by test14 so should be garbage */
    res = EMBX_SendMessage(remotePort, buffer1, 0);
    if(res != EMBX_INVALID_ARGUMENT)
    {
        EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 16 */
    res = EMBX_SendMessage(remotePort, buffer2, BUFFER_SIZE);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 17 */
    res = EMBX_ClosePort(remotePort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 18 */
    res = EMBX_CloseTransport(tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }
    
    /* Test 19 */
    res = EMBX_Deinit();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* These test a different code path to the identical tests done before
     * EMBX_Init.
     */

    /* Test 20 - Depends on buffer2 not having been freed so we get through
     * to checking the state of the driver.
     */
    res = EMBX_SendMessage(remotePort, buffer2, 0);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 21 */
    res = EMBX_UnregisterTransport(factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    return bFailed?-1:0;

skip_remaining_tests:
    EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n"));
    return -1;
}
int run_test(void)
{
EMBX_ERROR     res;
EMBX_TRANSPORT tp;
EMBX_FACTORY   factory;

    tp = EMBX_INVALID_HANDLE_VALUE;

    /* Test 1 */
    res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &blocking_loopback_config, sizeof(EMBXLB_Config_t), &factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s, exiting\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 2 */
    res = EMBX_Init();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 3 */
    res = EMBX_OpenTransport("lo_blocking", &tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 4 */
    res = EMBX_CloseTransport(tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 5 */
    res = EMBX_UnregisterTransport(factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 6 */
    res = EMBX_RegisterTransport(EMBXLB_loopback_factory,&blocking_loopback_config,sizeof(EMBXLB_Config_t),&factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s, exiting\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    if(!EMBX_OS_ThreadCreate(deinit_thread, (void *)2000, EMBX_DEFAULT_THREAD_PRIORITY, "deinit"))
    {
        EMBX_Info(EMBX_TRUE, ("Unable to create thread\n"));
        goto skip_remaining_tests;
    }

    /* Test 7 */
    res = EMBX_OpenTransport("lo_blocking", &tp);
    if(res != EMBX_TRANSPORT_CLOSED)
    {
        EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 8 */
    res = EMBX_Deinit();
    if(res != EMBX_DRIVER_NOT_INITIALIZED)
    {
        EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    return 0;

skip_remaining_tests:
    EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n"));
    return -1;
}
int run_test(void)
{
EMBX_UINT    i;
EMBX_ERROR   res;
EMBX_TPINFO  tpinfo1;
EMBX_BOOL    bFailed;
EMBX_PORT    localPort,remotePort;
EMBX_VOID   *buffer1;
EMBX_FACTORY factory;

EMBX_RECEIVE_EVENT ev;

    bFailed = EMBX_FALSE;
    buffer1 = 0;

    /* Test 1 */
    res = EMBX_ReceiveBlock(EMBX_INVALID_HANDLE_VALUE, &ev);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 2 */
    res = EMBX_Init();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 3 */
    res = EMBX_GetFirstTransport(&tpinfo1);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }


    /* Test 4 */
    res = EMBX_OpenTransport(tpinfo1.name, &tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }


    /* Test 5 */
    res = EMBX_CreatePort(tp, "testport", &localPort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    
    /* Test 6 */
    res = EMBX_Connect(tp, "testport", &remotePort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 7 */
    res = EMBX_ReceiveBlock(tp, &ev);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }
        
    /* Test 8 */
    res = EMBX_ReceiveBlock(remotePort, &ev);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 9 */
    res = EMBX_ReceiveBlock(localPort, 0);
    if(res != EMBX_INVALID_ARGUMENT)
    {
        EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }


    /* Test 10 */
    res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    for(i=0;i<BUFFER_SIZE;i++)
    {
        ((unsigned char *)buffer1)[i] = (unsigned char)i;
    }

    /* Test 11 */
    res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }


    /* Test 12 */
    res = EMBX_ReceiveBlock(localPort, &ev);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    if(ev.handle != EMBX_INVALID_HANDLE_VALUE ||
       ev.offset != 0 ||
       ev.type   != EMBX_REC_MESSAGE ||
       ev.size   != BUFFER_SIZE)
    {
        EMBX_Info(EMBX_TRUE, ("Test13 failed, event structure incorrect\n"));
        goto skip_remaining_tests;
    }

    for(i=0;i<ev.size;i++)
    {
        if( ((unsigned char *)ev.data)[i] != (unsigned char)i )
        {
            EMBX_Info(EMBX_TRUE, ("Test13 failed, buffer contents incorrect\n"));
            bFailed = EMBX_TRUE;
            break;
        }
    }

    /* Test 13 */
    res = EMBX_Free(ev.data);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    if(!EMBX_OS_ThreadCreate(send_thread, (void *)remotePort, EMBX_DEFAULT_THREAD_PRIORITY, "send"))
    {
        EMBX_Info(EMBX_TRUE, ("Unable to create thread\n"));
        goto skip_remaining_tests;
    }

    /* Test 14 */
    res = EMBX_ReceiveBlock(localPort, &ev);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    if(ev.handle != EMBX_INVALID_HANDLE_VALUE ||
       ev.offset != 0 ||
       ev.type   != EMBX_REC_MESSAGE ||
       ev.size   != BUFFER_SIZE)
    {
        EMBX_Info(EMBX_TRUE, ("Test15 failed, event structure incorrect\n"));
        goto skip_remaining_tests;
    }

    /* Test 15 */
    res = EMBX_Free(ev.data);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 16 */
    res = EMBX_ClosePort(remotePort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 17 */
    res = EMBX_ClosePort(localPort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 18 */
    res = EMBX_CloseTransport(tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }
    
    /* Test 19 */
    res = EMBX_Deinit();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* These test a different code path to the identical tests done before
     * EMBX_Init
     */

    /* Test 20 */
    res = EMBX_ReceiveBlock(localPort, &ev);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 21 */
    res = EMBX_UnregisterTransport(factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    return bFailed?-1:0;

skip_remaining_tests:
    EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n"));
    return -1;
}
Beispiel #7
0
int main(void)
{
    MME_TransformerInitParams_t initParams = { sizeof(MME_TransformerInitParams_t) };
    MixerParamsInit_t mixerInit;
    MME_TransformerHandle_t localHdl, remoteHdl;

    MME_ERROR err;

    /* initialize the underlying EMBX transport */
    embxRuntimeInit();

    /* initialize the MME API */
    err = MME_Init();
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot initialize the MME API (%d)\n", err);
    }

    /* other misc. initialization */
    OS_SIGNAL_INIT(&callbackSignal);

    /* pre-construct the data structure to be passed at transformer
     * initialization time
     */
    initParams.Priority = MME_PRIORITY_NORMAL;
    initParams.Callback = mixerCallback;
    initParams.TransformerInitParamsSize = sizeof(MixerParamsInit_t);
    initParams.TransformerInitParams_p = &mixerInit;
    MME_INDEXED_PARAM(mixerInit, MixerParamsInit_volume, 0) = 1.0;
    MME_INDEXED_PARAM(mixerInit, MixerParamsInit_volume, 1) = 4.0/3.0;


    /* display the waveforms that will be mixed */
    printf("ORIGINAL WAVEFORMS\n"
           "------------------\n\n");
    printTwinSignal(sample1, sample2, sizeof(sample1));


    printf("\nSIMPLE MIXING USING A LOCALLY REGISTERED TRANSFORMER\n"
           "----------------------------------------------------\n\n");

    /* register a local transformer */
    err = Mixer_RegisterTransformer("local.8bit_mixer");
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot register local.8bit_mixer (%d)\n", err);
    }

    /* initialize the local transformer */
    err = MME_InitTransformer("local.8bit_mixer", &initParams, &localHdl);
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot instanciate local.8bit_mixer (%d)\n", err);
    }

    /* perform a simple mix using the local transformer */
    err = simpleMix(localHdl);
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot perform mixer transformer on mme.8bit_mixer (%d)\n", err);
    }


    printf("\nSIMPLE MIXING USING A REMOTELY REGISTERED TRANSFORMER\n"
           "-----------------------------------------------------\n\n");

#if !(defined(__LINUX__) && !defined(__KERNEL__))
    /* register the transport for the remote transformer (at this point we will
     * block until the remote processor initializes itself)
     */
    err = MME_RegisterTransport("shm");
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot register transport to external processors (%d)\n", err);
    }
#endif

    /* repeatly attempt to connect to the remote transformer until it is registered or
     * a serious error occurs.
     */
    do {
        err = MME_InitTransformer("mme.8bit_mixer", &initParams, &remoteHdl);
    } while (err == MME_UNKNOWN_TRANSFORMER);
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot instanciate mme.8bit_mixer (%d)\n", err);
    }

    /* perform the same mix as above using a remotely registered transformer. the
     * results should be identical assuming both processors implement IEEE single
     * precision floating point maths.
     */
    err = simpleMix(remoteHdl);
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot perform mixer transformer on mme.8bit_mixer (%d)\n", err);
    }

    /* clean up prior to shutting down */
    err = MME_TermTransformer(remoteHdl);
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot terminate mme.8bit_mixer (%d)\n", err);
    }

    err = MME_TermTransformer(localHdl);
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot terminate local.8bit_mixer (%d)\n", err);
    }

    err = MME_Term();
    if (MME_SUCCESS != err) {
        printf("ERROR: cannot terminate the MME API (%d)\n", err);
    }

#ifndef __LINUX__
    (void) EMBX_Deinit();
#endif

    return 0;
}
Beispiel #8
0
int main()
{
EMBX_TRANSPORT hTrans;
EMBX_PORT consumer, bufferpool;
EMBX_ERROR err;

	embxRuntimeInit();

	err = EMBX_OpenTransport("shm", &hTrans);
	assert(err == EMBX_SUCCESS);

	/* Create the port which the consumer will receive work
	 * messages on.
	 */
	err = EMBX_CreatePort(hTrans, "consumer", &consumer);
	assert(err == EMBX_SUCCESS);

	/* Connect to the buffer pool on the producer, we will send
	 * back finished message buffers to this so the producer can
	 * re-use them.
	 */
	err = EMBX_ConnectBlock(hTrans, "bufferpool", &bufferpool);
	assert(err == EMBX_SUCCESS);

	while(1)
	{
	EMBX_RECEIVE_EVENT ev;

		/* Wait for some work to do */
		err = EMBX_ReceiveBlock(consumer, &ev);
		if(err != EMBX_SUCCESS)
		{
			/* Assume, for the purposes of this example
			 * that this means the producer wants to close
			 * down. Hence clean up the transport and close
			 * down EMBX.
			 */
			EMBX_ClosePort(bufferpool);
			EMBX_ClosePort(consumer);
			EMBX_CloseTransport(hTrans);
			EMBX_Deinit();
			exit(1);
		}

		/* Do some work with the received message data here */
		printf("consumer: Processing message\n");
	
		/* Now send the message buffer back, note the zero size
		 * for the message length, this will prevent any data copying
		 * on a non shared memory transport.
		 */	
		err = EMBX_SendMessage(bufferpool, ev.data, 0);
		if(err != EMBX_SUCCESS)
		{
			EMBX_ClosePort(bufferpool);
			EMBX_ClosePort(consumer);
			EMBX_CloseTransport(hTrans);
			EMBX_Deinit();
			exit(1);
		}
	}

	return 0;
}
Beispiel #9
0
int main(void)
{
	MME_TransformerInitParams_t initParams[2] = {{ sizeof(MME_TransformerInitParams_t) },
                                                     { sizeof(MME_TransformerInitParams_t) }};
	MixerParamsInit_t mixerInit[2];
	MME_TransformerHandle_t remoteHdl[2];

	MME_ERROR err;

	/* initialize the underlying EMBX transport */
	setupEMBXAndOS();

	/* initialize the MME API */
	err = MME_Init();
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot initialize the MME API (%d)\n", err);
	}

	/* other misc. initialization */
	OS_SIGNAL_INIT(&callbackSignal);

	/* pre-construct the data structure to be passed at transformer 
	 * initialization time
	 */
	initParams[0].Priority = MME_PRIORITY_NORMAL;
	initParams[0].Callback = mixerCallback;
	initParams[0].TransformerInitParamsSize = sizeof(MixerParamsInit_t);
	initParams[0].TransformerInitParams_p = &mixerInit[0];
	MME_INDEXED_PARAM(mixerInit[0], MixerParamsInit_volume, 0) = 1.0;
	MME_INDEXED_PARAM(mixerInit[0], MixerParamsInit_volume, 1) = 4.0/3.0;

	initParams[1].Priority = MME_PRIORITY_NORMAL;
	initParams[1].Callback = mixerCallback;
	initParams[1].TransformerInitParamsSize = sizeof(MixerParamsInit_t);
	initParams[1].TransformerInitParams_p = &mixerInit[1];
	MME_INDEXED_PARAM(mixerInit[1], MixerParamsInit_volume, 0) = 0.4;
	MME_INDEXED_PARAM(mixerInit[1], MixerParamsInit_volume, 1) = 0.7;
	
#if !(defined(__LINUX__) && !defined(__KERNEL__))
	/* register the transport for the remote transformer (at this point we will
	 * block until the remote processor initializes itself)
	 */
	printf("Trying to register transport shm\n");

	err = MME_RegisterTransport("shm");
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot register transport to external processors (%d)\n", err);
	}
#endif

	/* repeatly attempt to connect to the remote transformer until it is registered or
	 * a serious error occurs.
	 */
	do {
		task_delay(time_ticks_per_sec() * 2);
		printf("Trying to init mme.8bit_mix_1\n");
		err = MME_InitTransformer("mme.8bit_mixer_1", &initParams[0], &remoteHdl[0]);
	} while (err == MME_UNKNOWN_TRANSFORMER);

	if (MME_SUCCESS != err) {
		printf("ERROR: cannot instantiate mme.8bit_mixer_1 (%d)\n", err);
	}

	do {
		task_delay(time_ticks_per_sec() * 2);
		printf("Trying to init mme.8bit_mix_2\n");
		err = MME_InitTransformer("mme.8bit_mixer_2", &initParams[1], &remoteHdl[1]);
	} while (err == MME_UNKNOWN_TRANSFORMER);

	if (MME_SUCCESS != err) {
		printf("ERROR: cannot instantiate mme.8bit_mixer_2 (%d)\n", err);
	}

	/* display the waveforms that will be mixed */
	printf("ORIGINAL WAVEFORMS\n"
	       "------------------\n\n");
	printTwinSignal(sample1, sample2, sizeof(sample1));

	printf("\nSIMPLE MIXING USING TWO REMOTELY REGISTERED TRANSFORMERS\n"
	         "--------------------------------------------------------\n\n");

	/* perform the mix as above using remotely registered transformer. the 
	 * results should be identical assuming both processors implement IEEE single
	 * precision floating point maths.
	 */
	err = simpleMix(remoteHdl);
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot perform mixer transformer on mme.8bit_mixer (%d)\n", err);
	}

	/* clean up prior to shutting down */
	err = MME_TermTransformer(remoteHdl[0]);
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot terminate mme.8bit_mixer (%d)\n", err);
	}

	err = MME_TermTransformer(remoteHdl[1]);
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot terminate mme.8bit_mixer (%d)\n", err);
	}

	err = MME_Term();
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot terminate the MME API (%d)\n", err);
	}

	(void) EMBX_Deinit();

	return 0;
}
int run_test(void)
{
EMBX_UINT      i;
EMBX_ERROR     res;
EMBX_TPINFO    tpinfo1;
EMBX_BOOL      bFailed;
EMBX_TRANSPORT tp;
EMBX_PORT      localPort,remotePort;
EMBX_HANDLE    hObj;
EMBX_FACTORY   factory;

EMBX_RECEIVE_EVENT ev;

    bFailed = EMBX_FALSE;
    tp      = EMBX_INVALID_HANDLE_VALUE;
    hObj    = EMBX_INVALID_HANDLE_VALUE;

    /* Test 1 */
    res = EMBX_Receive(EMBX_INVALID_HANDLE_VALUE, &ev);
    if(res != EMBX_INVALID_PORT)
    {
        EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 2 */
    res = EMBX_Init();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 3 */
    res = EMBX_GetFirstTransport(&tpinfo1);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 4 */
    res = EMBX_OpenTransport(tpinfo1.name, &tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 5 */
    res = EMBX_CreatePort(tp, "testport", &localPort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }
    
    /* Test 6 */
    res = EMBX_Connect(tp, "testport", &remotePort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 7 */
    res = EMBX_RegisterObject(tp, object, BUFFER_SIZE, &hObj);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    for(i=0;i<BUFFER_SIZE;i++)
    {
        ((unsigned char *)object)[i] = (unsigned char)i;
    }

    /* Test 8 */
    res = EMBX_SendObject(remotePort, hObj, 0, BUFFER_SIZE);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 9 */
    res = EMBX_Receive(localPort, &ev);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    if(ev.handle != hObj || /* This is a specific quirk of the loopback transport */
       ev.offset != 0 ||
       ev.type   != EMBX_REC_OBJECT ||
       ev.size   != BUFFER_SIZE)
    {
        EMBX_Info(EMBX_TRUE, ("Test9 failed, event structure incorrect\n"));
        goto skip_remaining_tests;
    }

    for(i=0;i<ev.size;i++)
    {
        if( ((unsigned char *)ev.data)[i] != (unsigned char)i )
        {
            EMBX_Info(EMBX_TRUE, ("Test9 failed, buffer contents incorrect\n"));
            bFailed = EMBX_TRUE;
            break;
        }
    }

    /* Test 10 */
    res = EMBX_UpdateObject(remotePort, hObj, 0, BUFFER_SIZE);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 11 */
    res = EMBX_Receive(localPort, &ev);
    if(res != EMBX_INVALID_STATUS)
    {
        EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 12 */
    res = EMBX_DeregisterObject(tp, hObj);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    /* Test 13 */
    res = EMBX_ClosePort(remotePort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 14 */
    res = EMBX_ClosePort(localPort);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 15 */
    res = EMBX_CloseTransport(tp);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }
    
    /* Test 16 */
    res = EMBX_Deinit();
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res]));
        goto skip_remaining_tests;
    }

    /* Test 17 */
    res = EMBX_UnregisterTransport(factory);
    if(res != EMBX_SUCCESS)
    {
        EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res]));
        bFailed = EMBX_TRUE;
    }

    return bFailed?-1:0;

skip_remaining_tests:
    EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n"));
    return -1;
}