• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2013-2015. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote
13  *    products derived from this software without specific prior
14  *    written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Description: define mbox, ticks and memory adaptor
29  * Author: none
30  * Create: 2013
31  */
32 
33 #ifndef __ARCH_SYS_ARCH_H__
34 #define __ARCH_SYS_ARCH_H__
35 
36 #include "lwip/opt.h"
37 
38 #if NO_SYS == 0
39 #include "los_sem.h"
40 #include "pthread.h"
41 #include "los_typedef.h"
42 #include "semaphore.h"
43 #include "los_memory.h"
44 
45 #define LWIP_OFFSET_OF LOS_OFF_SET_OF
46 typedef struct posix_sem sys_sem_t;
47 typedef int sys_prot_t;
48 #if !LWIP_COMPAT_MUTEX
49 typedef u32_t sys_mutex_t;
50 #endif
51 
52 #define MBOX_NO_EXPAND    0
53 #define MBOX_AUTO_EXPAND  1
54 
55 struct sys_mbox {
56   int first, last;
57   void **msgs;
58   int mbox_size;
59   int mbox_origin_size;
60   unsigned char is_full;
61   unsigned char is_empty;
62   unsigned char is_auto_expand;
63   pthread_cond_t not_empty;
64   pthread_cond_t not_full;
65   pthread_mutex_t mutex;
66 };
67 
68 struct sys_dual_mbox {
69   int first, last;
70   void **msgs;
71   int mbox_size;
72   int mbox_total_used;
73   int is_full;
74   int is_empty;
75   int mbox_used;
76   pthread_cond_t not_empty;
77   pthread_cond_t not_full;
78   pthread_mutex_t mutex;
79 
80   int first_p, last_p;
81   void **msgs_priority;
82   int mbox_size_priority;
83   int mbox_used_priority;
84 };
85 typedef struct sys_dual_mbox *sys_dual_mbox_t;
86 
87 typedef struct sys_mbox *sys_mbox_t;
88 
89 struct sys_thread {
90   struct sys_thread *next;
91   pthread_t pthread;
92 };
93 
94 typedef unsigned int sys_thread_t;
95 
96 #define sys_sem_valid(x)        (((*x).sem == NULL) ? 0 : 1)
97 #define sys_sem_set_invalid(x)  ((*x).sem = NULL)
98 
99 
100 #define SYS_MBOX_NULL (NULL)
101 #define sys_mbox_valid(mbox) (((mbox) != (void *)NULL) && (*(mbox) != (void *)NULL))
102 #define sys_mbox_set_invalid(mbox) do { \
103   if ((mbox) != NULL) { \
104     *(mbox) = NULL; \
105   } \
106 } while (0)
107 
108 /* Note: Please make sure the mbox passed is an valid pointer */
109 #define sys_dual_mbox_valid(mbox) (*(mbox) != NULL)
110 
111 #if (MEM_MALLOC_DMA_ALIGN != 1)
112 static inline void *
sys_align_malloc(u16_t length)113 sys_align_malloc(u16_t length)
114 {
115   return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, length, MEM_MALLOC_DMA_ALIGN);
116 }
117 
118 static inline void
sys_align_free(void * mem)119 sys_align_free(void *mem)
120 {
121   (void)LOS_MemFree(OS_SYS_MEM_ADDR, mem);
122 }
123 #endif
124 
125 #else
126 #if defined (__cplusplus) && __cplusplus
127 extern "C" {
128 #endif
129 /* \brief  Get the current systick time in milliSeconds
130  *
131  *  Returns the current systick time in milliSeconds. This function is only
132  *  used in standalone systems.
133  *
134  *  /returns current systick time in milliSeconds
135  */
136 u32_t sys_now(void);
137 
138 #if defined (__cplusplus) && __cplusplus
139 }
140 #endif
141 
142 #endif
143 
144 #endif /* __ARCH_SYS_ARCH_H__ */
145