• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 /*******************************      analog control registers: 0xb8      ******************************/
19 /**	@page ANALOG
20  *
21  *	Introduction
22  *	===============
23  *	TLSRB91 analog support dma and normal mode, in each mode, support byte/halfword/word/buffer write and read.
24  *
25  *	API Reference
26  *	===============
27  *	Header File: analog.h
28  */
29 #pragma once
30 
31 #include "compiler.h"
32 #include "dma.h"
33 #include "reg_include/register_b91.h"
34 
35 /**********************************************************************************************************************
36  *                                         global constants                                                           *
37  *********************************************************************************************************************/
38 
39 /**********************************************************************************************************************
40  *                                           global macro                                                             *
41  *********************************************************************************************************************/
42 
43 /**********************************************************************************************************************
44  *                                         global data type                                                           *
45  *********************************************************************************************************************/
46 /**********************************************************************************************************************
47  *                                     global variable declaration                                                    *
48  *********************************************************************************************************************/
49 
50 /**********************************************************************************************************************
51  *                                      global function prototype                                                     *
52  *********************************************************************************************************************/
53 
54 /**
55  * @brief      This function serves to analog register read by byte.
56  * @param[in]  addr - address need to be read.
57  * @return     the result of read.
58  */
59 _attribute_ram_code_sec_noinline_ unsigned char analog_read_reg8(unsigned char addr);
60 
61 /**
62  * @brief      This function serves to analog register write by byte.
63  * @param[in]  addr - address need to be write.
64  * @param[in]  data - the value need to be write.
65  * @return     none.
66  */
67 _attribute_ram_code_sec_noinline_ void analog_write_reg8(unsigned char addr, unsigned char data);
68 
69 /**
70  * @brief      This function serves to analog register read by halfword.
71  * @param[in]  addr - address need to be read.
72  * @return     the result of read.
73  */
74 unsigned short analog_read_reg16(unsigned char addr);
75 
76 /**
77  * @brief      This function serves to analog register write by halfword.
78  * @param[in]  addr - address need to be write.
79  * @param[in]  data - the value need to be write.
80  * @return     none.
81  */
82 void analog_write_reg16(unsigned char addr, unsigned short data);
83 
84 /**
85  * @brief      This function serves to analog register read by word.
86  * @param[in]  addr - address need to be read.
87  * @return     the result of read.
88  */
89 unsigned int analog_read_reg32(unsigned char addr);
90 
91 /**
92   * @brief      This function serves to analog register write by word.
93   * @param[in]  addr - address need to be write.
94   * @param[in]  data - the value need to be write.
95   * @return     none.
96   */
97 void analog_write_reg32(unsigned char addr, unsigned int data);
98 /**
99  * @brief      This function serves to analog register read.
100  * @param[in]  addr  - address need to be read.
101  * @param[out] buff  - the ptr of buffer to store the read data.
102  * @param[in]  len   - the length of read value.
103  * @return     none.
104  */
105 _attribute_ram_code_sec_noinline_ void analog_read_buff(unsigned char addr, unsigned char *buff, int len);
106 
107 /**
108  * @brief      This function serves to analog register write.
109  * @param[in]  addr  - address need to be write.
110  * @param[in]  buff  - the ptr of value need to be write.
111  * @param[in]  len   - the length of write value.
112  * @return     none.
113  */
114 _attribute_ram_code_sec_noinline_ void analog_write_buff(unsigned char addr, unsigned char *buff, int len);
115 
116 /**
117  * @brief      This function serves to analog register write by word using dma.
118  * @param[in]  chn  - the dma channel.
119  * @param[in]  addr - address need to be write.
120  * @param[in]  pdat - the ptr of data need to be write.
121  * @return     none.
122  */
123 void analog_write_reg32_dma(dma_chn_e chn, unsigned char addr, void *pdat);
124 
125 /**
126  * @brief      This function serves to analog register write by word using dma.
127  * @param[in]  chn  - the dma channel.
128  * @param[in]  addr - address need to be read.
129  * @param[out] pdat - the buffer ptr to store read data.
130  * @return     none.
131  */
132 void analog_read_reg32_dma(dma_chn_e chn, unsigned char addr, void *pdat);
133 
134 /**
135  * @brief      This function write buffer to analog register by dma channel.
136  * @param[in]  chn  - the dma channel.
137  * @param[in]  addr - address need to be write.
138  * @param[in]  pdat - the buffer ptr need to be write.
139  * @param[in]  len  - the length of buffer.
140  * @return     none.
141  */
142 void analog_write_buff_dma(dma_chn_e chn, unsigned char addr, unsigned char *pdat, unsigned int len);
143 
144 /**
145  * @brief      This function write buffer to analog register by dma channel.
146  * @param[in]  chn  - the dma channel.
147  * @param[in]  addr - address need to be read from.
148  * @param[out] pdat - the buffer ptr to store read data.
149  * 			   note: The size of array pdat must be a multiple of 4.
150  * 			  	 	For example, if you just need read 5 byte by dma, you should
151  * 			  	 	define the size of array pdat to be greater than 8 other than 5.
152  * 			  	 	Because the dma would return 4 byte data every time, 5 byte is
153  * 			  	 	not enough to store them.
154  * @param[in]  len  - the length of read data.
155  * @return     none.
156  */
157 void analog_read_buff_dma(dma_chn_e chn, unsigned char addr, unsigned char *pdat, unsigned int len);
158 
159 /**
160  * @brief      This function write buffer to analog register by dma channel.
161  * @param[in]  chn  - the dma channel.
162  * @param[in]  pdat - the buffer(addr & data) ptr need to be write,
163  * 			   note: The array pdat should look like this,
164  * 			   |  pdat     |            |        |
165  * 			   |  :------  | :----------|  :---- |
166  * 			   |  pdat[0]  |   address  |  0x3a  |
167  * 			   |  pdat[1]  |    data    |  0x11  |
168  * 			   |  pdat[2]  |   address  |  0x3b  |
169  *			   |  pdat[3]  |    data    |  0x22  |
170  *			   |  ......   |            |        |
171  * 				It means write data 0x11 to address 0x3a,
172  * 						 write data 0x22 to address 0x3b,
173  * 						 ......
174  * @param[in]  len - the length of read data.
175  * @return     none.
176  */
177 void analog_write_addr_data_dma(dma_chn_e chn, void *pdat, int len);
178