Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ArduinoZeroTemplate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GRASP
ArduinoZeroTemplate
Commits
ceb88d6b
Commit
ceb88d6b
authored
3 years ago
by
Bengt
Browse files
Options
Downloads
Patches
Plain Diff
Cleaning up
parent
f09c215f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ArduinoZeroTemplate.c
+0
-116
0 additions, 116 deletions
ArduinoZeroTemplate.c
with
0 additions
and
116 deletions
ArduinoZeroTemplate.c
deleted
100644 → 0
+
0
−
116
View file @
f09c215f
/*
* ArduinoZeroTemplate.c
*
* Created: 2020-12-09 09:56:19
* Author: ilosz01
*/
#include
<asf.h>
#include
"ArduinoZeroTemplate.h"
// Globala variabler
// Instances for peripherals. One for each used.
struct
rtc_module
rtc_instance_struct
;
//struct spi_module spi1_instance_struct;
uint32_t
t1ms_timer
=
0
;
void
ArduinoZeroTemplate
(
void
)
{
while
(
true
)
{
}
// end while (true) infinite loop
}
// end ArduinoZeroTemplate
void
ArduinoZeroTemplateInit
(
void
)
{
// Temporary Configuration structures
struct
rtc_count_config
rtc_count_config_struct
;
// If used: struct spi_config spi_config_struct;
// I/O
// Set pin input/output directions.
// For outputs, only the direction bit needs to be set.
// For inputs direction bit is already set but the input buffer must be enabled.
// Most pin functions is set through the PINCFG registers, one for each pin.
// Before writing to any port registers, enable constant input sampling on pins that shall be able to use the faster IOBUS.
// Note: Only Data Output Value, Data Input Value and Pin Direction registers can be accessed through IOBUS operation.
PORT_SET_CTRLSAMPLING
(
LED0_PIN_PORTNR
,
LED_0_PIN
);
PORT_SET_CTRLSAMPLING
(
MY_OUTPUT_PIN_PORTNR
,
MY_OUTPUT_PIN
);
PORT_SET_CTRLSAMPLING
(
MY_INPUT_PIN_PORTNR
,
MY_INPUT_PIN
);
// Configure output pins
// To in all circumstances avoid glitches, set the default value of the pin before setting the direction.
PORT_CLR_PIN
(
LED0_PIN_PORTNR
,
LED_0_PIN
);
// LED
PORT_OUTPUT_PIN
(
LED0_PIN_PORTNR
,
LED_0_PIN
);
// PORT_SET_PIN(MY_OUTPUT_PIN_PORTNR,MY_OUTPUT_PIN) // MY_OUTPUT
// PORT_OUTPUT_PIN(MY_OUTPUT_PIN_PORTNR,MY_OUTPUT_PIN);
// Configure input pins
// All IN-buffers for pins used as inputs must be enabled. This is controlled through the PINCFG.INEN bit
PORT_INPUT_PIN
(
MY_INPUT_PIN_PORTNR
,
MY_INPUT_PIN
);
// MY_INPUT
PORT_INPUT_PIN_EN
(
MY_INPUT_PIN_PORTNR
,
MY_INPUT_PIN
);
// End I/O configuration
// RTC
// Time is measured by saving start time and then compare desired time with current time.
rtc_count_get_config_defaults
(
&
rtc_count_config_struct
);
// Clock source is hardcoded to GCLK_2 in rtc_count_init and set to prescaler of 1 in Channel8ForceClocks.h
rtc_count_config_struct
.
mode
=
RTC_COUNT_MODE_32BIT
;
rtc_count_config_struct
.
prescaler
=
RTC_COUNT_PRESCALER_DIV_4
;
// 32kHz/1/4 ~ 12,2 s
rtc_count_config_struct
.
clear_on_match
=
false
;
//rtc_count_config_struct.continuously_update = true;
//rtc_count_config_struct.enable_read_sync = true;
rtc_count_init
(
&
rtc_instance_struct
,
RTC
,
&
rtc_count_config_struct
);
rtc_count_enable
(
&
rtc_instance_struct
);
// USART 1
/* If used
// I/O does not need top be defined separately for USARTS. Is done automatically when defining the use (SPI) below.
port_get_config_defaults(&port_config_struct);
port_config_struct.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(SCK, &port_config_struct); // SCK, Mode 1. Normally low, trigg negative edge. CPOL=0, CPHA=1
port_pin_set_config(MOSI, &port_config_struct);
*/
// SPI
/* If used
spi_get_config_defaults(&spi_config_struct);
spi_config_struct.generator_source = GCLK_GENERATOR_3;
spi_config_struct.mode = SPI_MODE_MASTER;
spi_config_struct.data_order = SPI_DATA_ORDER_MSB;
spi_config_struct.transfer_mode = SPI_TRANSFER_MODE_1;
spi_config_struct.mux_setting = SPI_SIGNAL_MUX_SETTING_D;
spi_config_struct.character_size = SPI_CHARACTER_SIZE_8BIT;
spi_config_struct.pinmux_pad0 = PINMUX_PA16C_SERCOM1_PAD0;
spi_config_struct.pinmux_pad1 = PINMUX_PA17C_SERCOM1_PAD1;
spi_config_struct.pinmux_pad2 = PINMUX_PA18C_SERCOM1_PAD2; // Not used. Can it be ignored to leave open for other use?
spi_config_struct.pinmux_pad3 = PINMUX_PA19C_SERCOM1_PAD3;
spi_config_struct.mode_specific.master.baudrate = 2000000;
spi_init(&spi1_instance_struct, SERCOM1, &spi_config_struct);
spi_enable(&spi1_instance_struct);
*/
}
// end init
void
Update1msClock
(
void
)
{
// Create a 1 ms clock (0.9765625 ms)
// Note that the program will hang here a maximum of 400 s to synchronize the system clock to the slower RTC clock.
static
uint32_t
current_time
;
// Counts in ticks of the RTC clock
static
uint32_t
previous_time_1ms
=
0
;
// Also counts in ticks of the RTC clock
current_time
=
rtc_count_get_count
(
&
rtc_instance_struct
);
if
(
current_time
>=
(
previous_time_1ms
+
8
))
// That is 1 ms!
{
t1ms_timer
++
;
// Increase our 1 ms clock
previous_time_1ms
=
current_time
;
// Remember the RTC time of the 1 ms tick
}
}
// end Create1msClock
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment