Sample application to explain how to use the debug call back of the Unzen Framework

Dependencies:   mbed shimabara unzen_lpcxpresso_4337

雲仙フレームワークにはデバッグ用のコールバックを登録することができます。

これらのコールバックはそれぞれ割り込み処理の前、割り込み処理の後、信号処理の前、信号処理の後に毎回読み出されるため、リアルタイムに進む時間計測をオシロスコープなどで観測することができます。

このアプリケーションは、それらのコールバックの宣言方法、使用方法を説明しています。

コールバックの宣言

デバッグ用コールバックは全てvoidを受け取り、voidを返すプロトタイプを持っています。これらはユーザー関数ですので名前は任意です。

コールバックの宣言

void pre_int_callback(void);
void post_int_callback(void);
void pre_process_callback(void);
void post_process_callback(void);

コールバックの定義

デバッグ用コールバックは、割り込みコンテキストで呼び出されます。ですので、割り込みコンテキストでやってもいい処理ならば、何をしてもかまいません。

今回の例ではデバッグ用の信号ピンをトグルしています。すなわち、割り込みの入り口で1にし、出口で0に戻しています。

コールバックの定義

void pre_int_callback(void)
{
    debug_flag_1 = 1;
}

void post_int_callback(void)
{
    debug_flag_1 = 0;
}

void pre_process_callback(void)
{
    debug_flag_2= 1;
}

void post_process_callback(void)
{
    debug_flag_2 = 0;

}

コールバックの登録

デバッグ用コールバックの登録メソッドがフレームワークに用意されています。これらの登録は、start()メソッドの呼び出しよりも前にしなければなりません。

コールバックの登録

        // debug call back registration
    audio.set_pre_interrupt_callback( pre_int_callback );
    audio.set_post_interrupt_callback( post_int_callback );
    audio.set_pre_process_callback( pre_process_callback );
    audio.set_post_process_callback( post_process_callback );

set_pre_interrupt_callback() および set_post_interrupt_callback() で登録されたデバッグ用コールバックは、I2S割り込みの前後でそれぞれ呼び出されます。そのため、デバッグピンをトグルすれば、割り込み処理ルーチンの実行時間を知ることができます。

set_pre_process_callback() および set_post_process_callback() で登録されたデバッグ用コールバックは、信号処理コールバックの前後でそれぞれ呼び出されます。そのため、デバッグピンをトグルすれば、信号処理ルーチンの実行時間を知ることができます。

波形観測

このサンプルを実行した結果をオシロスコープで測定しました。割り込みハンドラの処理終了に続いて、信号処理コールバックが実行されていることがわかります。

/media/uploads/shorie/office_lens_20160611-170247.jpg

main.cpp

Committer:
shorie
Date:
2016-06-11
Revision:
0:25d899a39c2c

File content as of revision 0:25d899a39c2c:

#include "unzen.h"          // audio framework include file
#include "umb_adau1361a.h"     // audio codec contoler include file
#include "mbed.h"
 
#define CODEC_I2C_ADDR 0x38
 
DigitalOut myled1(LED1);
DigitalOut debug_flag_1(D6);
DigitalOut debug_flag_2(D7);
 
 
   // customer signal processing initialization call back.
void init_callback(
           unsigned int block_size     // block size [sample]
           )
{
       // place initialization code here
}
 
 
   // customer signal processing call back.
void process_callback(
           float rx_left_buffer[],     // array of the left input samples
           float rx_right_buffer[],    // array of the right input samples
           float tx_left_buffer[],     // place to write the left output samples
           float tx_right_buffer[],    // place to write the left output samples
           unsigned int block_size     // block size [sample]
           )
{
       // Sample processing
   for ( int i=0; i<block_size; i++)   // for all sample
   {
       tx_left_buffer[i] = rx_left_buffer[i];      // copy from input to output
       tx_right_buffer[i] = rx_right_buffer[i];
       
   }
}
 
void pre_int_callback(void);
void post_int_callback(void);
void pre_process_callback(void);
void post_process_callback(void);
 
 
int main() 
{    
       // I2C is essential to talk with ADAU1361
   I2C i2c(SDA, SCL);
 
       // create an audio codec contoler
   shimabara::UMB_ADAU1361A codec(shimabara::Fs_32, i2c, CODEC_I2C_ADDR ); // Default Fs is 48kHz
//    shimabara::UMB_ADAU1361A codec(shimabara::Fs_441, i2c, CODEC_I2C_ADDR );
//    shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR );
//    shimabara::UMB_ADAU1361A codec(shimabara::Fs_96, i2c, CODEC_I2C_ADDR );
 
      // create an audio framework by singlton pattern
   unzen::Framework audio;
 
        // Set I3C clock to 100kHz
   i2c.frequency( 100000 );
 
 
       // Configure the optional block size of signal processing. By default, it is 1[Sample] 
//    audio.set_block_size(16);
 
        // debug call back registration
    audio.set_pre_interrupt_callback( pre_int_callback );
    audio.set_post_interrupt_callback( post_int_callback );
    audio.set_pre_process_callback( pre_process_callback );
    audio.set_post_process_callback( post_process_callback );
 
   
       // Start the ADAU1361. Audio codec starts to generate the I2C signals 
   codec.start();
 
       // Start the audio framework on ARM processor.  
   audio.start( init_callback, process_callback);     // path the initializaiton and process call back to framework 
 
 
       // periodically changing gain for test
   while(1)     
   {
       for ( int i=-15; i<4; i++ )
       {
           codec.set_hp_output_gain( i, i );
           codec.set_line_output_gain( i, i );
           myled1 = 1;
           wait(0.2);
           myled1 = 0;
           wait(0.2);
       }
   }
}

void pre_int_callback(void)
{
    debug_flag_1 = 1;
}

void post_int_callback(void)
{
    debug_flag_1 = 0;
}

void pre_process_callback(void)
{
    debug_flag_2= 1;
}

void post_process_callback(void)
{
    debug_flag_2 = 0;

}