WPILibC++  2020.3.2
DMA.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include "hal/AnalogTrigger.h"
13 #include "hal/Types.h"
14 
15 // clang-format off
19 HAL_ENUM(HAL_DMAReadStatus ) {
20  HAL_DMA_OK = 1,
21  HAL_DMA_TIMEOUT = 2,
22  HAL_DMA_ERROR = 3,
23 };
24 // clang-format on
25 
26 struct HAL_DMASample {
27  uint32_t readBuffer[74];
28  int32_t channelOffsets[22];
29  uint64_t timeStamp;
30  uint32_t captureSize;
31  uint8_t triggerChannels;
32 };
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 HAL_DMAHandle HAL_InitializeDMA(int32_t* status);
39 void HAL_FreeDMA(HAL_DMAHandle handle);
40 
41 void HAL_SetDMAPause(HAL_DMAHandle handle, HAL_Bool pause, int32_t* status);
42 void HAL_SetDMARate(HAL_DMAHandle handle, int32_t cycles, int32_t* status);
43 
44 void HAL_AddDMAEncoder(HAL_DMAHandle handle, HAL_EncoderHandle encoderHandle,
45  int32_t* status);
46 void HAL_AddDMAEncoderPeriod(HAL_DMAHandle handle,
47  HAL_EncoderHandle encoderHandle, int32_t* status);
48 void HAL_AddDMACounter(HAL_DMAHandle handle, HAL_CounterHandle counterHandle,
49  int32_t* status);
50 void HAL_AddDMACounterPeriod(HAL_DMAHandle handle,
51  HAL_CounterHandle counterHandle, int32_t* status);
52 void HAL_AddDMADigitalSource(HAL_DMAHandle handle,
53  HAL_Handle digitalSourceHandle, int32_t* status);
54 void HAL_AddDMAAnalogInput(HAL_DMAHandle handle,
55  HAL_AnalogInputHandle aInHandle, int32_t* status);
56 
57 void HAL_AddDMAAveragedAnalogInput(HAL_DMAHandle handle,
58  HAL_AnalogInputHandle aInHandle,
59  int32_t* status);
60 
61 void HAL_AddDMAAnalogAccumulator(HAL_DMAHandle handle,
62  HAL_AnalogInputHandle aInHandle,
63  int32_t* status);
64 
65 void HAL_AddDMADutyCycle(HAL_DMAHandle handle,
66  HAL_DutyCycleHandle dutyCycleHandle, int32_t* status);
67 
68 void HAL_SetDMAExternalTrigger(HAL_DMAHandle handle,
69  HAL_Handle digitalSourceHandle,
70  HAL_AnalogTriggerType analogTriggerType,
71  HAL_Bool rising, HAL_Bool falling,
72  int32_t* status);
73 
74 void HAL_StartDMA(HAL_DMAHandle handle, int32_t queueDepth, int32_t* status);
75 void HAL_StopDMA(HAL_DMAHandle handle, int32_t* status);
76 
77 void* HAL_GetDMADirectPointer(HAL_DMAHandle handle);
78 
79 enum HAL_DMAReadStatus HAL_ReadDMADirect(void* dmaPointer,
80  HAL_DMASample* dmaSample,
81  int32_t timeoutMs,
82  int32_t* remainingOut,
83  int32_t* status);
84 
85 enum HAL_DMAReadStatus HAL_ReadDMA(HAL_DMAHandle handle,
86  HAL_DMASample* dmaSample, int32_t timeoutMs,
87  int32_t* remainingOut, int32_t* status);
88 
89 // Sampling Code
90 uint64_t HAL_GetDMASampleTime(const HAL_DMASample* dmaSample, int32_t* status);
91 
92 int32_t HAL_GetDMASampleEncoderRaw(const HAL_DMASample* dmaSample,
93  HAL_EncoderHandle encoderHandle,
94  int32_t* status);
95 
96 int32_t HAL_GetDMASampleCounter(const HAL_DMASample* dmaSample,
97  HAL_CounterHandle counterHandle,
98  int32_t* status);
99 
100 int32_t HAL_GetDMASampleEncoderPeriodRaw(const HAL_DMASample* dmaSample,
101  HAL_EncoderHandle encoderHandle,
102  int32_t* status);
103 
104 int32_t HAL_GetDMASampleCounterPeriod(const HAL_DMASample* dmaSample,
105  HAL_CounterHandle counterHandle,
106  int32_t* status);
107 HAL_Bool HAL_GetDMASampleDigitalSource(const HAL_DMASample* dmaSample,
108  HAL_Handle dSourceHandle,
109  int32_t* status);
110 int32_t HAL_GetDMASampleAnalogInputRaw(const HAL_DMASample* dmaSample,
111  HAL_AnalogInputHandle aInHandle,
112  int32_t* status);
113 
114 int32_t HAL_GetDMASampleAveragedAnalogInputRaw(const HAL_DMASample* dmaSample,
115  HAL_AnalogInputHandle aInHandle,
116  int32_t* status);
117 
118 void HAL_GetDMASampleAnalogAccumulator(const HAL_DMASample* dmaSample,
119  HAL_AnalogInputHandle aInHandle,
120  int64_t* count, int64_t* value,
121  int32_t* status);
122 
123 int32_t HAL_GetDMASampleDutyCycleOutputRaw(const HAL_DMASample* dmaSample,
124  HAL_DutyCycleHandle dutyCycleHandle,
125  int32_t* status);
126 
127 #ifdef __cplusplus
128 } // extern "C"
129 #endif
HAL_DMASample
Definition: DMA.h:26