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() で登録されたデバッグ用コールバックは、信号処理コールバックの前後でそれぞれ呼び出されます。そのため、デバッグピンをトグルすれば、信号処理ルーチンの実行時間を知ることができます。
波形観測
このサンプルを実行した結果をオシロスコープで測定しました。割り込みハンドラの処理終了に続いて、信号処理コールバックが実行されていることがわかります。
main.cpp@0:25d899a39c2c, 2016-06-11 (annotated)
- Committer:
- shorie
- Date:
- Sat Jun 11 08:08:56 2016 +0000
- Revision:
- 0:25d899a39c2c
Commit for publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 0:25d899a39c2c | 1 | #include "unzen.h" // audio framework include file |
shorie | 0:25d899a39c2c | 2 | #include "umb_adau1361a.h" // audio codec contoler include file |
shorie | 0:25d899a39c2c | 3 | #include "mbed.h" |
shorie | 0:25d899a39c2c | 4 | |
shorie | 0:25d899a39c2c | 5 | #define CODEC_I2C_ADDR 0x38 |
shorie | 0:25d899a39c2c | 6 | |
shorie | 0:25d899a39c2c | 7 | DigitalOut myled1(LED1); |
shorie | 0:25d899a39c2c | 8 | DigitalOut debug_flag_1(D6); |
shorie | 0:25d899a39c2c | 9 | DigitalOut debug_flag_2(D7); |
shorie | 0:25d899a39c2c | 10 | |
shorie | 0:25d899a39c2c | 11 | |
shorie | 0:25d899a39c2c | 12 | // customer signal processing initialization call back. |
shorie | 0:25d899a39c2c | 13 | void init_callback( |
shorie | 0:25d899a39c2c | 14 | unsigned int block_size // block size [sample] |
shorie | 0:25d899a39c2c | 15 | ) |
shorie | 0:25d899a39c2c | 16 | { |
shorie | 0:25d899a39c2c | 17 | // place initialization code here |
shorie | 0:25d899a39c2c | 18 | } |
shorie | 0:25d899a39c2c | 19 | |
shorie | 0:25d899a39c2c | 20 | |
shorie | 0:25d899a39c2c | 21 | // customer signal processing call back. |
shorie | 0:25d899a39c2c | 22 | void process_callback( |
shorie | 0:25d899a39c2c | 23 | float rx_left_buffer[], // array of the left input samples |
shorie | 0:25d899a39c2c | 24 | float rx_right_buffer[], // array of the right input samples |
shorie | 0:25d899a39c2c | 25 | float tx_left_buffer[], // place to write the left output samples |
shorie | 0:25d899a39c2c | 26 | float tx_right_buffer[], // place to write the left output samples |
shorie | 0:25d899a39c2c | 27 | unsigned int block_size // block size [sample] |
shorie | 0:25d899a39c2c | 28 | ) |
shorie | 0:25d899a39c2c | 29 | { |
shorie | 0:25d899a39c2c | 30 | // Sample processing |
shorie | 0:25d899a39c2c | 31 | for ( int i=0; i<block_size; i++) // for all sample |
shorie | 0:25d899a39c2c | 32 | { |
shorie | 0:25d899a39c2c | 33 | tx_left_buffer[i] = rx_left_buffer[i]; // copy from input to output |
shorie | 0:25d899a39c2c | 34 | tx_right_buffer[i] = rx_right_buffer[i]; |
shorie | 0:25d899a39c2c | 35 | |
shorie | 0:25d899a39c2c | 36 | } |
shorie | 0:25d899a39c2c | 37 | } |
shorie | 0:25d899a39c2c | 38 | |
shorie | 0:25d899a39c2c | 39 | void pre_int_callback(void); |
shorie | 0:25d899a39c2c | 40 | void post_int_callback(void); |
shorie | 0:25d899a39c2c | 41 | void pre_process_callback(void); |
shorie | 0:25d899a39c2c | 42 | void post_process_callback(void); |
shorie | 0:25d899a39c2c | 43 | |
shorie | 0:25d899a39c2c | 44 | |
shorie | 0:25d899a39c2c | 45 | int main() |
shorie | 0:25d899a39c2c | 46 | { |
shorie | 0:25d899a39c2c | 47 | // I2C is essential to talk with ADAU1361 |
shorie | 0:25d899a39c2c | 48 | I2C i2c(SDA, SCL); |
shorie | 0:25d899a39c2c | 49 | |
shorie | 0:25d899a39c2c | 50 | // create an audio codec contoler |
shorie | 0:25d899a39c2c | 51 | shimabara::UMB_ADAU1361A codec(shimabara::Fs_32, i2c, CODEC_I2C_ADDR ); // Default Fs is 48kHz |
shorie | 0:25d899a39c2c | 52 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_441, i2c, CODEC_I2C_ADDR ); |
shorie | 0:25d899a39c2c | 53 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); |
shorie | 0:25d899a39c2c | 54 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_96, i2c, CODEC_I2C_ADDR ); |
shorie | 0:25d899a39c2c | 55 | |
shorie | 0:25d899a39c2c | 56 | // create an audio framework by singlton pattern |
shorie | 0:25d899a39c2c | 57 | unzen::Framework audio; |
shorie | 0:25d899a39c2c | 58 | |
shorie | 0:25d899a39c2c | 59 | // Set I3C clock to 100kHz |
shorie | 0:25d899a39c2c | 60 | i2c.frequency( 100000 ); |
shorie | 0:25d899a39c2c | 61 | |
shorie | 0:25d899a39c2c | 62 | |
shorie | 0:25d899a39c2c | 63 | // Configure the optional block size of signal processing. By default, it is 1[Sample] |
shorie | 0:25d899a39c2c | 64 | // audio.set_block_size(16); |
shorie | 0:25d899a39c2c | 65 | |
shorie | 0:25d899a39c2c | 66 | // debug call back registration |
shorie | 0:25d899a39c2c | 67 | audio.set_pre_interrupt_callback( pre_int_callback ); |
shorie | 0:25d899a39c2c | 68 | audio.set_post_interrupt_callback( post_int_callback ); |
shorie | 0:25d899a39c2c | 69 | audio.set_pre_process_callback( pre_process_callback ); |
shorie | 0:25d899a39c2c | 70 | audio.set_post_process_callback( post_process_callback ); |
shorie | 0:25d899a39c2c | 71 | |
shorie | 0:25d899a39c2c | 72 | |
shorie | 0:25d899a39c2c | 73 | // Start the ADAU1361. Audio codec starts to generate the I2C signals |
shorie | 0:25d899a39c2c | 74 | codec.start(); |
shorie | 0:25d899a39c2c | 75 | |
shorie | 0:25d899a39c2c | 76 | // Start the audio framework on ARM processor. |
shorie | 0:25d899a39c2c | 77 | audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework |
shorie | 0:25d899a39c2c | 78 | |
shorie | 0:25d899a39c2c | 79 | |
shorie | 0:25d899a39c2c | 80 | // periodically changing gain for test |
shorie | 0:25d899a39c2c | 81 | while(1) |
shorie | 0:25d899a39c2c | 82 | { |
shorie | 0:25d899a39c2c | 83 | for ( int i=-15; i<4; i++ ) |
shorie | 0:25d899a39c2c | 84 | { |
shorie | 0:25d899a39c2c | 85 | codec.set_hp_output_gain( i, i ); |
shorie | 0:25d899a39c2c | 86 | codec.set_line_output_gain( i, i ); |
shorie | 0:25d899a39c2c | 87 | myled1 = 1; |
shorie | 0:25d899a39c2c | 88 | wait(0.2); |
shorie | 0:25d899a39c2c | 89 | myled1 = 0; |
shorie | 0:25d899a39c2c | 90 | wait(0.2); |
shorie | 0:25d899a39c2c | 91 | } |
shorie | 0:25d899a39c2c | 92 | } |
shorie | 0:25d899a39c2c | 93 | } |
shorie | 0:25d899a39c2c | 94 | |
shorie | 0:25d899a39c2c | 95 | void pre_int_callback(void) |
shorie | 0:25d899a39c2c | 96 | { |
shorie | 0:25d899a39c2c | 97 | debug_flag_1 = 1; |
shorie | 0:25d899a39c2c | 98 | } |
shorie | 0:25d899a39c2c | 99 | |
shorie | 0:25d899a39c2c | 100 | void post_int_callback(void) |
shorie | 0:25d899a39c2c | 101 | { |
shorie | 0:25d899a39c2c | 102 | debug_flag_1 = 0; |
shorie | 0:25d899a39c2c | 103 | } |
shorie | 0:25d899a39c2c | 104 | |
shorie | 0:25d899a39c2c | 105 | void pre_process_callback(void) |
shorie | 0:25d899a39c2c | 106 | { |
shorie | 0:25d899a39c2c | 107 | debug_flag_2= 1; |
shorie | 0:25d899a39c2c | 108 | } |
shorie | 0:25d899a39c2c | 109 | |
shorie | 0:25d899a39c2c | 110 | void post_process_callback(void) |
shorie | 0:25d899a39c2c | 111 | { |
shorie | 0:25d899a39c2c | 112 | debug_flag_2 = 0; |
shorie | 0:25d899a39c2c | 113 | |
shorie | 0:25d899a39c2c | 114 | } |
shorie | 0:25d899a39c2c | 115 | |
shorie | 0:25d899a39c2c | 116 | |
shorie | 0:25d899a39c2c | 117 |