source: rtems/c/src/lib/libbsp/lm32/shared/milkymist_midi/midi.c @ dce1032b

4.115
Last change on this file since dce1032b was dce1032b, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/11 at 13:48:40

2011-08-01 Sebastien Bourdeauducq <sebastien.bourdeauducq@…>

PR 1869/bsps

  • startup/bspclean.c: New file.
  • include/tm27.h: Removed.
  • ChangeLog?, Makefile.am, README, preinstall.am, include/bsp.h, include/system_conf.h, make/custom/milkymist.cfg, startup/linkcmds: Complete BSP for Milkymist One supporting Milkymist SOC 1.0.x. Includes new or updated drivers for:
    • Multi-standard video input (PAL/SECAM/NTSC)
    • Two DMX512 (RS485) ports
    • MIDI IN and MIDI OUT ports
    • VGA output
    • AC'97 audio
    • NOR flash
    • 10/100 Ethernet
    • Memory card (experimental and incomplete)
    • USB host connectors (input devices only)
    • RC5 infrared receiver
    • RS232 debug port
  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*  midi.c
2 *
3 *  Milkymist MIDI driver for RTEMS
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 *
11 *  COPYRIGHT (c) 2010, 2011 Sebastien Bourdeauducq
12 */
13
14#define RTEMS_STATUS_CHECKS_USE_PRINTK
15
16#include <stdlib.h>
17#include <sys/types.h>
18#include <rtems.h>
19#include <rtems/status-checks.h>
20#include <bsp.h>
21#include <bsp/irq-generic.h>
22#include <rtems/libio.h>
23#include "../include/system_conf.h"
24#include "milkymist_midi.h"
25
26#define DEVICE_NAME "/dev/midi"
27
28static rtems_id midi_q;
29
30static rtems_isr interrupt_handler(rtems_vector_number n)
31{
32  unsigned char msg;
33
34  lm32_interrupt_ack(1 << MM_IRQ_MIDIRX);
35  msg = MM_READ(MM_MIDI_RXTX);
36  rtems_message_queue_send(midi_q, &msg, 1);
37}
38
39rtems_device_driver midi_initialize(
40  rtems_device_major_number major,
41  rtems_device_minor_number minor,
42  void *arg
43)
44{
45  rtems_status_code sc;
46  rtems_isr_entry dummy;
47
48  sc = rtems_io_register_name(DEVICE_NAME, major, 0);
49  RTEMS_CHECK_SC(sc, "create MIDI input device");
50
51 sc = rtems_message_queue_create(
52    rtems_build_name('M', 'I', 'D', 'I'),
53    64,
54    1,
55    0,
56    &midi_q
57  );
58  RTEMS_CHECK_SC(sc, "create MIDI queue");
59
60  rtems_interrupt_catch(interrupt_handler, MM_IRQ_MIDIRX, &dummy);
61  bsp_interrupt_vector_enable(MM_IRQ_MIDIRX);
62
63  /* Only MIDI THRU mode is supported atm */
64  MM_WRITE(MM_MIDI_THRU, 1);
65
66  return RTEMS_SUCCESSFUL;
67}
68
69rtems_device_driver midi_open(
70  rtems_device_major_number major,
71  rtems_device_minor_number minor,
72  void *arg
73)
74{
75  uint32_t count;
76
77  rtems_message_queue_flush(midi_q, &count);
78  return RTEMS_SUCCESSFUL;
79}
80
81rtems_device_driver midi_read(
82  rtems_device_major_number major,
83  rtems_device_minor_number minor,
84  void *arg
85)
86{
87  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
88  rtems_status_code sc;
89
90  sc = rtems_message_queue_receive(
91    midi_q,
92    rw_args->buffer,
93    (size_t *)&rw_args->bytes_moved,
94    RTEMS_WAIT,
95    RTEMS_NO_TIMEOUT
96  );
97
98  if(sc == RTEMS_SUCCESSFUL)
99    return RTEMS_SUCCESSFUL;
100  else {
101    rw_args->bytes_moved = 0;
102    return RTEMS_UNSATISFIED;
103  }
104}
Note: See TracBrowser for help on using the repository browser.