1 /*
2  * Copyright (C) 2017-2019 Alibaba Group Holding Limited
3  */
4 
5 /******************************************************************************
6  * @file     drv_etb.h
7  * @brief    header file for event trigger driver
8  * @version  V1.0
9  * @date     27. octorber 2017
10  * @model    etb
11  ******************************************************************************/
12 
13 #ifndef _CSI_ETB_H_
14 #define _CSI_ETB_H_
15 
16 
17 #include <stdint.h>
18 #include <soc.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 typedef enum {
24     ETB_SOURCE = 0,
25     ETB_DEST   = 1
26 }
27 etb_direct_e;
28 
29 typedef enum {
30     ETB_HARDWARE  = 0,   ///< etb channel inout is hardware trigger.
31     ETB_SOFTWWARE       ///< etb channel inout is software trigger.
32 } etb_source_type_e;
33 
34 typedef enum {
35     ETB_ONE_TRIGGER_ONE = 0,
36     ETB_ONE_TRIGGER_MORE = 1,
37     ETB_MORE_TRIGGER_ONE = 2
38 } etb_channel_func_e;
39 
40 /// definition for etb handle.
41 typedef void *etb_handle_t;
42 
43 typedef struct {
44     uint32_t busy : 1;
45 } etb_status_t;
46 
47 typedef enum {
48     ETB_EVENT_CHANNEL_BUSY = 0,   ///<
49     ETB_EVENT_MODE_FAULT          ///<
50 } etb_event_e;
51 
52 /**
53 \brief ETB Driver Capabilities.
54 */
55 typedef struct {
56     uint32_t sync_trigger : 1;
57     uint32_t async_trigger : 1;
58     uint32_t etb_31_channel : 1;
59     uint32_t one_trigger_one : 1;
60     uint32_t one_trigger_more : 1;
61     uint32_t more_trigger_one : 1;
62 } etb_capabilities_t;
63 
64 typedef void (*etb_event_cb_t)(int32_t idx, etb_event_e event);  ///< Pointer to \ref etb_event_cb_t : etb Event call back.
65 
66 /**
67   \brief       Get driver capabilities.
68   \param[in]   idx       etb index.
69   \return      \ref etb_capabilities_t
70 */
71 etb_capabilities_t drv_etb_get_capabilities(int32_t idx);
72 
73 /**
74   \brief       config etb channel.
75   \param[in]   source_lo    a specific number represent a location in an source trigger location map to trigger other ip(s).
76   \param[in]   dest_lo      a specific number represent an location in an dest trigger map to wait signal(s) from source ip(s) or location(s).
77   \param[in]   source_type  \ref etb_source_type_e the input source is hardware trigger or software trigger.
78   \param[in]   mode         \ref etb_channel_func_e channel function.
79   \return      channel nubmber or error code (negative).
80 */
81 int32_t drv_etb_channel_config(uint32_t source_ip, uint32_t dest_ip, etb_source_type_e source_type, etb_channel_func_e mode);
82 
83 /**
84   \brief       start etb.
85   \param[in]   channel   etb channel number to operate.
86   \return      none
87 */
88 void drv_etb_start(int32_t channel);
89 
90 /**
91   \brief       stop etb.
92   \param[in]   channel   etb channel number to operate.
93   \return      none
94 */
95 void drv_etb_stop(int32_t channel);
96 
97 /**
98   \brief       Get ETB status.
99   \param[in]   ch etb channel to operate.
100   \return      ETB status \ref etb_status_t
101 */
102 etb_status_t drv_etb_get_status(int32_t channel);
103 
104 #endif /* _CSI_ETB_H_ */
105