Record audio data to a .wav file, complete with header, using the TLV320 CODEC and I2S port

Dependencies:   mbed

Committer:
d_worrall
Date:
Fri Aug 05 15:00:51 2011 +0000
Revision:
0:e7efc8468066
version 2.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d_worrall 0:e7efc8468066 1 /* USB Mass Storage device file system
d_worrall 0:e7efc8468066 2 * Copyrigh (c) 2010, Igor Skochinsky
d_worrall 0:e7efc8468066 3 * based on SDFileStorage
d_worrall 0:e7efc8468066 4 * Copyright (c) 2008-2009, sford
d_worrall 0:e7efc8468066 5 */
d_worrall 0:e7efc8468066 6
d_worrall 0:e7efc8468066 7 /* Introduction
d_worrall 0:e7efc8468066 8 * ------------
d_worrall 0:e7efc8468066 9 * TODO: write one
d_worrall 0:e7efc8468066 10 * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library
d_worrall 0:e7efc8468066 11 */
d_worrall 0:e7efc8468066 12
d_worrall 0:e7efc8468066 13 #include "MSCFileSystem.h"
d_worrall 0:e7efc8468066 14 #include "usbhost_inc.h"
d_worrall 0:e7efc8468066 15
d_worrall 0:e7efc8468066 16 MSCFileSystem::MSCFileSystem(const char* name) :
d_worrall 0:e7efc8468066 17 FATFileSystem(name)
d_worrall 0:e7efc8468066 18 {
d_worrall 0:e7efc8468066 19 }
d_worrall 0:e7efc8468066 20
d_worrall 0:e7efc8468066 21 void print_inquiry(USB_INT08U *inqReply)
d_worrall 0:e7efc8468066 22 {
d_worrall 0:e7efc8468066 23 // see USB Mass Storage Class � UFI Command Specification,
d_worrall 0:e7efc8468066 24 // 4.2 INQUIRY Command
d_worrall 0:e7efc8468066 25 printf("Inquiry reply:\n\r");
d_worrall 0:e7efc8468066 26 uint8_t tmp = inqReply[0]&0x1F;
d_worrall 0:e7efc8468066 27 printf("Peripheral device type: %02Xh\n\r", tmp);
d_worrall 0:e7efc8468066 28 if ( tmp == 0 )
d_worrall 0:e7efc8468066 29 printf("\t- Direct access (floppy)\n\r");
d_worrall 0:e7efc8468066 30 else if ( tmp == 0x1F )
d_worrall 0:e7efc8468066 31 printf("\t- none (no FDD connected)\n\r");
d_worrall 0:e7efc8468066 32 else
d_worrall 0:e7efc8468066 33 printf("\t- unknown type\n\r");
d_worrall 0:e7efc8468066 34 tmp = inqReply[1] >> 7;
d_worrall 0:e7efc8468066 35 printf("Removable Media Bit: %d\n\r", tmp);
d_worrall 0:e7efc8468066 36 tmp = inqReply[2] & 3;
d_worrall 0:e7efc8468066 37 printf("ANSI Version: %02Xh\n\r", tmp);
d_worrall 0:e7efc8468066 38 if ( tmp != 0 )
d_worrall 0:e7efc8468066 39 printf("\t- warning! must be 0\n\r");
d_worrall 0:e7efc8468066 40 tmp = (inqReply[2]>>3) & 3;
d_worrall 0:e7efc8468066 41 printf("ECMA Version: %02Xh\n\r", tmp);
d_worrall 0:e7efc8468066 42 if ( tmp != 0 )
d_worrall 0:e7efc8468066 43 printf("\t- warning! should be 0\n\r");
d_worrall 0:e7efc8468066 44 tmp = inqReply[2]>>6;
d_worrall 0:e7efc8468066 45 printf("ISO Version: %02Xh\n\r", tmp);
d_worrall 0:e7efc8468066 46 if ( tmp != 0 )
d_worrall 0:e7efc8468066 47 printf("\t- warning! should be 0\n\r");
d_worrall 0:e7efc8468066 48 tmp = inqReply[3] & 0xF;
d_worrall 0:e7efc8468066 49 printf("Response Data Format: %02Xh\n\r", tmp);
d_worrall 0:e7efc8468066 50 if ( tmp != 1 )
d_worrall 0:e7efc8468066 51 printf("\t- warning! should be 1\n\r");
d_worrall 0:e7efc8468066 52 tmp = inqReply[4];
d_worrall 0:e7efc8468066 53 printf("Additional length: %02Xh\n\r", tmp);
d_worrall 0:e7efc8468066 54 if ( tmp != 0x1F )
d_worrall 0:e7efc8468066 55 printf("\t- warning! should be 1Fh\n\r");
d_worrall 0:e7efc8468066 56 printf("Vendor Information: '%.8s'\n\r", &inqReply[8]);
d_worrall 0:e7efc8468066 57 printf("Product Identification: '%.16s'\n\r", &inqReply[16]);
d_worrall 0:e7efc8468066 58 printf("Product Revision: '%.4s'\n\r", &inqReply[32]);
d_worrall 0:e7efc8468066 59 }
d_worrall 0:e7efc8468066 60
d_worrall 0:e7efc8468066 61 int MSCFileSystem::initialise_msc()
d_worrall 0:e7efc8468066 62 {
d_worrall 0:e7efc8468066 63 USB_INT32S rc;
d_worrall 0:e7efc8468066 64 USB_INT08U inquiryResult[INQUIRY_LENGTH];
d_worrall 0:e7efc8468066 65
d_worrall 0:e7efc8468066 66 //print_clock();
d_worrall 0:e7efc8468066 67 Host_Init(); /* Initialize the host controller */
d_worrall 0:e7efc8468066 68 rc = Host_EnumDev(); /* Enumerate the device connected */
d_worrall 0:e7efc8468066 69 if (rc != OK)
d_worrall 0:e7efc8468066 70 {
d_worrall 0:e7efc8468066 71 fprintf(stderr, "Could not enumerate device: %d\n\r", rc);
d_worrall 0:e7efc8468066 72 return rc;
d_worrall 0:e7efc8468066 73 }
d_worrall 0:e7efc8468066 74
d_worrall 0:e7efc8468066 75
d_worrall 0:e7efc8468066 76 /* Initialize the mass storage and scsi interfaces */
d_worrall 0:e7efc8468066 77 rc = MS_Init( &_blkSize, &_numBlks, inquiryResult );
d_worrall 0:e7efc8468066 78 if (rc != OK)
d_worrall 0:e7efc8468066 79 {
d_worrall 0:e7efc8468066 80 fprintf(stderr, "Could not initialize mass storage interface: %d\n\r", rc);
d_worrall 0:e7efc8468066 81 return rc;
d_worrall 0:e7efc8468066 82 }
d_worrall 0:e7efc8468066 83 printf("Successfully initialized mass storage interface; %d blocks of size %d\n\r", _numBlks, _blkSize);
d_worrall 0:e7efc8468066 84 print_inquiry(inquiryResult);
d_worrall 0:e7efc8468066 85 // FATFileSystem supports only 512-byte blocks
d_worrall 0:e7efc8468066 86 return _blkSize == 512 ? OK : 1;
d_worrall 0:e7efc8468066 87 }
d_worrall 0:e7efc8468066 88
d_worrall 0:e7efc8468066 89 int MSCFileSystem::disk_initialize()
d_worrall 0:e7efc8468066 90 {
d_worrall 0:e7efc8468066 91 if ( initialise_msc() != OK )
d_worrall 0:e7efc8468066 92 return 1;
d_worrall 0:e7efc8468066 93
d_worrall 0:e7efc8468066 94 return 0;
d_worrall 0:e7efc8468066 95 }
d_worrall 0:e7efc8468066 96
d_worrall 0:e7efc8468066 97 int MSCFileSystem::disk_write(const char *buffer, int block_number)
d_worrall 0:e7efc8468066 98 {
d_worrall 0:e7efc8468066 99 if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) )
d_worrall 0:e7efc8468066 100 return 0;
d_worrall 0:e7efc8468066 101 return 1;
d_worrall 0:e7efc8468066 102 }
d_worrall 0:e7efc8468066 103
d_worrall 0:e7efc8468066 104 int MSCFileSystem::disk_read(char *buffer, int block_number)
d_worrall 0:e7efc8468066 105 {
d_worrall 0:e7efc8468066 106 if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) )
d_worrall 0:e7efc8468066 107 return 0;
d_worrall 0:e7efc8468066 108 return 1;
d_worrall 0:e7efc8468066 109 }
d_worrall 0:e7efc8468066 110
d_worrall 0:e7efc8468066 111 int MSCFileSystem::disk_status() { return 0; }
d_worrall 0:e7efc8468066 112 int MSCFileSystem::disk_sync() { return 0; }
d_worrall 0:e7efc8468066 113 int MSCFileSystem::disk_sectors() { return _numBlks; }