This program displays heart rate and time between heart beats on LCD, prints it to a USB serial port, print it to a bluetooth serial port and store it on a USB mass storage device. The program has two interrupt routines: 1.Every 1ms a counter is increased with one, 2. On every heart beat the counter is value copied. In the main loop the beats per minute are calculated. Ext.Modules:- Polar RMCM-01 heart rate module connected to pin8. - 2x16 LCD - a RF-BT0417CB bluetooth serial device connected to p27 and p28 - an USB mass storage device
MSCFileSystem.cpp@2:e660e68a91fa, 2011-01-04 (annotated)
- Committer:
- jrsikken
- Date:
- Tue Jan 04 21:33:59 2011 +0000
- Revision:
- 2:e660e68a91fa
- Parent:
- 1:8b001f936bb0
Now the heart rate is also send over a serial port to a bluetooth device.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jrsikken | 1:8b001f936bb0 | 1 | /* USB Mass Storage device file system |
jrsikken | 1:8b001f936bb0 | 2 | * Copyrigh (c) 2010, Igor Skochinsky |
jrsikken | 1:8b001f936bb0 | 3 | * based on SDFileStorage |
jrsikken | 1:8b001f936bb0 | 4 | * Copyright (c) 2008-2009, sford |
jrsikken | 1:8b001f936bb0 | 5 | */ |
jrsikken | 1:8b001f936bb0 | 6 | |
jrsikken | 1:8b001f936bb0 | 7 | /* Introduction |
jrsikken | 1:8b001f936bb0 | 8 | * ------------ |
jrsikken | 1:8b001f936bb0 | 9 | * TODO: write one |
jrsikken | 1:8b001f936bb0 | 10 | * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library |
jrsikken | 1:8b001f936bb0 | 11 | */ |
jrsikken | 1:8b001f936bb0 | 12 | |
jrsikken | 1:8b001f936bb0 | 13 | #include "MSCFileSystem.h" |
jrsikken | 1:8b001f936bb0 | 14 | #include "usbhost_inc.h" |
jrsikken | 1:8b001f936bb0 | 15 | |
jrsikken | 1:8b001f936bb0 | 16 | MSCFileSystem::MSCFileSystem(const char* name) : |
jrsikken | 1:8b001f936bb0 | 17 | FATFileSystem(name) |
jrsikken | 1:8b001f936bb0 | 18 | { |
jrsikken | 1:8b001f936bb0 | 19 | } |
jrsikken | 1:8b001f936bb0 | 20 | |
jrsikken | 1:8b001f936bb0 | 21 | void print_inquiry(USB_INT08U *inqReply) |
jrsikken | 1:8b001f936bb0 | 22 | { |
jrsikken | 1:8b001f936bb0 | 23 | // see USB Mass Storage Class – UFI Command Specification, |
jrsikken | 1:8b001f936bb0 | 24 | // 4.2 INQUIRY Command |
jrsikken | 1:8b001f936bb0 | 25 | printf("Inquiry reply:\n"); |
jrsikken | 1:8b001f936bb0 | 26 | uint8_t tmp = inqReply[0]&0x1F; |
jrsikken | 1:8b001f936bb0 | 27 | printf("Peripheral device type: %02Xh\n", tmp); |
jrsikken | 1:8b001f936bb0 | 28 | if ( tmp == 0 ) |
jrsikken | 1:8b001f936bb0 | 29 | printf("\t- Direct access (floppy)\n"); |
jrsikken | 1:8b001f936bb0 | 30 | else if ( tmp == 0x1F ) |
jrsikken | 1:8b001f936bb0 | 31 | printf("\t- none (no FDD connected)\n"); |
jrsikken | 1:8b001f936bb0 | 32 | else |
jrsikken | 1:8b001f936bb0 | 33 | printf("\t- unknown type\n"); |
jrsikken | 1:8b001f936bb0 | 34 | tmp = inqReply[1] >> 7; |
jrsikken | 1:8b001f936bb0 | 35 | printf("Removable Media Bit: %d\n", tmp); |
jrsikken | 1:8b001f936bb0 | 36 | tmp = inqReply[2] & 3; |
jrsikken | 1:8b001f936bb0 | 37 | printf("ANSI Version: %02Xh\n", tmp); |
jrsikken | 1:8b001f936bb0 | 38 | if ( tmp != 0 ) |
jrsikken | 1:8b001f936bb0 | 39 | printf("\t- warning! must be 0\n"); |
jrsikken | 1:8b001f936bb0 | 40 | tmp = (inqReply[2]>>3) & 3; |
jrsikken | 1:8b001f936bb0 | 41 | printf("ECMA Version: %02Xh\n", tmp); |
jrsikken | 1:8b001f936bb0 | 42 | if ( tmp != 0 ) |
jrsikken | 1:8b001f936bb0 | 43 | printf("\t- warning! should be 0\n"); |
jrsikken | 1:8b001f936bb0 | 44 | tmp = inqReply[2]>>6; |
jrsikken | 1:8b001f936bb0 | 45 | printf("ISO Version: %02Xh\n", tmp); |
jrsikken | 1:8b001f936bb0 | 46 | if ( tmp != 0 ) |
jrsikken | 1:8b001f936bb0 | 47 | printf("\t- warning! should be 0\n"); |
jrsikken | 1:8b001f936bb0 | 48 | tmp = inqReply[3] & 0xF; |
jrsikken | 1:8b001f936bb0 | 49 | printf("Response Data Format: %02Xh\n", tmp); |
jrsikken | 1:8b001f936bb0 | 50 | if ( tmp != 1 ) |
jrsikken | 1:8b001f936bb0 | 51 | printf("\t- warning! should be 1\n"); |
jrsikken | 1:8b001f936bb0 | 52 | tmp = inqReply[4]; |
jrsikken | 1:8b001f936bb0 | 53 | printf("Additional length: %02Xh\n", tmp); |
jrsikken | 1:8b001f936bb0 | 54 | if ( tmp != 0x1F ) |
jrsikken | 1:8b001f936bb0 | 55 | printf("\t- warning! should be 1Fh\n"); |
jrsikken | 1:8b001f936bb0 | 56 | printf("Vendor Information: '%.8s'\n", &inqReply[8]); |
jrsikken | 1:8b001f936bb0 | 57 | printf("Product Identification: '%.16s'\n", &inqReply[16]); |
jrsikken | 1:8b001f936bb0 | 58 | printf("Product Revision: '%.4s'\n", &inqReply[32]); |
jrsikken | 1:8b001f936bb0 | 59 | } |
jrsikken | 1:8b001f936bb0 | 60 | |
jrsikken | 1:8b001f936bb0 | 61 | int MSCFileSystem::initialise_msc() |
jrsikken | 1:8b001f936bb0 | 62 | { |
jrsikken | 1:8b001f936bb0 | 63 | USB_INT32S rc; |
jrsikken | 1:8b001f936bb0 | 64 | USB_INT08U inquiryResult[INQUIRY_LENGTH]; |
jrsikken | 1:8b001f936bb0 | 65 | |
jrsikken | 1:8b001f936bb0 | 66 | //print_clock(); |
jrsikken | 1:8b001f936bb0 | 67 | Host_Init(); /* Initialize the host controller */ |
jrsikken | 1:8b001f936bb0 | 68 | rc = Host_EnumDev(); /* Enumerate the device connected */ |
jrsikken | 1:8b001f936bb0 | 69 | if (rc != OK) |
jrsikken | 1:8b001f936bb0 | 70 | { |
jrsikken | 1:8b001f936bb0 | 71 | fprintf(stderr, "Could not enumerate device: %d\n", rc); |
jrsikken | 1:8b001f936bb0 | 72 | return rc; |
jrsikken | 1:8b001f936bb0 | 73 | } |
jrsikken | 1:8b001f936bb0 | 74 | |
jrsikken | 1:8b001f936bb0 | 75 | |
jrsikken | 1:8b001f936bb0 | 76 | /* Initialize the mass storage and scsi interfaces */ |
jrsikken | 1:8b001f936bb0 | 77 | rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); |
jrsikken | 1:8b001f936bb0 | 78 | if (rc != OK) |
jrsikken | 1:8b001f936bb0 | 79 | { |
jrsikken | 1:8b001f936bb0 | 80 | fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); |
jrsikken | 1:8b001f936bb0 | 81 | return rc; |
jrsikken | 1:8b001f936bb0 | 82 | } |
jrsikken | 1:8b001f936bb0 | 83 | printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); |
jrsikken | 1:8b001f936bb0 | 84 | print_inquiry(inquiryResult); |
jrsikken | 1:8b001f936bb0 | 85 | // FATFileSystem supports only 512-byte blocks |
jrsikken | 1:8b001f936bb0 | 86 | return _blkSize == 512 ? OK : 1; |
jrsikken | 1:8b001f936bb0 | 87 | } |
jrsikken | 1:8b001f936bb0 | 88 | |
jrsikken | 1:8b001f936bb0 | 89 | int MSCFileSystem::disk_initialize() |
jrsikken | 1:8b001f936bb0 | 90 | { |
jrsikken | 1:8b001f936bb0 | 91 | if ( initialise_msc() != OK ) |
jrsikken | 1:8b001f936bb0 | 92 | return 1; |
jrsikken | 1:8b001f936bb0 | 93 | |
jrsikken | 1:8b001f936bb0 | 94 | return 0; |
jrsikken | 1:8b001f936bb0 | 95 | } |
jrsikken | 1:8b001f936bb0 | 96 | |
jrsikken | 1:8b001f936bb0 | 97 | int MSCFileSystem::disk_write(const char *buffer, int block_number) |
jrsikken | 1:8b001f936bb0 | 98 | { |
jrsikken | 1:8b001f936bb0 | 99 | if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) ) |
jrsikken | 1:8b001f936bb0 | 100 | return 0; |
jrsikken | 1:8b001f936bb0 | 101 | return 1; |
jrsikken | 1:8b001f936bb0 | 102 | } |
jrsikken | 1:8b001f936bb0 | 103 | |
jrsikken | 1:8b001f936bb0 | 104 | int MSCFileSystem::disk_read(char *buffer, int block_number) |
jrsikken | 1:8b001f936bb0 | 105 | { |
jrsikken | 1:8b001f936bb0 | 106 | if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) ) |
jrsikken | 1:8b001f936bb0 | 107 | return 0; |
jrsikken | 1:8b001f936bb0 | 108 | return 1; |
jrsikken | 1:8b001f936bb0 | 109 | } |
jrsikken | 1:8b001f936bb0 | 110 | |
jrsikken | 1:8b001f936bb0 | 111 | int MSCFileSystem::disk_status() { return 0; } |
jrsikken | 1:8b001f936bb0 | 112 | int MSCFileSystem::disk_sync() { return 0; } |
jrsikken | 1:8b001f936bb0 | 113 | int MSCFileSystem::disk_sectors() { return _numBlks; } |