Skip to content

Commit 588ac81

Browse files
committed
docs: documentation for interval routines
1 parent 8bfbf9c commit 588ac81

File tree

6 files changed

+130
-34
lines changed

6 files changed

+130
-34
lines changed

pslab-core.X/helpers/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ response_t BUFFER_FetchInt(void) {
2626
LED_SetLow();
2727
uint16_t i;
2828
for (i = 0; i < counter; i++) {
29-
UART1_WriteInt(BUFFER[i + 2 * channel * (BUFFER_SIZE / 4)]);
29+
UART1_WriteInt(BUFFER[i + channel * (BUFFER_SIZE / 4)]);
3030
}
3131
LED_SetHigh();
3232

pslab-core.X/helpers/buffer.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ extern "C" {
1212
extern int16_t volatile __attribute__((section(".adc_buffer"), far)) BUFFER[BUFFER_SIZE];
1313

1414
/**
15-
* @brief
16-
* Send buffer contents.
15+
* @brief Send buffer contents.
1716
*
1817
* @description
1918
* This command function takes two arguments over serial:
@@ -26,8 +25,34 @@ extern "C" {
2625
*/
2726
response_t BUFFER_Retrieve(void);
2827

28+
/**
29+
* @brief Send buffer content as integers.
30+
*
31+
* @description
32+
* This command function takes two arguments over serial:
33+
* 1. The starting index in the buffer from which to send values.
34+
* 2. The number of values to be sent.
35+
*
36+
* It returns the requested data over serial.
37+
* It sends an acknowledge byte (SUCCESS)
38+
*
39+
* @return SUCCESS
40+
*/
2941
response_t BUFFER_FetchInt(void);
3042

43+
/**
44+
* @brief Send buffer content as longs.
45+
*
46+
* @description
47+
* This command function takes two arguments over serial:
48+
* 1. The starting index in the buffer from which to send values.
49+
* 2. The number of values to be sent.
50+
*
51+
* It returns the requested data over serial.
52+
* It sends an acknowledge byte (SUCCESS)
53+
*
54+
* @return SUCCESS
55+
*/
3156
response_t BUFFER_FetchLong(void);
3257

3358
#ifdef __cplusplus

pslab-core.X/helpers/interval.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "../bus/uart/uart1.h"
2+
#include "../registers/comparators/cmp4.h"
3+
#include "../registers/comparators/cvr.h"
24
#include "../registers/comparators/ic1.h"
35
#include "../registers/comparators/ic2.h"
46
#include "../registers/comparators/ic3.h"
57
#include "../registers/comparators/ic4.h"
68
#include "../registers/comparators/ic_params.h"
79
#include "../registers/memory/dma.h"
10+
#include "../registers/system/interrupt_manager.h"
811
#include "../registers/system/pin_manager.h"
912
#include "../registers/timers/tmr2.h"
10-
#include "../registers/comparators/cvr.h"
11-
#include "../registers/comparators/cmp4.h"
12-
#include "../registers/system/interrupt_manager.h"
1313
#include "buffer.h"
1414

1515
static uint8_t DIGITAL_STATES = 0;
@@ -77,10 +77,7 @@ void INTERVAL_CaptureOne(uint16_t count, uint8_t channel, uint8_t mode, uint8_t
7777

7878
void INTERVAL_CaptureTwo(uint16_t count, uint8_t mode, uint8_t channel) {
7979

80-
DMA_ChannelDisable(DMA_CHANNEL_0);
81-
DMA_ChannelDisable(DMA_CHANNEL_1);
82-
DMA_ChannelDisable(DMA_CHANNEL_2);
83-
DMA_ChannelDisable(DMA_CHANNEL_3);
80+
DMA_DisableAllChannels();
8481

8582
DMA_PrepareChannel0(count, __builtin_dmapage(&BUFFER),
8683
__builtin_dmaoffset(&BUFFER), DMA_PERIPHERAL_IRQ_IC1);
@@ -93,10 +90,7 @@ void INTERVAL_CaptureTwo(uint16_t count, uint8_t mode, uint8_t channel) {
9390

9491
DMA_InterruptEnable(DMA_CHANNEL_0);
9592

96-
IC1_Initialize();
97-
IC2_Initialize();
98-
IC3_Initialize();
99-
IC4_Initialize();
93+
IC_PARAMS_InitiateAll();
10094

10195
SetDMA_MODE(DMA_MODES_TWO_CHANNEL);
10296

@@ -107,10 +101,7 @@ void INTERVAL_CaptureTwo(uint16_t count, uint8_t mode, uint8_t channel) {
107101
IC_PARAMS_CombineOddEvenModules();
108102
IC_PARAMS_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
109103

110-
DMA_ChannelEnable(DMA_CHANNEL_0);
111-
DMA_ChannelEnable(DMA_CHANNEL_1);
112-
DMA_ChannelEnable(DMA_CHANNEL_2);
113-
DMA_ChannelEnable(DMA_CHANNEL_3);
104+
DMA_EnableAllChannels();
114105

115106
IC1_SetCaptureMode(mode & 0xF);
116107
IC2_SetCaptureMode(mode & 0xF);
@@ -133,10 +124,7 @@ void INTERVAL_CaptureThree(uint16_t count, uint16_t mode, uint8_t trig) {
133124

134125
DMA_InterruptEnable(DMA_CHANNEL_0);
135126

136-
IC1_Initialize();
137-
IC2_Initialize();
138-
IC3_Initialize();
139-
IC4_Initialize();
127+
IC_PARAMS_InitiateAll();
140128

141129
SetDMA_MODE(DMA_MODES_THREE_CHANNEL);
142130

@@ -173,10 +161,7 @@ void INTERVAL_CaptureThree(uint16_t count, uint16_t mode, uint8_t trig) {
173161

174162
void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler) {
175163

176-
DMA_ChannelDisable(DMA_CHANNEL_0);
177-
DMA_ChannelDisable(DMA_CHANNEL_1);
178-
DMA_ChannelDisable(DMA_CHANNEL_2);
179-
DMA_ChannelDisable(DMA_CHANNEL_3);
164+
DMA_DisableAllChannels();
180165

181166
DMA_PrepareChannel0(count, __builtin_dmapage(&BUFFER),
182167
__builtin_dmaoffset(&BUFFER), DMA_PERIPHERAL_IRQ_IC1);
@@ -189,10 +174,7 @@ void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler) {
189174

190175
DMA_InterruptEnable(DMA_CHANNEL_0);
191176

192-
IC1_Initialize();
193-
IC2_Initialize();
194-
IC3_Initialize();
195-
IC4_Initialize();
177+
IC_PARAMS_InitiateAll();
196178

197179
SetDMA_MODE(DMA_MODES_FOUR_CHANNEL);
198180

@@ -208,10 +190,7 @@ void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler) {
208190
IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER2);
209191
IC_PARAMS_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
210192

211-
DMA_ChannelEnable(DMA_CHANNEL_0);
212-
DMA_ChannelEnable(DMA_CHANNEL_1);
213-
DMA_ChannelEnable(DMA_CHANNEL_2);
214-
DMA_ChannelEnable(DMA_CHANNEL_3);
193+
DMA_EnableAllChannels();
215194

216195
IC1_SetCaptureMode(mode & 0xF);
217196
IC2_SetCaptureMode((mode >> 4) & 0xF);
@@ -220,6 +199,7 @@ void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler) {
220199
}
221200

222201
response_t INTERVAL_GetState(void) {
202+
223203
UART1_WriteInt(__builtin_dmaoffset(&BUFFER));
224204
UART1_WriteInt(DMA0STAL);
225205
UART1_WriteInt(DMA1STAL);

pslab-core.X/helpers/interval.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,83 @@
88
extern "C" {
99
#endif
1010

11+
/**
12+
* @brief Setup input capture on one channel
13+
*
14+
* @description
15+
* This routing will configure IC1,2 and DMA0,1 modules to listen to logic
16+
* level changes on a pin defined by the channel byte and log timer values
17+
* in BUFFER 1st and 2nd quarters. If trigger is set by the trig byte, this
18+
* will use IC4 module to listen to the trigger observation and time log will
19+
* then start.
20+
* It will combine both IC1 and IC2 modules to form a 32-bit timer which will
21+
* have support for more data points than `CaptureThree` and `CaptureFour`
22+
* routines.
23+
*
24+
* @param count : number of data points to capture
25+
* @param channel : the pin that needs to be monitored
26+
* @param mode : logic level variation. Refer to `IC_PARAMS_CAPTURE_MODE`
27+
* @param trig : en/disable trigger using IC4
28+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
29+
* | TRIG PIN | X | TRIG MODE |
30+
*
31+
* @return None
32+
*/
1133
void INTERVAL_CaptureOne(uint16_t count, uint8_t channel, uint8_t mode, uint8_t trig);
1234

35+
/**
36+
* @brief Setup input capture on two channels
37+
*
38+
* @description
39+
* This routing will configure IC1,2,3,4 and DMA0,1,2,3 modules to listen to
40+
* logic level changes on pins defined by the channel byte and log timer
41+
* values in BUFFER.
42+
* It will combine both IC1, IC2 and IC3, IC4 modules to form a 32-bit timer
43+
* which will have support for more data points than `CaptureThree` and
44+
* `CaptureFour` routines.
45+
*
46+
* @param count : number of data points to capture
47+
* @param mode : logic level variation. Refer to `IC_PARAMS_CAPTURE_MODE`
48+
* @param channel : the pin that needs to be monitored
49+
*
50+
* @return None
51+
*/
1352
void INTERVAL_CaptureTwo(uint16_t count, uint8_t mode, uint8_t channel);
1453

54+
/**
55+
* @brief Setup input capture on three channels
56+
*
57+
* @description
58+
* This routing will use IC1,2,3 modules with DMA0,1,2 channels to capture
59+
* logic level variations in LA1, LA2 and LA3 pins. These pins are fixed.
60+
* If trigger is set by the trig byte, this will use IC4 module to listen to
61+
* the trigger observation and time log will then start.
62+
*
63+
* @param count : number of data points to capture
64+
* @param mode : logic level variation. Refer to `IC_PARAMS_CAPTURE_MODE`
65+
* @param trig : en/disable trigger using IC4
66+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
67+
* | TRIG PIN | X | TRIG MODE |
68+
*
69+
* @return None
70+
*/
1571
void INTERVAL_CaptureThree(uint16_t count, uint16_t mode, uint8_t trig);
1672

73+
/**
74+
* @brief Setup input capture on four channels
75+
*
76+
* @description
77+
* This routing will use IC1,2,3,4 modules with DMA0,1,2,3 channels to capture
78+
* logic level variations in LA1, LA2, LA3 and LA4 pins. These pins are fixed.
79+
* Timer 2 will be used as the timer source unlike the other three capture
80+
* methods that use peripheral clock as the timer source.
81+
*
82+
* @param count : number of data points to capture
83+
* @param mode : logic level variation. Refer to `IC_PARAMS_CAPTURE_MODE`
84+
* @param prescaler : pre-scaler value for timer 2 module
85+
*
86+
* @return None
87+
*/
1788
void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler);
1889

1990
response_t INTERVAL_GetState(void);

pslab-core.X/registers/memory/dma.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,17 @@ void DMA_PrepareChannel3(uint16_t count, uint16_t high_address, uint16_t low_add
251251
DMA_FlagInterruptClear(DMA_CHANNEL_3);
252252
DMA_InterruptDisable(DMA_CHANNEL_3);
253253
}
254+
255+
void DMA_EnableAllChannels(void) {
256+
DMA_ChannelEnable(DMA_CHANNEL_0);
257+
DMA_ChannelEnable(DMA_CHANNEL_1);
258+
DMA_ChannelEnable(DMA_CHANNEL_2);
259+
DMA_ChannelEnable(DMA_CHANNEL_3);
260+
}
261+
262+
void DMA_DisableAllChannels(void) {
263+
DMA_ChannelDisable(DMA_CHANNEL_0);
264+
DMA_ChannelDisable(DMA_CHANNEL_1);
265+
DMA_ChannelDisable(DMA_CHANNEL_2);
266+
DMA_ChannelDisable(DMA_CHANNEL_3);
267+
}

pslab-core.X/registers/memory/dma.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,12 @@ extern "C" {
967967
*/
968968
void DMA_PrepareChannel3(uint16_t count, uint16_t high_address, uint16_t low_address,
969969
DMA_PERIPHERAL_IRQ_NUMBER trigger);
970+
971+
// Enable all four channels in one go
972+
void DMA_EnableAllChannels(void);
973+
974+
// Disable all four channels in one go
975+
void DMA_DisableAllChannels(void);
970976

971977
// Getters and Setters
972978
void SetDMA_MODE(DMA_MODES mode);

0 commit comments

Comments
 (0)