A => platform_samd_dma.c +67 -0
@@ 0,0 1,67 @@
+/* Peripheral Library for Atmel SAMD20 and SAMD21
+ *
+ * Permissive open source ISC license.
+ *
+ * Copyright (c) 2017 Tero Koskinen <tero.koskinen@iki.fi>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#include <stddef.h>
+#include <ctl_api.h>
+
+#include <sam.h>
+
+#include "libtools/ctl_tools.h"
+#include "platform_samd_dma.h"
+
+#define DMA_CHANNEL_AMOUNT 8
+
+static samd_dma_interrupt interrupt_handlers[DMA_CHANNEL_AMOUNT];
+
+__attribute__ ((aligned (8))) DmacDescriptor dma_descriptors[DMA_CHANNEL_AMOUNT];
+__attribute__ ((aligned (8))) DmacDescriptor dma_descriptors_wb[DMA_CHANNEL_AMOUNT];
+
+CTL_STATUS_t samd_dma_register_int_handler(uint8_t channel_no, samd_dma_interrupt handler)
+{
+ if (channel_no < DMA_CHANNEL_AMOUNT) {
+ interrupt_handlers[channel_no] = handler;
+ } else {
+ return CTL_PARAMETER_ERROR;
+ }
+
+ return CTL_NO_ERROR;
+}
+
+CTL_STATUS_t samd_dma_forget_int_handler(uint8_t channel_no)
+{
+ if (channel_no < DMA_CHANNEL_AMOUNT) {
+ interrupt_handlers[channel_no] = NULL;
+ } else {
+ return CTL_PARAMETER_ERROR;
+ }
+
+ return CTL_NO_ERROR;
+}
+
+void samd_dma_enable_interrupt(void)
+{
+ ctl_set_priority(DMAC_IRQn, 1);
+ ctl_unmask_isr(DMAC_IRQn);
+}
+
+void samd_dma_disable_interrupt(void)
+{
+ ctl_mask_isr(DMAC_IRQn);
+}
A => platform_samd_dma.h +36 -0
@@ 0,0 1,36 @@
+/* Peripheral Library for Atmel SAMD20 and SAMD21
+ *
+ * Permissive open source ISC license.
+ *
+ * Copyright (c) 2017 Tero Koskinen <tero.koskinen@iki.fi>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <ctl_api.h>
+
+#include <sam.h>
+
+#include "libtools/ctl_tools.h"
+
+typedef void (*samd_dma_interrupt)(uint8_t channel_no);
+
+CTL_STATUS_t samd_dma_register_int_handler(uint8_t channel_no, samd_dma_interrupt handler);
+CTL_STATUS_t samd_dma_forget_int_handler(uint8_t channel_no);
+void samd_dma_enable_interrupt(void);
+void samd_dma_disable_interrupt(void);