# modules/msd/LPC17xx/msd.c File Reference

`#include <mios32.h>`
`#include <msd.h>`
`#include <string.h>`
`#include <usbapi.h>`
`#include "msc_bot.h"`
`#include "msc_scsi.h"`
`#include "blockdev.h"`

#define | MAX_PACKET_SIZE 64
#define | LE_WORD(x) ((x)&0xFF),((x)>>8)
#define | BUFFER_SIZE 75
s32 | MSD_Init (u32 mode)
s32 | MSD_Periodic_mS (void)
s32 | MSD_CheckAvailable (void)
s32 | MSD_LUN_AvailableSet (u8 lun, u8 available)
s32 | MSD_LUN_AvailableGet (u8 lun)
s32 | MSD_RdLEDGet (u16 lag_ms)
s32 | MSD_WrLEDGet (u16 lag_ms)

## Define Documentation

#define BUFFER_SIZE 75

#define LE_WORD | ( | x |  | ) | ((x)&0xFF),((x)>>8)

#define MAX_PACKET_SIZE 64

MSD Driver for MIOS32 running on a LPC17xx derivative Based on Code from Bertrik Sikken (bertrik@sikken.nl)

## Function Documentation

s32 MSD_CheckAvailable | ( | void |  | ) |

This function returns the connection status of the USB MIDI interface

Returns:
  1: interface available
  0: interface not available

s32 MSD_Init | ( | u32 | mode | ) |

Initializes the USB Device Driver for a Mass Storage Device

Should be called during runtime once a SD Card has been connected.
It is possible to switch back to the original device driver provided by MIOS32 (e.g. MIOS32_USB_MIDI) by calling MIOS32_USB_Init(1)

Parameters:

  `[in]` | mode | currently only mode 0 supported

Returns:
  < 0 if initialisation failed

s32 MSD_LUN_AvailableGet | ( | u8 | lun | ) |

Returns:
  1 if device is mounted by host
  0 if device is not mounted by host

s32 MSD_LUN_AvailableSet | ( | u8 | lun,
|  | u8 | available |
| ) |  |  |

The logical unit is available whenever MSD_Init() is called, or the USB cable has been reconnected.

It will be disabled when the host unmounts the file system (like if the SD Card would be removed.

When this happens, the application can either call MIOS32_USB_Init(1) again, e.g. to switch to USB MIDI, or it can make the LUN available again by calling MSD_LUN_AvailableSet(0, 1)

Parameters:

  `[in]` | lun | Logical Unit number (0)
  `[in]` | available | 0 or 1

Returns:
  < 0 on errors

s32 MSD_Periodic_mS | ( | void |  | ) |

Should be called periodically each millisecond so long this driver is active (and only then!) to handle USBtransfers.

Take care that no other task accesses SD Card while this function is processed!

Ensure that this function isn't called when a MIOS32 USB driver like MIOS32_USB_MIDI is running!

Returns:
  < 0 on errors

s32 MSD_RdLEDGet | ( | u16 | lag_ms | ) |

Returns status of "Read LED"

Parameters:

  `[in]` | lag_ms | The "lag" of the LED (e.g. 250 for 250 mS)

Returns:
  1: a read operation has happened in the last x mS (x == time defined by "lag")
  0: no read operation has happened in the last x mS (x == time defined by "lag")

s32 MSD_WrLEDGet | ( | u16 | lag_ms | ) |

Returns status of "Write LED"

Parameters:

  `[in]` | lag_ms | The "lag" of the LED (e.g. 250 for 250 mS)

Returns:
  1: a write operation has happened in the last x mS (x == time defined by "lag")
  0: no write operation has happened in the last x mS (x == time defined by "lag")