Skip to content

Commit 8bfbf9c

Browse files
committed
docs: documentation for LA
1 parent 46af697 commit 8bfbf9c

File tree

8 files changed

+156
-31
lines changed

8 files changed

+156
-31
lines changed

pslab-core.X/bus/i2c/i2c.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,8 @@ response_t I2C_CommandEnableSMBus(void) {
800800
I2C2CONbits.SMEN = 1;
801801
// Enables I2C2 module and configure SDA2 and SCL2 as serial port pins
802802
I2C2CONbits.I2CEN = 1;
803+
804+
return SUCCESS;
803805
}
804806

805807
response_t I2C_CommandDisableSMBus(void) {
@@ -809,6 +811,7 @@ response_t I2C_CommandDisableSMBus(void) {
809811
I2C2CONbits.SMEN = 0;
810812
// Enables I2C2 module and configure SDA2 and SCL2 as serial port pins
811813
I2C2CONbits.I2CEN = 1;
814+
812815
return SUCCESS;
813816
}
814817

pslab-core.X/commands.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
227227
// 0 1 GET_TIMING 2 3
228228
Undefined, Unimplemented, Undefined, Undefined,
229229
// 4 START_ONE_CHAN_LA 5 START_TWO_CHAN_LA 6 START_FOUR_CHAN_LA 7 FETCH_DMA_DATA
230-
LOGICANALYZER_OneChannel, LOGICANALYZER_TwoChannel, LOGICANALYZER_FourChannel, Unimplemented,
230+
LOGICANALYZER_OneChannel, LOGICANALYZER_TwoChannel, LOGICANALYZER_FourChannel, Removed,
231231
// 8 FETCH_INT_DMA_DATA 9 FETCH_LONG_DMA_DATA 10 COMPARATOR_TO_LA 11 GET_INITIAL_STATES
232232
BUFFER_FetchInt, BUFFER_FetchLong, Unimplemented, INTERVAL_GetState,
233233
// 12 TIMING_MEASUREMENTS 13 INTERVAL_MEASUREMENTS 14 CONFIGURE_COMPARATOR 15 START_ALTERNATE_ONE_CHAN_LA
234-
Unimplemented, Unimplemented, Unimplemented, LOGICANALYZER_OneChannelAlt,
234+
Unimplemented, Unimplemented, Removed, LOGICANALYZER_OneChannelAlt,
235235
// 16 START_THREE_CHAN_LA 17 STOP_LA 18 19
236236
LOGICANALYZER_ThreeChannel, LOGICANALYZER_Stop, Undefined, Undefined,
237237
// 20 21 22 23

pslab-core.X/commands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" {
1717
* This is used to set the dimensions of the command table, and to sanitize
1818
* received commands.
1919
*/
20-
#define NUM_PRIMARY_CMDS 12
20+
#define NUM_PRIMARY_CMDS 13
2121
#define NUM_FLASH_CMDS 4
2222
#define NUM_ADC_CMDS 23
2323
#define NUM_SPI_CMDS 7

pslab-core.X/helpers/interval.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void INTERVAL_CaptureOne(uint16_t count, uint8_t channel, uint8_t mode, uint8_t
6161
CMP4_SetupComparator();
6262
}
6363
RPINR8bits.IC4R = PIN_MANAGER_DIGITAL_PINS[(trig >> 4) & 0xF];
64-
6564
IC4_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER_PERIPHERAL);
6665
IC1_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE_IC4);
6766
IC2_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE_IC4);
@@ -102,7 +101,7 @@ void INTERVAL_CaptureTwo(uint16_t count, uint8_t mode, uint8_t channel) {
102101
SetDMA_MODE(DMA_MODES_TWO_CHANNEL);
103102

104103
RPINR7bits.IC1R = PIN_MANAGER_DIGITAL_PINS[channel & 0xF];
105-
RPINR8bits.IC3R = PIN_MANAGER_DIGITAL_PINS[(channel >> 4)&0xF];
104+
RPINR8bits.IC3R = PIN_MANAGER_DIGITAL_PINS[(channel >> 4) & 0xF];
106105

107106
IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER_PERIPHERAL);
108107
IC_PARAMS_CombineOddEvenModules();
@@ -152,7 +151,11 @@ void INTERVAL_CaptureThree(uint16_t count, uint16_t mode, uint8_t trig) {
152151
IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
153152

154153
if (trig & 7) {
155-
RPINR8bits.IC4R = PIN_MANAGER_DIGITAL_PINS[(trig >> 4) & 0xF];
154+
if ((trig >> 4) == 4) {
155+
CVR_SetupComparator();
156+
CMP4_SetupComparator();
157+
}
158+
RPINR8bits.IC4R = PIN_MANAGER_DIGITAL_PINS[(trig >> 4) & 0xF];
156159
IC1_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE_IC4);
157160
IC2_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE_IC4);
158161
IC3_SetCaptureSource(IC_PARAMS_CAPTURE_SOURCE_IC4);

pslab-core.X/instruments/logicanalyzer.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "../registers/comparators/ic3.h"
77
#include "../registers/comparators/ic4.h"
88
#include "../registers/comparators/ic_params.h"
9-
#include "../registers/system/pin_manager.h"
109
#include "../registers/system/interrupt_manager.h"
10+
#include "../registers/system/pin_manager.h"
1111
#include "../registers/timers/tmr2.h"
1212
#include "../commands.h"
1313

@@ -94,12 +94,16 @@ response_t LOGICANALYZER_TwoChannel(void) {
9494
}
9595

9696
return SUCCESS;
97+
98+
// TODO: Implement trigger actions for any of the two channels. Right now
99+
// only one channel can be set as trigger source. Using CN interrupts, this
100+
// can be extended to listen to multiple trigger sources.
97101
}
98102

99103
response_t LOGICANALYZER_ThreeChannel(void) {
100104

101105
uint16_t points = UART1_ReadInt();
102-
uint8_t config = UART1_Read();
106+
uint8_t config = UART1_ReadInt();
103107
uint8_t trigger = UART1_Read();
104108

105109
IC4_InterruptHighPriority();
@@ -119,6 +123,10 @@ response_t LOGICANALYZER_ThreeChannel(void) {
119123
}
120124

121125
return SUCCESS;
126+
127+
// TODO: Implement trigger actions for any of the three channels. Right now
128+
// only one channel can be set as trigger source. Using CN interrupts, this
129+
// can be extended to listen to multiple trigger sources.
122130
}
123131

124132
response_t LOGICANALYZER_FourChannel(void) {
@@ -132,7 +140,7 @@ response_t LOGICANALYZER_FourChannel(void) {
132140
INTERVAL_CaptureFour(points, mode, prescaler);
133141

134142
if (trigger & 1) {
135-
LA_TRIGGER_STATE = (trigger & 2) ? 1 : 0;
143+
LA_TRIGGER_STATE = trigger & 2 ? FALLING_EDGE : RISING_EDGE;
136144
LA_TRIGGER_CHANNEL = 0;
137145

138146
if ((trigger >> 2) & 1) {
@@ -151,7 +159,6 @@ response_t LOGICANALYZER_FourChannel(void) {
151159
INTERRUPT_LA4PinChange(true);
152160
LA_TRIGGER_CHANNEL |= 8;
153161
}
154-
155162
INTERRUPT_ClearPinChangeInterruptsFlag();
156163
INTERRUPT_EnablePinChangeInterrupts();
157164
} else {

pslab-core.X/instruments/logicanalyzer.h

Lines changed: 122 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@
77
* @brief Capture logic level changes on a single channel.
88
*
99
* @description
10+
* This routine will log timer values for the changes occurred in a pin defined
11+
* by the configuration byte.
12+
*
13+
* If a trigger is enabled, this will use an external interrupt service routine
14+
* attached to a pin defined by the trigger byte. Once the logic level is observed
15+
* to be the same as in EDGE bit, IC1 and IC2 modules will start the combined
16+
* timer (32-bits) and pass them to BUFFER using first two DMA channels.
17+
*
18+
* If no trigger is set, the timers will be started right away once the function
19+
* is called and logic level changes will logged referring to IC1 and IC2 capture
20+
* timers in BUFFER using the same DMA channels.
21+
*
1022
* This command function takes three arguments over serial:
1123
* 1. (uint16) number of data points to capture
1224
* 2. (uint8) trigger conditions:
1325
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
14-
* | PIN | X | X | EDGE | EN |
26+
* | TRIGGER PIN | X | X | EDGE | EN |
1527
* PIN: Digital pin from map:
1628
* 0: LA1,
1729
* 1: LA2,
@@ -22,9 +34,9 @@
2234
* 6: FREQ
2335
* EDGE: Falling (1) or Rising (0) edge trigger
2436
* EN: Enable trigger
25-
* 3. (uint8) Configuration byte:
26-
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
27-
* | CHANNEL | MODE |
37+
* 3. (uint8) channel and mode configurations:
38+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
39+
* | DIGITAL PIN | TRANSITIONS |
2840
* CHANNEL: Digital pin from the same map as above `PIN` maps
2941
* MODE: Logic transitions to capture. Refer `IC_PARAMS_CAPTURE_MODE`
3042
*
@@ -41,10 +53,29 @@ response_t LOGICANALYZER_OneChannel(void);
4153
* @brief Capture logic level changes in one channel
4254
*
4355
* @description
56+
* This routine is much similar to `LOGICANALYZER_OneChannel` except the trigger
57+
* is handled differently. If trigger is enabled, IC4 pin will be connected to a
58+
* pin defined by the trigger byte and an ISR will be activated for IC4 module.
59+
* This will trigger an interrupt when a logic change defined by the trigger byte
60+
* is observed at the pin attached to IC4. At the same time, IC1 and IC2 start
61+
* their timers and log timer values to BUFFER using DMA0 and DMA1 channels
62+
*
4463
* This command function takes three arguments over serial:
45-
* 1. (uint16) Number of data points/change events to capture
46-
* 2. (uint8) Trigger settings
47-
* 3. (uint8) Channel and mode configurations
64+
* 1. (uint16) number of data points to capture
65+
* 2. (uint8) trigger conditions:
66+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
67+
* | TRIG PIN | X | TRIG MODE |
68+
* PIN: Digital pin from map:
69+
* 0: LA1,
70+
* 1: LA2,
71+
* 2: LA3,
72+
* 3: LA4,
73+
* 4: COMP4,
74+
* 5: SPI_CS,
75+
* 6: FREQ
76+
* 3. (uint8) channel and mode configuration:
77+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
78+
* | DIGITAL PIN | TRANSITIONS |
4879
*
4980
* It returns nothing over serial.
5081
* It sends an acknowledge byte (SUCCESS).
@@ -57,10 +88,37 @@ response_t LOGICANALYZER_OneChannelAlt(void);
5788
* @brief Capture logic level changes in two channels
5889
*
5990
* @description
60-
* This command function takes three arguments over serial:
61-
* 1. (uint16) Number of data points/change events to capture
62-
* 2. (uint8) Trigger settings
63-
* 3. (uint8) Channel and mode configurations
91+
* This routine will log timer values on logic level changes in two different
92+
* pins defined by the channel byte.
93+
*
94+
* If a trigger is enabled, this will use an external interrupt service routine
95+
* attached to a pin defined by trigger byte. Once the logic level is observed
96+
* to be the same as in EDGE bit, All IC modules will start the combined
97+
* timers (32-bits) and pass them to BUFFER using all four DMA channels.
98+
*
99+
* If no trigger is enabled, the timers will be started right away once the
100+
* function is called and logic level changes will logged referring to IC1 and
101+
* IC3 combined capture timers in BUFFER using the same DMA channels.
102+
*
103+
* This command function takes four arguments over serial:
104+
* 1. (uint16) number of data points to capture
105+
* 2. (uint8) trigger conditions:
106+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
107+
* | TRIG PIN | X | X | EDGE | EN |
108+
* PIN: Digital pin from map:
109+
* 0: LA1,
110+
* 1: LA2,
111+
* 2: LA3,
112+
* 3: LA4,
113+
* 4: COMP4,
114+
* 5: SPI_CS,
115+
* 6: FREQ
116+
* 3. (uint8) mode configurations:
117+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
118+
* | PIN 2 MODES | PIN 1 MODES |
119+
* 4. (uint8) channel configurations:
120+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
121+
* | PIN 2 CHANNEL | PIN 1 CHANNEL |
64122
*
65123
* It returns nothing over serial.
66124
* It sends an acknowledge byte (SUCCESS).
@@ -73,10 +131,36 @@ response_t LOGICANALYZER_TwoChannel(void);
73131
* @brief Capture logic level changes in three channels
74132
*
75133
* @description
134+
* This routine will log timer values on logic level changes in LA1, LA2 and LA3
135+
* pins. These pins are fixed for this mode of operation.
136+
*
137+
* If a trigger is enabled, this will use IC4 module as a trigger source to start
138+
* IC1, 2 and 3 timers. Once the logic level change as defined in trigger byte is
139+
* observed at IC4, it will generate an interrupt that will turn on all IC1,2,3
140+
* timers which will capture logic level changes defined in configuration integer.
141+
* IC modules will have 16-bit timers and the value is logged to BUFFER using
142+
* three DMA channels.
143+
*
144+
* If no trigger is enabled, the timers will be started right away once the
145+
* function is called and logic level changes will logged referring to IC1, 2
146+
* and IC3 combined capture timers in BUFFER using the same DMA channels.
147+
*
76148
* This command function takes three arguments over serial:
77-
* 1. (uint16) Number of data points/change events to capture
78-
* 2. (uint8) Trigger settings
79-
* 3. (uint8) Channel and mode configurations
149+
* 1. (uint16) number of data points to capture
150+
* 2. (uint16) configurations:
151+
* | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
152+
* | X | X | X | X | LA3 EDGES | LA2 EDGES | LA1 EDGES |
153+
* 3. (uint8) trigger conditions:
154+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
155+
* | TRIG PIN | X | TRIG MODE |
156+
* PIN: Trig pin from map:
157+
* 0: LA1,
158+
* 1: LA2,
159+
* 2: LA3,
160+
* 3: LA4,
161+
* 4: COMP4,
162+
* 5: SPI_CS,
163+
* 6: FREQ
80164
*
81165
* It returns nothing over serial.
82166
* It sends an acknowledge byte (SUCCESS).
@@ -89,10 +173,29 @@ response_t LOGICANALYZER_ThreeChannel(void);
89173
* @brief Capture logic level changes in four channels
90174
*
91175
* @description
92-
* This command function takes three arguments over serial:
93-
* 1. (uint16) Number of data points/change events to capture
94-
* 2. (uint8) Trigger settings
95-
* 3. (uint8) Channel and mode configurations
176+
* This routine will log timer values on logic level changes in LA1, LA2, LA3
177+
* and LA4 pins. These pins are fixed for this mode of operation.
178+
*
179+
* If a trigger is enabled, this will use CN (Change Notifier) Interrupt Service
180+
* Routine to trigger the IC timers to log logic level changes. If any of the 4
181+
* pins observe a logic change as defined in trigger byte, the timers will get
182+
* started logging logic level changes in all 4 pins defined in the configuration
183+
* integer. IC modules will have 16-bit timers and the value is logged to BUFFER
184+
* using all four DMA channels.
185+
*
186+
* If no trigger is enabled, the timers will be started right away once the
187+
* function is called and logic level changes will logged referring to IC1, IC2,
188+
* IC3 and IC4 capture timers in BUFFER using the same DMA channels.
189+
*
190+
* This command function takes four arguments over serial:
191+
* 1. (uint16) number of data points to capture
192+
* 2. (uint16) mode configurations:
193+
* | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
194+
* | LA4 EDGES | LA3 EDGES | LA2 EDGES | LA1 EDGES |
195+
* 3. (uint8) pre-scaler settings for timer 2
196+
* 4. (uint8) trigger settings:
197+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
198+
* | X | X | LA4 | LA3 | LA2 | LA1 | EDGE | EN |
96199
*
97200
* It returns nothing over serial.
98201
* It sends an acknowledge byte (SUCCESS).
@@ -106,7 +209,7 @@ response_t LOGICANALYZER_FourChannel(void);
106209
*
107210
* @description
108211
* This command function does not take any arguments over serial. It will stop
109-
* all the capture modules.
212+
* all the input capture modules.
110213
*
111214
* It returns nothing over serial.
112215
* It sends an acknowledge byte (SUCCESS).

pslab-core.X/registers/comparators/ic4.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
#include "ic4.h"
2+
#include "../../helpers/interval.h"
3+
4+
void __attribute__((__interrupt__, no_auto_psv)) _IC4Interrupt(void) {
5+
SetDefaultDIGITAL_STATES();
6+
IC4_Stop();
7+
IC4_InterruptFlagClear();
8+
IC4_InterruptDisable();
9+
SetDefaultDIGITAL_STATES_ERROR();
10+
}
211

312
void IC4_Initialize(void) {
413
IC4_InitializeCON1();

pslab-core.X/registers/system/interrupt_manager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ void __attribute__((__interrupt__, no_auto_psv)) _CNInterrupt(void) {
1717
INTERRUPT_LA2PinChange(DISABLE);
1818
INTERRUPT_LA3PinChange(DISABLE);
1919
INTERRUPT_LA4PinChange(DISABLE);
20-
2120
INTERRUPT_DisablePinChangeInterrupts();
21+
22+
TMR2_Start();
2223
SetDefaultDIGITAL_STATES();
2324
IC_PARAMS_ManualTriggerAll();
24-
TMR2_Start();
2525
SetDefaultDIGITAL_STATES_ERROR();
2626
}
2727
INTERRUPT_ClearPinChangeInterruptsFlag();

0 commit comments

Comments
 (0)