Examples.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <signal.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sched.h>
#include <math.h>
#include <time.h>
#include <semaphore.h>
#include <signal.h>
#include <time.h>
#include <semaphore.h>
#include "TargetInfo.h"
typedef struct ConfigParameters
{
float coreSpeed;
float profileSpeed;
float sampleRate;
UINT32 fundamentalBlockSize;
UINT32 inChannels;
UINT32 outChannels;
UINT32 profileStatus;
INT32 tuningPort;
} ConfigParameters;
static ConfigParameters configParams;
const unsigned int loopback_dualcore_startAudio_InitCommands[] = {
0x0002000c, 0x00060006, 0x473b8000, 0x40040002, 0x00000100, 0x00000000, 0x00060006, 0x473b8000,
0x40040002, 0x00000100, 0x00000000, 0x00060006, 0x473b8000, 0x40040002, 0x00000100, 0x00000000,
0x00060106, 0x473b8000, 0x40040002, 0x00000100, 0x00000000, 0x00040007, 0x00000001, 0x00000001,
0x00040007, 0x00000002, 0x00000002, 0x000b000f, 0xbeef1039, 0x00000001, 0x00000005, 0x00000003,
0x00000000, 0x00000001, 0x00000000, 0x00000100, 0x00000000, 0x000b010f, 0xbeef1039, 0x00000001,
0x00000005, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000100, 0x00000000, 0x0009000f,
0xbeef0866, 0x00000101, 0x00000002, 0x00000001, 0x00000003, 0x00000001, 0x00000000, 0x0007000f,
0xbeef086d, 0x00000001, 0x00000001, 0x00000003, 0x00000000, 0x00080065, 0x0000680a, 0x00000000,
0x00000400, 0x00000002, 0xc0a00000, 0x40a00000, 0x000c010f, 0xbeef103a, 0x00000100, 0x00000006,
0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000000, 0x0007010f,
0xbeef086d, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00080165, 0x0000480a, 0x00000000,
0x00000400, 0x00000002, 0xc0a00000, 0x40a00000, 0x000c000f, 0xbeef103a, 0x00000100, 0x00000006,
0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000000, 0x0007000f,
0xbeef086d, 0x00000001, 0x00000001, 0x00000003, 0x00000000, 0x00080065, 0x0000880a, 0x00000000,
0x00000400, 0x00000002, 0xc0a00000, 0x40a00000, 0x0009000f, 0xbeef0866, 0x00000101, 0x00000002,
0x00000003, 0x00000002, 0x00000000, 0x00000001, 0x00040010, 0x00000006, 0x00000001, 0x000a002f,
0x0000000a, 0x00000000, 0x00000005, 0x00000004, 0x00000006, 0x00000007, 0x00000008, 0x00000009,
0x00040110, 0x00000003, 0x00000001, 0x0007012f, 0x00000005, 0x00000000, 0x00000003, 0x00000002,
0x00000004, 0x0006013c, 0x00003008, 0x00000000, 0x00000100, 0x00000000, 0x0006003c, 0x00007008,
0x00000001, 0x00000100, 0x00000000, 0x0002001b, 0x00000000,
};
const unsigned int loopback_dualcore_startAudio_InitCommands_Len = sizeof(loopback_dualcore_startAudio_InitCommands) / sizeof(int);
#define LOAD_MULTICORE_AWB 1
#define NUM_INSTANCES 4
#ifndef TUNING_MASTER_INSTANCE
#define TUNING_MASTER_INSTANCE 0
#endif
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
#define FLASH_ERASABLE_BLOCK_SIZE 1024*4
#define FLASH_SIZE_PER_INSTANCE 1024*1024*4
#define FLASH_ERASE_TIME_SEC 5
UINT32 g_AWEEmulatedFFS[1024*1024*NUM_INSTANCES];
#endif
#define MAX_PUMP_COUNT 30
INT32 g_nPumpCount[NUM_INSTANCES];
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
#endif
static IOPinDescriptor aweInputPin;
static IOPinDescriptor aweOutputPin;
const void* module_descriptor_table[] =
{
LISTOFCLASSOBJECTS
};
UINT32 sharedHeap[SHARED_HEAP_SIZE_LINUX];
UINT32 tuningPacketBuffer[MAX_COMMAND_BUFFER_LEN];
#ifdef USE_SAME_BUFFER_PACKET_REPLY
UINT32 *tuningReplyBuffer = tuningPacketBuffer;
#else
UINT32 tuningReplyBuffer[MAX_COMMAND_BUFFER_LEN];
#endif
UINT32 *audioInputBuffer;
UINT32 *audioOutputBuffer;
pthread_t packetProcessHandles[NUM_INSTANCES];
pthread_t audioCallbackThreadHandle;
pthread_t audioPumpAllThreadHandles[NUM_INSTANCES];
sem_t pumpSems[NUM_INSTANCES];
INT32 exitAudioCallbackThread;
INT32 audioStarted;
unsigned long long callbackCnt;
unsigned long long pumpCnts[NUM_INSTANCES];
INT32 quiet;
int sockfd, newsockfd;
int exitTuning = 0;
#define DEFAULT_TUNING_PORT (15092)
#define DEFAULT_BLOCK_SIZE (256)
#define AUDIO_CALLBACK_PRIO (99)
#define AUDIO_PUMP_PRIO (AUDIO_CALLBACK_PRIO - 1)
#define TUNING_THREAD_PRIO (AUDIO_PUMP_PRIO - NUM_INSTANCES)
void error(const char *msg)
{
perror(msg);
exit(1);
}
void sig_handler(int signo)
{
if (signo == SIGINT)
{
exitTuning = 1;
shutdown(newsockfd, SHUT_RDWR);
close(newsockfd);
shutdown(sockfd, SHUT_RDWR);
close(sockfd);
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
{
FILE *fPtr = NULL;
fPtr = fopen("AWE_FFS_Emulated.bin", "wb");
if (fPtr)
{
fwrite(g_AWEEmulatedFFS, 1, sizeof(g_AWEEmulatedFFS), fPtr);
fclose(fPtr);
}
}
#endif
if (!quiet)
{
printf("Exiting LinuxAppMulti\n");
}
exit(0);
}
}
static void usage(const char *program)
{
printf(
"Usage: %s [args]\n"
" -sr:sampling_rate value in Hz, default 48KHz\n"
" -pf:profile_frequency value in Hz, default 10MHz\n"
" -cf:cpu_frequency value in Hz, default 1GHz\n"
" -profStatus:N set profiling status (0 - disable, 1 - enable(default), 2 - enable module level only, 3 - enable top level only)\n"
" -bsize:N default 256, Audio block size for the system\n"
" -inchans:N default 2, number of input channels\n"
" -outchans:N default 2, number of output channels\n"
" -tport:N default 15092, port number for socket interface. User can choose between 15002 - 15098\n"
" -quiet print only error messages\n"
" -h, -help show this message\n"
"This program exercises the AWECore library with 2 AWEInstances.\n",
program);
exit(0);
}
void* tuningPacketThread(void* arg)
{
(void) arg;
socklen_t clilen;
struct sockaddr_in serv_addr, cli_addr;
INT32 schedPolicy, ret;
struct sched_param schedParam;
int socketOption;
pthread_t currentHandle = pthread_self();
schedParam.sched_priority = TUNING_THREAD_PRIO;
schedPolicy = SCHED_RR;
ret = pthread_setschedparam(currentHandle, schedPolicy, &schedParam);
if (ret != 0)
{
printf("Failed to increase priority of tuning thread with error: %s \nTry running with sudo\n", strerror(ret));
}
char threadNameBuffer[16];
snprintf(threadNameBuffer, 16, "awe0_packet");
ret = pthread_setname_np(packetProcessHandles[0], threadNameBuffer);
if (ret)
{
printf("Failed to set thread name to %s\n", threadNameBuffer);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
error("ERROR opening socket");
}
socketOption = 1;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &socketOption, sizeof(socketOption));
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(configParams.tuningPort);
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
{
error("ERROR on binding");
}
while (!exitTuning)
{
listen(sockfd,5);
if (!quiet)
{
printf("Listening for connection on port %d\n", configParams.tuningPort);
}
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr,
&clilen);
if (newsockfd < 0)
{
error("ERROR on accept");
}
if (!quiet)
{
printf( "Found connection!\n");
}
struct timespec ts;
ts.tv_nsec = 5000000;
ts.tv_sec = 0;
while(1)
{
unsigned int plen;
ssize_t readBytes, n;
g_nPumpCount[TUNING_MASTER_INSTANCE] = 0;
{
readBytes = read(newsockfd, tuningPacketBuffer, MAX_COMMAND_BUFFER_LEN * sizeof(tuningPacketBuffer[0]));
if (readBytes == 0)
{
break;
}
else if (readBytes < 0)
{
error("ERROR reading from socket");
}
while (readBytes < plen)
{
n = read(newsockfd,&((char*)tuningPacketBuffer)[readBytes], MAX_COMMAND_BUFFER_LEN * sizeof(tuningPacketBuffer[0]));
if (n == 0)
{
break;
}
else if (n < 0)
{
error("ERROR reading from socket");
}
else
{
readBytes += n;
}
}
}
{
n = write(newsockfd, tuningReplyBuffer, plen * sizeof(tuningReplyBuffer[0]));
if (n < plen)
{
error("ERROR writing to socket");
}
}
else
{
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
}
}
}
return NULL;
}
void* packetProcessThread(void * args)
{
INT32 schedPolicy, ret;
struct sched_param schedParam;
struct timespec ts;
pthread_t currentHandle = pthread_self();
schedParam.sched_priority = TUNING_THREAD_PRIO - instanceId;
schedPolicy = SCHED_RR;
ret = pthread_setschedparam(currentHandle, schedPolicy, &schedParam);
if (ret != 0)
{
printf("Failed to increase priority of tuning thread %d with error: %s \nTry running with sudo\n", instanceId, strerror(ret));
}
char threadNameBuffer[16];
snprintf(threadNameBuffer, 16, "awe%d_packet", instanceId);
pthread_setname_np(packetProcessHandles[instanceId], threadNameBuffer);
if (ret)
{
printf("Failed to set thread name to %s\n", threadNameBuffer);
}
if (!quiet)
{
printf("Starting instance %d packet process thread\n", instanceId);
}
ts.tv_nsec = 5000000;
ts.tv_sec = 0;
while(1)
{
g_nPumpCount[instanceId] = 0;
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
}
return NULL;
}
void* aweuser_pumpAudio(void * args)
{
INT32 pumpMask;
INT32 schedPolicy, ret, targetPriority;
struct sched_param schedParam;
pthread_t currentHandle = pthread_self();
targetPriority = AUDIO_PUMP_PRIO - instanceId;
schedParam.sched_priority = targetPriority;
schedPolicy = SCHED_FIFO;
pthread_setschedparam(currentHandle, schedPolicy, &schedParam);
int policy;
pthread_getschedparam(currentHandle, &policy, &schedParam);
if ((SCHED_FIFO != policy) || (schedParam.sched_priority != targetPriority))
{
printf("Warning: Failed to increase priority of audio simulation thread to %d\nTry running as root\n", targetPriority);
}
char threadNameBuffer[16];
snprintf(threadNameBuffer, 16, "awe%d_pump", instanceId);
ret = pthread_setname_np(audioPumpAllThreadHandles[instanceId], threadNameBuffer);
if (!quiet)
{
printf("Starting pump thread for instance %d\n", instanceId);
}
while (1)
{
sem_wait(&pumpSems[instanceId]);
{
if (instanceId == 0)
{
for (int i = 0; i < configParams.inChannels ; i++)
{
if (ret)
{
printf("Error: awe_audioImportSamples() failed, channel = %d, error = %d\n", i, ret);
}
}
}
if (instanceId == 0)
{
for (int ix = 1; ix < NUM_INSTANCES; ix++)
{
{
sem_post(&pumpSems[ix]);
}
}
}
if (g_nPumpCount[instanceId] < MAX_PUMP_COUNT)
{
for (int j = 0; j < NUM_THREADS; j++)
{
if (pumpMask & (1U << j))
{
}
}
if (ret > 0)
{
}
g_nPumpCount[instanceId]++;
}
if (instanceId == 0)
{
for (int i = 0; i < configParams.outChannels ; i++)
{
if (ret)
{
printf("Error: awe_audioExportSamples() failed, channel = %d, error = %d\n", i, ret);
}
}
}
pumpCnts[instanceId]++;
}
}
return NULL;
}
void* audioCallbackSimulator(void * args)
{
struct timespec ts;
struct timespec ts_tmp;
long time_nsec;
long long accumulated_time1;
long long accumulated_time2;
long long overshoot = 0.0;
(void) args;
INT32 schedPolicy, ret;
struct sched_param schedParam;
time_nsec = (long) ((float)1000000000L * ((float)configParams.fundamentalBlockSize / configParams.sampleRate));
ts.tv_sec = 0;
ts_tmp.tv_sec = 0;
ts_tmp.tv_nsec = 0;
pthread_t currentHandle = pthread_self();
schedParam.sched_priority = AUDIO_CALLBACK_PRIO;
schedPolicy = SCHED_FIFO;
pthread_setschedparam(currentHandle, schedPolicy, &schedParam);
int policy;
pthread_getschedparam(currentHandle, &policy, &schedParam);
if ((SCHED_FIFO != policy) || (schedParam.sched_priority != AUDIO_CALLBACK_PRIO))
{
printf("Warning: Failed to increase priority of audio simulation thread to %d\nTry running as root\n", AUDIO_CALLBACK_PRIO);
}
char threadNameBuffer[32];
snprintf(threadNameBuffer, 32, "awe_callback");
ret = pthread_setname_np(audioCallbackThreadHandle, threadNameBuffer);
if (ret)
{
printf("Failed to set thread name to %s\n", threadNameBuffer);
}
while (!exitAudioCallbackThread)
{
callbackCnt++;
sem_post(&pumpSems[0]);
ts.tv_nsec = time_nsec - overshoot;
clock_gettime(CLOCK_MONOTONIC, &ts_tmp);
accumulated_time1 = ((long long)ts_tmp.tv_sec*1000000000) + ts_tmp.tv_nsec + time_nsec - overshoot;
while(1)
{
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
clock_gettime(CLOCK_MONOTONIC, &ts_tmp);
accumulated_time2 = ((long long)ts_tmp.tv_sec*1000000000) + ts_tmp.tv_nsec;
if (accumulated_time2 >= accumulated_time1)
{
overshoot = (accumulated_time2 - accumulated_time1);
break;
}
else
{
ts.tv_nsec = (long)(accumulated_time1 - accumulated_time2);
}
}
}
return NULL;
}
{
{
exitAudioCallbackThread = 0;
callbackCnt = 0;
memset(pumpCnts, 0, sizeof(pumpCnts));
INT32 ret = pthread_create(&audioCallbackThreadHandle, NULL, audioCallbackSimulator, NULL);
if (ret)
{
printf("Error creating audio callback simulator! ret = %d\n", ret);
return 0;
}
audioStarted = 1;
if (!quiet)
{
printf("Audio Started\n");
}
}
return 0;
}
{
if (audioStarted)
{
INT32 ret;
exitAudioCallbackThread = 1;
ret = pthread_join(audioCallbackThreadHandle, NULL);
if (ret != 0)
{
printf("Failed to join audio simulator thread: ret = %d\n", ret);
}
if (!quiet)
{
UINT32 avgCycles;
const FLOAT32 clockRatios = configParams.coreSpeed / configParams.profileSpeed;
printf("\nAudio Stopped\n");
for (int i = 0; i < NUM_INSTANCES; i++)
{
{
avgCycles = 0;
}
printf("-- Pumped instance %d %llu times, average cycles per pump: %f\n", i, pumpCnts[i],
(avgCycles >> 8) * clockRatios);
}
}
audioStarted = 0;
}
return 0;
}
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
BOOL usrInitFlashFileSystem(void)
{
return SUCCESS;
}
BOOL usrReadFlashMemory(UINT32 nAddress, UINT32 * pBuffer, UINT32 nDWordsToRead)
{
BOOL bSuccess = 0;
if(nDWordsToRead == 0)
{
return SUCCESS;
}
memcpy(pBuffer, &g_AWEEmulatedFFS[nAddress >> 2], nDWordsToRead*sizeof(UINT32));
return SUCCESS;
}
BOOL usrWriteFlashMemory(UINT32 nAddress, UINT32 * pBuffer, UINT32 nDWordsToWrite)
{
BOOL bSuccess = 0;
if(nDWordsToWrite == 0)
{
return SUCCESS;
}
memcpy(&g_AWEEmulatedFFS[nAddress >> 2], pBuffer, nDWordsToWrite*sizeof(UINT32));
return SUCCESS;
}
BOOL usrEraseFlashMemorySector(UINT32 nStartingAddress, UINT32 nNumberOfSectors)
{
memset(&g_AWEEmulatedFFS[nStartingAddress >> 2], 0xffu, nNumberOfSectors * FLASH_ERASABLE_BLOCK_SIZE);
}
#endif
void InitializeAWEInstance(
AWEInstance * awePtr, INT32 instanceId)
{
int ret = 0;
UINT32 module_descriptor_table_size = sizeof(module_descriptor_table) / sizeof(module_descriptor_table[0]);
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
#endif
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
pAweFFSPtr->
cbInit = &usrInitFlashFileSystem;
#endif
awePtr->
numModules = module_descriptor_table_size;
awePtr->
slowHeapSize = SLOW_HEAP_SIZE_LINUX / NUM_INSTANCES;
awePtr->
pName = malloc(
sizeof(
char) * 8);
sprintf((
char*)awePtr->
pName,
"awe#%d", instanceId);
if (instanceId == 0)
{
int i, j;
ret =
awe_initPin(&aweInputPin, configParams.inChannels, NULL);
if (ret != 0)
{
printf("awe_initPin inputPin failed on AWEInstance 0\n");
}
ret =
awe_initPin(&aweOutputPin, configParams.outChannels, NULL);
if (ret != 0)
{
printf("awe_initPin outputPin failed on AWEInstance 0\n");
}
#ifndef PI
#define PI 3.141592653589793
#endif
float blockRate = configParams.sampleRate / configParams.fundamentalBlockSize;
for (i = 0; i < configParams.fundamentalBlockSize; i++)
{
for (j = 0; j < configParams.inChannels; j++)
{
audioInputBuffer[i * configParams.inChannels + j] =
float_to_fract32(sinf(2.f * PI *
(j + 1) * blockRate * (i / configParams.sampleRate)));
}
}
}
if (ret != 0)
{
printf("awe_init on instance %d failed with %d\n", instanceId, ret);
}
else
{
if (!quiet)
{
printf("Initialized instance %d\n", instanceId);
}
}
}
int main( int argc, const char* argv[] )
{
int i;
if ((TUNING_MASTER_INSTANCE < 0) || (TUNING_MASTER_INSTANCE >= NUM_INSTANCES))
{
printf("Provided TUNING_MASTER_INSTANCE of %d is out of range. Value should be [0 %d]\n",TUNING_MASTER_INSTANCE, NUM_INSTANCES-1);
return 0;
}
configParams.coreSpeed = CORE_SPEED;
configParams.profileSpeed = PROFILE_SPEED;
configParams.sampleRate = SAMPLE_RATE;
configParams.fundamentalBlockSize = DEFAULT_BLOCK_SIZE;
configParams.inChannels = NUM_INPUT_CHANNELS;
configParams.outChannels = NUM_OUTPUT_CHANNELS;
configParams.tuningPort = DEFAULT_TUNING_PORT;
configParams.profileStatus = 1;
quiet = 0;
for (i = 1; i < argc; i++)
{
const char *arg = argv[i];
if (0 == strncmp(arg, "-profStatus:", 12))
{
configParams.profileStatus = atoi(arg + 12);
}
else if (0 == strncmp(arg, "-bsize:", 7))
{
configParams.fundamentalBlockSize = atoi(arg + 7);
}
else if (0 == strncmp(arg, "-inchans:", 9))
{
configParams.inChannels = atoi(arg + 9);
}
else if (0 == strncmp(arg, "-outchans:", 10))
{
configParams.outChannels = atoi(arg + 10);
}
else if(0 == strncmp(arg, "-sr:", 4))
{
configParams.sampleRate = (float)atof(arg + 4);
}
else if (0 == strncmp(arg, "-cf:", 4))
{
configParams.coreSpeed = (float)atof(arg + 4);
}
else if (0 == strncmp(arg, "-pf:", 4))
{
configParams.profileSpeed = (float)atof(arg + 4);
}
else if (0 == strncmp(arg, "-tport:", 7))
{
configParams.tuningPort = atoi(arg + 7);
}
else if (0 == strncmp(arg, "-quiet", 6))
{
quiet = 1;
}
else if ((0 == strncmp(arg, "-help", 5)) || (0 == strncmp(arg, "-h", 2)))
{
usage(argv[0]);
}
}
if (!quiet)
{
printf("\nAWECore initialised with the following parameters\n");
printf("-cf: %f Hz\n", configParams.coreSpeed);
printf("-pf: %f Hz\n", configParams.profileSpeed);
printf("-sr: %f Hz\n", configParams.sampleRate);
printf("-bsize: %u\n", configParams.fundamentalBlockSize);
printf("-inchans: %u\n", configParams.inChannels);
printf("-outchans: %u\n", configParams.outChannels);
printf("-tport: %d\n", configParams.tuningPort);
printf("-profStatus: %u\n", configParams.profileStatus);
printf("TUNING_MASTER_INSTANCE: %d\n", TUNING_MASTER_INSTANCE);
#ifdef USE_SAME_BUFFER_PACKET_REPLY
printf("Running with same buffer for packet and reply.\n");
#endif
}
if (signal(SIGINT, sig_handler) == SIG_ERR)
{
printf("Can't catch SIGINT (%d)\n", SIGINT);
}
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
{
FILE *fPtr = NULL;
memset(g_AWEEmulatedFFS, 0xffu, sizeof(g_AWEEmulatedFFS));
fPtr = fopen("AWE_FFS_Emulated.bin", "rb");
if (fPtr)
{
INT32 ret;
ret = fread(g_AWEEmulatedFFS, 1, sizeof(g_AWEEmulatedFFS), fPtr);
if (ret <= 0)
{
printf("Failed to read emulated AWE FFS from the file.");
}
fclose(fPtr);
}
}
#endif
audioInputBuffer = malloc(configParams.inChannels * configParams.fundamentalBlockSize * sizeof(UINT32));
audioOutputBuffer = malloc(configParams.outChannels * configParams.fundamentalBlockSize * sizeof(UINT32));
for (i = 0; i < NUM_INSTANCES; i++)
{
g_nPumpCount[i] = 0;
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
#endif
InitializeAWEInstance(pInstances[i], i);
}
pthread_create(&packetProcessHandles[TUNING_MASTER_INSTANCE], NULL, tuningPacketThread, pInstances[TUNING_MASTER_INSTANCE]);
for (i = 0; i < NUM_INSTANCES; i++)
{
if (i != TUNING_MASTER_INSTANCE)
{
pthread_create(&packetProcessHandles[i], NULL, packetProcessThread, pInstances[i]);
}
}
for (i = 0; i < NUM_INSTANCES; i++)
{
sem_init(&pumpSems[i], 0, 0);
pthread_create(&audioPumpAllThreadHandles[i], NULL, aweuser_pumpAudio, pInstances[i]);
}
if (LOAD_MULTICORE_AWB)
{
UINT32 position;
INT32 ret =
awe_loadAWBfromArray(pInstances[TUNING_MASTER_INSTANCE], loopback_dualcore_startAudio_InitCommands, loopback_dualcore_startAudio_InitCommands_Len, &position);
{
printf("Error loading awb: error = %d, at offset %u\n", ret, position);
}
else
{
printf("Loaded multi-instance awb\n");
}
}
for (i = 0; i < NUM_INSTANCES; i++)
{
pthread_join(packetProcessHandles[i], NULL);
pthread_join(audioPumpAllThreadHandles[i], NULL);
}
free(audioInputBuffer);
free(audioOutputBuffer);
for (i = 0; i < NUM_INSTANCES; i++)
{
free(pInstances[i]->pFastHeapA);
free(pInstances[i]->pFastHeapB);
free(pInstances[i]->pSlowHeap);
free((void*)pInstances[i]->pName);
free(pInstances[i]);
#ifdef ENABLE_FAKE_FLASH_FILE_SYSTEM
free(pFlashFSInstances[i]);
#endif
}
return 0;
}
The AWECore API Header File.
The AWECore Helper Functions File.
INT32 float_to_fract32(FLOAT32 x)
Convert audio data from floating point to Fract32 sample by sample.
#define PACKET_LENGTH_WORDS(x)
This will determine the length of a packet in words.
Definition: AWECoreUtils.h:40
#define PACKET_LENGTH_BYTES(x)
This will determine the length of a packet in bytes.
Definition: AWECoreUtils.h:43
INT32 awe_initPin(IOPinDescriptor *pPin, UINT32 channels, const char *name)
Initialize an input or output pin.
INT32 awe_packetProcessMulti(AWEInstance *pAWE, BOOL isTuningInstance)
Multi-instance Wrapper for tuning packet processing.
INT32 awe_deferredSetCall(AWEInstance *pAWE)
Perform deferred awe set on a module.
INT32 awe_audioPump(AWEInstance *pAWE, UINT32 layoutIndex)
Audio pump function.
void awe_setInstancesInfo(AWEInstance **pInstances, INT32 numAweInstancesOnCore)
Setup function only intended for systems with multiple AWE Instances in a single core.
INT32 awe_getAverageLayoutCycles(AWEInstance *pAWE, UINT32 layoutIdx, UINT32 *averageCycles)
Get the average cycles of a running layout, in units of cycles at profileSpeed.
void awe_initFlashFS(AWEInstance *pAWE, AWEFlashFSInstance *pAWEFlashFSInstance)
Initialize the file system.
INT32 awe_audioImportSamples(const AWEInstance *pAWE, const void *inSamples, INT32 inStride, INT32 channel, SampleType inType)
Import samples from a user buffer to a channel.
INT32 awe_layoutIsValid(const AWEInstance *pAWE)
Determines if a layout is loaded and valid.
INT32 awe_loadAWBfromArray(AWEInstance *pAWE, const UINT32 *pCommands, UINT32 arraySize, UINT32 *pPos)
Executes packet commands from an in-memory array.
INT32 awe_audioExportSamples(const AWEInstance *pAWE, void *outSamples, INT32 outStride, INT32 channel, SampleType outType)
Export samples to a user buffer from a channel.
INT32 awe_audioGetPumpMask(AWEInstance *pAWE)
Test if AWE is ready to run.
INT32 awe_setProfilingStatus(AWEInstance *pAWE, UINT32 status)
Enable or disable the profiling ability of the AWE Core.
INT32 awe_audioIsReadyToPumpMulti(AWEInstance *pAWE, UINT32 instanceID)
Test if AWE is ready to run on secondary instances (ID > 0).
INT32 awe_init(AWEInstance *pAWE)
Initialize the instance.
INT32 awe_audioIsStarted(const AWEInstance *pAWE)
Check if this instance is running.
#define E_MULTI_PACKET_WAITING
Multi-instance packet has been forwarded but has not yet been serviced.
Definition: Errors.h:384
#define E_SUCCESS
OK result.
Definition: Errors.h:31
A list of all AWE Server Commands.
@ Sample32bit
Data is 32 bit PCM .
Definition: StandardDefs.h:231
The AWE instance.
Definition: AWEInstance.h:82
IOPinDescriptor * pInputPin
A BSP author must define/allocate an input pin in their BSP and assign it to this member NOTE: AudioW...
Definition: AWEInstance.h:146
const char * pName
The name of the AWE Instance that will be displayed in Server.
Definition: AWEInstance.h:215
float profileSpeed
Profiling clock speed in Hz.
Definition: AWEInstance.h:207
UINT32 * pReplyBuffer
Reply buffer pointer.
Definition: AWEInstance.h:189
UINT32 * pFastHeapB
The second fast heap, B .
Definition: AWEInstance.h:94
UINT32 numThreads
Number of threads supported for multithreaded systems(1-4).
Definition: AWEInstance.h:219
IOPinDescriptor * pOutputPin
A BSP author must define/allocate an output pin in their BSP and assign it to this member NOTE: Audio...
Definition: AWEInstance.h:152
UINT32 * pPacketBuffer
The Packet buffer pointer.
Definition: AWEInstance.h:180
INT32(* cbAudioStart)(struct _AWEInstance *PAWE)
OPTIONAL This callback is invoked when a layout is run or when a StartAudio command is sent.
Definition: AWEInstance.h:116
INT32(* cbAudioStop)(struct _AWEInstance *pAWE)
OPTIONAL.
Definition: AWEInstance.h:122
UINT32 slowHeapSize
The slow heap size.
Definition: AWEInstance.h:108
UINT32 fundamentalBlockSize
Base frame size of this instance.
Definition: AWEInstance.h:226
UINT32 * pSlowHeap
The slow heap.
Definition: AWEInstance.h:97
float sampleRate
Default sample rate of this instance.
Definition: AWEInstance.h:222
UINT32 packetBufferSize
Packet buffer size.
Definition: AWEInstance.h:196
volatile UINT32 * pSharedHeap
AWE Core shared memory definitions.
Definition: AWEInstance.h:237
UINT32 fastHeapBSize
The fast heap B size.
Definition: AWEInstance.h:105
UINT32 numProcessingInstances
The number of audio processing instances of AWE Core configured on a single target.
Definition: AWEInstance.h:243
UINT32 sharedHeapSize
The shared heap size, in 32-bit words.
Definition: AWEInstance.h:240
AWEFlashFSInstance * pFlashFileSystem
DSPC Flash file system instance.
Definition: AWEInstance.h:231
float coreSpeed
A BSP author will set this to the speed of the CPU they are integrating into.
Definition: AWEInstance.h:204
UINT32 instanceId
The ID of this instance.
Definition: AWEInstance.h:87
UINT32 numModules
Number of modules in module table.
Definition: AWEInstance.h:162
const ModClassModule ** pModuleDescriptorTable
Pointer to module table.
Definition: AWEInstance.h:170
UINT32 fastHeapASize
The fast heap A size in 32-bit words.
Definition: AWEInstance.h:102
UINT32 * pFastHeapA
Fast heap A.
Definition: AWEInstance.h:91
The DSPC Flash File System Instance.
Definition: FlashFSInstance.h:40
UINT32 flashEraseTimeInMs
Flash erase time in milliseconds.
Definition: FlashFSInstance.h:51
BOOL(* cbFlashRead)(UINT32 nFlashAddress, UINT32 *pBuffer, UINT32 nDWordsToRead)
User function to read from flash.
Definition: FlashFSInstance.h:63
BOOL(* cbFlashWrite)(UINT32 nFlashAddress, UINT32 *pBuffer, UINT32 nDWordsToWrite)
User callback function to write to flash.
Definition: FlashFSInstance.h:60
UINT32 flashStartOffsetInBytes
Offset into start of flash used for file system.
Definition: FlashFSInstance.h:48
UINT32 flashSizeInBytes
Size of flash memory - if non-zero, next two values must also be non-zero.
Definition: FlashFSInstance.h:42
BOOL(* cbEraseSector)(UINT32 nStartingAddress, UINT32 nNumberOfSectors)
User callback function to erase one or more sectors.
Definition: FlashFSInstance.h:57
UINT32 flashErasableBlockSizeInBytes
Size of flash erase block.
Definition: FlashFSInstance.h:45
BOOL(* cbInit)(void)
User function to initialize flash file system.
Definition: FlashFSInstance.h:54