aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c
diff options
context:
space:
mode:
authoredolomb <none@example.com>2018-01-22 19:51:16 +0000
committeredolomb <none@example.com>2018-01-22 19:51:16 +0000
commit53044c14a465c3868e80f59eab0a4ea1dbdca1f8 (patch)
treee990d650387bc0d5a40a994663907faab3a6dfca /os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c
parent8b9d39d2a8f8685e68ac2a84f7e1a54f45c93c58 (diff)
downloadChibiOS-53044c14a465c3868e80f59eab0a4ea1dbdca1f8.tar.gz
ChibiOS-53044c14a465c3868e80f59eab0a4ea1dbdca1f8.tar.bz2
ChibiOS-53044c14a465c3868e80f59eab0a4ea1dbdca1f8.zip
Splitted boards for secure and not secure configuration
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11393 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c')
-rw-r--r--os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c b/os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c
new file mode 100644
index 000000000..b548ad608
--- /dev/null
+++ b/os/hal/boards/ATSAMA5D2_XULT_NSEC/board.c
@@ -0,0 +1,138 @@
+/*
+ ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+
+#define _PIOA ((Pio*)0xFC038000U)
+/*
+ * SAMA PIO CFGR masks.
+ */
+#define SAMA_PIO_FUNC_GPIO 0U
+#define SAMA_PIO_FUNC_PERIPH_A 1U
+#define SAMA_PIO_FUNC_PERIPH_B 2U
+#define SAMA_PIO_FUNC_PERIPH_C 3U
+#define SAMA_PIO_FUNC_PERIPH_D 4U
+#define SAMA_PIO_FUNC_PERIPH_E 5U
+#define SAMA_PIO_FUNC_PERIPH_F 6U
+#define SAMA_PIO_FUNC_PERIPH_G 7U
+#define SAMA_PIO_FUNC(n) (n)
+#define SAMA_PIO_DIR_INPUT (0U)
+#define SAMA_PIO_DIR_OUTPUT (1U << 8U)
+#define SAMA_PIO_PUEN (1U << 9U)
+#define SAMA_PIO_PDEN (1U << 10U)
+#define SAMA_PIO_IFEN (1U << 12U)
+#define SAMA_PIO_IFSCEN (1U << 13U)
+#define SAMA_PIO_OPD (1U << 14U)
+#define SAMA_PIO_SCHMITT (1U << 15U)
+#define SAMA_PIO_DRVSTR_LO (0U << 16U)
+#define SAMA_PIO_DRVSTR_ME (2U << 16U)
+#define SAMA_PIO_DRVSTR_HI (3U << 16U)
+
+#define SAMA_PIO_LOW 0U
+#define SAMA_PIO_HIGH 1U
+/*
+ * SAMA PIO default SIOSR, MSKR and CFGR values.
+ */
+#define SAMA_DEFAULT_SIOSR 0x00000000U
+#define SAMA_DEFAULT_SIONR 0xFFFFFFFFU
+#define SAMA_DEFAULT_MSKR 0xFFFFFFFFU
+#define SAMA_DEFAULT_CFGR SAMA_PIO_FUNC_GPIO | SAMA_PIO_PUEN | \
+ SAMA_PIO_DIR_INPUT | SAMA_PIO_SCHMITT
+
+/*
+ * This macro converts a pin identifier to a bitmask.
+ */
+#define SAMA_PIN_N(n) (1U << n)
+
+/**
+ * @brief SIU/SIUL register initializer type.
+ */
+typedef struct {
+ int32_t pio_id;
+ uint32_t pio_msk;
+ uint32_t pio_cfg;
+ uint32_t pio_ods;
+} sama_pio_init_t;
+
+/*
+ * @brief Initial setup of all defined pads.
+ * @note All pads are secured when SAMA_HAL_IS_SECURE is set as @p TRUE.
+ * @note The list is terminated by a {-1, 0, 0, 0}
+ */
+static const sama_pio_init_t sama_inits[] = {
+ /* RGB Led */
+ {SAMA_PIOB,
+ SAMA_PIN_N(PIOB_LED_RED),
+ SAMA_PIO_FUNC_GPIO | SAMA_PIO_DIR_OUTPUT | SAMA_PIO_DRVSTR_HI,
+ SAMA_PIO_HIGH},
+ /* list terminated*/
+ {-1, 0, 0, 0}
+};
+
+/**
+ * @brief Early initialization code.
+ * @details This initialization must be performed just after stack setup
+ * and before any other initialization.
+ */
+void __early_init(void) {
+
+ sama_clock_init();
+}
+
+/**
+ * @brief Board-specific initialization code.
+ */
+void boardInit(void) {
+ unsigned i;
+
+ /* Configuring all PIO A pads with default configuration. */
+#if SAMA_HAS_PIOA
+ _PIOA->PIO_PIO_[SAMA_PIOA].S_PIO_MSKR = SAMA_DEFAULT_MSKR;
+ _PIOA->PIO_PIO_[SAMA_PIOA].S_PIO_CFGR = SAMA_DEFAULT_CFGR;
+#endif /* SAMA_HAS_PIOA */
+
+ /* Configuring all PIO B pads with default configuration. */
+#if SAMA_HAS_PIOB
+ _PIOA->PIO_PIO_[SAMA_PIOB].S_PIO_MSKR = SAMA_DEFAULT_MSKR;
+ _PIOA->PIO_PIO_[SAMA_PIOB].S_PIO_CFGR = SAMA_DEFAULT_CFGR;
+#endif /* SAMA_HAS_PIOB */
+
+ /* Configuring all PIO C pads with default configuration. */
+#if SAMA_HAS_PIOC
+ _PIOA->PIO_PIO_[SAMA_PIOC].S_PIO_MSKR = SAMA_DEFAULT_MSKR;
+ _PIOA->PIO_PIO_[SAMA_PIOC].S_PIO_CFGR = SAMA_DEFAULT_CFGR;
+#endif /* SAMA_HAS_PIOC */
+
+ /* Configuring all PIO D pads with default configuration. */
+#if SAMA_HAS_PIOD
+ _PIOA->PIO_PIO_[SAMA_PIOD].S_PIO_MSKR = SAMA_DEFAULT_MSKR;
+ _PIOA->PIO_PIO_[SAMA_PIOD].S_PIO_CFGR = SAMA_DEFAULT_CFGR;
+#endif /* SAMA_HAS_PIOD */
+
+ /* Initialize PIO registers for defined pads.*/
+ i = 0;
+ while (sama_inits[i].pio_id != -1) {
+ _PIOA->PIO_IO_GROUP[sama_inits[i].pio_id].PIO_MSKR = sama_inits[i].pio_msk;
+ _PIOA->PIO_IO_GROUP[sama_inits[i].pio_id].PIO_CFGR = sama_inits[i].pio_cfg;
+ if(sama_inits[i].pio_ods == SAMA_PIO_HIGH) {
+ _PIOA->PIO_IO_GROUP[sama_inits[i].pio_id].PIO_SODR = sama_inits[i].pio_msk;
+ }
+ else {
+ _PIOA->PIO_IO_GROUP[sama_inits[i].pio_id].PIO_CODR = sama_inits[i].pio_msk;
+ }
+ i++;
+ }
+}