<commit_before>#include <board.h>
#include <armv7m/nvic.h>
#include <mach/rcc-stm32.h>
#include <mach/pio-stm32.h>
#include <mach/usb-stm32.h>
#include <errno.h>
#include <fdtparse.h>
#include <drv/device.h>
#include <init.h>
#include <string.h>
#include <kernel/printk.h>
#include <kernel/ksem.h>
#include <drv/irq.h>
#include <mm/mm.h>
#include <drv/usb.h>

extern uint32_t USBD_OTG_ISR_Handler(USB_OTG_CORE_HANDLE *pdev);

static int stm32_usb_write(struct usb_device *usbdev, unsigned char *buff, unsigned int len)
{
	int ret = len;

	struct usb_pdata *pdata = usbdev->priv;

	DCD_EP_Tx(&pdata->USB_OTG_dev, CDC_IN_EP, buff, len);

	return ret;
}

static int stm32_usb_read(struct usb_device *usbdev, unsigned char *buff, unsigned int len)
{
	int ret = 0;
	struct usb_pdata *pdata = usbdev->priv;
	unsigned char tmp[64]; // min usb packet size

	if (len < 64)
		pdata->user_buffer = tmp;
	else
		pdata->user_buffer = buff;

	DCD_EP_PrepareRx(&pdata->USB_OTG_dev, CDC_OUT_EP, pdata->user_buffer, len);

	ksem_wait(&pdata->acknoledge);
		
	if(pdata->abort)
	{
		ret = 0;
	}
	else
	{
		if (len < 64)
			memcpy(buff, tmp, len);

		ret = pdata->len;
		pdata->len = 0;
	}
	
	pdata->abort = 0;

	return ret;
}

static void stm32_usb_isr(void *arg)
{
	struct usb_pdata *pdata = (struct usb_pdata *)arg;

	USBD_OTG_ISR_Handler(&pdata->USB_OTG_dev);
}

unsigned short VCP_DataRx(struct usb_pdata *pdata, unsigned char *buff, unsigned int len)
{
	if(pdata->user_buffer) {
		pdata->user_buffer = 0;
		pdata->len = len;
		ksem_post(&pdata->acknoledge);
	}

	return USBD_OK;
}

struct usb_operations usb_ops = {
	.write = stm32_usb_write,
	.read = stm32_usb_read,
};

static int stm32_usb_of_init(struct usb_device *usb)
{
	int offset;
	int ret = 0;
	const void *fdt_blob = fdtparse_get_blob();

	offset = fdt_path_offset(fdt_blob, usb->dev.of_path);<commit_msg>mach-stm32: usb: remove logic relative to min packet sizeof 64<commit_after>#include <board.h>
#include <armv7m/nvic.h>
#include <mach/rcc-stm32.h>
#include <mach/pio-stm32.h>
#include <mach/usb-stm32.h>
#include <errno.h>
#include <fdtparse.h>
#include <drv/device.h>
#include <init.h>
#include <string.h>
#include <kernel/printk.h>
#include <kernel/ksem.h>
#include <drv/irq.h>
#include <mm/mm.h>
#include <drv/usb.h>

extern uint32_t USBD_OTG_ISR_Handler(USB_OTG_CORE_HANDLE *pdev);

static int stm32_usb_write(struct usb_device *usbdev, unsigned char *buff, unsigned int len)
{
	int ret = len;

	struct usb_pdata *pdata = usbdev->priv;

	DCD_EP_Tx(&pdata->USB_OTG_dev, CDC_IN_EP, buff, len);

	return ret;
}

static int stm32_usb_read(struct usb_device *usbdev, unsigned char *buff, unsigned int len)
{
	int ret = 0;
	struct usb_pdata *pdata = usbdev->priv;

	pdata->user_buffer = buff;

	DCD_EP_PrepareRx(&pdata->USB_OTG_dev, CDC_OUT_EP, pdata->user_buffer, len);

	ksem_wait(&pdata->acknoledge);
		
	if(pdata->abort)
	{
		ret = 0;
	}
	else
	{
		ret = pdata->len;
		pdata->len = 0;
	}
	
	pdata->abort = 0;

	return ret;
}

static void stm32_usb_isr(void *arg)
{
	struct usb_pdata *pdata = (struct usb_pdata *)arg;

	USBD_OTG_ISR_Handler(&pdata->USB_OTG_dev);
}

unsigned short VCP_DataRx(struct usb_pdata *pdata, unsigned char *buff, unsigned int len)
{
	if(pdata->user_buffer) {
		pdata->user_buffer = NULL;
		pdata->len = len;
		ksem_post_isr(&pdata->acknoledge);
	}

	return USBD_OK;
}

struct usb_operations usb_ops = {
	.write = stm32_usb_write,
	.read = stm32_usb_read,
};

static int stm32_usb_of_init(struct usb_device *usb)
{
	int offset;
	int ret = 0;
	const void *fdt_blob = fdtparse_get_blob();

	offset = fdt_path_offset(fdt_blob, usb->dev.of_path);
{'fraction_non_alphanumeric': 0.1389886709035645, 'fraction_numerical': 0.017408123791102514, 'mean_word_length': 4.700787401574803, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3803018', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1554, 'n_words': 325}