• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: OS Abstract Layer.
15  */
16 
17 /**
18  * @defgroup osal_proc osal_proc
19  */
20 #ifndef __OSAL_PROC_H__
21 #define __OSAL_PROC_H__
22 
23 #include "osal_list.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 #define OSAL_PROC_NAME_LENGTH 32
32 #define PROC_CMD_SINGEL_LENGTH_MAX 32
33 #define PROC_CMD_ALL_LENGTH_MAX 128
34 #define PROC_CMD_NUM_MAX 16
35 
36 typedef struct osal_proc_cmd_ {
37     char name[OSAL_PROC_NAME_LENGTH];
38     int (*handler)(unsigned int argc, char (*argv)[PROC_CMD_SINGEL_LENGTH_MAX], void *private_data);
39 } osal_proc_cmd;
40 
41 typedef struct osal_proc_dir_entry {
42     char name[OSAL_PROC_NAME_LENGTH];
43     unsigned int cmd_cnt;
44     osal_proc_cmd *cmd_list;
45     void *proc_dir_entry;
46     int (*open)(struct osal_proc_dir_entry *entry);
47     int (*read)(struct osal_proc_dir_entry *entry);
48     int (*write)(struct osal_proc_dir_entry *entry, const char *buf, int count, long long *);
49     void *private_data;
50     void *seqfile;
51     struct osal_list_head node;
52 } osal_proc_entry;
53 
54 /**
55  * @ingroup osal_proc
56  * @brief Create a directory in /proc.
57  *
58  * @par Description:
59  * Create a directory in /proc.
60  *
61  * @attention
62  * This interface should be invoked only once.
63  * That is, in the /proc directory, you can only have one directory created by yourself at the same time.
64  *
65  * @param name [in] Name of the directory to be created.
66  *
67  * @par Support System:
68  * linux liteos.
69  */
70 void osal_proc_init(const char *name);
71 
72 /**
73  * @ingroup osal_proc
74  * @brief Delete the directory created by osal_proc_init() and all the files in the directory.
75  *
76  * @par Description:
77  * Delete the directory created by osal_proc_init() and all the files in the directory.
78  *
79  * @param name [in] Name of the directory to be deleted, created by osal_proc_init().
80  * @par Support System:
81  * linux liteos.
82  */
83 void osal_proc_exit(const char *name);
84 
85 /**
86  * @ingroup osal_proc
87  * @brief Delete the file created by the function osal_create_proc_entry.
88  *
89  * @par Description:
90  * Delete the file created by the function osal_create_proc_entry.
91  *
92  * @param name   [in] The file name, same as the first parameter of osal_create_proc_entry.
93  * @param parent [in] osal_proc_entry*, returned by the osal_create_proc_entry.
94  *
95  * @par Support System:
96  * linux liteos.
97  */
98 void osal_remove_proc_entry(const char *name, osal_proc_entry *parent);
99 
100 /**
101  * @ingroup osal_proc
102  * @brief Create a file in the directory created by the function osal_proc_init.
103  *
104  * @par Description:
105  * Create a file in the directory created by the function osal_proc_init.
106  *
107  * @param name   [in] Name of the directory to be created.
108  * @param parent [in] Reserved parameter, not used for now.
109  *
110  * @return osal_proc_entry*, parent directory of the file to be created.
111  * Generally, it stands for "/proc/xxx", where xxx is the first parameter of osal_proc_init.
112  *
113  * @par Support System:
114  * linux liteos.
115  */
116 osal_proc_entry *osal_create_proc_entry(const char *name, osal_proc_entry *parent);
117 
118 #if defined(__LITEOS__)
119 #define osal_seq_printf(seqfile, fmt, ...) seq_printf(seqfile, fmt, ##__VA_ARGS__)
120 #else
121 void osal_seq_printf(void *seqfile, const char *fmt, ...);
122 #endif
123 
124 #ifdef __cplusplus
125 #if __cplusplus
126 }
127 #endif
128 #endif
129 #endif /* __OSAL_PROC_H__ */