1 /* 2 * Copyright (C) 2018 GreenWaves Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef HAL_INCLUDE_HAL_PMSIS_TYPES_H_ 18 #define HAL_INCLUDE_HAL_PMSIS_TYPES_H_ 19 #include "inttypes.h" 20 #include "sys/types.h" 21 22 /** 23 * @defgroup groupDrivers Drivers 24 */ 25 26 /// @cond IMPLEM 27 28 /** 29 * @ingroup PMSIS_OS 30 */ 31 32 /** 33 * @defgroup PMSISTypes PMSIS common types 34 */ 35 36 /** 37 * @addtogroup PMSISTypes 38 * @{ 39 */ 40 41 /**@{*/ 42 43 struct pi_device; 44 struct pmsis_event_kernel_wrap; 45 46 // device type placed at the top of conf 47 typedef enum { 48 PI_DEVICE_UNKWN_TYPE, 49 PI_DEVICE_CLUSTER_TYPE, 50 PI_DEVICE_HYPERBUS_TYPE, 51 PI_DEVICE_SPI_TYPE, 52 PI_DEVICE_CPI_TYPE, 53 PI_DEVICE_I2C_TYPE, 54 PI_DEVICE_GPIO_TYPE, 55 PI_DEVICE_PWM_TYPE 56 } pi_device_e; 57 58 typedef struct pi_task pi_task_t; 59 60 typedef void (*callback_t)(void *arg); 61 62 typedef struct spinlock { 63 int32_t *lock_ptr; // with test and set mask 64 int32_t *release_ptr; // standard pointer 65 } spinlock_t; 66 67 typedef struct pi_device_config { 68 const char *name; // to open, FIXME: device tree 69 // initialize the device struct (api+ init data) using init_conf 70 int (*init)(struct pi_device *device); 71 const void *init_conf; 72 } pi_device_config_t; 73 74 // device struct, it wont stay here 75 typedef struct pi_device { 76 struct pi_device_api *api; // function pointers 77 void *config; // driver conf: might be filled either using device tree or manually 78 void *data; // driver data 79 } pi_device_t; 80 81 82 typedef uint32_t (*device_rw_func)(struct pi_device *device, uintptr_t size, 83 const void *addr, const void *buffer); 84 85 typedef uint32_t (*device_ioctl_func)(struct pi_device *device, 86 uint32_t func_id, 87 void *arg); 88 89 typedef uint32_t (*device_rw_func_async)(struct pi_device *device, 90 uintptr_t size, const void *addr, const void *buffer, pi_task_t *async); 91 92 typedef uint32_t (*device_ioctl_func_async)(struct pi_device *device, 93 uint32_t func_id, void *arg, pi_task_t *async); 94 95 typedef int (*open_func)(struct pi_device *device); 96 typedef int (*close_func)(struct pi_device *device); 97 98 typedef int (*open_func_async)(struct pi_device *device, 99 pi_task_t *async); 100 typedef int (*close_func_async)(struct pi_device *device, pi_task_t *async); 101 102 // pmsis device minimal api: used for basic inheritance 103 typedef struct pi_device_api 104 { 105 int (*open)(struct pi_device *device); 106 int (*close)(struct pi_device *device); 107 int (*open_async)(struct pi_device *device, pi_task_t *async); 108 int (*close_async)(struct pi_device *device, pi_task_t *async); 109 ssize_t (*read)(struct pi_device *device, uint32_t ext_addr, 110 void *buffer, uint32_t size, pi_task_t *async); 111 ssize_t (*write)(struct pi_device *device, uint32_t ext_addr, 112 const void *buffer, uint32_t size, pi_task_t *async); 113 int (*ioctl)(struct pi_device *device, uint32_t func_id, void *arg); 114 int (*ioctl_async)(struct pi_device *device, uint32_t func_id, 115 void *arg, pi_task_t *async); 116 void *specific_api; 117 } pi_device_api_t; 118 119 #ifndef IMPLEM_MUTEX_OBJECT_TYPE 120 #define IMPLEM_MUTEX_OBJECT_TYPE \ 121 void* mutex_object; 122 #endif 123 124 /** Memory slab allocator */ 125 typedef struct pi_mem_slab pi_mem_slab_t; 126 127 /** Task types **/ 128 typedef void (*__pmsis_mutex_func)(void *mutex_object); 129 130 typedef struct pmsis_mutex { 131 IMPLEM_MUTEX_OBJECT_TYPE 132 __pmsis_mutex_func take; 133 __pmsis_mutex_func release; 134 } pmsis_mutex_t, pi_mutex_t; 135 136 137 #ifndef IMPLEM_SEM_OBJECT_TYPE 138 #define IMPLEM_SEM_OBJECT_TYPE \ 139 void* sem_object; 140 #endif 141 142 /** Task types **/ 143 typedef void (*__pi_sem_func)(void *sem_object); 144 145 typedef struct pi_sem { 146 IMPLEM_SEM_OBJECT_TYPE 147 __pi_sem_func take; 148 __pi_sem_func give; 149 } pi_sem_t; 150 151 typedef struct pmsis_spinlock { 152 uint32_t lock; 153 } pmsis_spinlock_t; 154 155 struct pmsis_event_kernel_wrap { 156 void *__os_native_task; 157 void (*event_kernel_main)(struct pmsis_event_kernel_wrap*); 158 // real event kernel (might be just an api stub for pulpOS) 159 void *priv; 160 }; 161 162 enum pi_task_id { 163 PI_TASK_CALLBACK_ID, 164 PI_TASK_NONE_ID, 165 }; 166 167 168 /// @endcond 169 170 #endif /* HAL_INCLUDE_HAL_PMSIS_TYPES_H_ */ 171