giuliomoro@74: /* giuliomoro@74: * giuliomoro@74: * Andrew McPherson and Victor Zappi giuliomoro@74: * Queen Mary, University of London giuliomoro@74: */ giuliomoro@74: giuliomoro@74: #include giuliomoro@74: #include giuliomoro@74: #include giuliomoro@74: #include giuliomoro@74: giuliomoro@74: // setup() is called once before the audio rendering starts. giuliomoro@74: // Use it to perform any initialisation and allocation which is dependent giuliomoro@74: // on the period size or sample rate. giuliomoro@74: // giuliomoro@74: // userData holds an opaque pointer to a data structure that was passed giuliomoro@74: // in from the call to initAudio(). giuliomoro@74: // giuliomoro@74: // Return true on success; returning false halts the program. giuliomoro@74: giuliomoro@74: bool setup(BeagleRTContext *context, void *userData) giuliomoro@74: { giuliomoro@74: return true; giuliomoro@74: } giuliomoro@74: giuliomoro@74: // render() is called regularly at the highest priority by the audio engine. giuliomoro@74: // Input and output are given from the audio hardware and the other giuliomoro@74: // ADCs and DACs (if available). If only audio is available, numAnalogFrames giuliomoro@74: // will be 0. giuliomoro@74: giuliomoro@74: void render(BeagleRTContext *context, void *userData) giuliomoro@74: { giuliomoro@74: //connect an LED in series with a 470ohm resistor between P8_07 and ground giuliomoro@74: static int count=0; //counts elapsed samples giuliomoro@74: float interval=0.5; //how often to toggle the LED (in seconds) giuliomoro@74: static int status=GPIO_LOW; giuliomoro@74: for(unsigned int n=0; ndigitalFrames; n++){ giuliomoro@74: if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed giuliomoro@74: count=0; //reset the counter giuliomoro@74: // status=digitalReadFrame(context, 0, P8_07); giuliomoro@74: if(status==GPIO_LOW) //toggle the status giuliomoro@74: status=GPIO_HIGH; giuliomoro@74: else giuliomoro@74: status=GPIO_LOW; giuliomoro@74: pinModeFrame(context, 0, P8_07, OUTPUT); giuliomoro@74: digitalWriteFrame(context, n, P8_07, status); //write the status to the LED giuliomoro@74: // rt_printf("there %d\n", context->digital[n]); giuliomoro@74: } giuliomoro@74: context->digital[n]=status*0x00010000; giuliomoro@74: count++; giuliomoro@74: } giuliomoro@74: } giuliomoro@74: giuliomoro@74: // cleanup() is called once at the end, after the audio has stopped. giuliomoro@74: // Release any resources that were allocated in setup(). giuliomoro@74: giuliomoro@74: void cleanup(BeagleRTContext *context, void *userData) giuliomoro@74: { giuliomoro@74: // Nothing to do here giuliomoro@74: }