Skip to content

Commit df3cbd7

Browse files
authored
Merge pull request #7 from harp-tech/fw-implement_remaining_features
Implements the remaining features
2 parents 3e3ffa5 + 44204f7 commit df3cbd7

15 files changed

+941
-135
lines changed

Assets/HardwareUnitTests.bonsai

Lines changed: 676 additions & 0 deletions
Large diffs are not rendered by default.

Firmware/AnalogInput/AnalogInput.cppproj

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -131,65 +131,65 @@
131131
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
132132
<ToolchainSettings>
133133
<AvrGccCpp>
134-
<avrgcc.common.Device>-mmcu=atxmega128a4u -B "%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\gcc\dev\atxmega128a4u"</avrgcc.common.Device>
135-
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
136-
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
137-
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
138-
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
139-
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
140-
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
141-
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
142-
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
143-
<avrgcc.compiler.symbols.DefSymbols>
144-
<ListValues>
145-
<Value>DEBUG</Value>
146-
</ListValues>
147-
</avrgcc.compiler.symbols.DefSymbols>
148-
<avrgcc.compiler.directories.IncludePaths>
149-
<ListValues>
150-
<Value>%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\include</Value>
151-
</ListValues>
152-
</avrgcc.compiler.directories.IncludePaths>
153-
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
154-
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
155-
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
156-
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
157-
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
158-
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
159-
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
160-
<avrgcccpp.compiler.symbols.DefSymbols>
161-
<ListValues>
162-
<Value>DEBUG</Value>
163-
</ListValues>
164-
</avrgcccpp.compiler.symbols.DefSymbols>
165-
<avrgcccpp.compiler.directories.IncludePaths>
166-
<ListValues>
167-
<Value>%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\include</Value>
168-
</ListValues>
169-
</avrgcccpp.compiler.directories.IncludePaths>
170-
<avrgcccpp.compiler.optimization.level>Optimize most (-O3)</avrgcccpp.compiler.optimization.level>
171-
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
172-
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
173-
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
174-
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
175-
<avrgcccpp.linker.libraries.Libraries>
176-
<ListValues>
177-
<Value>libm</Value>
178-
<Value>libATxmega128A4U-1.9.a</Value>
179-
</ListValues>
180-
</avrgcccpp.linker.libraries.Libraries>
181-
<avrgcccpp.linker.libraries.LibrarySearchPaths>
182-
<ListValues>
183-
<Value>..</Value>
184-
</ListValues>
185-
</avrgcccpp.linker.libraries.LibrarySearchPaths>
186-
<avrgcccpp.assembler.general.IncludePaths>
187-
<ListValues>
188-
<Value>%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\include</Value>
189-
</ListValues>
190-
</avrgcccpp.assembler.general.IncludePaths>
191-
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
192-
</AvrGccCpp>
134+
<avrgcc.common.Device>-mmcu=atxmega128a4u -B "%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\gcc\dev\atxmega128a4u"</avrgcc.common.Device>
135+
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
136+
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
137+
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
138+
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
139+
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
140+
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
141+
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
142+
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
143+
<avrgcc.compiler.symbols.DefSymbols>
144+
<ListValues>
145+
<Value>DEBUG</Value>
146+
</ListValues>
147+
</avrgcc.compiler.symbols.DefSymbols>
148+
<avrgcc.compiler.directories.IncludePaths>
149+
<ListValues>
150+
<Value>%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\include</Value>
151+
</ListValues>
152+
</avrgcc.compiler.directories.IncludePaths>
153+
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
154+
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
155+
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
156+
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
157+
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
158+
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
159+
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
160+
<avrgcccpp.compiler.symbols.DefSymbols>
161+
<ListValues>
162+
<Value>DEBUG</Value>
163+
</ListValues>
164+
</avrgcccpp.compiler.symbols.DefSymbols>
165+
<avrgcccpp.compiler.directories.IncludePaths>
166+
<ListValues>
167+
<Value>%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\include</Value>
168+
</ListValues>
169+
</avrgcccpp.compiler.directories.IncludePaths>
170+
<avrgcccpp.compiler.optimization.level>Optimize most (-O3)</avrgcccpp.compiler.optimization.level>
171+
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
172+
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
173+
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
174+
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
175+
<avrgcccpp.linker.libraries.Libraries>
176+
<ListValues>
177+
<Value>libm</Value>
178+
<Value>libATxmega128A4U-1.12.a</Value>
179+
</ListValues>
180+
</avrgcccpp.linker.libraries.Libraries>
181+
<avrgcccpp.linker.libraries.LibrarySearchPaths>
182+
<ListValues>
183+
<Value>..</Value>
184+
</ListValues>
185+
</avrgcccpp.linker.libraries.LibrarySearchPaths>
186+
<avrgcccpp.assembler.general.IncludePaths>
187+
<ListValues>
188+
<Value>%24(PackRepoDir)\atmel\XMEGAA_DFP\1.1.68\include</Value>
189+
</ListValues>
190+
</avrgcccpp.assembler.general.IncludePaths>
191+
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
192+
</AvrGccCpp>
193193
</ToolchainSettings>
194194
</PropertyGroup>
195195
<ItemGroup>

Firmware/AnalogInput/app.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void hwbp_app_initialize(void)
3030
uint8_t hwH = 1;
3131
uint8_t hwL = 0;
3232
uint8_t fwH = 1;
33-
uint8_t fwL = 0;
33+
uint8_t fwL = 2;
3434
uint8_t ass = 0;
3535

3636
/* Start core */
@@ -42,7 +42,10 @@ void hwbp_app_initialize(void)
4242
(uint8_t*)(&app_regs),
4343
APP_NBYTES_OF_REG_BANK,
4444
APP_REGS_ADD_MAX - APP_REGS_ADD_MIN + 1,
45-
default_device_name
45+
default_device_name,
46+
false, // The device is _not_ able to repeat the harp timestamp clock
47+
false, // The device is _not_ able to generate the harp timestamp clock
48+
0
4649
);
4750
}
4851

@@ -62,7 +65,11 @@ void core_callback_catastrophic_error_detected(void)
6265
/************************************************************************/
6366
/* Initialization Callbacks */
6467
/************************************************************************/
65-
void core_callback_1st_config_hw_after_boot(void)
68+
extern bool previous_DIO;
69+
70+
void core_callback_define_clock_default(void) {}
71+
72+
void core_callback_initialize_hardware(void)
6673
{
6774
/* Initialize IOs */
6875
/* Don't delete this function!!! */
@@ -78,7 +85,17 @@ void core_callback_1st_config_hw_after_boot(void)
7885
set_RESET;
7986
_delay_ms(1);
8087
clr_RESET;
81-
_delay_ms(1);
88+
_delay_ms(1);
89+
90+
/* Get initial state of DI0 */
91+
if (read_DI0)
92+
{
93+
previous_DIO = true;
94+
}
95+
else
96+
{
97+
previous_DIO = false;
98+
}
8299
}
83100

84101
void core_callback_reset_registers(void)
@@ -247,6 +264,14 @@ void core_callback_t_1ms(void)
247264
}
248265
}
249266

267+
/************************************************************************/
268+
/* Callbacks: clock control */
269+
/************************************************************************/
270+
void core_callback_clock_to_repeater(void) {}
271+
void core_callback_clock_to_generator(void) {}
272+
void core_callback_clock_to_unlock(void) {}
273+
void core_callback_clock_to_lock(void) {}
274+
250275
/************************************************************************/
251276
/* Callbacks: uart control */
252277
/************************************************************************/

Firmware/AnalogInput/app_funcs.c

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ bool app_write_REG_ANALOG_INPUTS(void *a)
176176
/************************************************************************/
177177
void app_read_REG_DI0(void)
178178
{
179-
//app_regs.REG_DI0 = 0;
180-
179+
if (read_DI0)
180+
app_regs.REG_DI0 = B_DI0;
181+
else
182+
app_regs.REG_DI0 = 0;
181183
}
182184

183185
bool app_write_REG_DI0(void *a)
@@ -312,6 +314,12 @@ void app_read_REG_DO0_PULSE(void)
312314
bool app_write_REG_DO0_PULSE(void *a)
313315
{
314316
uint8_t reg = *((uint8_t*)a);
317+
318+
if (reg < 1)
319+
return false;
320+
321+
if (reg > 250)
322+
return false;
315323

316324
app_regs.REG_DO0_PULSE = reg;
317325
return true;
@@ -326,11 +334,23 @@ bool app_write_REG_DO_SET(void *a)
326334
{
327335
uint8_t reg = *((uint8_t*)a);
328336

329-
//PORTA_OUTSET = reg & 0x0F;
330-
//if (reg & B_DO0)
331-
// pulse_counter_ms = app_regs.REG_DO0_PULSE + 1;
332-
333-
app_regs.REG_DO_WRITE = PORTA_OUT & 0x0F;
337+
if ((reg & B_DO0) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO0))
338+
{
339+
if (app_regs.REG_DO0_CONF == GM_DO0_DIG)
340+
{
341+
set_DO0;
342+
}
343+
if (app_regs.REG_DO0_CONF == GM_DO0_PULSE)
344+
{
345+
set_DO0;
346+
pulse_counter_ms = app_regs.REG_DO0_PULSE + 1;
347+
}
348+
}
349+
350+
if ((reg & B_DO1) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO1)) set_DO1;
351+
if ((reg & B_DO2) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO2)) set_DO2;
352+
if ((reg & B_DO3) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO3)) set_DO3;
353+
334354
app_regs.REG_DO_SET = reg;
335355
return true;
336356
}
@@ -344,9 +364,19 @@ bool app_write_REG_DO_CLEAR(void *a)
344364
{
345365
uint8_t reg = *((uint8_t*)a);
346366

347-
//PORTA_OUTCLR = reg & 0x0F;
348-
349-
app_regs.REG_DO_WRITE = PORTA_OUT & 0x0F;
367+
if ((reg & B_DO0) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO0))
368+
{
369+
if (app_regs.REG_DO0_CONF != GM_DO0_TGL_EACH_SEC)
370+
{
371+
clr_DO0;
372+
pulse_counter_ms = 0;
373+
}
374+
}
375+
376+
if ((reg & B_DO1) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO1)) clr_DO1;
377+
if ((reg & B_DO2) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO2)) clr_DO2;
378+
if ((reg & B_DO3) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO3)) clr_DO3;
379+
350380
app_regs.REG_DO_CLEAR = reg;
351381
return true;
352382
}
@@ -360,13 +390,34 @@ bool app_write_REG_DO_TOGGLE(void *a)
360390
{
361391
uint8_t reg = *((uint8_t*)a);
362392

363-
//if (!read_DO0)
364-
// if (reg & B_DO0)
365-
// pulse_counter_ms = app_regs.REG_DO0_PULSE + 1;
366-
367-
//PORTA_OUTTGL = reg & 0x0F;
393+
if ((reg & B_DO0) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO0))
394+
{
395+
if (read_DO0)
396+
{
397+
if (app_regs.REG_DO0_CONF != GM_DO0_TGL_EACH_SEC)
398+
{
399+
clr_DO0;
400+
pulse_counter_ms = 0;
401+
}
402+
}
403+
else
404+
{
405+
if (app_regs.REG_DO0_CONF == GM_DO0_DIG)
406+
{
407+
set_DO0;
408+
}
409+
if (app_regs.REG_DO0_CONF == GM_DO0_PULSE)
410+
{
411+
set_DO0;
412+
pulse_counter_ms = app_regs.REG_DO0_PULSE + 1;
413+
}
414+
}
415+
}
416+
417+
if ((reg & B_DO1) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO1)) tgl_DO1;
418+
if ((reg & B_DO2) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO2)) tgl_DO2;
419+
if ((reg & B_DO3) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO3)) tgl_DO3;
368420

369-
app_regs.REG_DO_WRITE = PORTA_OUT & 0x0F;
370421
app_regs.REG_DO_TOGGLE = reg;
371422
return true;
372423
}
@@ -375,15 +426,35 @@ bool app_write_REG_DO_TOGGLE(void *a)
375426
/************************************************************************/
376427
/* REG_DO_WRITE */
377428
/************************************************************************/
378-
void app_read_REG_DO_WRITE(void) {}
429+
void app_read_REG_DO_WRITE(void)
430+
{
431+
app_regs.REG_DO_WRITE = PORTA_IN & 0x0F;
432+
}
379433
bool app_write_REG_DO_WRITE(void *a)
380434
{
381435
uint8_t reg = *((uint8_t*)a);
382436

383-
//PORTA_OUT = (PORTA_OUT & (~0x0F)) | (reg & 0x0F);
437+
if ((app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO0) && (app_regs.REG_DO0_CONF != GM_DO0_TGL_EACH_SEC))
438+
{
439+
if (reg & B_DO0)
440+
{
441+
set_DO0;
442+
443+
if (app_regs.REG_DO0_CONF == GM_DO0_PULSE)
444+
{
445+
pulse_counter_ms = app_regs.REG_DO0_PULSE + 1;
446+
}
447+
}
448+
else
449+
{
450+
clr_DO0;
451+
pulse_counter_ms = 0;
452+
}
453+
}
384454

385-
//if (reg & B_DO0)
386-
// pulse_counter_ms = app_regs.REG_DO0_PULSE + 1;
455+
if ((reg & B_DO1) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO1)) set_DO1; else clr_DO1;
456+
if ((reg & B_DO2) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO2)) set_DO2; else clr_DO2;
457+
if ((reg & B_DO3) && (app_regs.REG_TRIGGER_DESTINY != GM_TRIG_TO_DO3)) set_DO3; else clr_DO3;
387458

388459
app_regs.REG_DO_WRITE = PORTA_OUT & 0x0F;
389460
return true;

Firmware/AnalogInput/app_ios_and_regs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void init_ios(void)
2525
io_pin2out(&PORTC, 1, OUT_IO_DIGITAL, IN_EN_IO_EN); // CONVSTB
2626
io_pin2out(&PORTC, 5, OUT_IO_DIGITAL, IN_EN_IO_DIS); // MOSI
2727
io_pin2out(&PORTC, 7, OUT_IO_DIGITAL, IN_EN_IO_DIS); // SCK
28-
io_pin2out(&PORTD, 0, OUT_IO_WIREDAND, IN_EN_IO_EN); // RESET
28+
io_pin2out(&PORTD, 0, OUT_IO_DIGITAL, IN_EN_IO_EN); // RESET
2929
io_pin2out(&PORTD, 2, OUT_IO_DIGITAL, IN_EN_IO_EN); // OS0
3030
io_pin2out(&PORTD, 3, OUT_IO_DIGITAL, IN_EN_IO_DIS); // OS1
3131
io_pin2out(&PORTD, 4, OUT_IO_DIGITAL, IN_EN_IO_DIS); // OS2

Firmware/AnalogInput/app_ios_and_regs.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ typedef struct
196196
#define ADD_REG_SAMPLE_FREQUENCY 38 // U8 Sample rate of analog conversions
197197
#define ADD_REG_DI0_CONF 39 // U8 Configuration of the digital input 0 (DI0)
198198
#define ADD_REG_DO0_CONF 40 // U8 Configuration of the digital output 0 (DO0)
199-
#define ADD_REG_DO0_PULSE 41 // U8 Pulse for the digital output 0 (DO0) [1:255]
199+
#define ADD_REG_DO0_PULSE 41 // U8 Pulse for the digital output 0 (DO0) [1:250]
200200
#define ADD_REG_DO_SET 42 // U8 Set the digital outputs
201201
#define ADD_REG_DO_CLEAR 43 // U8 Clear the digital outputs
202202
#define ADD_REG_DO_TOGGLE 44 // U8 Toggle the digital outputs
@@ -279,12 +279,11 @@ typedef struct
279279
#define MSK_SAMPLE_FREQUENCY (3<<0) //
280280
#define GM_1KHZ 0x00 //
281281
#define GM_2KHZ 0x01 //
282-
#define MSK_DI0_SEL (7<<0) //
282+
#define MSK_DI0_SEL (3<<0) //
283283
#define GM_DI0_SYNC (0<<0) // Use as a pure digital input
284284
#define GM_DI0_RISE_START_ACQ (1<<0) // Start acquisition when rising edge and stop when falling edge
285285
#define GM_DI0_FALL_START_ACQ (2<<0) // Start acquisition when falling edge and stop when rising edge
286286
#define GM_DI0_RISE_CATCH_SAMPLE (3<<0) // Acquire a sample when a rising edge is detected
287-
#define GM_DI0_FALL_CATCH_SAMPLE (4<<0) // Acquire a sample when a falling edge is detected
288287
#define MSK_DO0_SEL (3<<0) //
289288
#define GM_DO0_DIG (0<<0) // Use as a pure digital output like all the other digital outputs
290289
#define GM_DO0_TGL_EACH_SEC (1<<0) // Toggle each second when acquiring

0 commit comments

Comments
 (0)