1 /* 2 * Copyright 2024 Microchip Technology Inc. and its subsidiaries. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef _MEC_BCLINK_API_H 7 #define _MEC_BCLINK_API_H 8 9 #include <stdbool.h> 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include "mec_defs.h" 14 #include "mec_retval.h" 15 16 /* Interfaces to any C modules */ 17 #ifdef __cplusplus 18 extern "C" 19 { 20 #endif 21 22 /* BC-Link */ 23 24 #define MEC_BCL_NUM_IRQS 2 /* number of IRQ sources per instance */ 25 26 #define MEC_BCL_SOURCE_CLOCK_FREQ 48000000u 27 #define MEC_BCL_MAX_CLK_FREQ (MEC_BCL_SOURCE_CLOCK_FREQ) 28 #define MEC_BCL_MIN_CLK_FREQ (MEC_BCL_SOURCE_CLOCK_FREQ / 256u) 29 30 /* forward reference */ 31 struct mec_bcl_regs; 32 33 /* configuration */ 34 #define MEC_BCL_CFG_FREQ_DIV_POS 0 35 #define MEC_BCL_CFG_FREQ_DIV_MSK 0xffu 36 37 /* Start API flags */ 38 #define MEC_BCL_START_FLAG_WRITE 0 39 #define MEC_BCL_START_FLAG_READ 1 40 #define MEC_BCL_START_FLAG_BCLR_IEN 2 41 #define MEC_BCL_START_FLAG_BERR_IEN 4 42 43 enum mec_bcl_intr_flags { 44 MEC_BCL_BCLR_IRQ_POS = 0, /* interrupt when busy clears */ 45 MEC_BCL_BERR_IRQ_POS, /* interrupt if protocol error */ 46 }; 47 48 enum mec_bcl_status_pos { 49 MEC_BCL_STS_BUSY_POS = 0, 50 MEC_BCL_STS_ERR_POS, 51 }; 52 53 int mec_hal_bcl_init(struct mec_bcl_regs *base, uint32_t flags); 54 55 int mec_hal_bcl_soft_reset(struct mec_bcl_regs *regs, uint8_t enable); 56 57 int mec_hal_bcl_get_freq(struct mec_bcl_regs *regs, uint32_t *freq_hz); 58 int mec_hal_bcl_set_freq(struct mec_bcl_regs *regs, uint32_t freq_hz); 59 60 bool mec_hal_bcl_is_busy(struct mec_bcl_regs *regs); 61 bool mec_hal_bcl_is_error(struct mec_bcl_regs *regs); 62 int mec_hal_bcl_clear_error(struct mec_bcl_regs *regs); 63 int mec_hal_bcl_clear_not_busy(struct mec_bcl_regs *regs); 64 65 int mec_hal_bcl_intr_ctrl(struct mec_bcl_regs *regs, uint8_t msk, uint8_t enable); 66 67 int mec_hal_bcl_get_target_address(struct mec_bcl_regs *regs, uint8_t *target_address); 68 int mec_hal_bcl_set_target_address(struct mec_bcl_regs *regs, uint8_t target_address); 69 70 int mec_hal_bcl_start(struct mec_bcl_regs *regs, uint8_t target_reg, uint8_t wrdata, 71 uint32_t flags); 72 73 int mec_hal_bcl_get_data(struct mec_bcl_regs *regs, uint8_t *data); 74 int mec_hal_bcl_set_data(struct mec_bcl_regs *regs, uint8_t data); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 #endif /* #ifndef _MEC_BCLINK_API_H */ 81