HALFRED  0.4.0
hali_nv.h
Go to the documentation of this file.
1 
10 #ifndef NVMEM_INTERNAL_H_
11 #define NVMEM_INTERNAL_H_
12 
13 
14 #if !defined(HAL_NV_C_) || (HAL_NV_C_ == 0)
15 #error "The hali_nv.h can be only included from hal_nv.c file."
16 #endif
17 
18 #define HAL_NV_CRITICAL_SECTION_DECLARE
19 #define HAL_NV_CRITICAL_SECTION_BEGIN() CORE_EnterCritical()
20 #define HAL_NV_CRITICAL_SECTION_END() CORE_ExitCritical()
21 
22 #define HAL_NV_MAX_DELAY 1000UL
23 
24 #if defined(HAL_NV_USE_WORKER_TASK) && (HAL_NV_USE_WORKER_TASK != 0)
25 
26 /* Binary sempahores */
27 #define HAL_NV_SEMAPHORE_DECLARE(name) OSSem name
28 /* semaphore should be created as "taken" (resource not available) */
29 #define HAL_NV_SEMAPHORE_CREATE(name) do { name = OSSEM_Create(); (void) OSSEM_Take(name, 0); } while(0)
30 #define HAL_NV_SEMAPHORE_DELETE(name) do { } while(0)
31 #define HAL_NV_SEMAPHORE_GIVE(name) OSSEM_Give(name)
32 #define HAL_NV_SEMAPHORE_TAKE(name) OSSEM_Take(name, HAL_NV_MAX_DELAY)
33 
34 
35 #if defined(HAL_NV_USE_SEM_TO_PROCESS_IDLE) && (HAL_NV_USE_SEM_TO_PROCESS_IDLE != 0)
36 /*
37  * Counting sempahores (up to number of entries in requests queue)
38  * initially semaphore should have counter set to 0 (no entries available)
39  */
40 /*#define HAL_NV_WAIT_SEM_PTR_DECLARE(name) xSemaphoreHandle name*/
41 #define HAL_NV_WAIT_SEM_CREATE(name, count) name = OSCNTSEM_Create(0, (count))
42 #define HAL_NV_WAIT_SEM_DELETE(name) do { } while(0)
43 #define HAL_NV_WAIT_SEM_POST(name) OSCNTSEM_Give(name)
44 #define HAL_NV_WAIT_SEM_WAIT(name) OSCNTSEM_Take(name, HAL_NV_MAX_DELAY)
45 #endif /* defined(HAL_NV_USE_SEM_TO_PROCESS_IDLE) && (HAL_NV_USE_SEM_TO_PROCESS_IDLE != 0) */
46 
47 #endif /* defined(HAL_NV_USE_WORKER_TASK) && (HAL_NV_USE_WORKER_TASK != 0) */
48 
49 
50 #if defined(HAL_NV_USE_WORKER_TASK) && (HAL_NV_USE_WORKER_TASK != 0)
51 
52 typedef struct NV_Semaphore_Tag
53 {
54  HAL_NV_SEMAPHORE_DECLARE(sem);
55  struct NV_SemaphorePool_Tag* pool;
56 } NV_Semaphore_T;
57 
58 typedef NV_Semaphore_T* NV_Semaphore;
59 
60 
61 typedef struct NV_SemaphorePool_Tag
62 {
63  NV_Semaphore semaphores;
64  uint32_t no_sems;
65 } NV_SemaphorePool_T;
66 
67 #endif /* defined(HAL_NV_USE_WORKER_TASK) && (HAL_NV_USE_WORKER_TASK != 0) */
68 
69 typedef union NV_OperationData_Tag
70 {
71  BP_PartialBuffer op_buf;
72  void* mem_ptr;
74 
75 typedef enum {
76  NV_NOP,
77  NV_READ,
78  NV_SYNC_WRITE,
79  NV_ASYNC_WRITE,
80  NV_ERASE,
81  NV_FLUSH
82 } NV_OpType;
83 
84 typedef struct NV_Request_Tag
85 {
86  NV_Memory dev;
87  NV_OpType op_type;
88  NV_Addressable nv_addr;
89  NV_OperationData_T data;
90  NV_Addressable length;
91  #if defined(HAL_NV_USE_WORKER_TASK) && (HAL_NV_USE_WORKER_TASK != 0)
92  NV_Semaphore notification;
93  #endif
94  volatile NV_OpResult* result;
95 } NV_Request_T;
96 
97 typedef NV_Request_T* NV_Request;
98 
99 
100 #if defined(HAL_NV_USE_WORKER_TASK) && (HAL_NV_USE_WORKER_TASK != 0)
101 typedef struct NV_RequestQueue_Tag
102 {
103  NV_Request requests;
104  uint32_t max_no_requests;
105  volatile uint32_t pending_requests;
106  volatile uint32_t head;
107  volatile uint32_t tail;
108 } NV_RequestQueue_T;
109 #endif
110 
116 #endif /* NVMEM_INTERNAL_H_ */
Definition: hali_nv.h:84
uint32_t NV_Addressable
Definition: hal_nv.h:153
Definition: hal_nv.h:249
Definition: hal_bp.h:90
Definition: hali_nv.h:69
NV_OpResult
Definition: hal_nv.h:137