|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -#include "zephyr/sys_clock.h" |
| 7 | +#include <zephyr/irq.h> |
| 8 | +#include <zephyr/init.h> |
8 | 9 | #include <zephyr/device.h> |
9 | 10 | #include <zephyr/devicetree.h> |
10 | | -#include <zephyr/init.h> |
11 | | -#include <zephyr/kernel.h> |
12 | | -#include <zephyr/irq.h> |
13 | | -#include <zephyr/sys/util.h> |
14 | | - |
| 11 | +#include <zephyr/logging/log.h> |
15 | 12 | #include <ethosu_driver.h> |
16 | 13 |
|
17 | | -#include <zephyr/logging/log.h> |
18 | | -LOG_MODULE_REGISTER(ethos_u, CONFIG_ARM_ETHOS_U_LOG_LEVEL); |
| 14 | +#include "ethos_u_common.h" |
19 | 15 |
|
20 | 16 | #define DT_DRV_COMPAT arm_ethos_u |
21 | | - |
22 | | -/******************************************************************************* |
23 | | - * Re-implementation/Overrides __((weak)) symbol functions from ethosu_driver.c |
24 | | - * To handle mutex and semaphores |
25 | | - *******************************************************************************/ |
26 | | - |
27 | | -void *ethosu_mutex_create(void) |
28 | | -{ |
29 | | - struct k_mutex *mutex; |
30 | | - |
31 | | - mutex = k_malloc(sizeof(*mutex)); |
32 | | - if (mutex == NULL) { |
33 | | - LOG_ERR("Failed allocate mutex"); |
34 | | - return NULL; |
35 | | - } |
36 | | - |
37 | | - k_mutex_init(mutex); |
38 | | - |
39 | | - return (void *)mutex; |
40 | | -} |
41 | | - |
42 | | -int ethosu_mutex_lock(void *mutex) |
43 | | -{ |
44 | | - int status; |
45 | | - |
46 | | - status = k_mutex_lock((struct k_mutex *)mutex, K_FOREVER); |
47 | | - if (status != 0) { |
48 | | - LOG_ERR("Failed to lock mutex with error - %d", status); |
49 | | - return -1; |
50 | | - } |
51 | | - |
52 | | - return 0; |
53 | | -} |
54 | | - |
55 | | -int ethosu_mutex_unlock(void *mutex) |
56 | | -{ |
57 | | - k_mutex_unlock((struct k_mutex *)mutex); |
58 | | - return 0; |
59 | | -} |
60 | | - |
61 | | -void *ethosu_semaphore_create(void) |
62 | | -{ |
63 | | - struct k_sem *sem; |
64 | | - |
65 | | - sem = k_malloc(sizeof(*sem)); |
66 | | - if (sem == NULL) { |
67 | | - LOG_ERR("Failed to allocate semaphore"); |
68 | | - return NULL; |
69 | | - } |
70 | | - |
71 | | - k_sem_init(sem, 0, 100); |
72 | | - |
73 | | - return (void *)sem; |
74 | | -} |
75 | | - |
76 | | -int ethosu_semaphore_take(void *sem, uint64_t timeout) |
77 | | -{ |
78 | | - int status; |
79 | | - |
80 | | - status = k_sem_take((struct k_sem *)sem, (timeout == ETHOSU_SEMAPHORE_WAIT_FOREVER) |
81 | | - ? K_FOREVER |
82 | | - : Z_TIMEOUT_TICKS(timeout)); |
83 | | - |
84 | | - if (status != 0) { |
85 | | - /* The Ethos-U driver expects the semaphore implementation to never fail except for |
86 | | - * when a timeout occurs, and the current ethosu_semaphore_take implementation makes |
87 | | - * no distinction, in terms of return codes, between a timeout and other semaphore |
88 | | - * take failures. Also, note that a timeout is virtually indistinguishable from |
89 | | - * other failures if the driver logging is disabled. Handling errors other than a |
90 | | - * timeout is therefore not covered here and is deferred to the application |
91 | | - * developer if necessary. |
92 | | - */ |
93 | | - if (status != -EAGAIN) { |
94 | | - LOG_ERR("Failed to take semaphore with error - %d", status); |
95 | | - } |
96 | | - return -1; |
97 | | - } |
98 | | - |
99 | | - return 0; |
100 | | -} |
101 | | - |
102 | | -int ethosu_semaphore_give(void *sem) |
103 | | -{ |
104 | | - k_sem_give((struct k_sem *)sem); |
105 | | - return 0; |
106 | | -} |
107 | | - |
108 | | -struct ethosu_dts_info { |
109 | | - void *base_addr; |
110 | | - bool secure_enable; |
111 | | - bool privilege_enable; |
112 | | - void (*irq_config)(void); |
113 | | -}; |
114 | | - |
115 | | -struct ethosu_data { |
116 | | - struct ethosu_driver drv; |
117 | | -}; |
| 17 | +LOG_MODULE_REGISTER(arm_ethos_u, CONFIG_ETHOS_U_LOG_LEVEL); |
118 | 18 |
|
119 | 19 | void ethosu_zephyr_irq_handler(const struct device *dev) |
120 | 20 | { |
|
0 commit comments