1 
2 #include <ti/drivers/rcl/LRF.h>
3 #include <ti/devices/DeviceFamily.h>
4 #include DeviceFamily_constructPath(inc/hw_lrfddbell.h)
5 #include DeviceFamily_constructPath(inc/hw_lrfdtrc.h)
6 
7 #include DeviceFamily_constructPath(inc/hw_types.h)
8 #include DeviceFamily_constructPath(inc/hw_memmap.h)
9 #include DeviceFamily_constructPath(inc/hw_clkctl.h)
10 #include DeviceFamily_constructPath(inc/hw_ioc.h)
11 
12 #include <ti/drivers/Power.h>
13 #include <ti/drivers/rcl/RCL_Tracer.h>
14 #ifndef RCL_LITE_ONLY
15 #include <ti/drivers/rcl/RCL.h>
16 #endif
17 
18 static bool tracerEnabled = false;
19 
RCL_Tracer_enable(void)20 void RCL_Tracer_enable(void)
21 {
22     /* TODO: As part of RCL-96, this should be changed so that enabling the clock is not part of
23      * the tracer wakeup routine, only the first enabling. That avoids the need for this global variable */
24     if (!tracerEnabled)
25     {
26         tracerEnabled = true;
27 
28         /* Enable tracer clock */
29         Power_setDependency(PowerLPF3_PERIPH_LRFD_TRC);
30 
31 #ifndef RCL_LITE_ONLY
32         /* Request power notification to keep tracer up after standby */
33         RCL_openPowerNotifications();
34 #endif
35 
36         /* Do the same enabling as after wakeup */
37         RCL_Tracer_wakeup();
38     }
39 }
40 
RCL_Tracer_disable(void)41 void RCL_Tracer_disable(void)
42 {
43     if (tracerEnabled)
44     {
45         /* Disable tracer pins as when going to standby */
46         RCL_Tracer_standby();
47 
48 #ifndef RCL_LITE_ONLY
49         /* Remove power notifications */
50         RCL_closePowerNotifications();
51 #endif
52 
53         /* Disable the tracer */
54         HWREG_WRITE_LRF(LRFDTRC_BASE + LRFDTRC_O_CFG) = (LRFDTRC_CFG_CH1EN_OFF) |
55                                                         (LRFDTRC_CFG_CH2EN_OFF) |
56                                                         (LRFDTRC_CFG_CH3EN_OFF) |
57                                                         (LRFDTRC_CFG_TSEN_OFF);
58 
59         /* Disable tracer clock */
60         Power_releaseDependency(PowerLPF3_PERIPH_LRFD_TRC);
61 
62         tracerEnabled = false;
63     }
64 }
65 
RCL_Tracer_wakeup(void)66 void RCL_Tracer_wakeup(void)
67 {
68     if (tracerEnabled)
69     {
70         /* Enable the Tracer */
71         HWREG_WRITE_LRF(LRFDTRC_BASE + LRFDTRC_O_CFG) = LRFDTRC_CFG_CH1EN_NORM |
72                                                         LRFDTRC_CFG_CH2EN_TOPSM |
73                                                         LRFDTRC_CFG_CH3EN_TOPSM |
74                                                         LRFDTRC_CFG_TSEN_M |
75                                                         LRFDTRC_CFG_PRESCAL_DIV1;
76 
77 #ifdef DeviceFamily_CC23X0R2
78         /* Set tracer on GPO6 */
79         HWREG_WRITE_LRF(LRFDDBELL_BASE + LRFDDBELL_O_GPOSEL0) = HWREG_READ_LRF(LRFDDBELL_BASE + LRFDDBELL_O_GPOSEL0) | (LRFDDBELL_GPOSEL0_SRC2_RFCTRC);
80         HWREG(IOC_BASE + IOC_O_IOC6) = IOC_IOC6_PORTCFG_PFUNC4; // LRFD2 [trace]
81 #elif defined(DeviceFamily_CC23X0R5) || defined(DeviceFamily_CC23X0R22) || defined(DeviceFamily_CC2340R53)
82         /* Set tracer on GPO5 */
83         HWREG_WRITE_LRF(LRFDDBELL_BASE + LRFDDBELL_O_GPOSEL1) = HWREG_READ_LRF(LRFDDBELL_BASE + LRFDDBELL_O_GPOSEL1) | (LRFDDBELL_GPOSEL1_SRC6_RFCTRC);
84         HWREG(IOC_BASE + IOC_O_IOC5) = IOC_IOC5_PORTCFG_PFUNC3; // LRFD6 [trace]
85 #elif defined (DeviceFamily_CC27XX)
86         /* Set tracer on GPO20 */
87         HWREG_WRITE_LRF(LRFDDBELL_BASE + LRFDDBELL_O_GPOSEL0) = HWREG_READ_LRF(LRFDDBELL_BASE + LRFDDBELL_O_GPOSEL0) | (LRFDDBELL_GPOSEL0_SRC3_RFCTRC);
88         HWREG(IOC_BASE + IOC_O_IOC20) = IOC_IOC20_PORTCFG_PFUNC5; // LRFD3 [trace]
89 #endif
90     }
91 }
92 
RCL_Tracer_standby(void)93 void RCL_Tracer_standby(void)
94 {
95     if (tracerEnabled)
96     {
97 #ifdef DeviceFamily_CC23X0R2
98         HWREG(IOC_BASE + IOC_O_IOC6) = 0;
99 #elif defined(DeviceFamily_CC23X0R5) || defined(DeviceFamily_CC23X0R22) || defined(DeviceFamily_CC2340R53)
100         HWREG(IOC_BASE + IOC_O_IOC5) = 0;
101 #elif defined (DeviceFamily_CC27XX)
102         HWREG(IOC_BASE + IOC_O_IOC20) = 0;
103 #endif
104     }
105     /* Do not disable tracer module here, as it can give a lockup if tracing was ongoing and another trace is started */
106 }
107