1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 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 */ 15 16 #ifndef _DUET_COMM_H_ 17 #define _DUET_COMM_H_ 18 19 #include <stdint.h> 20 21 #define DUET_STR_TO_INT_ERR 0xFFFFFFFF 22 #define LEGA_STR_TO_INT_ERR DUET_STR_TO_INT_ERR 23 void jumpToApp(int addr); 24 void duet_memset(char *buf, int value, int size); 25 void duet_memcpy(char *dst, char *src, int size); 26 void udelay(unsigned int us); 27 void delay(unsigned int cycles); 28 int convert_str_to_int(char *str); 29 void convert_int_to_str(unsigned int val, unsigned int type, char *ch); 30 31 // Macro to read a register 32 #define REG_RD(addr) (*(volatile uint32_t *)(addr)) 33 // Macro to write a register 34 #define REG_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) 35 36 // Macro to read a register 37 #define REG_BLE_RD(addr) (*(volatile uint32_t *)(addr)) 38 // Macro to write a register 39 #define REG_BLE_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) 40 41 #ifdef DUET_BLE_NO_BLOCK 42 #define FLASH_COMMON2_SEG __attribute__((section("seg_wf_flash_driver"))) 43 void lega_enter_critical_expble(void); 44 void lega_exit_critical_expble(void); 45 #else 46 #define FLASH_COMMON2_SEG 47 #define lega_enter_critical_expble() lega_rtos_enter_critical() 48 #define lega_exit_critical_expble() lega_rtos_exit_critical() 49 #endif 50 51 void duet_write32_bit(uint32_t reg, uint8_t start_bit, uint8_t len, uint32_t src_val); 52 uint32_t duet_read32_bit(uint32_t reg, uint8_t start_bit, uint8_t len); 53 #endif // _LEGA_COMM_H_ 54