1 #ifndef _BFLB_CORE_H
2 #define _BFLB_CORE_H
3 
4 #include <stdint.h>
5 #include <string.h>
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <errno.h>
10 #include <risc-v/csr.h>
11 #include <risc-v/riscv_arch.h>
12 #include <compiler/compiler_gcc.h>
13 #include <compiler/compiler_ld.h>
14 #include "bflb_list.h"
15 #include "bflb_mtimer.h"
16 #include "bflb_irq.h"
17 #include "bflb_common.h"
18 
19 /** @addtogroup LHAL
20   * @{
21   */
22 
23 /** @addtogroup CORE
24   * @{
25   */
26 
27 #if !defined(BL602) && !defined(BL702) && !defined(BL702L) && \
28     !defined(BL616) && !defined(BL606P) && !defined(BL808) && !defined(BL628)
29 #error please define a supported chip
30 #endif
31 
32 #ifdef CONFIG_PARAM_ASSERT
33 #define ASSERT_PARAM(expr) ((expr) ? (void)0 : assert_func(__FILE__, __LINE__, __FUNCTION__, #expr))
34 void assert_func(uint8_t *file, uint32_t line, uint8_t *function, uint8_t *string);
35 #else
36 #define ASSERT_PARAM(expr) ((void)0U)
37 #endif
38 
39 #if defined(BL702)
40 #define BFLB_PSRAM_BASE 0x26000000
41 #elif defined(BL616)
42 #define BFLB_PSRAM_BASE 0xA8000000
43 #elif defined(BL808)
44 #define BFLB_PSRAM_BASE 0x50000000
45 #elif defined(BL606P)
46 #define BFLB_PSRAM_BASE 0x54000000
47 #endif
48 
49 #define BFLB_DEVICE_TYPE_ADC      0
50 #define BFLB_DEVICE_TYPE_DAC      1
51 #define BFLB_DEVICE_TYPE_AUDIOADC 2
52 #define BFLB_DEVICE_TYPE_AUDIODAC 3
53 #define BFLB_DEVICE_TYPE_GPIO     4
54 #define BFLB_DEVICE_TYPE_UART     5
55 #define BFLB_DEVICE_TYPE_SPI      6
56 #define BFLB_DEVICE_TYPE_I2C      7
57 #define BFLB_DEVICE_TYPE_DMA      8
58 #define BFLB_DEVICE_TYPE_I2S      9
59 #define BFLB_DEVICE_TYPE_IR       10
60 #define BFLB_DEVICE_TYPE_TIMER    11
61 #define BFLB_DEVICE_TYPE_PWM      12
62 #define BFLB_DEVICE_TYPE_CAMERA   14
63 #define BFLB_DEVICE_TYPE_FLASH    15
64 #define BFLB_DEVICE_TYPE_QSPI     16
65 #define BFLB_DEVICE_TYPE_SDH      17
66 #define BFLB_DEVICE_TYPE_SDU      18
67 #define BFLB_DEVICE_TYPE_ETH      19
68 #define BFLB_DEVICE_TYPE_RTC      20
69 #define BFLB_DEVICE_TYPE_CRC      21
70 #define BFLB_DEVICE_TYPE_RNG      22
71 #define BFLB_DEVICE_TYPE_MIPI     23
72 #define BFLB_DEVICE_TYPE_DPI      24
73 #define BFLB_DEVICE_TYPE_DSI      25
74 #define BFLB_DEVICE_TYPE_CSI      26
75 #define BFLB_DEVICE_TYPE_USB      27
76 #define BFLB_DEVICE_TYPE_AES      28
77 #define BFLB_DEVICE_TYPE_SHA      29
78 #define BFLB_DEVICE_TYPE_MD5      30
79 #define BFLB_DEVICE_TYPE_TRNG     31
80 #define BFLB_DEVICE_TYPE_PKA      32
81 #define BFLB_DEVICE_TYPE_CKS      33
82 #define BFLB_DEVICE_TYPE_MJPEG    34
83 #define BFLB_DEVICE_TYPE_KYS      35
84 #define BFLB_DEVICE_TYPE_DBI      36
85 #define BFLB_DEVICE_TYPE_WDT      37
86 #define BFLB_DEVICE_TYPE_EF_CTRL  38
87 #define BFLB_DEVICE_TYPE_SDIO2    39
88 #define BFLB_DEVICE_TYPE_SDIO3    40
89 #define BFLB_DEVICE_TYPE_PLFMDMA  41
90 
91 struct bflb_device_s {
92     const char *name;
93     uint32_t reg_base;
94     uint8_t irq_num;
95     uint8_t idx;
96     uint8_t sub_idx;
97     uint8_t dev_type;
98     void *user_data;
99 };
100 
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104 
105 /**
106  * @brief Get device handle by name.
107  *
108  * @param [in] name device name
109  * @return device handle
110  */
111 struct bflb_device_s *bflb_device_get_by_name(const char *name);
112 
113 /**
114  * @brief Get device handle by type and index.
115  *
116  * @param [in] type device type
117  * @param [in] idx device index
118  * @return device handle
119  */
120 struct bflb_device_s *bflb_device_get_by_id(uint8_t type, uint8_t idx);
121 
122 /**
123  * @brief Set user data into device handle.
124  *
125  * @param [in] device device handle
126  * @param [in] user_data pointer to user data
127  */
128 void bflb_device_set_userdata(struct bflb_device_s *device, void *user_data);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 /**
135   * @}
136   */
137 
138 /**
139   * @}
140   */
141 
142 #endif
143