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 19 /******************************************************************************************************** 20 * @file analog.h 21 * 22 * @brief This is the header file for B91 23 * 24 * @author Driver Group 25 * 26 *******************************************************************************************************/ 27 /******************************* analog control registers: 0xb8 ******************************/ 28 /** @page ANALOG 29 * 30 * Introduction 31 * =============== 32 * TLSRB91 analog support dma and normal mode, in each mode, support byte/halfword/word/buffer write and read. 33 * 34 * API Reference 35 * =============== 36 * Header File: analog.h 37 */ 38 #pragma once 39 40 41 #include "dma.h" 42 #include "compiler.h" 43 #include "reg_include/register_b91.h" 44 45 /********************************************************************************************************************** 46 * global constants * 47 *********************************************************************************************************************/ 48 49 /********************************************************************************************************************** 50 * global macro * 51 *********************************************************************************************************************/ 52 53 /********************************************************************************************************************** 54 * global data type * 55 *********************************************************************************************************************/ 56 /********************************************************************************************************************** 57 * global variable declaration * 58 *********************************************************************************************************************/ 59 60 /********************************************************************************************************************** 61 * global function prototype * 62 *********************************************************************************************************************/ 63 64 /** 65 * @brief This function serves to analog register read by byte. 66 * @param[in] addr - address need to be read. 67 * @return the result of read. 68 */ 69 _attribute_ram_code_sec_noinline_ unsigned char analog_read_reg8(unsigned char addr); 70 71 /** 72 * @brief This function serves to analog register write by byte. 73 * @param[in] addr - address need to be write. 74 * @param[in] data - the value need to be write. 75 * @return none. 76 */ 77 _attribute_ram_code_sec_noinline_ void analog_write_reg8(unsigned char addr, unsigned char data); 78 79 /** 80 * @brief This function serves to analog register read by halfword. 81 * @param[in] addr - address need to be read. 82 * @return the result of read. 83 */ 84 unsigned short analog_read_reg16(unsigned char addr); 85 86 /** 87 * @brief This function serves to analog register write by halfword. 88 * @param[in] addr - address need to be write. 89 * @param[in] data - the value need to be write. 90 * @return none. 91 */ 92 void analog_write_reg16(unsigned char addr, unsigned short data); 93 94 /** 95 * @brief This function serves to analog register read by word. 96 * @param[in] addr - address need to be read. 97 * @return the result of read. 98 */ 99 unsigned int analog_read_reg32(unsigned char addr); 100 101 /** 102 * @brief This function serves to analog register write by word. 103 * @param[in] addr - address need to be write. 104 * @param[in] data - the value need to be write. 105 * @return none. 106 */ 107 void analog_write_reg32(unsigned char addr, unsigned int data); 108 /** 109 * @brief This function serves to analog register read. 110 * @param[in] addr - address need to be read. 111 * @param[out] buff - the ptr of buffer to store the read data. 112 * @param[in] len - the length of read value. 113 * @return none. 114 */ 115 _attribute_ram_code_sec_noinline_ void analog_read_buff(unsigned char addr, unsigned char *buff, int len); 116 117 /** 118 * @brief This function serves to analog register write. 119 * @param[in] addr - address need to be write. 120 * @param[in] buff - the ptr of value need to be write. 121 * @param[in] len - the length of write value. 122 * @return none. 123 */ 124 _attribute_ram_code_sec_noinline_ void analog_write_buff(unsigned char addr, unsigned char *buff, int len); 125 126 127 /** 128 * @brief This function serves to analog register write by word using dma. 129 * @param[in] chn - the dma channel. 130 * @param[in] addr - address need to be write. 131 * @param[in] pdat - the ptr of data need to be write. 132 * @return none. 133 */ 134 void analog_write_reg32_dma(dma_chn_e chn, unsigned char addr, void *pdat); 135 136 /** 137 * @brief This function serves to analog register write by word using dma. 138 * @param[in] chn - the dma channel. 139 * @param[in] addr - address need to be read. 140 * @param[out] pdat - the buffer ptr to store read data. 141 * @return none. 142 */ 143 void analog_read_reg32_dma(dma_chn_e chn, unsigned char addr,void *pdat); 144 145 /** 146 * @brief This function write buffer to analog register by dma channel. 147 * @param[in] chn - the dma channel. 148 * @param[in] addr - address need to be write. 149 * @param[in] pdat - the buffer ptr need to be write. 150 * @param[in] len - the length of buffer. 151 * @return none. 152 */ 153 void analog_write_buff_dma(dma_chn_e chn, unsigned char addr, unsigned char *pdat, unsigned int len); 154 155 /** 156 * @brief This function write buffer to analog register by dma channel. 157 * @param[in] chn - the dma channel. 158 * @param[in] addr - address need to be read from. 159 * @param[out] pdat - the buffer ptr to store read data. 160 * note: The size of array pdat must be a multiple of 4. 161 * For example, if you just need read 5 byte by dma, you should 162 * define the size of array pdat to be greater than 8 other than 5. 163 * Because the dma would return 4 byte data every time, 5 byte is 164 * not enough to store them. 165 * @param[in] len - the length of read data. 166 * @return none. 167 */ 168 void analog_read_buff_dma(dma_chn_e chn, unsigned char addr, unsigned char *pdat, unsigned int len); 169 170 /** 171 * @brief This function write buffer to analog register by dma channel. 172 * @param[in] chn - the dma channel. 173 * @param[in] pdat - the buffer(addr & data) ptr need to be write, 174 * note: The array pdat should look like this, 175 * | pdat | | | 176 * | :------ | :----------| :---- | 177 * | pdat[0] | address | 0x3a | 178 * | pdat[1] | data | 0x11 | 179 * | pdat[2] | address | 0x3b | 180 * | pdat[3] | data | 0x22 | 181 * | ...... | | | 182 * It means write data 0x11 to address 0x3a, 183 * write data 0x22 to address 0x3b, 184 * ...... 185 * @param[in] len - the length of read data. 186 * @return none. 187 */ 188 void analog_write_addr_data_dma(dma_chn_e chn, void *pdat, int len); 189