File: test.c

package info (click to toggle)
alsadriver 0.2.0-pre8-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,808 kB
  • ctags: 6,550
  • sloc: ansic: 43,490; sh: 916; makefile: 759; perl: 54
file content (123 lines) | stat: -rw-r--r-- 3,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 *  Test module
 *  Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#define SND_MAIN_OBJECT_FILE
#include "driver.h"
#include "minors.h"
#include "timer.h"
#include "midi.h"

#define MIDI_TEST

struct snd_test {
  snd_sleep_define( sleeper );
};

static struct snd_test t;

#ifdef TIMER_TEST

static void snd_test_timer_handler( snd_timer_t *timer, void *data )
{
  snd_printk( "timer tick!!! timer '%s' is ok, jiffies = %li\n", timer -> name, jiffies );
  snd_wakeup( &t, sleeper );
}

static void snd_timer_test( void )
{
  static int resolutions[] = { 0, 1000, 80000, 320000, -1 };
  snd_timer_t *timer;
  int idx;
  unsigned int resolution;
  
  memset( &t, 0, sizeof( t ) );
  for ( idx = 0; resolutions[ idx ] >= 0; idx++ ) {
    if ( resolutions[ idx ] == 0 ) {
      if ( (timer = snd_timer_open_system( "test" )) == NULL ) {
        snd_printk( "system timer open failed!!!\n" );
        continue;
      }      
    } else {
      if ( (timer = snd_timer_open_always( "test", resolutions[ idx ] )) == NULL ) {
        snd_printk( "timer open failed for resolution %i!!!\n", resolutions[ idx ] );
        continue;
      }
    }
    resolution = snd_timer_resolution( timer );
    snd_printk( "timer open ok: %s (resolution = %u.%u), jiffies = %li\n", timer -> name, resolution / 1000, resolution % 1000, jiffies );
    timer -> callback = snd_test_timer_handler;
    snd_timer_start( timer, idx == 0 ? 256 : 50 * 256 );
    snd_sleep( &t, sleeper, HZ * 60 );
    snd_timer_stop( timer );		/* only for sure */
    snd_timer_close_always( timer );
  }
}

#endif

#ifdef MIDI_TEST

static void snd_midi_command( snd_rawmidi_t *rmidi, void *cmd_private_data, unsigned char *command, int count )
{
  snd_printk( "rx command '%s': ", rmidi -> name );
  while ( count-- > 0 )
    printk( "%02x:", *command++ );
  printk( "\n" );
}

static void snd_midi_test( void )
{
  snd_rawmidi_t *rmidi;
  char buf[16];
  
  if ( (snd_midi_open( 0, 0, SND_RAWMIDI_LFLG_OUTPUT | SND_RAWMIDI_LFLG_INPUT, &rmidi )) < 0 ) {
    snd_printk( "midi open failed!!!\n" );
    return;
  }
  buf[0] = 0x90;
  buf[1] = 0x40;
  buf[2] = 0x7f;
#if 0
  snd_midi_transmit( rmidi, buf, 3 );
  snd_midi_flush_output( rmidi );
#endif
  rmidi -> input.u.p.command = snd_midi_command;
  snd_midi_start_input( rmidi );
  snd_sleep( &t, sleeper, HZ * 10 );
  snd_midi_close( 0, 0, SND_RAWMIDI_LFLG_OUTPUT | SND_RAWMIDI_LFLG_INPUT );
}

#endif

int init_module( void )
{
#ifdef TIMER_TEST
  snd_timer_test();
#endif
#ifdef MIDI_TEST
  snd_midi_test();
#endif
  return -EBUSY;
}

void cleanup_module( void )
{
}