1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: usb_host.c
* Date: 2022-07-22 13:57:42
* LastEditTime: 2022-07-22 13:57:43
* Description: This files is for cherry usb host function implementation
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 zhugengyu 2022/9/20 init commit
*/
/***************************** Include Files *********************************/
#include <stdio.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "ft_assert.h"
#include "interrupt.h"
#include "cpu_info.h"
#include "ft_debug.h"
#include "cache.h"
#include "usbh_core.h"
#include "fmemory_pool.h"
/************************** Constant Definitions *****************************/
#define FUSB_MEMP_TOTAL_SIZE SZ_1M
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
static FMemp memp;
static u8 memp_buf[FUSB_MEMP_TOTAL_SIZE];
/***************** Macros (Inline Functions) Definitions *********************/
#define FUSB_DEBUG_TAG "USB-HC"
#define FUSB_ERROR(format, ...) FT_DEBUG_PRINT_E(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
#define FUSB_WARN(format, ...) FT_DEBUG_PRINT_W(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
#define FUSB_INFO(format, ...) FT_DEBUG_PRINT_I(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
#define FUSB_DEBUG(format, ...) FT_DEBUG_PRINT_D(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
/************************** Function Prototypes ******************************/
extern void USBH_IRQHandler(void);
/*****************************************************************************/
static void UsbHcInterrruptHandler(s32 vector, void *param)
{
USBH_IRQHandler();
}
static void UsbHcSetupInterrupt(void)
{
u32 cpu_id;
u32 irq_num = CONFIG_XHCI_IRQ_NUM;
u32 irq_priority = 13U;
GetCpuId(&cpu_id);
InterruptSetTargetCpus(irq_num, cpu_id);
InterruptSetPriority(irq_num, irq_priority);
/* register intr callback */
InterruptInstall(irq_num,
UsbHcInterrruptHandler,
NULL,
NULL);
/* enable irq */
InterruptUmask(irq_num);
}
void UsbHcSetupMemp(void)
{
if (FT_COMPONENT_IS_READY != memp.is_ready)
{
USB_ASSERT(FT_SUCCESS == FMempInit(&memp, &memp_buf[0], &memp_buf[0] + FUSB_MEMP_TOTAL_SIZE));
}
}
/* implement cherryusb */
void usb_hc_low_level_init(void)
{
UsbHcSetupMemp();
UsbHcSetupInterrupt();
}
void *usb_hc_malloc(size_t size)
{
return usb_hc_malloc_align(sizeof(void *), size);
}
void *usb_hc_malloc_align(size_t align, size_t size)
{
void *result = FMempMallocAlign(&memp, size, align);
if (result)
memset(result, 0U, size);
return result;
}
void usb_hc_free(void *ptr)
{
if (NULL != ptr)
FMempFree(&memp, ptr);
}
void usb_assert(const char *filename, int linenum)
{
FAssert(filename, linenum, 0xff);
}
void usb_hc_dcache_invalidate(void *addr, unsigned long len)
{
FCacheDCacheInvalidateRange((uintptr)addr, len);
}
static void UsbInitTask(void * args)
{
usbh_initialize();
vTaskDelete(NULL);
}
BaseType_t FFreeRTOSInitUsb(void)
{
BaseType_t ret = pdPASS;
taskENTER_CRITICAL(); /* no schedule when create task */
ret = xTaskCreate((TaskFunction_t )UsbInitTask,
(const char* )"UsbInitTask",
(uint16_t )2048,
NULL,
(UBaseType_t )configMAX_PRIORITIES - 1,
NULL);
FASSERT_MSG(pdPASS == ret, "create task failed");
taskEXIT_CRITICAL(); /* allow schedule since task created */
return ret;
}
BaseType_t FFreeRTOSListUsb(int argc, char *argv[])
{
return lsusb(argc, argv);
}
|