Ejemplo n.º 1
0
static void acm_received(uint32_t _tkn, int32_t _amt)
{
	if(acm_file_ptr != NULL && acm_file_recv_left > 0)
	{
		if(_amt >= acm_file_recv_left)
		{
			memcpy(acm_file_ptr, acm_recv_buffer, acm_file_recv_left);

			bufferPrintf("ACM: Received file (finished at 0x%08x)!\n", acm_file_ptr + acm_file_recv_left);

			acm_busy = FALSE;

			acm_file_ptr = NULL;
			acm_file_recv_left = 0;
			usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps);
			return;
		}
		else
		{

			memcpy(acm_file_ptr, acm_recv_buffer, _amt);
			acm_file_ptr += _amt;
			acm_file_recv_left -= _amt;
			//bufferPrintf("ACM: Got %d of file (%d remain).\n", _amt, acm_file_recv_left);

			usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps);
			return;
		}
	}

	task_start(&acm_parse_task, &acm_parse, (void*)_amt);
}
Ejemplo n.º 2
0
static void acm_started()
{
	acm_is_ready = 0;

	if(usb_get_speed() == USBHighSpeed)
		acm_usb_mps = 512;
	else
		acm_usb_mps = 0x80;

	usb_enable_endpoint(ACM_EP_SEND, USBIn, USBBulk, acm_usb_mps);
	usb_enable_endpoint(ACM_EP_RECV, USBOut, USBBulk, acm_usb_mps);

	acm_busy = FALSE;
	acm_file_ptr = NULL;
	acm_file_recv_left = 0;
	acm_file_send_left = 0;
	acm_unprocessed = 0;

	usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps);

	acm_send();
	acm_is_ready = 1;

	bufferPrintf("ACM: Ready.\n");
}
Ejemplo n.º 3
0
static void acm_parse(int32_t _amt)
{
	int i = 0;
	char **argv;
	int argc;
	char scratch[ACM_BUFFER_SIZE];

	for(; i < _amt; i++)
	{
		if(acm_recv_buffer[i] == '\n'
				|| acm_recv_buffer[i] == '\r')
		{
			_amt = i;
			break;
		}
	}

	acm_recv_buffer[_amt] = 0;

	memcpy(scratch, acm_recv_buffer, _amt+1);
	argv = command_parse(scratch, &argc);

	if(argc >= 3 && strcmp(argv[0], "sendfile") == 0)
	{
		acm_busy = TRUE;

		acm_file_ptr = (char*)parseNumber(argv[1]);
		acm_file_recv_left = parseNumber(argv[2]);
		received_file_size = acm_file_recv_left;
		bufferPrintf("ACM: Started receiving file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_recv_left, acm_file_recv_left);
	}
	else if(argc >= 3 && strcmp(argv[0], "recvfile") == 0)
	{
		acm_busy = TRUE;

		acm_file_ptr = (char*)parseNumber(argv[1]);
		acm_file_send_left = parseNumber(argv[2]);

		bufferPrintf("ACM: Started sending file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_send_left, acm_file_send_left);

		int amt = sprintf(acm_send_buffer, "ACM: Starting File: %d %d\n", (uint32_t)acm_file_ptr, acm_file_send_left);
		usb_send_bulk(ACM_EP_SEND, acm_send_buffer, amt);
	}
	else
	{
		bufferPrintf("ACM: Starting %s\n", acm_recv_buffer);
		if(command_run(argc, argv) == 0)
			bufferPrintf("ACM: Done: %s\n", acm_recv_buffer);
		else
			bufferPrintf("ACM: Unknown command: %s\n", argv[0]);
	}

	free(argv);

	EnterCriticalSection(); // Deliberately unended.
	usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps);
	task_stop();
}
Ejemplo n.º 4
0
static void controlReceived(uint32_t token) {
	OpenIBootCmd* cmd = (OpenIBootCmd*)controlRecvBuffer;
	OpenIBootCmd* reply = (OpenIBootCmd*)controlSendBuffer;

	if(cmd->command == OPENIBOOTCMD_DUMPBUFFER) {
		int length;

		if(sendFileBytesLeft > 0) {
			length = sendFileBytesLeft;
		} else {
			length = getScrollbackLen(); // getScrollbackLen();// USB_BYTES_AT_A_TIME;
		}

		reply->command = OPENIBOOTCMD_DUMPBUFFER_LEN;
		reply->dataLen = length;
		usb_send_interrupt(3, controlSendBuffer, sizeof(OpenIBootCmd));
		//uartPrintf("got dumpbuffer cmd, returning length: %d\r\n", length);
	} else if(cmd->command == OPENIBOOTCMD_DUMPBUFFER_GOAHEAD) {
		left = cmd->dataLen;

		//uartPrintf("got dumpbuffer goahead, writing length: %d\r\n", (int)left);

		size_t toRead = (left > USB_BYTES_AT_A_TIME) ? USB_BYTES_AT_A_TIME: left;
		if(sendFileBytesLeft > 0) {
			usb_send_bulk(1, sendFilePtr, toRead);
			sendFilePtr += toRead;
			sendFileBytesLeft -= toRead;
			if(sendFileBytesLeft == 0) {
				bufferPrintf("file sent.\r\n");
			}
		} else {
			bufferFlush((char*) dataSendBuffer, toRead);
			usb_send_bulk(1, dataSendBuffer, toRead);
		}
		left -= toRead;
	} else if(cmd->command == OPENIBOOTCMD_SENDCOMMAND) {
		dataRecvPtr = dataRecvBuffer;
		rxLeft = cmd->dataLen;
		lastRxLen = rxLeft;

		//uartPrintf("got sendcommand, receiving length: %d\r\n", (int)rxLeft);

		reply->command = OPENIBOOTCMD_SENDCOMMAND_GOAHEAD;
		reply->dataLen = cmd->dataLen;
		usb_send_interrupt(3, controlSendBuffer, sizeof(OpenIBootCmd));

		size_t toRead = (rxLeft > USB_BYTES_AT_A_TIME) ? USB_BYTES_AT_A_TIME: rxLeft;
		usb_receive_bulk(2, dataRecvPtr, toRead);
		rxLeft -= toRead;
		dataRecvPtr += toRead;
	}

	usb_receive_interrupt(4, controlRecvBuffer, sizeof(OpenIBootCmd));
}
Ejemplo n.º 5
0
static void dataReceived(uint32_t token) {
	//uartPrintf("receiving remainder: %d\r\n", (int)rxLeft);
	if(rxLeft > 0) {
		size_t toRead = (rxLeft > USB_BYTES_AT_A_TIME) ? USB_BYTES_AT_A_TIME: rxLeft;
		usb_receive_bulk(2, dataRecvPtr, toRead);
		rxLeft -= toRead;
		dataRecvPtr += toRead;
	} else {
		*dataRecvPtr = '\0';
		addToCommandQueue((char*)dataRecvBuffer);
	}
}
Ejemplo n.º 6
0
static void acm_parse(int32_t _amt)
{
	int start = 0;
	int i = 0;

	if(acm_file_ptr != NULL && acm_file_recv_left > 0)
	{
		if(_amt >= acm_file_recv_left)
		{
			memcpy(acm_file_ptr, acm_recv_buffer, acm_file_recv_left);
			i = acm_file_recv_left;
			start = i;

			bufferPrintf("ACM: Received file (finished at 0x%08x)!\n", acm_file_ptr + acm_file_recv_left);

			acm_file_ptr = NULL;
			acm_file_recv_left = 0;
		}
		else
		{

			memcpy(acm_file_ptr, acm_recv_buffer, _amt);
			acm_file_ptr += _amt;
			acm_file_recv_left -= _amt;
			//bufferPrintf("ACM: Got %d of file (%d remain).\n", _amt, acm_file_recv_left);

			EnterCriticalSection(); // Deliberately unended.
			usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps);
			return;
		}
	}

	for(; i < _amt; i++)
	{
		if(acm_recv_buffer[i] == '\n')
		{
			acm_recv_buffer[i] = 0;
			if(i > 0)
				if(acm_recv_buffer[i-1] == '\r')
					acm_recv_buffer[i-1] = 0;

			char safeCommand[ACM_BUFFER_SIZE];
			char *command = &acm_recv_buffer[start];
			strcpy(safeCommand, command);
			int argc;
			char** argv = command_parse(command, &argc);

			if(argc >= 3 && strcmp(argv[0], "sendfile") == 0)
			{
				acm_file_ptr = (char*)parseNumber(argv[1]);
				acm_file_recv_left = parseNumber(argv[2]);
				received_file_size = acm_file_recv_left;
				bufferPrintf("ACM: Started receiving file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_recv_left, acm_file_recv_left);
				i = _amt;
				start = i;
			}
			else if(argc >= 3 && strcmp(argv[0], "recvfile") == 0)
			{
				acm_busy = TRUE;

				acm_file_ptr = (char*)parseNumber(argv[1]);
				acm_file_send_left = parseNumber(argv[2]);

				bufferPrintf("ACM: Started sending file at 0x%08x - 0x%08x (%d bytes).\n", acm_file_ptr, acm_file_ptr + acm_file_send_left, acm_file_send_left);

				int amt = sprintf(acm_send_buffer, "ACM: Starting File: %d %d\n", (uint32_t)acm_file_ptr, acm_file_send_left);
				usb_send_bulk(ACM_EP_SEND, acm_send_buffer, amt+1);

				i = _amt;
				start = i;
			}
			else
			{
				bufferPrintf("ACM: Starting %s\n", safeCommand);
				if(command_run(argc, argv) == 0)
					bufferPrintf("ACM: Done: %s\n", safeCommand);
				else
					bufferPrintf("ACM: Unknown command: %s\n", command);
				
				start = i+1;
			}

			free(argv);
		}
	}

	EnterCriticalSection(); // Deliberately unended.

	if(start < _amt)
	{
		if(acm_unprocessed > 0)
		{
			bufferPrintf("ACM: command too long, discarding...\n");
			acm_unprocessed = 0;
			usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer, acm_usb_mps);
			task_stop();
			return;
		}
		else
			memcpy(acm_recv_buffer, acm_recv_buffer+start, _amt-start);
	}

	acm_unprocessed = _amt-start;
	usb_receive_bulk(ACM_EP_RECV, acm_recv_buffer+acm_unprocessed, acm_usb_mps);
	task_stop();
}