Пример #1
0
void  Main_Copy (void)
{
    USB_INT32S  fdr;
    USB_INT32S  fdw;
    USB_INT32U  bytes_read;


    fdr = FILE_Open(FILENAME_R, RDONLY);
    if (fdr > 0) {
        fdw = FILE_Open(FILENAME_W, RDWR);
        if (fdw > 0) {
            PRINT_Log("Copying from %s to %s...\n", FILENAME_R, FILENAME_W);
            do {
                bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
                FILE_Write(fdw, UserBuffer, bytes_read);
            } while (bytes_read);
            FILE_Close(fdw);
        } else {
            PRINT_Log("Could not open file %s\n", FILENAME_W);
            return;
        }
        FILE_Close(fdr);
        PRINT_Log("Copy completed\n");
    } else {
        PRINT_Log("Could not open file %s\n", FILENAME_R);
        return;
    }
}
Пример #2
0
void  Main_Write (void)
{
    USB_INT32S  fdw;
    USB_INT32S  fdr;
    USB_INT32U  tot_bytes_written;
    USB_INT32U  bytes_written;


    fdr = FILE_Open(FILENAME_R, RDONLY);
    if (fdr > 0) {
        FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
        fdw = FILE_Open(FILENAME_W, RDWR);
        if (fdw > 0) {
            tot_bytes_written = 0;
            PRINT_Log("Writing to %s...\n", FILENAME_W);
            do {
                bytes_written = FILE_Write(fdw, UserBuffer, MAX_BUFFER_SIZE);
                tot_bytes_written += bytes_written;
            } while (tot_bytes_written < WRITE_SIZE);
            FILE_Close(fdw);
            PRINT_Log("Write completed\n");
        } else {
            PRINT_Log("Could not open file %s\n", FILENAME_W);
            return;
        }
        FILE_Close(fdr);
    } else {
        PRINT_Log("Could not open file %s\n", FILENAME_R);
        return;
    }
}
Пример #3
0
DSTATUS disk_initialize (
	BYTE drv				/* Physical drive nmuber (0..) */
)
{
	DSTATUS stat = STA_NOINIT;
	int result;
	PRINT_Log("disk_initialize for disk %x \n\r",drv);

	switch (drv) {
	case ATA :
		//result = ATA_disk_initialize();
		// translate the reslut code here

		return stat;

	case MMC :
		result = MMC_disk_initialize(0);
		// translate the reslut code here
		stat = RES_OK ;
		driveAttached = TRUE ;
		return stat;

	case USB :
		result = USB_disk_initialize();
		// translate the reslut code here
		stat = RES_OK ;
		driveAttached = TRUE ;
		return stat;
	}
	PRINT_Log("disk_initialize return problem");
	return STA_NOINIT;
}
Пример #4
0
void USB_IRQHandler (void)
{
    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_TDControlStatus = (TDHead->Control >> 28) & 0xf;
            HOST_WdhIntr = 1;
        }            
        LPC_USB->HcInterruptStatus = int_status;                         /* Clear interrupt status register      */
    }
Пример #5
0
void  Main_Read (void)
{
    USB_INT32S  fdr;
    USB_INT32U  bytes_read;
    

    fdr = FILE_Open(FILENAME_R, RDONLY);
    if (fdr > 0) {
        PRINT_Log("Reading from %s...\n", FILENAME_R);
        do {
            bytes_read = FILE_Read(fdr, UserBuffer, MAX_BUFFER_SIZE);
        } while (bytes_read);

        FILE_Close(fdr);
        PRINT_Log("Read Complete\n");
    } else {
        PRINT_Log("Could not open file %s\n", FILENAME_R);
        return;
    }
}
Пример #6
0
void vZigbeeTask( void *pvParameters )
{
	uint8_t output[100] ;
	uint8_t length = 0 ;

	PRINT_Log("vZigbeeTask Starting");
	//quick check to see if we have communication or not
	UART_Init_Zigbee(9600);
	
	//lets try to read the version number of the Zigbee

	//wait for one second
	vTaskDelay(1000);
	PRINT_Log("vZigbeeTask Sending +++\n");
	//UART_Printf_Zigbee("+++");
	UART_PrintChar_Zigbee('+');
	vTaskDelay(50);
	UART_PrintChar_Zigbee('+');
	vTaskDelay(50);
	UART_PrintChar_Zigbee('+');

	vTaskDelay(2000);
	length = UARTReceive_Zigbee(LPC_UART3, output, sizeof(output));
	PRINT_Log("Zigbee Message with length %d \n",length);
	if (length == 0)
	{
		UART_PrintChar_Zigbee('+');
		vTaskDelay(50);
		UART_PrintChar_Zigbee('+');
		vTaskDelay(50);
		UART_PrintChar_Zigbee('+');
		//check the ok
		length = UARTReceive_Zigbee(LPC_UART3, output, sizeof(output));

	}

	if(length != 0)
	{
		output[length] = '\0';
		PRINT_Log("Zigbee Message with length %d and content %s\n",length,output);
	}
	PRINT_Log("vZigbeeTask Sending ATVR command to check version number\n");
	//read response
	UART_Printf_Zigbee("ATVL\n");
	length = 0;
	vTaskDelay(100);
	length = UARTReceive_Zigbee(LPC_UART3, output, sizeof(output));

	output[length] = '\0';

	PRINT_Log("Zigbee Message with length %d and content %s\n",length,output);
	//
	while(1)
	{
	    vTaskDelay(100);

	}

    return ;
}
Пример #7
0
/*********************************************************************//**
 * @brief 			This function is the main function where the execution begins
 * @param[in]		None
 * @return 		    None
 **********************************************************************/
int main()
{
    int32_t  rc;
    uint32_t  numBlks, blkSize;	
		uint8_t buffer[30];
		UINT nun;
    uint8_t  inquiryResult[INQUIRY_LENGTH];
		FATFS fs;
	   FIL fsrc, fdst;
  
		const TCHAR  a=1;
  
		  SystemInit();
	  debug_frmwrk_init();
			print_menu();
		
    Host_Init();               /* Initialize the lpc17xx host controller                                    */

    PRINT_Log("Host Initialized\r\n");
    PRINT_Log("Connect a Mass Storage device\r\n");
    rc = Host_EnumDev();       /* Enumerate the device connected                                            */
		 PRINT_Log("Á¬½ÓÉ豸\r\n");
    if ((rc == USB_HOST_FUNC_OK) && (Host_GetDeviceType() == MASS_STORAGE_DEVICE))
			{
					
					PRINT_Log("Mass Storage device connected\r\n");

				rc = 	f_mount(&fs,"0:",1);  
				if(rc==0)
				{
					  rc = f_open(&fdst, "0:read.txt", FA_READ);
					if(rc==0)
					{
						PRINT_Log("open ok\r\n");
						f_read (&fdst,   buffer, 30, &nun );
						PRINT_Log(buffer);
						f_close(&fdst);
					}
				}
    
    } 
		else {
	    PRINT_Log("Not a Mass Storage device\n");							
        return (0);
    }


   return 0;
}
Пример #8
0
/*
**************************************************************************************************************
*                                         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");
}
Пример #9
0
int32_t  MS_ParseConfiguration (void)
{
    volatile  uint8_t  *desc_ptr;
              uint8_t   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])) {
//  while (desc_ptr != TDBuffer + *((uint16_t *) &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\r\n");
        return (OK);
    } else {
        PRINT_Log("Not a Mass Storage device\r\n");
        return (ERR_NO_MS_INTERFACE);
    }
}
Пример #10
0
/*
 * This function is called whenever an uIP event occurs (e.g. when
 * a new connection is established, new data arrives, sent data is
 * acknowledged, data needs to be retransmitted, etc.), from the 
 * uip_tcp_appcall() callback.
 */
void ftpd_appcall( void )
{


    u16_t i;

    //PRINT_Log("\r\nftpd_appcall\r\n");

    /*
     * First we must check that it is the port we are listening on as
     * this function will be called for all events on all connections.
     */
    if (uip_conn->lport == HTONS(FTPD_CONTROL_PORT))
    {

    	ftpd_appstate_t *s = (ftpd_appstate_t *)uip_conn->appdata;
        /*
         * If a new connection we need to check for a few possibilities.
         */
        if (uip_connected())
        {
        	PRINT_Log("\r\nNew command connection from IP Address %d.%d.%d.%d:%d",
                   uip_ipaddr1(uip_conn->ripaddr), uip_ipaddr2(uip_conn->ripaddr),
                   uip_ipaddr3(uip_conn->ripaddr), uip_ipaddr4(uip_conn->ripaddr),
                   ntohs(uip_conn->rport));


            if (!driveAttached)
            {
            	PRINT_Log("\r\nNo drive attached!");
                // Initialise the ProtoSocket for the 421 message
                PSOCK_INIT(&s->ps, NULL, 0);
                // Set the flag to cause it to be sent
                s->resp421_flag = TRUE;
            }
            else
            {
                // find a new FTP server structure
                for (i = 0; i < NUM_FTP_DAEMONS; i++)
                {
                    if (FTP_UNUSED == ftpd_state[i].state)
                    {
                        break;
                    }
                }
                
                // Check if we found a free ftpd_state
                if (NUM_FTP_DAEMONS == i)
                {
                	PRINT_Log("\r\nNo daemons available!");
                    // Initialise the ProtoSocket for the 421 message
                    PSOCK_INIT(&s->ps, NULL, 0);
                    // Set the flag to cause it to be sent
                    s->resp421_flag = TRUE;
                }
                else
                {
                	PRINT_Log("\r\nFound unused deamon %d", i);
                    s->ftpd_state_ptr = &ftpd_state[i];
                    // Initialise the FTP Daemon state
                    ftpd_state[i].state = LOGGED_OUT;
                    ftpd_state[i].data_conn = NULL;
                    //ftpd_state[i].clientip = uip_conn->ripaddr;
                    memcpy(ftpd_state[i].clientip,uip_conn->ripaddr,sizeof(uip_ipaddr_t));
                    ftpd_state[i].clientport = FTPC_DATA_PORT;
                    // Clear the command index down
                    ftpd_state[i].cmd_index = CMD_INDEX_IDLE;
                    // Reset the directory pointer
                    //ftpd_state[i].pCurrent_dir = NULL;
                    // Clear the current path
                    strcpy(ftpd_state[i].Current_path, "/");
                    // Setup the PASV information
                    ftpd_state[i].pasvflag = FALSE;
                    
                    // Initialise the ProtoSockets and ProtoThread used by the command parser
                    PSOCK_INIT(&ftpd_state[i].cmdpsin, ftpd_state[i].cmdinputbuffer, CMD_BUFFER_SIZE);
                    PT_INIT(&ftpd_state[i].cmdpt);
                    // Clear the 421 response flag
                    s->resp421_flag = FALSE;
                }
            }
        }
        else if (uip_closed() || uip_aborted() || uip_timedout())
        {
        	PRINT_Log("\r\nCommand connection closing");
            if (s->ftpd_state_ptr)
            {
            	PRINT_Log(" for daemon %d", s->ftpd_state_ptr->pasvport - PASV_PORT_OFFSET);
                // Free up the FTP daemon
                s->ftpd_state_ptr->state = FTP_UNUSED;
                s->ftpd_state_ptr = NULL;
            }
        }
      
        if (s->resp421_flag)
        {
            send_421_response(s);
        }
        else if (s->ftpd_state_ptr)
        {
            handle_cmd_input(s->ftpd_state_ptr);
            handle_cmd_output(s->ftpd_state_ptr);
        }
    }
    else
    {
    	//PRINT_Log("\r\nSearch though all the FTPD Structures and see if this one of our data connections.");
        /* 
         * Search though all the FTPD Structures and see if this one of our data connections.
         */
        u16_t i;
        for (i = 0; i < NUM_FTP_DAEMONS; i++)
        {
            if (ftpd_state[i].data_conn == uip_conn)
            {
                if (uip_connected())
                {
                	PRINT_Log("\r\nNew active data connection for daemon %d to IP Address %d.%d.%d.%d:%d", i,
                           uip_ipaddr1(uip_conn->ripaddr), uip_ipaddr2(uip_conn->ripaddr),
                           uip_ipaddr3(uip_conn->ripaddr), uip_ipaddr4(uip_conn->ripaddr),
                           ntohs(uip_conn->rport));
                    PSOCK_INIT(&ftpd_state[i].dataps, ftpd_state[i].datainputbuffer, DATA_BUFFER_SIZE);
                    // Move the state on as required
                    if (WAITING_FOR_CONNECT == ftpd_state[i].state)
                    {
                        ftpd_state[i].state = CONNECT_OK;
                    }
                }
                else if (uip_closed() || uip_aborted() || uip_timedout())
                {
                	PRINT_Log("\r\nData connection closing for daemon %d", i);
                    if (uip_closed() && (TRANSFER_RECV == ftpd_state[i].state))
                    {
                        // There may be data in this last packet
                        handle_data_connection(&ftpd_state[i]);
                        // Closing of the connection in a RECV state indicates end of file
#if 1
                        CloseFile(&ftpd_state[i]);

#endif
                        //close the file in here

                        PRINT_Log("\r\nFinished file receive for daemon %d", i);
                        ftpd_state[i].state = TRANSFER_DONE;
                    }
                    else if((TRANSFER_LIST == ftpd_state[i].state) || (TRANSFER_SEND == ftpd_state[i].state) || (TRANSFER_RECV == ftpd_state[i].state))
                    {
                    	PRINT_Log("\r\nAborting data transfer for daemon %d", i);
                        ftpd_state[i].state = TRANSFER_ABORT;
                    }
                    ftpd_state[i].data_conn = NULL;
                }
                
                if (ftpd_state[i].data_conn)
                {
                    handle_data_connection(&ftpd_state[i]);
                }
                // Leave the loop early
                break;
            }
            else
            {
                // Check for a new connection in Passive mode
                if(ftpd_state[i].pasvflag && uip_connected() && (ntohs(uip_conn->lport) == ftpd_state[i].pasvport))
                {
                	PRINT_Log("\r\nNew passive data connection for daemon %d from IP Address %d.%d.%d.%d:%d", i,
                           uip_ipaddr1(uip_conn->ripaddr), uip_ipaddr2(uip_conn->ripaddr),
                           uip_ipaddr3(uip_conn->ripaddr), uip_ipaddr4(uip_conn->ripaddr),
                           ntohs(uip_conn->rport));
                    ftpd_state[i].data_conn = uip_conn;
                    PSOCK_INIT(&ftpd_state[i].dataps, ftpd_state[i].datainputbuffer, DATA_BUFFER_SIZE);
                    // Move the state on as required
                    if (WAITING_FOR_CONNECT == ftpd_state[i].state)
                    {
                        ftpd_state[i].state = CONNECT_OK;
                    }
                    handle_data_connection(&ftpd_state[i]);
                    // Leave the loop early
                    break;
                }
            }
        }
    }
}