Subversion Repositories svn.mios32

Rev

Rev 1919 | Rev 1942 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1260 tk 1
// $Id: app.c 1920 2014-01-08 19:29:35Z 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
199
  xTaskCreate(TASK_Period_1mS, (signed portCHAR *)"1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS, NULL);
1268 tk 200
  xTaskCreate(TASK_Period_1mS_LP, (signed portCHAR *)"1mS_LP", 2*configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_LP, NULL);
1297 tk 201
  xTaskCreate(TASK_Period_1mS_SD, (signed portCHAR *)"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
{
268
  // -> MIDIO
269
  MIDIO_SYSEX_Parser(port, midi_in);
270
 
1293 tk 271
  // -> MIDI Router
1492 tk 272
  MIDI_ROUTER_ReceiveSysEx(port, midi_in);
1260 tk 273
 
274
  return 0; // no error
275
}
276
 
277
/////////////////////////////////////////////////////////////////////////////
278
// This hook is called before the shift register chain is scanned
279
/////////////////////////////////////////////////////////////////////////////
280
void APP_SRIO_ServicePrepare(void)
281
{
282
  // pass current pin state of J10
283
  // only available for LPC17xx, all others (like STM32) default to SRIO
284
  SCS_AllPinsSet(0xff00 | MIOS32_BOARD_J10_Get());
285
 
286
  // update encoders/buttons of SCS
287
  SCS_EncButtonUpdate_Tick();
1292 tk 288
 
289
  // Matrix handler
290
  MIDIO_MATRIX_PrepareCol();
1260 tk 291
}
292
 
293
 
294
/////////////////////////////////////////////////////////////////////////////
295
// This hook is called after the shift register chain has been scanned
296
/////////////////////////////////////////////////////////////////////////////
297
void APP_SRIO_ServiceFinish(void)
298
{
1292 tk 299
  // Matrix handler
300
  MIDIO_MATRIX_GetRow();
1260 tk 301
}
302
 
303
 
304
/////////////////////////////////////////////////////////////////////////////
305
// This hook is called when a button has been toggled
306
// pin_value is 1 when button released, and 0 when button pressed
307
/////////////////////////////////////////////////////////////////////////////
308
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
309
{
310
  // -> MIDIO_DIN once enabled
1298 tk 311
  if( hw_enabled )
1260 tk 312
    MIDIO_DIN_NotifyToggle(pin, pin_value);
313
}
314
 
315
 
316
/////////////////////////////////////////////////////////////////////////////
317
// This hook is called when an encoder has been moved
318
// incrementer is positive when encoder has been turned clockwise, else
319
// it is negative
320
/////////////////////////////////////////////////////////////////////////////
321
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
322
{
323
  // pass encoder event to SCS handler
324
  if( encoder == SCS_ENC_MENU_ID )
325
    SCS_ENC_MENU_NotifyChange(incrementer);
1480 tk 326
  else {
327
#if ENABLE_ROTARY_ENCODERS
328
    // determine relative value: 64 +/- <incrementer>
329
    int value = 64 + incrementer;
330
 
331
    // ensure that value is in range of 0..127
332
    if( value < 0 )
333
      value = 0;
334
    else if( value > 127 )
335
      value = 127;
336
 
337
    // send event
338
    MIOS32_MIDI_SendCC(DEFAULT, Chn2, 0x10 + encoder - 1, value);
339
#endif
340
  }
1260 tk 341
}
342
 
343
 
344
/////////////////////////////////////////////////////////////////////////////
345
// This hook is called when a pot has been moved
346
/////////////////////////////////////////////////////////////////////////////
347
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
348
{
1303 tk 349
  // -> MIDIO_AIN once enabled
350
  if( hw_enabled )
351
    MIDIO_AIN_NotifyChange(pin, pin_value);
1260 tk 352
}
353
 
354
 
1441 tk 355
/////////////////////////////////////////////////////////////////////////////
356
// This hook is called when an AINSER pot has been moved
357
/////////////////////////////////////////////////////////////////////////////
358
static void APP_AINSER_NotifyChange(u32 module, u32 pin, u32 pin_value)
359
{
360
  // -> MIDIO_AIN once enabled
361
  if( hw_enabled )
362
    MIDIO_AIN_NotifyChange_SER64(module, pin, pin_value);
363
}
1261 tk 364
 
365
 
1260 tk 366
/////////////////////////////////////////////////////////////////////////////
367
// This task handles the control surface
368
/////////////////////////////////////////////////////////////////////////////
369
static void TASK_Period_1mS_LP(void *pvParameters)
370
{
371
  MIOS32_LCD_Clear();
372
 
373
  while( 1 ) {
374
    vTaskDelay(1 / portTICK_RATE_MS);
375
 
376
    // call SCS handler
377
    SCS_Tick();
1299 tk 378
 
379
    // MIDI In/Out monitor
1492 tk 380
    MIDI_PORT_Period1mS();
1261 tk 381
  }
1260 tk 382
 
1261 tk 383
}
384
 
385
 
386
/////////////////////////////////////////////////////////////////////////////
1297 tk 387
// This task handles the SD Card
388
/////////////////////////////////////////////////////////////////////////////
389
static void TASK_Period_1mS_SD(void *pvParameters)
390
{
1540 tk 391
  const u16 sdcard_check_delay = 1000;
1297 tk 392
  u16 sdcard_check_ctr = 0;
393
  u8 lun_available = 0;
394
 
395
  while( 1 ) {
396
    vTaskDelay(1 / portTICK_RATE_MS);
397
 
398
    // each second: check if SD Card (still) available
1540 tk 399
    if( msd_state == MSD_DISABLED && ++sdcard_check_ctr >= sdcard_check_delay ) {
1297 tk 400
      sdcard_check_ctr = 0;
401
 
402
      MUTEX_SDCARD_TAKE;
403
      s32 status = FILE_CheckSDCard();
404
 
405
      if( status == 1 ) {
406
    DEBUG_MSG("SD Card connected: %s\n", FILE_VolumeLabel());
1540 tk 407
 
408
    // stop sequencer
409
    SEQ_BPM_Stop();
410
 
1297 tk 411
    // load all file infos
412
    MIDIO_FILE_LoadAllFiles(1); // including HW info
1540 tk 413
 
414
    // immediately go to next step
415
    sdcard_check_ctr = sdcard_check_delay;
1297 tk 416
      } else if( status == 2 ) {
417
    DEBUG_MSG("SD Card disconnected\n");
418
    // invalidate all file infos
419
    MIDIO_FILE_UnloadAllFiles();
420
 
421
    // stop sequencer
422
    SEQ_BPM_Stop();
423
 
1298 tk 424
    // change status
425
    MIDIO_FILE_StatusMsgSet("No SD Card");
1297 tk 426
      } else if( status == 3 ) {
427
    if( !FILE_SDCardAvailable() ) {
428
      DEBUG_MSG("SD Card not found\n");
1298 tk 429
      MIDIO_FILE_StatusMsgSet("No SD Card");
1297 tk 430
    } else if( !FILE_VolumeAvailable() ) {
431
      DEBUG_MSG("ERROR: SD Card contains invalid FAT!\n");
1298 tk 432
      MIDIO_FILE_StatusMsgSet("No FAT");
1297 tk 433
    } else {
1653 tk 434
      // create the default files if they don't exist on SD Card
435
      MIDIO_FILE_CreateDefaultFiles();
1297 tk 436
 
1540 tk 437
      // load first MIDI file
438
      MID_FILE_UI_NameClear();
439
      SEQ_SetPauseMode(1);
440
      SEQ_PlayFileReq(0, 1);
1297 tk 441
    }
1585 tk 442
 
443
    hw_enabled = 1; // enable hardware after first read...
1297 tk 444
      }
445
 
446
      MUTEX_SDCARD_GIVE;
447
    }
448
 
449
    // MSD driver
450
    if( msd_state != MSD_DISABLED ) {
451
      MUTEX_SDCARD_TAKE;
452
 
453
      switch( msd_state ) {
454
      case MSD_SHUTDOWN:
455
    // switch back to USB MIDI
456
    MIOS32_USB_Init(1);
457
    msd_state = MSD_DISABLED;
458
    break;
459
 
460
      case MSD_INIT:
461
    // LUN not mounted yet
462
    lun_available = 0;
463
 
464
    // enable MSD USB driver
465
    //MUTEX_J16_TAKE;
466
    if( MSD_Init(0) >= 0 )
467
      msd_state = MSD_READY;
468
    else
469
      msd_state = MSD_SHUTDOWN;
470
    //MUTEX_J16_GIVE;
471
    break;
472
 
473
      case MSD_READY:
474
    // service MSD USB driver
475
    MSD_Periodic_mS();
476
 
477
    // this mechanism shuts down the MSD driver if SD card has been unmounted by OS
478
    if( lun_available && !MSD_LUN_AvailableGet(0) )
479
      msd_state = MSD_SHUTDOWN;
480
    else if( !lun_available && MSD_LUN_AvailableGet(0) )
481
      lun_available = 1;
482
    break;
483
      }
484
 
485
      MUTEX_SDCARD_GIVE;
486
    }
487
  }
488
 
489
}
490
 
491
 
492
/////////////////////////////////////////////////////////////////////////////
1261 tk 493
// This task is called periodically each mS to handle sequencer requests
494
/////////////////////////////////////////////////////////////////////////////
495
static void TASK_Period_1mS(void *pvParameters)
496
{
497
  portTickType xLastExecutionTime;
498
 
499
  // Initialise the xLastExecutionTime variable on task entry
500
  xLastExecutionTime = xTaskGetTickCount();
501
 
502
  while( 1 ) {
503
    vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
504
 
1297 tk 505
    // skip delay gap if we had to wait for more than 5 ticks to avoid 
506
    // unnecessary repeats until xLastExecutionTime reached xTaskGetTickCount() again
507
    portTickType xCurrentTickCount = xTaskGetTickCount();
508
    if( xLastExecutionTime < (xCurrentTickCount-5) )
509
      xLastExecutionTime = xCurrentTickCount;
510
 
1610 tk 511
 
1261 tk 512
    // execute sequencer handler
513
    MUTEX_SDCARD_TAKE;
514
    SEQ_Handler();
1260 tk 515
    MUTEX_SDCARD_GIVE;
1261 tk 516
 
517
    // send timestamped MIDI events
518
    MUTEX_MIDIOUT_TAKE;
519
    SEQ_MIDI_OUT_Handler();
520
    MUTEX_MIDIOUT_GIVE;
1292 tk 521
 
522
    // Scan Matrix button handler
523
    MIDIO_MATRIX_ButtonHandler();
1441 tk 524
 
525
    // scan AINSER pins
526
    AINSER_Handler(APP_AINSER_NotifyChange);
1260 tk 527
  }
528
}
529
 
530
 
531
/////////////////////////////////////////////////////////////////////////////
1261 tk 532
// Installed via MIOS32_MIDI_DirectRxCallback_Init
533
/////////////////////////////////////////////////////////////////////////////
534
static s32 NOTIFY_MIDI_Rx(mios32_midi_port_t port, u8 midi_byte)
535
{
1299 tk 536
  // filter MIDI In port which controls the MIDI clock
1492 tk 537
  if( MIDI_ROUTER_MIDIClockInGet(port) == 1 )
1299 tk 538
    SEQ_BPM_NotifyMIDIRx(midi_byte);
1261 tk 539
 
540
  return 0; // no error, no filtering
541
}
1297 tk 542
 
1299 tk 543
/////////////////////////////////////////////////////////////////////////////
544
// Installed via MIOS32_MIDI_DirectTxCallback_Init
545
/////////////////////////////////////////////////////////////////////////////
546
static s32 NOTIFY_MIDI_Tx(mios32_midi_port_t port, mios32_midi_package_t package)
547
{
1492 tk 548
  return MIDI_PORT_NotifyMIDITx(port, package);
1299 tk 549
}
1297 tk 550
 
551
/////////////////////////////////////////////////////////////////////////////
1299 tk 552
// Installed via MIOS32_MIDI_TimeoutCallback_Init
553
/////////////////////////////////////////////////////////////////////////////
554
static s32 NOTIFY_MIDI_TimeOut(mios32_midi_port_t port)
555
{  
556
  // forward to SysEx parser
557
  MIDIO_SYSEX_TimeOut(port);
558
 
559
  // print message on screen
560
  SCS_Msg(SCS_MSG_L, 2000, "MIDI Protocol", "TIMEOUT !!!");
561
 
562
  return 0;
563
}
564
 
565
 
566
/////////////////////////////////////////////////////////////////////////////
1297 tk 567
// MSD access functions
568
/////////////////////////////////////////////////////////////////////////////
569
s32 TASK_MSD_EnableSet(u8 enable)
570
{
571
  MIOS32_IRQ_Disable();
572
  if( msd_state == MSD_DISABLED && enable ) {
573
    msd_state = MSD_INIT;
574
  } else if( msd_state == MSD_READY && !enable )
575
    msd_state = MSD_SHUTDOWN;
576
  MIOS32_IRQ_Enable();
577
 
578
  return 0; // no error
579
}
580
 
581
s32 TASK_MSD_EnableGet()
582
{
583
  return (msd_state == MSD_READY) ? 1 : 0;
584
}
585
 
586
s32 TASK_MSD_FlagStrGet(char str[5])
587
{
588
  str[0] = MSD_CheckAvailable() ? 'U' : '-';
589
  str[1] = MSD_LUN_AvailableGet(0) ? 'M' : '-';
590
  str[2] = MSD_RdLEDGet(250) ? 'R' : '-';
591
  str[3] = MSD_WrLEDGet(250) ? 'W' : '-';
592
  str[4] = 0;
593
 
594
  return 0; // no error
595
}
1610 tk 596
 
597
/////////////////////////////////////////////////////////////////////////////
598
// functions to access MIDI IN/Out Mutex
599
// see also mios32_config.h
600
/////////////////////////////////////////////////////////////////////////////
601
void APP_MUTEX_MIDIOUT_Take(void) { MUTEX_MIDIOUT_TAKE; }
602
void APP_MUTEX_MIDIOUT_Give(void) { MUTEX_MIDIOUT_GIVE; }
603
void APP_MUTEX_MIDIIN_Take(void) { MUTEX_MIDIIN_TAKE; }
604
void APP_MUTEX_MIDIIN_Give(void) { MUTEX_MIDIIN_GIVE; }