Proyecto realizado para controlar el desplazamiento de un cuadro como obra de arte
Dependencies: DS1307 FPointer TextLCD USBHost keypad mbed
Fork of MSCUsbHost_FULL by
Revision 1:4daed536a970, committed 2013-09-17
- Comitter:
- sherckuith
- Date:
- Tue Sep 17 01:37:10 2013 +0000
- Parent:
- 0:144fed3d9420
- Commit message:
- Publicacion de trabajo hecho para Patricio Barberan
Changed in this revision
diff -r 144fed3d9420 -r 4daed536a970 DS1307.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DS1307.lib Tue Sep 17 01:37:10 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sherckuith/code/DS1307/#ab60603c51d1
diff -r 144fed3d9420 -r 4daed536a970 FATFileSystem.lib --- a/FATFileSystem.lib Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
diff -r 144fed3d9420 -r 4daed536a970 FPointer.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FPointer.lib Tue Sep 17 01:37:10 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/FPointer/#56e309e76c19
diff -r 144fed3d9420 -r 4daed536a970 MSCFileSystem.cpp --- a/MSCFileSystem.cpp Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* USB Mass Storage device file system - * Copyrigh (c) 2010, Igor Skochinsky - * based on SDFileStorage - * Copyright (c) 2008-2009, sford - */ - -/* Introduction - * ------------ - * TODO: write one - * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library - */ - -#include "MSCFileSystem.h" -#include "usbhost_inc.h" - -MSCFileSystem::MSCFileSystem(const char* name) : - FATFileSystem(name) -{ -} - -void print_inquiry(USB_INT08U *inqReply) -{ - // see USB Mass Storage Class – UFI Command Specification, - // 4.2 INQUIRY Command - printf("Inquiry reply:\n"); - uint8_t tmp = inqReply[0]&0x1F; - printf("Peripheral device type: %02Xh\n", tmp); - if ( tmp == 0 ) - printf("\t- Direct access (floppy)\n"); - else if ( tmp == 0x1F ) - printf("\t- none (no FDD connected)\n"); - else - printf("\t- unknown type\n"); - tmp = inqReply[1] >> 7; - printf("Removable Media Bit: %d\n", tmp); - tmp = inqReply[2] & 3; - printf("ANSI Version: %02Xh\n", tmp); - if ( tmp != 0 ) - printf("\t- warning! must be 0\n"); - tmp = (inqReply[2]>>3) & 3; - printf("ECMA Version: %02Xh\n", tmp); - if ( tmp != 0 ) - printf("\t- warning! should be 0\n"); - tmp = inqReply[2]>>6; - printf("ISO Version: %02Xh\n", tmp); - if ( tmp != 0 ) - printf("\t- warning! should be 0\n"); - tmp = inqReply[3] & 0xF; - printf("Response Data Format: %02Xh\n", tmp); - if ( tmp != 1 ) - printf("\t- warning! should be 1\n"); - tmp = inqReply[4]; - printf("Additional length: %02Xh\n", tmp); - if ( tmp != 0x1F ) - printf("\t- warning! should be 1Fh\n"); - printf("Vendor Information: '%.8s'\n", &inqReply[8]); - printf("Product Identification: '%.16s'\n", &inqReply[16]); - printf("Product Revision: '%.4s'\n", &inqReply[32]); -} - -int MSCFileSystem::initialise_msc() -{ - USB_INT32S rc; - USB_INT08U inquiryResult[INQUIRY_LENGTH]; - - //print_clock(); - Host_Init(); /* Initialize the host controller */ - rc = Host_EnumDev(); /* Enumerate the device connected */ - if (rc != OK) - { - fprintf(stderr, "Could not enumerate device: %d\n", rc); - return rc; - } - - - /* Initialize the mass storage and scsi interfaces */ - rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); - if (rc != OK) - { - fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); - return rc; - } - printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); - print_inquiry(inquiryResult); - // FATFileSystem supports only 512-byte blocks - return _blkSize == 512 ? OK : 1; -} - -int MSCFileSystem::disk_initialize() -{ - if ( initialise_msc() != OK ) - return 1; - - return 0; -} - -int MSCFileSystem::disk_write(const char *buffer, int block_number) -{ - if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) ) - return 0; - return 1; -} - -int MSCFileSystem::disk_read(char *buffer, int block_number) -{ - if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) ) - return 0; - return 1; -} - -int MSCFileSystem::disk_status() { return 0; } -int MSCFileSystem::disk_sync() { return 0; } -int MSCFileSystem::disk_sectors() { return _numBlks; }
diff -r 144fed3d9420 -r 4daed536a970 MSCFileSystem.h --- a/MSCFileSystem.h Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* USB Mass Storage device file system - * Copyrigh (c) 2010, Igor Skochinsky - * based on SDFileStorage - * Copyright (c) 2008-2009, sford - */ - -#ifndef MSCFILESYSTEM_H -#define MSCFILESYSTEM_H - -#include "mbed.h" -#include "FATFileSystem.h" - -/* Class: MSCFileSystem - * Access the filesystem on an attached USB mass storage device (e.g. a memory stick) - * - * Example: - * > MSCFileSystem msc("msc"); - * > - * > int main() { - * > FILE *fp = fopen("/msc/myfile.txt", "w"); - * > fprintf(fp, "Hello World!\n"); - * > fclose(fp); - * > } - */ -class MSCFileSystem : public FATFileSystem { -public: - - /* Constructor: MSCFileSystem - * Create the File System for accessing a USB mass storage device - * - * Parameters: - * name - The name used to access the filesystem - */ - MSCFileSystem(const char* name); - virtual int disk_initialize(); - virtual int disk_write(const char *buffer, int block_number); - virtual int disk_read(char *buffer, int block_number); - virtual int disk_status(); - virtual int disk_sync(); - virtual int disk_sectors(); - -protected: - - int initialise_msc(); - uint32_t _numBlks; - uint32_t _blkSize; -}; - -#endif
diff -r 144fed3d9420 -r 4daed536a970 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Sep 17 01:37:10 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 144fed3d9420 -r 4daed536a970 USBHost.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHost.lib Tue Sep 17 01:37:10 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sherckuith/code/USBHost/#4486f315fc09
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_cpu.h --- a/USBHostLite/usbhost_cpu.h Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_cpu.h -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -#ifndef USBHOST_CPU_H -#define USBHOST_CPU_H - -/* -************************************************************************************************************** -* TYPE DEFINITIONS OF DATA TYPES -************************************************************************************************************** -*/ - -typedef unsigned int USB_INT32U; -typedef signed int USB_INT32S; -typedef unsigned short USB_INT16U; -typedef signed short USB_INT16S; -typedef unsigned char USB_INT08U; -typedef signed char USB_INT08S; - -#endif
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_err.h --- a/USBHostLite/usbhost_err.h Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_err.h -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -#ifndef USBHOST_ERR_H -#define USBHOST_ERR_H - - -/* -************************************************************************************************************** -* GENERAL DEFINITIONS -************************************************************************************************************** -*/ - -#define OK 0 -#define MATCH_FOUND 0 - -/* -************************************************************************************************************** -* HOST CONTROLLER SPECIFIC ERROR CODES -************************************************************************************************************** -*/ - -#define ERR_TD_FAIL -1 - -/* -************************************************************************************************************** -* MASS STORAGE SPECIFIC ERROR CODES -************************************************************************************************************** -*/ - -#define ERR_MS_CMD_FAILED -10 -#define ERR_BAD_CONFIGURATION -11 -#define ERR_NO_MS_INTERFACE -12 - -/* -************************************************************************************************************** -* FAT SPECIFIC ERROR CODES -************************************************************************************************************** -*/ - -#define MATCH_NOT_FOUND -20 -#define ERR_FAT_NOT_SUPPORTED -21 -#define ERR_OPEN_LIMIT_REACHED -22 -#define ERR_INVALID_BOOT_SIG -23 -#define ERR_INVALID_BOOT_SEC -24 -#define ERR_ROOT_DIR_FULL -25 - -#endif
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_inc.h --- a/USBHostLite/usbhost_inc.h Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_inc.h -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -#ifndef USBHOST_INC_H -#define USBHOST_INC_H - -/* -************************************************************************************************************** -* INCLUDE HEADER FILES -************************************************************************************************************** -*/ - -#include "usbhost_cpu.h" -#include "usbhost_err.h" -#include "usbhost_lpc17xx.h" -#include "usbhost_ms.h" -#include "mbed.h" - - -#ifdef TARGET_LPC2368 -#error "There is no USB host on the LPC2368!" -#endif - -#endif
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_lpc17xx.c --- a/USBHostLite/usbhost_lpc17xx.c Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,820 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_lpc17xx.c -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -/* -************************************************************************************************************** -* INCLUDE HEADER FILES -************************************************************************************************************** -*/ - -#include "usbhost_lpc17xx.h" - -/* -************************************************************************************************************** -* GLOBAL VARIABLES -************************************************************************************************************** -*/ -int gUSBConnected; - -volatile USB_INT32U HOST_RhscIntr = 0; /* Root Hub Status Change interrupt */ -volatile USB_INT32U HOST_WdhIntr = 0; /* Semaphore to wait until the TD is submitted */ -volatile USB_INT08U HOST_TDControlStatus = 0; -volatile HCED *EDCtrl; /* Control endpoint descriptor structure */ -volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */ -volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */ -volatile HCTD *TDHead; /* Head transfer descriptor structure */ -volatile HCTD *TDTail; /* Tail transfer descriptor structure */ -volatile HCCA *Hcca; /* Host Controller Communications Area structure */ - USB_INT16U *TDBufNonVol; /* Identical to TDBuffer just to reduce compiler warnings */ -volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */ - -// USB host structures -// AHB SRAM block 1 -#define HOSTBASEADDR 0x2007C000 -// reserve memory for the linker -static USB_INT08U HostBuf[0x200] __attribute__((at(HOSTBASEADDR))); -/* -************************************************************************************************************** -* DELAY IN MILLI SECONDS -* -* Description: This function provides a delay in milli seconds -* -* Arguments : delay The delay required -* -* Returns : None -* -************************************************************************************************************** -*/ - -void Host_DelayMS (USB_INT32U delay) -{ - volatile USB_INT32U i; - - - for (i = 0; i < delay; i++) { - Host_DelayUS(1000); - } -} - -/* -************************************************************************************************************** -* DELAY IN MICRO SECONDS -* -* Description: This function provides a delay in micro seconds -* -* Arguments : delay The delay required -* -* Returns : None -* -************************************************************************************************************** -*/ - -void Host_DelayUS (USB_INT32U delay) -{ - volatile USB_INT32U i; - - - for (i = 0; i < (4 * delay); i++) { /* This logic was tested. It gives app. 1 micro sec delay */ - ; - } -} - -// bits of the USB/OTG clock control register -#define HOST_CLK_EN (1<<0) -#define DEV_CLK_EN (1<<1) -#define PORTSEL_CLK_EN (1<<3) -#define AHB_CLK_EN (1<<4) - -// bits of the USB/OTG clock status register -#define HOST_CLK_ON (1<<0) -#define DEV_CLK_ON (1<<1) -#define PORTSEL_CLK_ON (1<<3) -#define AHB_CLK_ON (1<<4) - -// we need host clock, OTG/portsel clock and AHB clock -#define CLOCK_MASK (HOST_CLK_EN | PORTSEL_CLK_EN | AHB_CLK_EN) - -/* -************************************************************************************************************** -* INITIALIZE THE HOST CONTROLLER -* -* Description: This function initializes lpc17xx host controller -* -* Arguments : None -* -* Returns : -* -************************************************************************************************************** -*/ -void Host_Init (void) -{ - PRINT_Log("In Host_Init\n"); - NVIC_DisableIRQ(USB_IRQn); /* Disable the USB interrupt source */ - - // turn on power for USB - LPC_SC->PCONP |= (1UL<<31); - // Enable USB host clock, port selection and AHB clock - LPC_USB->USBClkCtrl |= CLOCK_MASK; - // Wait for clocks to become available - while ((LPC_USB->USBClkSt & CLOCK_MASK) != CLOCK_MASK) - ; - - // it seems the bits[0:1] mean the following - // 0: U1=device, U2=host - // 1: U1=host, U2=host - // 2: reserved - // 3: U1=host, U2=device - // NB: this register is only available if OTG clock (aka "port select") is enabled!! - // since we don't care about port 2, set just bit 0 to 1 (U1=host) - LPC_USB->OTGStCtrl |= 1; - - // now that we've configured the ports, we can turn off the portsel clock - LPC_USB->USBClkCtrl &= ~PORTSEL_CLK_EN; - - // power pins are not connected on mbed, so we can skip them - /* P1[18] = USB_UP_LED, 01 */ - /* P1[19] = /USB_PPWR, 10 */ - /* P1[22] = USB_PWRD, 10 */ - /* P1[27] = /USB_OVRCR, 10 */ - /*LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22)); - LPC_PINCON->PINSEL3 |= ((1<<4)|(2<<6) | (2<<12) | (2<<22)); // 0x00802080 - */ - - // configure USB D+/D- pins - /* P0[29] = USB_D+, 01 */ - /* P0[30] = USB_D-, 01 */ - LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28)); - LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000 - - PRINT_Log("Initializing Host Stack\n"); - - Hcca = (volatile HCCA *)(HostBuf+0x000); - TDHead = (volatile HCTD *)(HostBuf+0x100); - TDTail = (volatile HCTD *)(HostBuf+0x110); - EDCtrl = (volatile HCED *)(HostBuf+0x120); - EDBulkIn = (volatile HCED *)(HostBuf+0x130); - EDBulkOut = (volatile HCED *)(HostBuf+0x140); - TDBuffer = (volatile USB_INT08U *)(HostBuf+0x150); - - /* Initialize all the TDs, EDs and HCCA to 0 */ - Host_EDInit(EDCtrl); - Host_EDInit(EDBulkIn); - Host_EDInit(EDBulkOut); - Host_TDInit(TDHead); - Host_TDInit(TDTail); - Host_HCCAInit(Hcca); - - Host_DelayMS(50); /* Wait 50 ms before apply reset */ - LPC_USB->HcControl = 0; /* HARDWARE RESET */ - LPC_USB->HcControlHeadED = 0; /* Initialize Control list head to Zero */ - LPC_USB->HcBulkHeadED = 0; /* Initialize Bulk list head to Zero */ - - /* SOFTWARE RESET */ - LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR; - LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; /* Write Fm Interval and Largest Data Packet Counter */ - - /* Put HC in operational state */ - LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER; - LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; /* Set Global Power */ - - LPC_USB->HcHCCA = (USB_INT32U)Hcca; - LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; /* Clear Interrrupt Status */ - - - LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE | - OR_INTR_ENABLE_WDH | - OR_INTR_ENABLE_RHSC; - - NVIC_SetPriority(USB_IRQn, 0); /* highest priority */ - /* Enable the USB Interrupt */ - NVIC_EnableIRQ(USB_IRQn); - PRINT_Log("Host Initialized\n"); -} - -/* -************************************************************************************************************** -* INTERRUPT SERVICE ROUTINE -* -* Description: This function services the interrupt caused by host controller -* -* Arguments : None -* -* Returns : None -* -************************************************************************************************************** -*/ - -void USB_IRQHandler (void) __irq -{ - USB_INT32U int_status; - USB_INT32U ie_status; - - int_status = LPC_USB->HcInterruptStatus; /* Read Interrupt Status */ - ie_status = LPC_USB->HcInterruptEnable; /* Read Interrupt enable status */ - - if (!(int_status & ie_status)) { - return; - } else { - - int_status = int_status & ie_status; - if (int_status & OR_INTR_STATUS_RHSC) { /* Root hub status change interrupt */ - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC) { - if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE) { - /* - * When DRWE is on, Connect Status Change - * means a remote wakeup event. - */ - HOST_RhscIntr = 1;// JUST SOMETHING FOR A BREAKPOINT - } - else { - /* - * When DRWE is off, Connect Status Change - * is NOT a remote wakeup event - */ - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) { - if (!gUSBConnected) { - HOST_TDControlStatus = 0; - HOST_WdhIntr = 0; - HOST_RhscIntr = 1; - gUSBConnected = 1; - } - else - PRINT_Log("Spurious status change (connected)?\n"); - } else { - if (gUSBConnected) { - LPC_USB->HcInterruptEnable = 0; // why do we get multiple disc. rupts??? - HOST_RhscIntr = 0; - gUSBConnected = 0; - } - else - PRINT_Log("Spurious status change (disconnected)?\n"); - } - } - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC; - } - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC) { - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; - } - } - if (int_status & OR_INTR_STATUS_WDH) { /* Writeback Done Head interrupt */ - HOST_WdhIntr = 1; - HOST_TDControlStatus = (TDHead->Control >> 28) & 0xf; - } - LPC_USB->HcInterruptStatus = int_status; /* Clear interrupt status register */ - } - return; -} - -/* -************************************************************************************************************** -* PROCESS TRANSFER DESCRIPTOR -* -* Description: This function processes the transfer descriptor -* -* Arguments : ed Endpoint descriptor that contains this transfer descriptor -* token SETUP, IN, OUT -* buffer Current Buffer Pointer of the transfer descriptor -* buffer_len Length of the buffer -* -* Returns : OK if TD submission is successful -* ERROR if TD submission fails -* -************************************************************************************************************** -*/ - -USB_INT32S Host_ProcessTD (volatile HCED *ed, - volatile USB_INT32U token, - volatile USB_INT08U *buffer, - USB_INT32U buffer_len) -{ - volatile USB_INT32U td_toggle; - - - if (ed == EDCtrl) { - if (token == TD_SETUP) { - td_toggle = TD_TOGGLE_0; - } else { - td_toggle = TD_TOGGLE_1; - } - } else { - td_toggle = 0; - } - TDHead->Control = (TD_ROUNDING | - token | - TD_DELAY_INT(0) | - td_toggle | - TD_CC); - TDTail->Control = 0; - TDHead->CurrBufPtr = (USB_INT32U) buffer; - TDTail->CurrBufPtr = 0; - TDHead->Next = (USB_INT32U) TDTail; - TDTail->Next = 0; - TDHead->BufEnd = (USB_INT32U)(buffer + (buffer_len - 1)); - TDTail->BufEnd = 0; - - ed->HeadTd = (USB_INT32U)TDHead | ((ed->HeadTd) & 0x00000002); - ed->TailTd = (USB_INT32U)TDTail; - ed->Next = 0; - - if (ed == EDCtrl) { - LPC_USB->HcControlHeadED = (USB_INT32U)ed; - LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF; - LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE; - } else { - LPC_USB->HcBulkHeadED = (USB_INT32U)ed; - LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF; - LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; - } - - Host_WDHWait(); - -// if (!(TDHead->Control & 0xF0000000)) { - if (!HOST_TDControlStatus) { - return (OK); - } else { - return (ERR_TD_FAIL); - } -} - -/* -************************************************************************************************************** -* ENUMERATE THE DEVICE -* -* Description: This function is used to enumerate the device connected -* -* Arguments : None -* -* Returns : None -* -************************************************************************************************************** -*/ - -USB_INT32S Host_EnumDev (void) -{ - USB_INT32S rc; - - PRINT_Log("Connect a Mass Storage device\n"); - while (!HOST_RhscIntr) - __WFI(); - Host_DelayMS(100); /* USB 2.0 spec says atleast 50ms delay beore port reset */ - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset - while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS) - __WFI(); // Wait for port reset to complete... - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal - Host_DelayMS(200); /* Wait for 100 MS after port reset */ - - EDCtrl->Control = 8 << 16; /* Put max pkt size = 8 */ - /* Read first 8 bytes of device desc */ - rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8); - if (rc != OK) { - PRINT_Err(rc); - return (rc); - } - EDCtrl->Control = TDBuffer[7] << 16; /* Get max pkt size of endpoint 0 */ - rc = HOST_SET_ADDRESS(1); /* Set the device address to 1 */ - if (rc != OK) { - PRINT_Err(rc); - return (rc); - } - Host_DelayMS(2); - EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */ - /* Get the configuration descriptor */ - rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9); - if (rc != OK) { - PRINT_Err(rc); - return (rc); - } - /* Get the first configuration data */ - rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2])); - if (rc != OK) { - PRINT_Err(rc); - return (rc); - } - rc = MS_ParseConfiguration(); /* Parse the configuration */ - if (rc != OK) { - PRINT_Err(rc); - return (rc); - } - rc = USBH_SET_CONFIGURATION(1); /* Select device configuration 1 */ - if (rc != OK) { - PRINT_Err(rc); - } - Host_DelayMS(100); /* Some devices may require this delay */ - return (rc); -} - -/* -************************************************************************************************************** -* RECEIVE THE CONTROL INFORMATION -* -* Description: This function is used to receive the control information -* -* Arguments : bm_request_type -* b_request -* w_value -* w_index -* w_length -* buffer -* -* Returns : OK if Success -* ERROR if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type, - USB_INT08U b_request, - USB_INT16U w_value, - USB_INT16U w_index, - USB_INT16U w_length, - volatile USB_INT08U *buffer) -{ - USB_INT32S rc; - - - Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length); - rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8); - if (rc == OK) { - if (w_length) { - rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length); - } - if (rc == OK) { - rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0); - } - } - return (rc); -} - -/* -************************************************************************************************************** -* SEND THE CONTROL INFORMATION -* -* Description: This function is used to send the control information -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type, - USB_INT08U b_request, - USB_INT16U w_value, - USB_INT16U w_index, - USB_INT16U w_length, - volatile USB_INT08U *buffer) -{ - USB_INT32S rc; - - - Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length); - - rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8); - if (rc == OK) { - if (w_length) { - rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length); - } - if (rc == OK) { - rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0); - } - } - return (rc); -} - -/* -************************************************************************************************************** -* FILL SETUP PACKET -* -* Description: This function is used to fill the setup packet -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -void Host_FillSetup (USB_INT08U bm_request_type, - USB_INT08U b_request, - USB_INT16U w_value, - USB_INT16U w_index, - USB_INT16U w_length) -{ - int i; - for (i=0;i<w_length;i++) - TDBuffer[i] = 0; - - TDBuffer[0] = bm_request_type; - TDBuffer[1] = b_request; - WriteLE16U(&TDBuffer[2], w_value); - WriteLE16U(&TDBuffer[4], w_index); - WriteLE16U(&TDBuffer[6], w_length); -} - - - -/* -************************************************************************************************************** -* INITIALIZE THE TRANSFER DESCRIPTOR -* -* Description: This function initializes transfer descriptor -* -* Arguments : Pointer to TD structure -* -* Returns : None -* -************************************************************************************************************** -*/ - -void Host_TDInit (volatile HCTD *td) -{ - - td->Control = 0; - td->CurrBufPtr = 0; - td->Next = 0; - td->BufEnd = 0; -} - -/* -************************************************************************************************************** -* INITIALIZE THE ENDPOINT DESCRIPTOR -* -* Description: This function initializes endpoint descriptor -* -* Arguments : Pointer to ED strcuture -* -* Returns : None -* -************************************************************************************************************** -*/ - -void Host_EDInit (volatile HCED *ed) -{ - - ed->Control = 0; - ed->TailTd = 0; - ed->HeadTd = 0; - ed->Next = 0; -} - -/* -************************************************************************************************************** -* INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA -* -* Description: This function initializes host controller communications area -* -* Arguments : Pointer to HCCA -* -* Returns : -* -************************************************************************************************************** -*/ - -void Host_HCCAInit (volatile HCCA *hcca) -{ - USB_INT32U i; - - - for (i = 0; i < 32; i++) { - - hcca->IntTable[i] = 0; - hcca->FrameNumber = 0; - hcca->DoneHead = 0; - } - -} - -/* -************************************************************************************************************** -* WAIT FOR WDH INTERRUPT -* -* Description: This function is infinite loop which breaks when ever a WDH interrupt rises -* -* Arguments : None -* -* Returns : None -* -************************************************************************************************************** -*/ - -void Host_WDHWait (void) -{ - while (!HOST_WdhIntr) - __WFI(); - - HOST_WdhIntr = 0; -} - -/* -************************************************************************************************************** -* READ LE 32U -* -* Description: This function is used to read an unsigned integer from a character buffer in the platform -* containing little endian processor -* -* Arguments : pmem Pointer to the character buffer -* -* Returns : val Unsigned integer -* -************************************************************************************************************** -*/ - -USB_INT32U ReadLE32U (volatile USB_INT08U *pmem) -{ - USB_INT32U val = *(USB_INT32U*)pmem; -#ifdef __BIG_ENDIAN - return __REV(val); -#else - return val; -#endif -} - -/* -************************************************************************************************************** -* WRITE LE 32U -* -* Description: This function is used to write an unsigned integer into a charecter buffer in the platform -* containing little endian processor. -* -* Arguments : pmem Pointer to the charecter buffer -* val Integer value to be placed in the charecter buffer -* -* Returns : None -* -************************************************************************************************************** -*/ - -void WriteLE32U (volatile USB_INT08U *pmem, - USB_INT32U val) -{ -#ifdef __BIG_ENDIAN - *(USB_INT32U*)pmem = __REV(val); -#else - *(USB_INT32U*)pmem = val; -#endif -} - -/* -************************************************************************************************************** -* READ LE 16U -* -* Description: This function is used to read an unsigned short integer from a charecter buffer in the platform -* containing little endian processor -* -* Arguments : pmem Pointer to the charecter buffer -* -* Returns : val Unsigned short integer -* -************************************************************************************************************** -*/ - -USB_INT16U ReadLE16U (volatile USB_INT08U *pmem) -{ - USB_INT16U val = *(USB_INT16U*)pmem; -#ifdef __BIG_ENDIAN - return __REV16(val); -#else - return val; -#endif -} - -/* -************************************************************************************************************** -* WRITE LE 16U -* -* Description: This function is used to write an unsigned short integer into a charecter buffer in the -* platform containing little endian processor -* -* Arguments : pmem Pointer to the charecter buffer -* val Value to be placed in the charecter buffer -* -* Returns : None -* -************************************************************************************************************** -*/ - -void WriteLE16U (volatile USB_INT08U *pmem, - USB_INT16U val) -{ -#ifdef __BIG_ENDIAN - *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF); -#else - *(USB_INT16U*)pmem = val; -#endif -} - -/* -************************************************************************************************************** -* READ BE 32U -* -* Description: This function is used to read an unsigned integer from a charecter buffer in the platform -* containing big endian processor -* -* Arguments : pmem Pointer to the charecter buffer -* -* Returns : val Unsigned integer -* -************************************************************************************************************** -*/ - -USB_INT32U ReadBE32U (volatile USB_INT08U *pmem) -{ - USB_INT32U val = *(USB_INT32U*)pmem; -#ifdef __BIG_ENDIAN - return val; -#else - return __REV(val); -#endif -} - -/* -************************************************************************************************************** -* WRITE BE 32U -* -* Description: This function is used to write an unsigned integer into a charecter buffer in the platform -* containing big endian processor -* -* Arguments : pmem Pointer to the charecter buffer -* val Value to be placed in the charecter buffer -* -* Returns : None -* -************************************************************************************************************** -*/ - -void WriteBE32U (volatile USB_INT08U *pmem, - USB_INT32U val) -{ -#ifdef __BIG_ENDIAN - *(USB_INT32U*)pmem = val; -#else - *(USB_INT32U*)pmem = __REV(val); -#endif -} - -/* -************************************************************************************************************** -* READ BE 16U -* -* Description: This function is used to read an unsigned short integer from a charecter buffer in the platform -* containing big endian processor -* -* Arguments : pmem Pointer to the charecter buffer -* -* Returns : val Unsigned short integer -* -************************************************************************************************************** -*/ - -USB_INT16U ReadBE16U (volatile USB_INT08U *pmem) -{ - USB_INT16U val = *(USB_INT16U*)pmem; -#ifdef __BIG_ENDIAN - return val; -#else - return __REV16(val); -#endif -} - -/* -************************************************************************************************************** -* WRITE BE 16U -* -* Description: This function is used to write an unsigned short integer into the charecter buffer in the -* platform containing big endian processor -* -* Arguments : pmem Pointer to the charecter buffer -* val Value to be placed in the charecter buffer -* -* Returns : None -* -************************************************************************************************************** -*/ - -void WriteBE16U (volatile USB_INT08U *pmem, - USB_INT16U val) -{ -#ifdef __BIG_ENDIAN - *(USB_INT16U*)pmem = val; -#else - *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF); -#endif -}
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_lpc17xx.h --- a/USBHostLite/usbhost_lpc17xx.h Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,254 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_lpc17xx.h -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -#ifndef USBHOST_LPC17xx_H -#define USBHOST_LPC17xx_H - -/* -************************************************************************************************************** -* INCLUDE HEADER FILES -************************************************************************************************************** -*/ - -#include "usbhost_inc.h" - -/* -************************************************************************************************************** -* PRINT CONFIGURATION -************************************************************************************************************** -*/ - -#define PRINT_ENABLE 1 - -#if PRINT_ENABLE -#define PRINT_Log(...) printf(__VA_ARGS__) -#define PRINT_Err(rc) printf("ERROR: In %s at Line %u - rc = %d\n", __FUNCTION__, __LINE__, rc) - -#else -#define PRINT_Log(...) do {} while(0) -#define PRINT_Err(rc) do {} while(0) - -#endif - -/* -************************************************************************************************************** -* GENERAL DEFINITIONS -************************************************************************************************************** -*/ - -#define DESC_LENGTH(x) x[0] -#define DESC_TYPE(x) x[1] - - -#define HOST_GET_DESCRIPTOR(descType, descIndex, data, length) \ - Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, \ - (descType << 8)|(descIndex), 0, length, data) - -#define HOST_SET_ADDRESS(new_addr) \ - Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_ADDRESS, \ - new_addr, 0, 0, NULL) - -#define USBH_SET_CONFIGURATION(configNum) \ - Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_CONFIGURATION, \ - configNum, 0, 0, NULL) - -#define USBH_SET_INTERFACE(ifNum, altNum) \ - Host_CtrlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE, SET_INTERFACE, \ - altNum, ifNum, 0, NULL) - -/* -************************************************************************************************************** -* OHCI OPERATIONAL REGISTER FIELD DEFINITIONS -************************************************************************************************************** -*/ - - /* ------------------ HcControl Register --------------------- */ -#define OR_CONTROL_CLE 0x00000010 -#define OR_CONTROL_BLE 0x00000020 -#define OR_CONTROL_HCFS 0x000000C0 -#define OR_CONTROL_HC_OPER 0x00000080 - /* ----------------- HcCommandStatus Register ----------------- */ -#define OR_CMD_STATUS_HCR 0x00000001 -#define OR_CMD_STATUS_CLF 0x00000002 -#define OR_CMD_STATUS_BLF 0x00000004 - /* --------------- HcInterruptStatus Register ----------------- */ -#define OR_INTR_STATUS_WDH 0x00000002 -#define OR_INTR_STATUS_RHSC 0x00000040 - /* --------------- HcInterruptEnable Register ----------------- */ -#define OR_INTR_ENABLE_WDH 0x00000002 -#define OR_INTR_ENABLE_RHSC 0x00000040 -#define OR_INTR_ENABLE_MIE 0x80000000 - /* ---------------- HcRhDescriptorA Register ------------------ */ -#define OR_RH_STATUS_LPSC 0x00010000 -#define OR_RH_STATUS_DRWE 0x00008000 - /* -------------- HcRhPortStatus[1:NDP] Register -------------- */ -#define OR_RH_PORT_CCS 0x00000001 -#define OR_RH_PORT_PRS 0x00000010 -#define OR_RH_PORT_CSC 0x00010000 -#define OR_RH_PORT_PRSC 0x00100000 - - -/* -************************************************************************************************************** -* FRAME INTERVAL -************************************************************************************************************** -*/ - -#define FI 0x2EDF /* 12000 bits per frame (-1) */ -#define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI) - -/* -************************************************************************************************************** -* TRANSFER DESCRIPTOR CONTROL FIELDS -************************************************************************************************************** -*/ - -#define TD_ROUNDING (USB_INT32U) (0x00040000) /* Buffer Rounding */ -#define TD_SETUP (USB_INT32U)(0) /* Direction of Setup Packet */ -#define TD_IN (USB_INT32U)(0x00100000) /* Direction In */ -#define TD_OUT (USB_INT32U)(0x00080000) /* Direction Out */ -#define TD_DELAY_INT(x) (USB_INT32U)((x) << 21) /* Delay Interrupt */ -#define TD_TOGGLE_0 (USB_INT32U)(0x02000000) /* Toggle 0 */ -#define TD_TOGGLE_1 (USB_INT32U)(0x03000000) /* Toggle 1 */ -#define TD_CC (USB_INT32U)(0xF0000000) /* Completion Code */ - -/* -************************************************************************************************************** -* USB STANDARD REQUEST DEFINITIONS -************************************************************************************************************** -*/ - -#define USB_DESCRIPTOR_TYPE_DEVICE 1 -#define USB_DESCRIPTOR_TYPE_CONFIGURATION 2 -#define USB_DESCRIPTOR_TYPE_INTERFACE 4 -#define USB_DESCRIPTOR_TYPE_ENDPOINT 5 - /* ----------- Control RequestType Fields ----------- */ -#define USB_DEVICE_TO_HOST 0x80 -#define USB_HOST_TO_DEVICE 0x00 -#define USB_REQUEST_TYPE_CLASS 0x20 -#define USB_RECIPIENT_DEVICE 0x00 -#define USB_RECIPIENT_INTERFACE 0x01 - /* -------------- USB Standard Requests -------------- */ -#define SET_ADDRESS 5 -#define GET_DESCRIPTOR 6 -#define SET_CONFIGURATION 9 -#define SET_INTERFACE 11 - -/* -************************************************************************************************************** -* TYPE DEFINITIONS -************************************************************************************************************** -*/ - -typedef struct hcEd { /* ----------- HostController EndPoint Descriptor ------------- */ - volatile USB_INT32U Control; /* Endpoint descriptor control */ - volatile USB_INT32U TailTd; /* Physical address of tail in Transfer descriptor list */ - volatile USB_INT32U HeadTd; /* Physcial address of head in Transfer descriptor list */ - volatile USB_INT32U Next; /* Physical address of next Endpoint descriptor */ -} HCED; - -typedef struct hcTd { /* ------------ HostController Transfer Descriptor ------------ */ - volatile USB_INT32U Control; /* Transfer descriptor control */ - volatile USB_INT32U CurrBufPtr; /* Physical address of current buffer pointer */ - volatile USB_INT32U Next; /* Physical pointer to next Transfer Descriptor */ - volatile USB_INT32U BufEnd; /* Physical address of end of buffer */ -} HCTD; - -typedef struct hcca { /* ----------- Host Controller Communication Area ------------ */ - volatile USB_INT32U IntTable[32]; /* Interrupt Table */ - volatile USB_INT32U FrameNumber; /* Frame Number */ - volatile USB_INT32U DoneHead; /* Done Head */ - volatile USB_INT08U Reserved[116]; /* Reserved for future use */ - volatile USB_INT08U Unknown[4]; /* Unused */ -} HCCA; - -/* -************************************************************************************************************** -* EXTERN DECLARATIONS -************************************************************************************************************** -*/ - -extern volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */ -extern volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */ -extern volatile HCTD *TDHead; /* Head transfer descriptor structure */ -extern volatile HCTD *TDTail; /* Tail transfer descriptor structure */ -extern volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */ - -/* -************************************************************************************************************** -* FUNCTION PROTOTYPES -************************************************************************************************************** -*/ - -void Host_Init (void); - -extern "C" void USB_IRQHandler(void) __irq; - -USB_INT32S Host_EnumDev (void); - -USB_INT32S Host_ProcessTD(volatile HCED *ed, - volatile USB_INT32U token, - volatile USB_INT08U *buffer, - USB_INT32U buffer_len); - -void Host_DelayUS ( USB_INT32U delay); -void Host_DelayMS ( USB_INT32U delay); - - -void Host_TDInit (volatile HCTD *td); -void Host_EDInit (volatile HCED *ed); -void Host_HCCAInit (volatile HCCA *hcca); - -USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type, - USB_INT08U b_request, - USB_INT16U w_value, - USB_INT16U w_index, - USB_INT16U w_length, - volatile USB_INT08U *buffer); - -USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type, - USB_INT08U b_request, - USB_INT16U w_value, - USB_INT16U w_index, - USB_INT16U w_length, - volatile USB_INT08U *buffer); - -void Host_FillSetup( USB_INT08U bm_request_type, - USB_INT08U b_request, - USB_INT16U w_value, - USB_INT16U w_index, - USB_INT16U w_length); - - -void Host_WDHWait (void); - - -USB_INT32U ReadLE32U (volatile USB_INT08U *pmem); -void WriteLE32U (volatile USB_INT08U *pmem, - USB_INT32U val); -USB_INT16U ReadLE16U (volatile USB_INT08U *pmem); -void WriteLE16U (volatile USB_INT08U *pmem, - USB_INT16U val); -USB_INT32U ReadBE32U (volatile USB_INT08U *pmem); -void WriteBE32U (volatile USB_INT08U *pmem, - USB_INT32U val); -USB_INT16U ReadBE16U (volatile USB_INT08U *pmem); -void WriteBE16U (volatile USB_INT08U *pmem, - USB_INT16U val); - -#endif
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_ms.c --- a/USBHostLite/usbhost_ms.c Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,455 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_ms.c -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -/* -************************************************************************************************************** -* INCLUDE HEADER FILES -************************************************************************************************************** -*/ - -#include "usbhost_ms.h" - -/* -************************************************************************************************************** -* GLOBAL VARIABLES -************************************************************************************************************** -*/ - -USB_INT32U MS_BlkSize; - -/* -************************************************************************************************************** -* INITIALIZE MASS STORAGE INTERFACE -* -* Description: This function initializes the mass storage interface -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_Init (USB_INT32U *blkSize, USB_INT32U *numBlks, USB_INT08U *inquiryResult) -{ - USB_INT08U retry; - USB_INT32S rc; - - MS_GetMaxLUN(); /* Get maximum logical unit number */ - retry = 80; - while(retry) { - rc = MS_TestUnitReady(); /* Test whether the unit is ready */ - if (rc == OK) { - break; - } - MS_GetSenseInfo(); /* Get sense information */ - retry--; - } - if (rc != OK) { - PRINT_Err(rc); - return (rc); - } - rc = MS_ReadCapacity(numBlks, blkSize); /* Read capacity of the disk */ - MS_BlkSize = *blkSize; // Set global - rc = MS_Inquire (inquiryResult); - return (rc); -} -/* -************************************************************************************************************** -* PARSE THE CONFIGURATION -* -* Description: This function is used to parse the configuration -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_ParseConfiguration (void) -{ - volatile USB_INT08U *desc_ptr; - USB_INT08U ms_int_found; - - - desc_ptr = TDBuffer; - ms_int_found = 0; - - if (desc_ptr[1] != USB_DESCRIPTOR_TYPE_CONFIGURATION) { - return (ERR_BAD_CONFIGURATION); - } - desc_ptr += desc_ptr[0]; - - while (desc_ptr != TDBuffer + ReadLE16U(&TDBuffer[2])) { - - switch (desc_ptr[1]) { - - case USB_DESCRIPTOR_TYPE_INTERFACE: /* If it is an interface descriptor */ - if (desc_ptr[5] == MASS_STORAGE_CLASS && /* check if the class is mass storage */ - desc_ptr[6] == MASS_STORAGE_SUBCLASS_SCSI && /* check if the subclass is SCSI */ - desc_ptr[7] == MASS_STORAGE_PROTOCOL_BO) { /* check if the protocol is Bulk only */ - ms_int_found = 1; - desc_ptr += desc_ptr[0]; /* Move to next descriptor start */ - } - break; - - case USB_DESCRIPTOR_TYPE_ENDPOINT: /* If it is an endpoint descriptor */ - if ((desc_ptr[3] & 0x03) == 0x02) { /* If it is Bulk endpoint */ - if (desc_ptr[2] & 0x80) { /* If it is In endpoint */ - EDBulkIn->Control = 1 | /* USB address */ - ((desc_ptr[2] & 0x7F) << 7) | /* Endpoint address */ - (2 << 11) | /* direction */ - (ReadLE16U(&desc_ptr[4]) << 16); /* MaxPkt Size */ - desc_ptr += desc_ptr[0]; /* Move to next descriptor start */ - } else { /* If it is Out endpoint */ - EDBulkOut->Control = 1 | /* USB address */ - ((desc_ptr[2] & 0x7F) << 7) | /* Endpoint address */ - (1 << 11) | /* direction */ - (ReadLE16U(&desc_ptr[4]) << 16); /* MaxPkt Size */ - desc_ptr += desc_ptr[0]; /* Move to next descriptor start */ - } - } else { /* If it is not bulk end point */ - desc_ptr += desc_ptr[0]; /* Move to next descriptor start */ - } - break; - - default: /* If the descriptor is neither interface nor endpoint */ - desc_ptr += desc_ptr[0]; /* Move to next descriptor start */ - break; - } - } - if (ms_int_found) { - PRINT_Log("Mass Storage device connected\n"); - return (OK); - } else { - PRINT_Log("Not a Mass Storage device\n"); - return (ERR_NO_MS_INTERFACE); - } -} - -/* -************************************************************************************************************** -* GET MAXIMUM LOGICAL UNIT -* -* Description: This function returns the maximum logical unit from the device -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_GetMaxLUN (void) -{ - USB_INT32S rc; - - - rc = Host_CtrlRecv(USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, - MS_GET_MAX_LUN_REQ, - 0, - 0, - 1, - TDBuffer); - return (rc); -} - -/* -************************************************************************************************************** -* GET SENSE INFORMATION -* -* Description: This function is used to get sense information from the device -* -* Arguments : None -* -* Returns : OK if Success -* ERROR if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_GetSenseInfo (void) -{ - USB_INT32S rc; - - - Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_REQUEST_SENSE, 6); - rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, 18); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); - if (rc == OK) { - if (TDBuffer[12] != 0) { - rc = ERR_MS_CMD_FAILED; - } - } - } - } - return (rc); -} - -/* -************************************************************************************************************** -* TEST UNIT READY -* -* Description: This function is used to test whether the unit is ready or not -* -* Arguments : None -* -* Returns : OK if Success -* ERROR if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_TestUnitReady (void) -{ - USB_INT32S rc; - - - Fill_MSCommand(0, 0, 0, MS_DATA_DIR_NONE, SCSI_CMD_TEST_UNIT_READY, 6); - rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); - if (rc == OK) { - if (TDBuffer[12] != 0) { - rc = ERR_MS_CMD_FAILED; - } - } - } - return (rc); -} - -/* -************************************************************************************************************** -* READ CAPACITY -* -* Description: This function is used to read the capacity of the mass storage device -* -* Arguments : None -* -* Returns : OK if Success -* ERROR if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_ReadCapacity (USB_INT32U *numBlks, USB_INT32U *blkSize) -{ - USB_INT32S rc; - - - Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_READ_CAPACITY, 10); - rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, 8); - if (rc == OK) { - if (numBlks) - *numBlks = ReadBE32U(&TDBuffer[0]); - if (blkSize) - *blkSize = ReadBE32U(&TDBuffer[4]); - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); - if (rc == OK) { - if (TDBuffer[12] != 0) { - rc = ERR_MS_CMD_FAILED; - } - } - } - } - return (rc); -} - - - -USB_INT32S MS_Inquire (USB_INT08U *response) -{ - USB_INT32S rc; - USB_INT32U i; - - Fill_MSCommand(0, 0, 0, MS_DATA_DIR_IN, SCSI_CMD_INQUIRY, 6); - rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, INQUIRY_LENGTH); - if (rc == OK) { - if (response) { - for ( i = 0; i < INQUIRY_LENGTH; i++ ) - *response++ = *TDBuffer++; -#if 0 - MemCpy (response, TDBuffer, INQUIRY_LENGTH); - StrNullTrailingSpace (response->vendorID, SCSI_INQUIRY_VENDORCHARS); - StrNullTrailingSpace (response->productID, SCSI_INQUIRY_PRODUCTCHARS); - StrNullTrailingSpace (response->productRev, SCSI_INQUIRY_REVCHARS); -#endif - } - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); - if (rc == OK) { - if (TDBuffer[12] != 0) { // bCSWStatus byte - rc = ERR_MS_CMD_FAILED; - } - } - } - } - return (rc); -} - -/* -************************************************************************************************************** -* RECEIVE THE BULK DATA -* -* Description: This function is used to receive the bulk data -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_BulkRecv ( USB_INT32U block_number, - USB_INT16U num_blocks, - volatile USB_INT08U *user_buffer) -{ - USB_INT32S rc; - int i; - volatile USB_INT08U *c = user_buffer; - for (i=0;i<MS_BlkSize*num_blocks;i++) - *c++ = 0; - - - Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_IN, SCSI_CMD_READ_10, 10); - - rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, user_buffer, MS_BlkSize * num_blocks); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); - if (rc == OK) { - if (TDBuffer[12] != 0) { - rc = ERR_MS_CMD_FAILED; - } - } - } - } - return (rc); -} - -/* -************************************************************************************************************** -* SEND BULK DATA -* -* Description: This function is used to send the bulk data -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -USB_INT32S MS_BulkSend ( USB_INT32U block_number, - USB_INT16U num_blocks, - volatile USB_INT08U *user_buffer) -{ - USB_INT32S rc; - - - Fill_MSCommand(block_number, MS_BlkSize, num_blocks, MS_DATA_DIR_OUT, SCSI_CMD_WRITE_10, 10); - - rc = Host_ProcessTD(EDBulkOut, TD_OUT, TDBuffer, CBW_SIZE); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkOut, TD_OUT, user_buffer, MS_BlkSize * num_blocks); - if (rc == OK) { - rc = Host_ProcessTD(EDBulkIn, TD_IN, TDBuffer, CSW_SIZE); - if (rc == OK) { - if (TDBuffer[12] != 0) { - rc = ERR_MS_CMD_FAILED; - } - } - } - } - return (rc); -} - -/* -************************************************************************************************************** -* FILL MASS STORAGE COMMAND -* -* Description: This function is used to fill the mass storage command -* -* Arguments : None -* -* Returns : OK if Success -* ERR_INVALID_BOOTSIG if Failed -* -************************************************************************************************************** -*/ - -void Fill_MSCommand (USB_INT32U block_number, - USB_INT32U block_size, - USB_INT16U num_blocks, - MS_DATA_DIR direction, - USB_INT08U scsi_cmd, - USB_INT08U scsi_cmd_len) -{ - USB_INT32U data_len; - static USB_INT32U tag_cnt = 0; - USB_INT32U cnt; - - - for (cnt = 0; cnt < CBW_SIZE; cnt++) { - TDBuffer[cnt] = 0; - } - switch(scsi_cmd) { - - case SCSI_CMD_TEST_UNIT_READY: - data_len = 0; - break; - case SCSI_CMD_READ_CAPACITY: - data_len = 8; - break; - case SCSI_CMD_REQUEST_SENSE: - data_len = 18; - break; - case SCSI_CMD_INQUIRY: - data_len = 36; - break; - default: - data_len = block_size * num_blocks; - break; - } - WriteLE32U(TDBuffer, CBW_SIGNATURE); - WriteLE32U(&TDBuffer[4], tag_cnt); - WriteLE32U(&TDBuffer[8], data_len); - TDBuffer[12] = (direction == MS_DATA_DIR_NONE) ? 0 : direction; - TDBuffer[14] = scsi_cmd_len; /* Length of the CBW */ - TDBuffer[15] = scsi_cmd; - if ((scsi_cmd == SCSI_CMD_REQUEST_SENSE) - || (scsi_cmd == SCSI_CMD_INQUIRY)) { - TDBuffer[19] = (USB_INT08U)data_len; - } else { - WriteBE32U(&TDBuffer[17], block_number); - } - WriteBE16U(&TDBuffer[22], num_blocks); -}
diff -r 144fed3d9420 -r 4daed536a970 USBHostLite/usbhost_ms.h --- a/USBHostLite/usbhost_ms.h Sat Mar 13 17:19:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_ms.h -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - -#ifndef USBHOST_MS_H -#define USBHOST_MS_H - -/* -************************************************************************************************************** -* INCLUDE HEADER FILES -************************************************************************************************************** -*/ - -#include "usbhost_inc.h" - -/* -************************************************************************************************************** -* MASS STORAGE SPECIFIC DEFINITIONS -************************************************************************************************************** -*/ - -#define MS_GET_MAX_LUN_REQ 0xFE -#define MASS_STORAGE_CLASS 0x08 -#define MASS_STORAGE_SUBCLASS_SCSI 0x06 -#define MASS_STORAGE_PROTOCOL_BO 0x50 - -#define INQUIRY_LENGTH 36 -/* -************************************************************************************************************** -* SCSI SPECIFIC DEFINITIONS -************************************************************************************************************** -*/ - -#define CBW_SIGNATURE 0x43425355 -#define CSW_SIGNATURE 0x53425355 -#define CBW_SIZE 31 -#define CSW_SIZE 13 -#define CSW_CMD_PASSED 0x00 -#define SCSI_CMD_REQUEST_SENSE 0x03 -#define SCSI_CMD_TEST_UNIT_READY 0x00 -#define SCSI_CMD_INQUIRY 0x12 -#define SCSI_CMD_READ_10 0x28 -#define SCSI_CMD_READ_CAPACITY 0x25 -#define SCSI_CMD_WRITE_10 0x2A - -/* -************************************************************************************************************** -* TYPE DEFINITIONS -************************************************************************************************************** -*/ - -typedef enum ms_data_dir { - - MS_DATA_DIR_IN = 0x80, - MS_DATA_DIR_OUT = 0x00, - MS_DATA_DIR_NONE = 0x01 - -} MS_DATA_DIR; - -/* -************************************************************************************************************** -* FUNCTION PROTOTYPES -************************************************************************************************************** -*/ - -USB_INT32S MS_BulkRecv ( USB_INT32U block_number, - USB_INT16U num_blocks, - volatile USB_INT08U *user_buffer); - -USB_INT32S MS_BulkSend ( USB_INT32U block_number, - USB_INT16U num_blocks, - volatile USB_INT08U *user_buffer); -USB_INT32S MS_ParseConfiguration(void); -USB_INT32S MS_TestUnitReady (void); -USB_INT32S MS_ReadCapacity (USB_INT32U *numBlks, USB_INT32U *blkSize); -USB_INT32S MS_GetMaxLUN (void); -USB_INT32S MS_GetSenseInfo (void); -USB_INT32S MS_Init (USB_INT32U *blkSize, USB_INT32U *numBlks, USB_INT08U *inquiryResult); -USB_INT32S MS_Inquire (USB_INT08U *response); - -void Fill_MSCommand ( USB_INT32U block_number, - USB_INT32U block_size, - USB_INT16U num_blocks, - MS_DATA_DIR direction, - USB_INT08U scsi_cmd, - USB_INT08U scsi_cmd_len); -#endif
diff -r 144fed3d9420 -r 4daed536a970 keypad.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/keypad.lib Tue Sep 17 01:37:10 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/yoonghm/code/keypad/#e48ba5b4c497
diff -r 144fed3d9420 -r 4daed536a970 main.cpp --- a/main.cpp Sat Mar 13 17:19:08 2010 +0000 +++ b/main.cpp Tue Sep 17 01:37:10 2013 +0000 @@ -1,17 +1,1101 @@ #include "mbed.h" -#include "MSCFileSystem.h" -#include "LIS302.h" +#include "keypad.h" +#include "ds1307.h" +#include "USBHostMSD.h" +#include "TextLCD.h" + +DigitalOut FW(p5); +DigitalOut RW(p6); +DigitalOut door_on(p7); +DigitalOut door_off(p8); + +DS1307 my1307(p9,p10); + +TextLCD lcd(p11, p12, p13, p14, p15, p16, TextLCD::LCD20x4); // rs, e, d4-d7 + +AnalogIn rigth_sense(p17); +AnalogIn left_sense(p19); +AnalogIn ain(p20); + + +DigitalOut led5(LED1); +DigitalOut led6(LED2); +DigitalOut led7(LED3); +DigitalOut led8(LED4); + +DigitalOut led1(p29); +DigitalOut led2(p30); +DigitalOut led3(USBTX); +DigitalOut led4(USBRX); + +//Serial pc(USBTX, USBRX); // tx, rx for debug and usb pc comunications + +Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24); +/* +Teclado membrana Mbed +C3 P21 +C2 P22 +C1 P23 +C0 P24 +F3 P25 +F2 P26 +F1 P27 +F0 P28 + +keypad.class: f3, f2 , f1 , f0 , c3 , c2 , c1 , c0 +mbed pinout: p25, p26, p27, p28, p21, p22, p23, p24 + 24 23 22 21 +25 '1', '2', '3', 'A', +26 '4', '5', '6', 'B', +27 '7', '8', '9', 'C', +28 '*', '0', '#', 'D' + +Teclado PLASTICO Mbed +F3 P21 +F2 P22 +F1 P23 +F0 P24 +C3 P25 +C2 P26 +C1 P27 +C0 P28 + +keypad.class: f3, f2 , f1 , f0 , c3 , c2 , c1 , c0 +mbed pinout: p21, p22, p23, p24, p25, p26, p27, p28 + 24 23 22 21 +25 '1', '2', '3', 'A', +26 '4', '5', '6', 'B', +27 '7', '8', '9', 'C', +28 '*', '0', '#', 'D' +*/ + + + + +//sensores +float rigth = 0, left = 0; + +//archivos USB +char file[80]; +int hours = 0, min = 0, sec = 0, year = 0, month = 0, date = 0, day = 0; +int a=0, b=0; + +const unsigned short page[229] = { + 0x3C,0x21,0x2D,0x2D,0x20,0x41,0x6C,0x6C,0x20,0x50,0x6F,0x77,0x65,0x72,0x20,0x4D, + 0x69,0x63,0x72,0x6F,0x63,0x6F,0x6E,0x74,0x72,0x6F,0x6C,0x6C,0x65,0x72,0x20,0x57, + 0x65,0x62,0x73,0x69,0x74,0x65,0x20,0x61,0x6E,0x64,0x20,0x41,0x75,0x74,0x68,0x65, + 0x6E,0x74,0x69,0x63,0x61,0x74,0x69,0x6F,0x6E,0x20,0x53,0x68,0x6F,0x72,0x74,0x63, + 0x75,0x74,0x20,0x2D,0x2D,0x3E,0x0D,0x0A,0x3C,0x68,0x74,0x6D,0x6C,0x3E,0x0D,0x0A, + 0x3C,0x68,0x65,0x61,0x64,0x3E,0x0D,0x0A,0x3C,0x6D,0x65,0x74,0x61,0x20,0x68,0x74, + 0x74,0x70,0x2D,0x65,0x71,0x75,0x69,0x76,0x3D,0x22,0x72,0x65,0x66,0x72,0x65,0x73, + 0x68,0x22,0x20,0x63,0x6F,0x6E,0x74,0x65,0x6E,0x74,0x3D,0x22,0x30,0x3B,0x20,0x75, + 0x72,0x6C,0x3D,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x61,0x70, + 0x6D,0x6D,0x69,0x63,0x72,0x6F,0x2E,0x63,0x6F,0x6D,0x22,0x2F,0x3E,0x0D,0x0A,0x3C, + 0x74,0x69,0x74,0x6C,0x65,0x3E,0x41,0x50,0x4D,0x20,0x57,0x65,0x62,0x73,0x69,0x74, + 0x65,0x20,0x53,0x68,0x6F,0x72,0x74,0x63,0x75,0x74,0x3C,0x2F,0x74,0x69,0x74,0x6C, + 0x65,0x3E,0x0D,0x0A,0x3C,0x2F,0x68,0x65,0x61,0x64,0x3E,0x0D,0x0A,0x3C,0x62,0x6F, + 0x64,0x79,0x3E,0x3C,0x2F,0x62,0x6F,0x64,0x79,0x3E,0x0D,0x0A,0x3C,0x2F,0x68,0x74, + 0x6D,0x6C,0x3E,0x0D,0x0A + +}; + +const unsigned short data_Os[976] = { + 0x42,0x6F,0x6F,0x74,0x6C,0x6F,0x61,0x64,0x65,0x72,0x2E,0x2E,0x2E,0x20,0x4F,0x4B, + 0x0D,0x0A,0x41,0x52,0x4D,0x20,0x43,0x6F,0x72,0x74,0x65,0x78,0x20,0x4D,0x33,0x20, + 0x43,0x50,0x55,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x47,0x72,0x61,0x70,0x68, + 0x69,0x63,0x20,0x50,0x72,0x6F,0x63,0x65,0x73,0x73,0x69,0x6E,0x67,0x20,0x55,0x6E, + 0x69,0x74,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x4C,0x69,0x62,0x72,0x65,0x72, + 0x69,0x65,0x73,0x20,0x46,0x61,0x74,0x20,0x46,0x2E,0x20,0x53,0x79,0x73,0x74,0x65, + 0x6D,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x50,0x44,0x53,0x2E,0x20,0x53,0x65, + 0x63,0x75,0x72,0x69,0x74,0x79,0x20,0x41,0x72,0x65,0x61,0x2E,0x2E,0x2E,0x20,0x4F, + 0x4B,0x0D,0x0A,0x52,0x53,0x41,0x2E,0x20,0x50,0x72,0x6F,0x74,0x65,0x63,0x74,0x69, + 0x6F,0x6E,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x48,0x6F,0x73,0x74,0x20,0x55, + 0x53,0x42,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x44,0x65,0x76,0x69,0x63,0x65, + 0x20,0x55,0x53,0x42,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x53,0x44,0x20,0x43, + 0x61,0x72,0x64,0x2E,0x2E,0x2E,0x20,0x4F,0x4B,0x0D,0x0A,0x53,0x61,0x76,0x65,0x3A, + 0x20,0x62,0x69,0x6F,0x73,0x2E,0x44,0x41,0x54,0x0D,0x0A,0x0D,0x0A,0x2A,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x0D,0x0A,0x41,0x6C,0x6C,0x20,0x50, + 0x6F,0x77,0x65,0x72,0x20,0x4D,0x69,0x63,0x72,0x6F,0x63,0x6F,0x6E,0x74,0x72,0x6F, + 0x6C,0x6C,0x65,0x72,0x2C,0x20,0x4F,0x70,0x65,0x72,0x61,0x74,0x69,0x76,0x65,0x20, + 0x53,0x79,0x73,0x74,0x65,0x6D,0x20,0x42,0x69,0x6F,0x5F,0x4F,0x73,0x0D,0x0A,0x0D, + 0x0A,0x46,0x61,0x74,0x20,0x46,0x69,0x6C,0x65,0x20,0x53,0x79,0x73,0x74,0x65,0x6D, + 0x20,0x4C,0x69,0x62,0x72,0x61,0x72,0x79,0x20,0x42,0x61,0x73,0x65,0x20,0x43,0x6C, + 0x61,0x73,0x73,0x20,0x61,0x6E,0x64,0x20,0x47,0x72,0x61,0x70,0x68,0x69,0x63,0x20, + 0x49,0x6E,0x74,0x65,0x72,0x66,0x61,0x63,0x65,0x20,0x69,0x73,0x20,0x70,0x72,0x6F, + 0x74,0x65,0x63,0x74,0x65,0x64,0x20,0x77,0x68,0x69,0x74,0x68,0x0D,0x0A,0x43,0x6F, + 0x70,0x79,0x72,0x69,0x67,0x68,0x74,0x20,0x28,0x63,0x29,0x20,0x32,0x30,0x30,0x31, + 0x31,0x2D,0x32,0x30,0x31,0x32,0x20,0x45,0x63,0x75,0x61,0x64,0x6F,0x72,0x0D,0x0A, + 0x52,0x65,0x6C,0x65,0x61,0x73,0x65,0x64,0x20,0x75,0x6E,0x64,0x65,0x72,0x20,0x4C, + 0x69,0x63,0x65,0x6E,0x73,0x65,0x20,0x6F,0x66,0x20,0x69,0x6E,0x74,0x65,0x6C,0x65, + 0x63,0x74,0x75,0x61,0x6C,0x20,0x70,0x72,0x6F,0x70,0x69,0x65,0x74,0x79,0x20,0x6F, + 0x66,0x20,0x41,0x6E,0x67,0x65,0x6C,0x20,0x44,0x2E,0x20,0x59,0x61,0x67,0x75,0x61, + 0x6E,0x61,0x0D,0x0A,0x0D,0x0A,0x45,0x6C,0x20,0x70,0x72,0x65,0x73,0x65,0x6E,0x74, + 0x65,0x20,0x70,0x72,0x6F,0x79,0x65,0x63,0x74,0x6F,0x20,0x65,0x73,0x20,0x72,0x65, + 0x61,0x6C,0x69,0x7A,0x61,0x64,0x6F,0x20,0x62,0x61,0x6A,0x6F,0x20,0x61,0x63,0x75, + 0x65,0x72,0x64,0x6F,0x20,0x64,0x65,0x20,0x6C,0x69,0x63,0x65,0x6E,0x63,0x69,0x61, + 0x20,0x6F,0x74,0x6F,0x72,0x67,0x61,0x64,0x6F,0x20,0x70,0x6F,0x72,0x20,0x65,0x6C, + 0x20,0x0D,0x0A,0x41,0x75,0x74,0x6F,0x72,0x20,0x63,0x6F,0x6E,0x20,0x74,0x65,0x72, + 0x6D,0x69,0x6E,0x6F,0x73,0x20,0x65,0x73,0x70,0x65,0x63,0x69,0x66,0x69,0x63,0x61, + 0x64,0x6F,0x73,0x20,0x70,0x6F,0x72,0x20,0x6C,0x61,0x20,0x6C,0x69,0x63,0x65,0x6E, + 0x63,0x69,0x61,0x20,0x47,0x4E,0x55,0x20,0x47,0x50,0x4C,0x20,0x6C,0x61,0x20,0x63, + 0x75,0x61,0x6C,0x20,0x6C,0x65,0x20,0x70,0x65,0x72,0x6D,0x69,0x74,0x65,0x20,0x0D, + 0x0A,0x75,0x73,0x61,0x72,0x20,0x6C,0x61,0x73,0x20,0x6C,0x69,0x62,0x72,0x65,0x72, + 0x69,0x61,0x73,0x20,0x70,0x65,0x72,0x6F,0x20,0x70,0x72,0x6F,0x68,0x69,0x62,0x65, + 0x20,0x73,0x75,0x20,0x76,0x65,0x6E,0x74,0x61,0x20,0x6F,0x20,0x63,0x6F,0x6D,0x65, + 0x72,0x63,0x69,0x61,0x6C,0x69,0x7A,0x61,0x63,0x69,0x6F,0x6E,0x20,0x63,0x6F,0x6E, + 0x20,0x66,0x69,0x6E,0x65,0x73,0x20,0x64,0x65,0x20,0x6C,0x75,0x63,0x72,0x6F,0x20, + 0x0D,0x0A,0x73,0x69,0x6E,0x20,0x70,0x72,0x65,0x76,0x69,0x61,0x20,0x72,0x65,0x74, + 0x72,0x69,0x62,0x75,0x63,0x69,0x6F,0x6E,0x20,0x70,0x6F,0x72,0x20,0x64,0x65,0x72, + 0x65,0x63,0x68,0x6F,0x73,0x20,0x64,0x65,0x20,0x70,0x72,0x6F,0x70,0x69,0x65,0x64, + 0x61,0x64,0x20,0x69,0x6E,0x74,0x65,0x6C,0x65,0x63,0x74,0x75,0x61,0x6C,0x20,0x64, + 0x65,0x20,0x42,0x69,0x6F,0x5F,0x4F,0x73,0x0D,0x0A,0x2A,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F, + 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x0D,0x0A,0x0D,0x0A,0x0D,0x0A,0x0D,0x0A,0x2F,0x2F, + 0x42,0x69,0x6F,0x5F,0x4F,0x73,0x20,0x77,0x61,0x73,0x20,0x64,0x65,0x76,0x65,0x6C, + 0x6F,0x70,0x6D,0x65,0x6E,0x74,0x20,0x62,0x79,0x20,0x53,0x68,0x65,0x72,0x63,0x6B, + 0x75,0x69,0x74,0x68,0x20,0x69,0x6E,0x20,0x32,0x30,0x31,0x32,0x2F,0x3C,0x00,0x00 +}; + + +//read_RAM var +int get_start_date_ram=0,get_start_month_ram=0,get_start_year_ram=0,get_start_hour_ram=0,get_start_min_ram=0,get_start_sec_ram=0; +int get_end_date_ram=0,get_end_month_ram=0,get_end_year_ram=0,get_end_hour_ram=0,get_end_min_ram=0,get_end_sec_ram=0; +int get_speed_ram= 0, get_sense_ram= 0,get_space_ram= 0; +float get_space_Z4= 0, speed_ram_powten_3= 0, sense_ram_powten_3= 0; + +//Config var +int set_start_hour=0,set_start_min=0,set_start_sec=0,set_start_date=0,set_start_month=0,set_start_year=0; +int set_end_hour=0,set_end_min=0,set_end_sec=0,set_end_date=0,set_end_month=0,set_end_year=0; +int set_speed= 0, set_sense= 0,set_space= 0; + +//Upload var +int new_hour=0,new_min=0,new_sec=0,new_date=0,new_mont=0,new_year=0,new_day=0; + +//Registre +int Old_Speed_RAM= 0, Old_sense_RAM= 0,Old_Space_RAM= 0; + +//Keypad +int t=0,cnt=1,j=0,key=0; +int pass=0,l=0; +char data[6]; +int key0=0, key1=0, key2=0, key3=0, key4=0, key5=0; +char Keytable[] = { '1', '2', '3', 'A', + '4', '5', '6', 'B', + '7', '8', '9', 'C', + '*', '0', '#', 'D' + }; +//EZ4 +float adc,cm5=0, prom=0,result=0, Radar=0; +int cnt_Z4=0; +int interval=0; + +//funciones +void Set_Time(int set_sec, int set_min, int set_hours, int set_day, int set_date, int set_month, int set_year); +void read_RAM(); +float get_Z4(); +uint32_t cbAfterInput(uint32_t index); +//extern "C" void mbed_reset(); + +int i = 0; +int flag_usb_1=0,flag_usb_2=0; +int c=0; + +int FLAG_DOOR_OFF=0; +int FLAG_DOOR_ON=0; +int FLAG_NEW_PASS=0; +int FLAG_PUT_PASS=0; +int FLAG_NEW_PASS_FULL=0; + + +int main() +{ + ////pc.baud(115200); + + keypad.CallAfterInput(&cbAfterInput); + keypad.Start(); + //rigth_sense.mode(PullDown); + //left_sense.mode(PullDown); + + for(i=0; i<10; i++) { + wait(0.1); + lcd.cls(); + } -MSCFileSystem fs("fs"); // Mount flash drive under the name "msc" + c=255; + lcd.locate(0,0); + lcd.printf(" %c%c %c%c%c %c %c ",c,c,c,c,c,c,c); + lcd.locate(0,1); + lcd.printf("%c %c %c %c %c%c %c%c GYE",c,c,c,c,c,c,c,c); + lcd.locate(0,2); + lcd.printf("%c%c%c%c %c%c%c %c %c %c ECU.",c,c,c,c,c,c,c,c,c,c); + lcd.locate(0,3); + lcd.printf("%c %c %c %c %c ",c,c,c,c,c); + for(int z=0; z<10; z++) { + wait(0.05); + led1=1; + led5=1; + led2=0; + led6=0; + led3=0; + led7=0; + led4=0; + led8=0; + wait(0.05); + led1=0; + led5=0; + led2=1; + led6=1; + led3=0; + led7=0; + led4=0; + led8=0; + wait(0.05); + led1=0; + led5=0; + led2=0; + led6=0; + led3=1; + led7=1; + led4=0; + led8=0; + wait(0.05); + led1=0; + led5=0; + led2=0; + led6=0; + led3=0; + led7=0; + led4=1; + led8=1; + wait(0.05); + led1=0; + led5=0; + led2=0; + led6=0; + led3=1; + led7=1; + led4=0; + led8=0; + wait(0.05); + led1=0; + led5=0; + led2=1; + led6=1; + led3=0; + led7=0; + led4=0; + led8=0; + wait(0.05); + led1=1; + led5=1; + led2=0; + led6=0; + led3=0; + led7=0; + led4=0; + led8=0; + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + wait(2); + lcd.cls(); + lcd.locate(0,0); + lcd.printf(" Los Rios #2914 "); + lcd.locate(0,1); + lcd.printf(" y Letamendi "); + lcd.locate(0,2); + lcd.printf("apm.litoral@gmail.co"); + lcd.locate(0,3); + lcd.printf(" Cell: 0991439123 "); + wait(5); + + for(i=0; i<5; i++) { + wait(0.1); + lcd.cls(); + } + + //pc.printf("Angel D. Yaguana...\r\n"); + //pc.printf("Proyecto Datafast de la vida...\r\n"); + //pc.printf("Artista: Patricio Barberan\r\n"); + + lcd.locate(0,0); + lcd.printf(" Proyecto \"Datafast\" "); + lcd.locate(0,1); + lcd.printf(" Patricio Barberan "); + wait(2); + lcd.locate(0,3); + lcd.printf(" Iniciando... "); + wait(3); + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Conecte una memoria "); + lcd.locate(0,1); + lcd.printf("USB para ingresar la"); + lcd.locate(0,2); + lcd.printf("nueva configuracion!"); + wait(5); + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + + USBHostMSD msd("host"); + + lcd.cls(); + lcd.locate(0,1); + lcd.printf(" Buscando"); + + for(i=0; i<5; i++) { + wait(0.5); + msd.connect(); + lcd.printf("."); + } + + if(msd.connected()) { + wait(1); + lcd.printf("!"); + led1=led2=led3=led4=1; + led5=led6=led7=led8=1; + wait(1); + lcd.cls(); + lcd.locate(0,1); + lcd.printf(" USB Stick "); + lcd.locate(0,2); + lcd.printf(" encontrado! "); + wait(1); + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; -LIS302 acc(p11, p12, p13, p10); // mosi, miso, clk, ncs + if(!msd.connected()) { + lcd.printf("?"); + wait(1); + lcd.cls(); + lcd.locate(0,1); + lcd.printf(" USB Stick "); + lcd.locate(0,2); + lcd.printf(" No encontrado! "); + wait(1); + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + if(msd.connected()) { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Generando archivo de"); + lcd.locate(0,1); + lcd.printf("ayuda en menoria USB"); + wait(1); + FILE *fp1; + if ((fp1 = fopen( "/host/Manual de ayuda.rtf", "w"))!=NULL) { + fprintf(fp1,"Archivos de configuracion:");//Start:14-03-2013 08:30:00 + fprintf(fp1,"\r\n\r\nClock.txt\r\n\r\n\r\n"); + fprintf(fp1,"Contenido:\r\n\r\n"); + fprintf(fp1,"Start:14-03-2013 08:30:00\r\n"); + fprintf(fp1,"End:01-12-2013 22:30:00\r\n"); + fprintf(fp1,"Speed:80\r\n"); + fprintf(fp1,"Sense:30\r\n"); + fprintf(fp1,"Space:90\r\n"); + fprintf(fp1,"\r\nExplicacion:\r\n\r\n"); + fprintf(fp1,"Start:(Fecha de inicio) (hora de inicio diaria)\r\n"); + fprintf(fp1,"End:(Fecha de finalizacion) (hora de finalizacion diaria)\r\n"); + fprintf(fp1,"Speed:(porcentaje de velocidad de desplazamiento del cuadro)\r\n"); + fprintf(fp1,"Sense:(Intervalo en segundos entre detecciones)\r\n"); + fprintf(fp1,"Space:(Distancia entre 30 y 300 para deteccion)\r\n"); + fprintf(fp1,"\r\n\r\n\r\nTimer.txt\r\n\r\n\r\n"); + fprintf(fp1,"Contenido:\r\n\r\n"); + fprintf(fp1,"7 29-05-2013 17:35:00\r\n"); + fprintf(fp1,"\r\nExplicacion:\r\n\r\n"); + fprintf(fp1,"7:(Dia de la semana)\r\n"); + fprintf(fp1,"29-05-2013:(Fecha actual para cargar)\r\n"); + fprintf(fp1,"17:35:00:(Hora actual para cargar)\r\n"); + fprintf(fp1,"\r\nFirmware propiedad de:\r\n"); + fprintf(fp1,"Angel D. Yaguana H. & Ivan A. Sanchez\r\n"); + fprintf(fp1,"All Power Microcontroller Litoral.\r\n"); + fprintf(fp1,"Los Rios 2912 y Letamendi\r\n"); + fprintf(fp1,"Cell: 0992430921-0991439123-0989200942\r\n"); + fprintf(fp1,"Email: apm.litoral@gmail.com\r\n"); + //pc.printf("\r\nPrint Help OK\r\n"); + fclose(fp1); + lcd.locate(0,2); + lcd.printf(" Listo! "); + wait(1); + } else { + //pc.printf("\r\nPrint Help fail\r\n"); + lcd.locate(0,2); + lcd.printf(" Error! "); + wait(1); + } + + FILE *binary = fopen("/host/All Power Microcontroller Litoral.html", "w"); + while (a<=229) { + fprintf(binary,(const char *)&page[a]); + a++; + } + fclose(binary); + + FILE *octal = fopen("/host/Status Bio_Os.rtf", "w"); + while (b<=976) { + fprintf(octal,(const char *)&data_Os[b]); + b++; + } + fclose(octal); + + FILE *fp2 = fopen( "/host/Clock_ejemplo.txt", "w"); + fprintf(fp1,"Start:14-03-2013 08:30:00\r\n"); + fprintf(fp1,"End:01-12-2013 22:30:00\r\n"); + fprintf(fp1,"Speed:80\r\n"); + fprintf(fp1,"Sense:30\r\n"); + fprintf(fp1,"Space:90\r\n"); + fclose(fp1); + + FILE *fp3 = fopen( "/host/Timer_ejemplo.txt", "w"); + fprintf(fp1,"7 29-05-2013 17:35:00\r\n"); + fclose(fp1); + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + + + if(msd.connected()) { + flag_usb_1=1; + lcd.cls(); + lcd.locate(0,1); + lcd.printf(" Actualizando Reloj "); + my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); + wait(1); + FILE *fp2; + if ((fp2 = fopen( "/host/Clock.txt", "r"))!=NULL) { + fscanf(fp2,"%2d %2d-%2d-20%2d %2d:%2d:%2d",&new_day,&new_date,&new_mont,&new_year,&new_hour,&new_min,&new_sec); + lcd.locate(0,2); + lcd.printf(" Listo! "); + //pc.printf("USB Time: %2d %2d/%2d/20%2d %2d:%2d:%2d\r\n",new_day,new_date,new_mont,new_year,new_hour,new_min,new_sec); + wait(1); + + Set_Time( new_sec, new_min, new_hour, new_day, new_date, new_mont, new_year); // Set the time on the DS1307 + //pc.printf("Old Time: %2d %2d/%2d/20%2d %2d:%2d:%2d\r\n",day,date,month,year,hours,min,sec); + lcd.locate(0,0); + lcd.printf("Temporizador actual"); + lcd.locate(0,1); + lcd.printf(" %02d-%02d-%02d %02d:%02d:%02d ",date,month,year,hours,min,sec); + + my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); + //pc.printf("New Time: %2d %2d/%2d/20%2d %2d:%2d:%2d\r\n",day,date,month,year,hours,min,sec); + lcd.locate(0,2); + lcd.printf("Temporizador nuevo "); + lcd.locate(0,3); + lcd.printf(" %02d-%02d-%02d %02d:%02d:%02d ",date,month,year,hours,min,sec); + wait(5); + //pc.printf("\r\nTime Uploaded succesfully!\r\n"); + fclose(fp2); + wait(1); + } else { + my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); + //pc.printf("Time: %2d %2d-%2d-20%2d %2d:%2d:%2d\r\n",day,date,month,year,hours,min,sec); + lcd.cls(); + lcd.locate(0,2); + lcd.printf(" Error! "); + wait(1); + } + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + + if(msd.connected()) { + flag_usb_2=1; + lcd.cls(); + lcd.locate(0,0); + lcd.printf(" Configurando "); + lcd.locate(0,1); + lcd.printf(" temporizador "); + + FILE *fp2; + if ((fp2 = fopen( "/host/Timer.txt", "r"))!=NULL) { + fscanf(fp2,"Start:%2d-%2d-20%2d %2d:%2d:%2d End:%2d-%2d-20%2d %2d:%2d:%2d Speed:%d Sense:%d Space:%d",&set_start_date,&set_start_month,&set_start_year,&set_start_hour,&set_start_min,&set_start_sec,&set_end_date,&set_end_month,&set_end_year,&set_end_hour,&set_end_min,&set_end_sec,&set_speed,&set_sense,&set_space); + lcd.locate(0,1); + lcd.printf(" Listo! "); + //pc.printf( "Start:%2d/%2d/20%2d %2d:%2d:%2d End:%2d/%2d/20%2d %2d:%2d:%2d Speed:%3d Sense:%3d Space:%3d\n",set_start_date,set_start_month,set_start_year,set_start_hour,set_start_min,set_start_sec,set_end_date,set_end_month,set_end_year,set_end_hour,set_end_min,set_end_sec,set_speed,set_sense,set_space); + + my1307.write( 0x08, set_start_date); + my1307.write( 0x09, set_start_month); + my1307.write( 0x0A, set_start_year); + my1307.write( 0x0B, set_start_hour); + my1307.write( 0x0C, set_start_min); + my1307.write( 0x0D, set_start_sec); + + my1307.write( 0x0E, set_end_date); + my1307.write( 0x0F, set_end_month); + my1307.write( 0x10, set_end_year); + my1307.write( 0x11, set_end_hour); + my1307.write( 0x12, set_end_min); + my1307.write( 0x13, set_end_sec); + + my1307.write( 0x14, set_speed); + my1307.write( 0x15, set_sense); + my1307.write( 0x16, set_space); -int main() { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("F.Inicio: %02d-%02d-20%02d",set_start_date,set_start_month,set_start_year); + lcd.locate(0,1); + lcd.printf("F.Fin : %02d-%02d-20%02d",set_end_date,set_end_month,set_end_year); + lcd.locate(0,2); + lcd.printf("H.Inicio: %02d:%02d:%02d",set_start_hour,set_start_min,set_start_sec); + lcd.locate(0,3); + lcd.printf("H.Fin : %02d:%02d:%02d",set_end_hour,set_end_min,set_end_sec); + wait(5); + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Configuracion nueva"); + lcd.locate(0,1); + lcd.printf("Velocidad : %3d%",set_speed); + lcd.locate(0,2); + lcd.printf("Sencibilidad : %3d%",set_sense); + lcd.locate(0,3); + lcd.printf("Distancia max: %3d",set_space); + wait(5); + //pc.printf("\nSet Timer succesfully\n"); + fclose(fp2); + } else { + //pc.printf("Set Timer fail\n"); + lcd.cls(); + lcd.locate(0,2); + lcd.printf(" Error! "); + wait(1); + } + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Iniciando aplicacion"); + wait(2); + + read_RAM(); + + my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); + my1307.read( 0x14, &Old_Speed_RAM); + my1307.read( 0x15, &Old_sense_RAM); + my1307.read( 0x16, &Old_Space_RAM); + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + if(msd.connected()) { + FILE *fp1; + if ((fp1 = fopen( "/host/Registro.csv", "a"))!=NULL) { + fprintf(fp1,"%2d %2d/%2d/20%2d %2d:%2d:%2d %3d %3d %3d;\n",day,date,month,year,hours,min,sec,Old_Speed_RAM,Old_sense_RAM,Old_Space_RAM); + //pc.printf( "Dia:%2d Fecha:%2d/%2d/20%2d Hora:%2d:%2d:%2d Speed RAM:%3d Sense RAM:%3d Space RAM:%3d;\r\n",day,date,month,year,hours,min,sec,Old_Speed_RAM,Old_sense_RAM,Old_Space_RAM); + //pc.printf("\r\nRegistro OK\r\n"); + fclose(fp1); + } else { + //pc.printf("\r\nRegistre fail\r\n"); + //pc.printf( "Dia:%2d Fecha:%2d/%2d/20%2d Hora:%2d:%2d:%2d Speed RAM:%3d Sense RAM:%3d Space RAM:%3d;\r\n",day,date,month,year,hours,min,sec,Old_Speed_RAM,Old_sense_RAM,Old_Space_RAM); + } + lcd.cls(); + lcd.locate(0,0); + lcd.printf(" Nueva "); + lcd.locate(0,1); + lcd.printf(" configuracion "); + lcd.locate(0,2); + lcd.printf(" satisfactoria "); + wait(3); + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Por favor remueva la"); + lcd.locate(0,2); + lcd.printf(" memoria USB ahora! "); + wait(5); + } + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + + //pc.printf("\r\nRun_app Start\r\n"); + /* + PwmOut led1(LED1); + PwmOut led2(LED2); + PwmOut led3(LED3); + PwmOut led4(LED4); + */ + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + wait(0.5); + + FW=0; + RW=0; + lcd.cls(); + int lcd_reset=0; + + while(1) { +/* + if(FLAG_DOOR_OFF==1) { + FLAG_DOOR_OFF=0; + lcd.locate(0,1); + lcd.printf(" Cerrando puerta "); + wait(2); + } + + if(FLAG_DOOR_ON==1) { + FLAG_DOOR_ON=0; + lcd.locate(0,1); + lcd.printf(" Abriendo puerta "); + wait(2); + } + + if(FLAG_NEW_PASS==1) { + FLAG_NEW_PASS=0; + lcd.locate(0,1); + lcd.printf(" Nueva clave "); + wait(2); + } + + if(FLAG_PUT_PASS==1) { + FLAG_PUT_PASS=0; + lcd.locate(0,1); + lcd.printf(" Ingrese clave "); + wait(2); + } + + if(FLAG_NEW_PASS_FULL==1) { + FLAG_NEW_PASS_FULL=0; + lcd.locate(0,1); + lcd.printf(" Nueva clave "); + lcd.locate(0,2); + lcd.printf("guardada en memoria!"); + wait(2); + } +*/ + if(lcd_reset<=65535) { + if(lcd_reset==65535) { + lcd_reset=0; + TextLCD lcd(p11, p12, p13, p14, p15, p16, TextLCD::LCD20x4); // rs, e, d4-d7 + wait(0.10); + lcd.cls(); + wait(0.10); + } + } + + lcd_reset++; + + wait(0.25); + //pc.printf("\r\nObstaculo 1: %8.6fcm\n",get_Z4()); + my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); + //pc.printf("RTC: [%2d:%.2d:%2d %2d/%2d/20%2d]\n",hours,min,sec,date,month,year); + Radar=get_Z4(); + + lcd.locate(0,3); + lcd.printf("Deteccion: %3.3fcm ",Radar); + lcd.locate(0,0); + lcd.printf(" %02d-%02d-%02d %02d-%02d-%02d ",get_start_date_ram, get_start_month_ram, get_start_year_ram, get_end_date_ram,get_end_month_ram,get_end_year_ram); + lcd.locate(0,1); + lcd.printf(" %02d:%02d:%02d %02d:%02d:%02d ",get_start_hour_ram, get_start_min_ram, get_start_sec_ram,get_end_hour_ram,get_end_min_ram,get_end_sec_ram); + lcd.locate(0,2); + lcd.printf(" %02d-%02d-%02d %02d:%02d:%02d ",date,month,year,hours,min,sec); + + int time_sec_onclock = 0, time_sec_start = 0, time_sec_end = 0; + + time_sec_onclock = (hours*60*60)+(min*60)+sec; + time_sec_start = (get_start_hour_ram*60*60)+(get_start_min_ram*60)+get_start_sec_ram; + time_sec_end = (get_end_hour_ram*60*60)+(get_end_min_ram*60)+get_end_sec_ram; + + float time_day_onclock = 0,time_day_start = 0,time_day_end = 0; + + time_day_onclock = (month*30.4166)-30.4166+date; + time_day_start = (get_start_month_ram*30.4166)-30.4166+get_start_date_ram; + time_day_end = (get_end_month_ram*30.4166)-30.4166+get_end_date_ram; - FILE *fp = fopen("/fs/acc_data.csv","w"); - for (int i = 0; i < 100; i++) { - fprintf(fp,"%.2f, %.2f, %.2f\n", acc.x(),acc.y(),acc.z()); - wait(0.1); - } - fclose(fp); -} \ No newline at end of file + if(time_day_onclock<=time_day_end && time_day_onclock>=time_day_start) { + if(time_sec_onclock<time_sec_end && time_sec_onclock>time_sec_start) { + //ejecucion de sensor de obstaculos + if(Radar<=get_space_ram*1.5) { + //pc.printf("Obstaculo 2: %8.6fcm\n",Radar); + lcd.locate(0,2); + lcd.printf(" Detectando...! "); + wait(1-sense_ram_powten_3); + Radar=get_Z4(); + if(Radar<=get_space_ram) { + lcd.locate(0,2); + lcd.printf(" Desplazando cuadro "); + //pc.printf("Obstaculo 3: %8.6fcm\n",Radar); + led1=1; + led5=1; + led2=0; + led6=0; + led3=0; + led7=0; + led4=0; + led8=0; + wait(0.025); + led1=0; + led5=0; + led2=1; + led6=1; + led3=0; + led7=0; + led4=0; + led8=0; + wait(0.025); + led1=0; + led5=0; + led2=0; + led6=0; + led3=1; + led7=1; + led4=0; + led8=0; + wait(0.025); + do { + FW=1; + RW=0; + led1=0; + led5=0; + led2=0; + led6=0; + led3=0; + led7=0; + led4=1; + led8=1; + lcd.locate(0,3); + lcd.printf(">>> >>> >>> >>> >>> "); + wait(0.025); + led1=0; + led5=0; + led2=0; + led6=0; + led3=1; + led7=1; + led4=0; + led8=0; + lcd.locate(0,3); + lcd.printf(" >>> >>> >>> >>> >>>"); + wait(0.025); + led1=0; + led5=0; + led2=1; + led6=1; + led3=0; + led7=0; + led4=0; + led8=0; + lcd.locate(0,3); + lcd.printf("> >>> >>> >>> >>> >>"); + wait(0.025); + led1=1; + led5=1; + led2=0; + led6=0; + led3=0; + led7=0; + led4=0; + led8=0; + lcd.locate(0,3); + lcd.printf(">> >>> >>> >>> >>> >"); + wait(0.025); + rigth=rigth_sense.read(); + } while(rigth<1); + //pc.printf("\r\nRIGHT_______: %8.6f\n",rigth); + FW=0; + RW=0; + wait(0.025); + led1=0; + led5=0; + led2=0; + led6=0; + led3=1; + led7=1; + led4=0; + led8=0; + wait(0.025); + led1=0; + led5=0; + led2=1; + led6=1; + led3=0; + led7=0; + led4=0; + led8=0; + wait(0.025); + //wait(3-sense_ram_powten_3); + do { + FW=0; + RW=1; + led1=1; + led5=1; + led2=0; + led6=0; + led3=0; + led7=0; + led4=0; + led8=0; + lcd.locate(0,3); + lcd.printf("<<< <<< <<< <<< <<< "); + wait(0.025); + led1=0; + led5=0; + led2=0; + led6=0; + led3=0; + led7=0; + led4=1; + led8=1; + lcd.locate(0,3); + lcd.printf(" <<< <<< <<< <<< <<<"); + wait(0.025); + led1=0; + led5=0; + led2=0; + led6=0; + led3=1; + led7=1; + led4=0; + led8=0; + lcd.locate(0,3); + lcd.printf("< <<< <<< <<< <<< <<"); + wait(0.025); + led1=0; + led5=0; + led2=1; + led6=1; + led3=0; + led7=0; + led4=0; + led8=0; + lcd.locate(0,3); + lcd.printf("<< <<< <<< <<< <<< <"); + wait(0.025); + left=left_sense.read(); + } while(left<1); + //pc.printf("\r\nLEFT_______: %8.6f\n",left); + FW=0; + RW=0; + //wait(1-sense_ram_powten_3); + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + } + } + } + } + } + +} + +float get_Z4() +{ + prom=0; + cnt_Z4=0; + result=0; + for(interval=0; interval<5; interval++) { + wait(1/20); + adc = ain.read(); // read analog as a float + if(adc >= 0 && adc <= 0.508) { + cm5 = ((adc * 5)*2.54)*100; + prom=prom+(cm5-10); + cnt_Z4++; + } + } + result=prom/cnt_Z4; + //pc.printf("#:%2d P:%5.3f D:%3.3f cm\n", cnt_Z4, prom, result); + //led1=led2=led3=led4=1;led5=led6=led7=led8=1; + //wait(1/20); + return result; +} + + +void read_RAM() +{ + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Leyendo datos desde"); + lcd.locate(0,2); + lcd.printf("la memoria..."); + wait(1); + + //pc.printf("\r\nVariables leidas:\r\n"); + + my1307.read( 0x08, &get_start_date_ram); + my1307.read( 0x09, &get_start_month_ram); + my1307.read( 0x0A, &get_start_year_ram); + my1307.read( 0x0B, &get_start_hour_ram); + my1307.read( 0x0C, &get_start_min_ram); + my1307.read( 0x0D, &get_start_sec_ram); + + my1307.read( 0x0E, &get_end_date_ram); + my1307.read( 0x0F, &get_end_month_ram); + my1307.read( 0x10, &get_end_year_ram); + my1307.read( 0x11, &get_end_hour_ram); + my1307.read( 0x12, &get_end_min_ram); + my1307.read( 0x13, &get_end_sec_ram); + + my1307.read( 0x14, &get_speed_ram); + my1307.read( 0x15, &get_sense_ram); + my1307.read( 0x16, &get_space_ram); + + //pc.printf( "Start:%2d/%2d/20%2d %2d:%2d:%2d \r\nEnd:%2d/%2d/20%2d %2d:%2d:%2d \r\nSpeed:%3d \r\nSense:%3d \r\nSpace:%3d\r\n",get_start_date_ram,get_start_month_ram,get_start_year_ram,get_start_hour_ram,get_start_min_ram,get_start_sec_ram,get_end_date_ram,get_end_month_ram,get_end_year_ram,get_end_hour_ram,get_end_min_ram,get_end_sec_ram,get_speed_ram,get_sense_ram,get_space_ram); + if(flag_usb_1 == 0 && flag_usb_2 ==0) { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("F.Inicio: %02d-%02d-20%02d",get_start_date_ram,get_start_month_ram,get_start_year_ram); + lcd.locate(0,1); + lcd.printf("F.Fin : %02d-%02d-20%02d",get_end_date_ram,get_end_month_ram,get_end_year_ram); + lcd.locate(0,2); + lcd.printf("H.Inicio: %02d:%02d:%02d",get_start_hour_ram,get_start_min_ram,get_start_sec_ram); + lcd.locate(0,3); + lcd.printf("H.Fin : %02d:%02d:%02d",get_end_hour_ram,get_end_min_ram,get_end_sec_ram); + wait(5); + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Configuracion actual"); + lcd.locate(0,1); + lcd.printf("Velocidad : %3d%",get_speed_ram); + lcd.locate(0,2); + lcd.printf("Sencibilidad : %3d%",get_sense_ram); + lcd.locate(0,3); + lcd.printf("Distancia max: %3d",get_space_ram); + wait(5); + } + if (get_speed_ram<100) { + speed_ram_powten_3 = get_speed_ram%100; + speed_ram_powten_3 = speed_ram_powten_3/100; + } else + speed_ram_powten_3 = get_speed_ram/get_speed_ram; + + if (get_sense_ram<100) { + sense_ram_powten_3 = get_sense_ram%100; + sense_ram_powten_3 = sense_ram_powten_3/100; + } else + sense_ram_powten_3 = get_sense_ram/get_sense_ram; + + //pc.printf("\r\nSpeed result: %f\r\n",speed_ram_powten_3); + //pc.printf("Sense result: %f\r\n",sense_ram_powten_3); + //pc.printf("Space result: %d\r\n",get_space_ram); + //pc.printf("/******************************************************************************************************************/\r\n"); +} + + +void Set_Time(int set_sec, int set_min, int set_hours, int set_day, int set_date, int set_month, int set_year) +{ + my1307.twentyfour_hour(); + my1307.settime( set_sec, set_min, set_hours, set_day, set_date, set_month, set_year); // Set the time on the DS1307 + my1307.write(0x07,0x10); +} + + + +uint32_t cbAfterInput(uint32_t index) +{ + //lcd.printf("TEST\n"); + ////pc.printf("Indice: %d\n", index); + ////pc.printf("Tecla: %c\n", Keytable[index]); + //led3!=led3; + + if (index == 12 || cnt>=5) { + ////pc.printf("cnt:%i\n",cnt); + if(cnt==5) { + FLAG_NEW_PASS=1; + } + led1=1; + led5=1; //Show that we are alive + wait(0.5); + led1=0; + led5=0; + cnt++; + if (cnt>=7 && j<=6) { + ////pc.printf("Index2:%d ===> Key2:%c\n", index, Keytable[index]); + j++; + my1307.write( 24+j, index); + led2=1; + led6=1; //Show that we are alive + wait(0.2); + led2=0; + led6=0; + + my1307.read( 24+j, &key); + ////pc.printf("J:%d, Key EEprom:%d, cnt:%i\n",j, key,cnt); + + if(j==6) { + FLAG_NEW_PASS_FULL=1; + ////pc.printf("New Pass was completed\n"); + j=0; + cnt=1; + led1=led2=led3=led4=1; + led5=led6=led7=led8=1; + wait(3); + led1=led2=led3=led4=0; + led5=led6=led7=led8=0; + + } + } + } else if (index == 14 || pass>0) { + FLAG_PUT_PASS=1; + ////pc.printf("index:%i, pass:%i\n", index,pass); + led1=1; + led5=1; //Show that we are alive + wait(0.5); + led1=0; + led5=0; + pass++; + if (pass>1 && l<=6) { + data[pass-2]= index; + ////pc.printf("J:%d, data[%d] = %d;\n", l, pass-2, index); + led2=1; + led6=1; //Show that we are alive + wait(0.2); + led2=0; + led6=0; + + l++; + if(l==6) { + ////pc.printf("Pass was completed\n"); + l=0; + pass=0; + //comprobar clave + my1307.read( 25, &key0); + my1307.read( 26, &key1); + my1307.read( 27, &key2); + my1307.read( 28, &key3); + my1307.read( 29, &key4); + my1307.read( 30, &key5); + + if(data[0]==key0 && data[1]==key1 && data[2]==key2 && data[3]==key3 && data[4]==key4 && data[5]==key5) { + led1=led3=1; + led5=led7=1; + door_off = 1; + wait(1.200); + door_off = 0; + FLAG_DOOR_OFF=1; + ////pc.printf("Door OPEN\n"); + wait(2); + led1=led3=0; + led5=led7=0; + } else { + led2=led4=1; + led6=led8=1; + door_on = 1; + wait(1.200); + door_on = 0; + FLAG_DOOR_ON=1; + ////pc.printf("Door Closed\n"); + wait(2); + led2=led4=0; + led6=led8=0; + } + } + } + } + + return 0; +}
diff -r 144fed3d9420 -r 4daed536a970 mbed.bld --- a/mbed.bld Sat Mar 13 17:19:08 2010 +0000 +++ b/mbed.bld Tue Sep 17 01:37:10 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0 +http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b \ No newline at end of file