Subversion Repositories svn.mios32

Rev

Rev 1942 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1260 tk 1
// $Id: app.c 2425 2016-11-03 00:44:22Z tk $
2
/*
3
 * MIDIO 128 V3
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2011 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
18
#include <mios32.h>
1297 tk 19
#include <msd.h>
1260 tk 20
#include "app.h"
21
#include "tasks.h"
22
 
1536 tk 23
#include <ainser.h>
1492 tk 24
#include <midi_port.h>
25
#include <midi_router.h>
26
#include <midimon.h>
27
 
1260 tk 28
#include "midio_sysex.h"
29
#include "midio_patch.h"
30
#include "midio_din.h"
31
#include "midio_dout.h"
1303 tk 32
#include "midio_ain.h"
1292 tk 33
#include "midio_matrix.h"
1260 tk 34
 
35
// include source of the SCS
36
#include <scs.h>
37
#include "scs_config.h"
38
 
1261 tk 39
#include "file.h"
1260 tk 40
#include "midio_file.h"
41
#include "midio_file_p.h"
42
 
1261 tk 43
#include <seq_bpm.h>
44
#include <seq_midi_out.h>
45
#include "seq.h"
46
#include "mid_file.h"
47
 
1260 tk 48
#include "terminal.h"
49
 
50
#include "uip_task.h"
51
#include "osc_client.h"
52
 
53
 
1261 tk 54
// define priority level for sequencer
55
// use same priority as MIOS32 specific tasks
56
#define PRIORITY_TASK_PERIOD_1mS ( tskIDLE_PRIORITY + 3 )
57
 
58
// local prototype of the task function
59
static void TASK_Period_1mS(void *pvParameters);
60
 
1260 tk 61
// define priority level for control surface handler
62
// use lower priority as MIOS32 specific tasks (2), so that slow LCDs don't affect overall performance
63
#define PRIORITY_TASK_PERIOD_1mS_LP ( tskIDLE_PRIORITY + 2 )
64
 
1297 tk 65
// SD Card with lower priority
66
#define PRIORITY_TASK_PERIOD_1mS_SD ( tskIDLE_PRIORITY + 2 )
67
 
1260 tk 68
// local prototype of the task function
69
static void TASK_Period_1mS_LP(void *pvParameters);
1297 tk 70
static void TASK_Period_1mS_SD(void *pvParameters);
1260 tk 71
 
1480 tk 72
 
73
// Extra hack: optionally map 16 encoders to the first DINX4 module (SR1..4)
74
// they send relative events CC16..CC23 over MIDI channel #2
75
#define ENABLE_ROTARY_ENCODERS 0
76
#define NUM_ROTARY_ENCODERS 16
77
 
78
 
1297 tk 79
/////////////////////////////////////////////////////////////////////////////
1657 tk 80
// global variables
81
/////////////////////////////////////////////////////////////////////////////
82
u8 hw_enabled;
83
 
84
 
85
/////////////////////////////////////////////////////////////////////////////
1297 tk 86
// Local types
87
/////////////////////////////////////////////////////////////////////////////
1260 tk 88
 
1297 tk 89
typedef enum {
90
  MSD_DISABLED,
91
  MSD_INIT,
92
  MSD_READY,
93
  MSD_SHUTDOWN
94
} msd_state_t;
95
 
96
 
1260 tk 97
/////////////////////////////////////////////////////////////////////////////
98
// local variables
99
/////////////////////////////////////////////////////////////////////////////
100
 
101
// for mutual exclusive SD Card access between different tasks
102
// The mutex is handled with MUTEX_SDCARD_TAKE and MUTEX_SDCARD_GIVE
103
// macros inside the application, which contain a different implementation 
104
// for emulation
105
xSemaphoreHandle xSDCardSemaphore;
106
 
107
// Mutex for MIDI IN/OUT handler
108
xSemaphoreHandle xMIDIINSemaphore;
109
xSemaphoreHandle xMIDIOUTSemaphore;
110
 
111
 
1299 tk 112
static volatile msd_state_t msd_state;
1260 tk 113
 
1297 tk 114
 
1260 tk 115
/////////////////////////////////////////////////////////////////////////////
116
// Local prototypes
117
/////////////////////////////////////////////////////////////////////////////
1261 tk 118
static s32 NOTIFY_MIDI_Rx(mios32_midi_port_t port, u8 byte);
1299 tk 119
static s32 NOTIFY_MIDI_Tx(mios32_midi_port_t port, mios32_midi_package_t package);
120
static s32 NOTIFY_MIDI_TimeOut(mios32_midi_port_t port);
1260 tk 121
 
122
 
123
/////////////////////////////////////////////////////////////////////////////
124
// This hook is called after startup to initialize the application
125
/////////////////////////////////////////////////////////////////////////////
126
void APP_Init(void)
127
{
128
  // initialize all LEDs
129
  MIOS32_BOARD_LED_Init(0xffffffff);
130
 
1299 tk 131
  // disable MSD by default (has to be enabled in SHIFT menu)
1297 tk 132
  msd_state = MSD_DISABLED;
133
 
1298 tk 134
  // hardware will be enabled once configuration has been loaded from SD Card
1260 tk 135
  // (resp. no SD Card is available)
1298 tk 136
  hw_enabled = 0;
1260 tk 137
 
138
  // initialize all J10 pins as inputs with internal Pull-Up
139
  int pin;
140
  for(pin=0; pin<8; ++pin)
141
    MIOS32_BOARD_J10_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);
142
 
1441 tk 143
  // initialize the AINSER module(s)
144
  AINSER_Init(0);
1260 tk 145
 
146
  // create semaphores
147
  xSDCardSemaphore = xSemaphoreCreateRecursiveMutex();
148
  xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex();
149
  xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex();
150
 
151
  // install SysEx callback
152
  MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser);
153
 
1299 tk 154
  // install MIDI Rx/Tx callback functions
155
  MIOS32_MIDI_DirectRxCallback_Init(&NOTIFY_MIDI_Rx);
156
  MIOS32_MIDI_DirectTxCallback_Init(&NOTIFY_MIDI_Tx);
1261 tk 157
 
1299 tk 158
  // install timeout callback function
159
  MIOS32_MIDI_TimeOutCallback_Init(&NOTIFY_MIDI_TimeOut);
160
 
1260 tk 161
  // initialize code modules
1492 tk 162
  MIDI_PORT_Init(0);
1260 tk 163
  MIDIO_SYSEX_Init(0);
1492 tk 164
  MIDI_ROUTER_Init(0);
1260 tk 165
  MIDIO_PATCH_Init(0);
166
  MIDIO_DIN_Init(0);
167
  MIDIO_DOUT_Init(0);
1303 tk 168
  MIDIO_AIN_Init(0);
1292 tk 169
  MIDIO_MATRIX_Init(0);
1260 tk 170
  UIP_TASK_Init(0);
171
  SCS_Init(0);
172
  SCS_CONFIG_Init(0);
173
  TERMINAL_Init(0);
174
  MIDIMON_Init(0);
175
  MIDIO_FILE_Init(0);
1261 tk 176
  SEQ_MIDI_OUT_Init(0);
177
  SEQ_Init(0);
1260 tk 178
 
1480 tk 179
#if ENABLE_ROTARY_ENCODERS
180
  // optionally enable rotary encoders
181
  int enc;
182
  for(enc=0; enc<NUM_ROTARY_ENCODERS; ++enc) {
183
    u8 pin_sr = enc >> 2; // each DIN SR has 4 encoders connected
184
    u8 pin_pos = (enc & 0x3) << 1; // Pin position of first ENC channel: either 0, 2, 4 or 6
185
 
186
    mios32_enc_config_t enc_config = MIOS32_ENC_ConfigGet(enc);
187
    enc_config.cfg.type = DETENTED3; // see mios32_enc.h for available types
188
    enc_config.cfg.sr = pin_sr;
189
    enc_config.cfg.pos = pin_pos;
190
    enc_config.cfg.speed = NORMAL;
191
    enc_config.cfg.speed_par = 0;
192
 
193
    // EXTRA: assign encoder to +1, since the first encoder entry is allocated by the SCS!
194
    MIOS32_ENC_ConfigSet(enc+1, enc_config);
195
  }
196
#endif
197
 
1261 tk 198
  // start tasks
2425 tk 199
  xTaskCreate(TASK_Period_1mS, "1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS, NULL);
200
  xTaskCreate(TASK_Period_1mS_LP, "1mS_LP", 2*configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_LP, NULL);
201
  xTaskCreate(TASK_Period_1mS_SD, "1mS_SD", 2*configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_SD, NULL);
1260 tk 202
 
203
}
204
 
205
 
206
/////////////////////////////////////////////////////////////////////////////
207
// This task is running endless in background
208
/////////////////////////////////////////////////////////////////////////////
209
void APP_Background(void)
210
{
211
}
212
 
213
 
214
/////////////////////////////////////////////////////////////////////////////
1919 tk 215
// This hook is called each mS from the main task which also handles DIN, ENC
216
// and AIN events. You could add more jobs here, but they shouldn't consume
217
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
218
// Alternatively you could create a dedicated task for application specific
219
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
220
/////////////////////////////////////////////////////////////////////////////
221
void APP_Tick(void)
222
{
1920 tk 223
  // PWM modulate the status LED (this is a sign of life)
224
  u32 timestamp = MIOS32_TIMESTAMP_Get();
225
  MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
1919 tk 226
}
227
 
228
 
229
/////////////////////////////////////////////////////////////////////////////
230
// This hook is called each mS from the MIDI task which checks for incoming
231
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
232
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
233
/////////////////////////////////////////////////////////////////////////////
234
void APP_MIDI_Tick(void)
235
{
236
}
237
 
238
 
239
/////////////////////////////////////////////////////////////////////////////
1260 tk 240
// This hook is called when a MIDI package has been received
241
/////////////////////////////////////////////////////////////////////////////
242
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
243
{
244
  // -> DOUT
245
  MIDIO_DOUT_MIDI_NotifyPackage(port, midi_package);
246
 
1293 tk 247
  // -> MIDI Router
1492 tk 248
  MIDI_ROUTER_Receive(port, midi_package);
1260 tk 249
 
1299 tk 250
  // -> MIDI Port Handler (used for MIDI monitor function)
1492 tk 251
  MIDI_PORT_NotifyMIDIRx(port, midi_package);
1299 tk 252
 
1536 tk 253
  // -> MIDI file recorder
1538 tk 254
  MID_FILE_Receive(port, midi_package);
1536 tk 255
 
1260 tk 256
  // forward to MIDI Monitor
257
  // SysEx messages have to be filtered for USB0 and UART0 to avoid data corruption
258
  // (the SysEx stream would interfere with monitor messages)
259
  u8 filter_sysex_message = (port == USB0) || (port == UART0);
1911 tk 260
  MIDIMON_Receive(port, midi_package, filter_sysex_message);
1260 tk 261
}
262
 
263
/////////////////////////////////////////////////////////////////////////////
264
// This function parses an incoming sysex stream for MIOS32 commands
265
/////////////////////////////////////////////////////////////////////////////
266
s32 APP_SYSEX_Parser(mios32_midi_port_t port, u8 midi_in)
267
{
1942 tk 268
  // -> MIDI file recorder
269
  MID_FILE_ReceiveSysEx(port, midi_in);
270
 
1260 tk 271
  // -> MIDIO
272
  MIDIO_SYSEX_Parser(port, midi_in);
273
 
1293 tk 274
  // -> MIDI Router
1492 tk 275
  MIDI_ROUTER_ReceiveSysEx(port, midi_in);
1260 tk 276
 
277
  return 0; // no error
278
}
279
 
280
/////////////////////////////////////////////////////////////////////////////
281
// This hook is called before the shift register chain is scanned
282
/////////////////////////////////////////////////////////////////////////////
283
void APP_SRIO_ServicePrepare(void)
284
{
285
  // pass current pin state of J10
286
  // only available for LPC17xx, all others (like STM32) default to SRIO
287
  SCS_AllPinsSet(0xff00 | MIOS32_BOARD_J10_Get());
288
 
289
  // update encoders/buttons of SCS
290
  SCS_EncButtonUpdate_Tick();
1292 tk 291
 
292
  // Matrix handler
293
  MIDIO_MATRIX_PrepareCol();
1260 tk 294
}
295
 
296
 
297
/////////////////////////////////////////////////////////////////////////////
298
// This hook is called after the shift register chain has been scanned
299
/////////////////////////////////////////////////////////////////////////////
300
void APP_SRIO_ServiceFinish(void)
301
{
1292 tk 302
  // Matrix handler
303
  MIDIO_MATRIX_GetRow();
1260 tk 304
}
305
 
306
 
307
/////////////////////////////////////////////////////////////////////////////
308
// This hook is called when a button has been toggled
309
// pin_value is 1 when button released, and 0 when button pressed
310
/////////////////////////////////////////////////////////////////////////////
311
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
312
{
313
  // -> MIDIO_DIN once enabled
1298 tk 314
  if( hw_enabled )
1260 tk 315
    MIDIO_DIN_NotifyToggle(pin, pin_value);
316
}
317
 
318
 
319
/////////////////////////////////////////////////////////////////////////////
320
// This hook is called when an encoder has been moved
321
// incrementer is positive when encoder has been turned clockwise, else
322
// it is negative
323
/////////////////////////////////////////////////////////////////////////////
324
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
325
{
326
  // pass encoder event to SCS handler
327
  if( encoder == SCS_ENC_MENU_ID )
328
    SCS_ENC_MENU_NotifyChange(incrementer);
1480 tk 329
  else {
330
#if ENABLE_ROTARY_ENCODERS
331
    // determine relative value: 64 +/- <incrementer>
332
    int value = 64 + incrementer;
333
 
334
    // ensure that value is in range of 0..127
335
    if( value < 0 )
336
      value = 0;
337
    else if( value > 127 )
338
      value = 127;
339
 
340
    // send event
341
    MIOS32_MIDI_SendCC(DEFAULT, Chn2, 0x10 + encoder - 1, value);
342
#endif
343
  }
1260 tk 344
}
345
 
346
 
347
/////////////////////////////////////////////////////////////////////////////
348
// This hook is called when a pot has been moved
349
/////////////////////////////////////////////////////////////////////////////
350
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
351
{
1303 tk 352
  // -> MIDIO_AIN once enabled
353
  if( hw_enabled )
354
    MIDIO_AIN_NotifyChange(pin, pin_value);
1260 tk 355
}
356
 
357
 
1441 tk 358
/////////////////////////////////////////////////////////////////////////////
359
// This hook is called when an AINSER pot has been moved
360
/////////////////////////////////////////////////////////////////////////////
361
static void APP_AINSER_NotifyChange(u32 module, u32 pin, u32 pin_value)
362
{
363
  // -> MIDIO_AIN once enabled
364
  if( hw_enabled )
365
    MIDIO_AIN_NotifyChange_SER64(module, pin, pin_value);
366
}
1261 tk 367
 
368
 
1260 tk 369
/////////////////////////////////////////////////////////////////////////////
370
// This task handles the control surface
371
/////////////////////////////////////////////////////////////////////////////
372
static void TASK_Period_1mS_LP(void *pvParameters)
373
{
374
  MIOS32_LCD_Clear();
375
 
376
  while( 1 ) {
377
    vTaskDelay(1 / portTICK_RATE_MS);
378
 
379
    // call SCS handler
380
    SCS_Tick();
1299 tk 381
 
382
    // MIDI In/Out monitor
1492 tk 383
    MIDI_PORT_Period1mS();
1261 tk 384
  }
1260 tk 385
 
1261 tk 386
}
387
 
388
 
389
/////////////////////////////////////////////////////////////////////////////
1297 tk 390
// This task handles the SD Card
391
/////////////////////////////////////////////////////////////////////////////
392
static void TASK_Period_1mS_SD(void *pvParameters)
393
{
1540 tk 394
  const u16 sdcard_check_delay = 1000;
1297 tk 395
  u16 sdcard_check_ctr = 0;
396
  u8 lun_available = 0;
397
 
398
  while( 1 ) {
399
    vTaskDelay(1 / portTICK_RATE_MS);
400
 
401
    // each second: check if SD Card (still) available
1540 tk 402
    if( msd_state == MSD_DISABLED && ++sdcard_check_ctr >= sdcard_check_delay ) {
1297 tk 403
      sdcard_check_ctr = 0;
404
 
405
      MUTEX_SDCARD_TAKE;
406
      s32 status = FILE_CheckSDCard();
407
 
408
      if( status == 1 ) {
409
    DEBUG_MSG("SD Card connected: %s\n", FILE_VolumeLabel());
1540 tk 410
 
411
    // stop sequencer
412
    SEQ_BPM_Stop();
413
 
1297 tk 414
    // load all file infos
415
    MIDIO_FILE_LoadAllFiles(1); // including HW info
1540 tk 416
 
417
    // immediately go to next step
418
    sdcard_check_ctr = sdcard_check_delay;
1297 tk 419
      } else if( status == 2 ) {
420
    DEBUG_MSG("SD Card disconnected\n");
421
    // invalidate all file infos
422
    MIDIO_FILE_UnloadAllFiles();
423
 
424
    // stop sequencer
425
    SEQ_BPM_Stop();
426
 
1298 tk 427
    // change status
428
    MIDIO_FILE_StatusMsgSet("No SD Card");
1297 tk 429
      } else if( status == 3 ) {
430
    if( !FILE_SDCardAvailable() ) {
431
      DEBUG_MSG("SD Card not found\n");
1298 tk 432
      MIDIO_FILE_StatusMsgSet("No SD Card");
1297 tk 433
    } else if( !FILE_VolumeAvailable() ) {
434
      DEBUG_MSG("ERROR: SD Card contains invalid FAT!\n");
1298 tk 435
      MIDIO_FILE_StatusMsgSet("No FAT");
1297 tk 436
    } else {
1653 tk 437
      // create the default files if they don't exist on SD Card
438
      MIDIO_FILE_CreateDefaultFiles();
1297 tk 439
 
1540 tk 440
      // load first MIDI file
441
      MID_FILE_UI_NameClear();
442
      SEQ_SetPauseMode(1);
443
      SEQ_PlayFileReq(0, 1);
1297 tk 444
    }
1585 tk 445
 
446
    hw_enabled = 1; // enable hardware after first read...
1297 tk 447
      }
448
 
449
      MUTEX_SDCARD_GIVE;
450
    }
451
 
452
    // MSD driver
453
    if( msd_state != MSD_DISABLED ) {
454
      MUTEX_SDCARD_TAKE;
455
 
456
      switch( msd_state ) {
457
      case MSD_SHUTDOWN:
458
    // switch back to USB MIDI
459
    MIOS32_USB_Init(1);
460
    msd_state = MSD_DISABLED;
461
    break;
462
 
463
      case MSD_INIT:
464
    // LUN not mounted yet
465
    lun_available = 0;
466
 
467
    // enable MSD USB driver
468
    //MUTEX_J16_TAKE;
469
    if( MSD_Init(0) >= 0 )
470
      msd_state = MSD_READY;
471
    else
472
      msd_state = MSD_SHUTDOWN;
473
    //MUTEX_J16_GIVE;
474
    break;
475
 
476
      case MSD_READY:
477
    // service MSD USB driver
478
    MSD_Periodic_mS();
479
 
480
    // this mechanism shuts down the MSD driver if SD card has been unmounted by OS
481
    if( lun_available && !MSD_LUN_AvailableGet(0) )
482
      msd_state = MSD_SHUTDOWN;
483
    else if( !lun_available && MSD_LUN_AvailableGet(0) )
484
      lun_available = 1;
485
    break;
486
      }
487
 
488
      MUTEX_SDCARD_GIVE;
489
    }
490
  }
491
 
492
}
493
 
494
 
495
/////////////////////////////////////////////////////////////////////////////
1261 tk 496
// This task is called periodically each mS to handle sequencer requests
497
/////////////////////////////////////////////////////////////////////////////
498
static void TASK_Period_1mS(void *pvParameters)
499
{
500
  portTickType xLastExecutionTime;
501
 
502
  // Initialise the xLastExecutionTime variable on task entry
503
  xLastExecutionTime = xTaskGetTickCount();
504
 
505
  while( 1 ) {
506
    vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
507
 
1297 tk 508
    // skip delay gap if we had to wait for more than 5 ticks to avoid 
509
    // unnecessary repeats until xLastExecutionTime reached xTaskGetTickCount() again
510
    portTickType xCurrentTickCount = xTaskGetTickCount();
511
    if( xLastExecutionTime < (xCurrentTickCount-5) )
512
      xLastExecutionTime = xCurrentTickCount;
513
 
1610 tk 514
 
1261 tk 515
    // execute sequencer handler
516
    MUTEX_SDCARD_TAKE;
517
    SEQ_Handler();
1260 tk 518
    MUTEX_SDCARD_GIVE;
1261 tk 519
 
520
    // send timestamped MIDI events
521
    MUTEX_MIDIOUT_TAKE;
522
    SEQ_MIDI_OUT_Handler();
523
    MUTEX_MIDIOUT_GIVE;
1292 tk 524
 
525
    // Scan Matrix button handler
526
    MIDIO_MATRIX_ButtonHandler();
1441 tk 527
 
528
    // scan AINSER pins
529
    AINSER_Handler(APP_AINSER_NotifyChange);
1260 tk 530
  }
531
}
532
 
533
 
534
/////////////////////////////////////////////////////////////////////////////
1261 tk 535
// Installed via MIOS32_MIDI_DirectRxCallback_Init
536
/////////////////////////////////////////////////////////////////////////////
537
static s32 NOTIFY_MIDI_Rx(mios32_midi_port_t port, u8 midi_byte)
538
{
1299 tk 539
  // filter MIDI In port which controls the MIDI clock
1492 tk 540
  if( MIDI_ROUTER_MIDIClockInGet(port) == 1 )
1299 tk 541
    SEQ_BPM_NotifyMIDIRx(midi_byte);
1261 tk 542
 
543
  return 0; // no error, no filtering
544
}
1297 tk 545
 
1299 tk 546
/////////////////////////////////////////////////////////////////////////////
547
// Installed via MIOS32_MIDI_DirectTxCallback_Init
548
/////////////////////////////////////////////////////////////////////////////
549
static s32 NOTIFY_MIDI_Tx(mios32_midi_port_t port, mios32_midi_package_t package)
550
{
1492 tk 551
  return MIDI_PORT_NotifyMIDITx(port, package);
1299 tk 552
}
1297 tk 553
 
554
/////////////////////////////////////////////////////////////////////////////
1299 tk 555
// Installed via MIOS32_MIDI_TimeoutCallback_Init
556
/////////////////////////////////////////////////////////////////////////////
557
static s32 NOTIFY_MIDI_TimeOut(mios32_midi_port_t port)
558
{  
559
  // forward to SysEx parser
560
  MIDIO_SYSEX_TimeOut(port);
561
 
562
  // print message on screen
563
  SCS_Msg(SCS_MSG_L, 2000, "MIDI Protocol", "TIMEOUT !!!");
564
 
565
  return 0;
566
}
567
 
568
 
569
/////////////////////////////////////////////////////////////////////////////
1297 tk 570
// MSD access functions
571
/////////////////////////////////////////////////////////////////////////////
572
s32 TASK_MSD_EnableSet(u8 enable)
573
{
574
  MIOS32_IRQ_Disable();
575
  if( msd_state == MSD_DISABLED && enable ) {
576
    msd_state = MSD_INIT;
577
  } else if( msd_state == MSD_READY && !enable )
578
    msd_state = MSD_SHUTDOWN;
579
  MIOS32_IRQ_Enable();
580
 
581
  return 0; // no error
582
}
583
 
584
s32 TASK_MSD_EnableGet()
585
{
586
  return (msd_state == MSD_READY) ? 1 : 0;
587
}
588
 
589
s32 TASK_MSD_FlagStrGet(char str[5])
590
{
591
  str[0] = MSD_CheckAvailable() ? 'U' : '-';
592
  str[1] = MSD_LUN_AvailableGet(0) ? 'M' : '-';
593
  str[2] = MSD_RdLEDGet(250) ? 'R' : '-';
594
  str[3] = MSD_WrLEDGet(250) ? 'W' : '-';
595
  str[4] = 0;
596
 
597
  return 0; // no error
598
}
1610 tk 599
 
600
/////////////////////////////////////////////////////////////////////////////
601
// functions to access MIDI IN/Out Mutex
602
// see also mios32_config.h
603
/////////////////////////////////////////////////////////////////////////////
604
void APP_MUTEX_MIDIOUT_Take(void) { MUTEX_MIDIOUT_TAKE; }
605
void APP_MUTEX_MIDIOUT_Give(void) { MUTEX_MIDIOUT_GIVE; }
606
void APP_MUTEX_MIDIIN_Take(void) { MUTEX_MIDIIN_TAKE; }
607
void APP_MUTEX_MIDIIN_Give(void) { MUTEX_MIDIIN_GIVE; }