Add startup code for sam3x8e
This commit is contained in:
parent
dfd949efdd
commit
9817db1841
9 changed files with 751 additions and 3 deletions
3
Makefile
3
Makefile
|
@ -70,9 +70,10 @@ ifdef DEBUG
|
|||
endif
|
||||
|
||||
ARDIX_ASM_SOURCES =
|
||||
ARDIX_SOURCES =
|
||||
|
||||
include arch/Makefile
|
||||
|
||||
ARDIX_SOURCES =
|
||||
include init/Makefile
|
||||
include lib/Makefile
|
||||
|
||||
|
|
|
@ -25,5 +25,11 @@
|
|||
|
||||
ARDIX_ARCH_PWD = $(PWD)/arch/at91sam3x8e
|
||||
|
||||
ARDIX_SOURCES += \
|
||||
$(ARDIX_ARCH_PWD)/startup.c
|
||||
|
||||
CFLAGS += \
|
||||
-DARCH_AT91SAM3X8E
|
||||
|
||||
LDFLAGS += \
|
||||
-T$(ARDIX_ARCH_PWD)/flash.ld
|
||||
|
|
144
arch/at91sam3x8e/flash.ld
Normal file
144
arch/at91sam3x8e/flash.ld
Normal file
|
@ -0,0 +1,144 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* SAM Software Package License
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2012, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following condition is met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000 /* Flash, 512K */
|
||||
sram0 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 /* sram0, 64K */
|
||||
sram1 (rwx) : ORIGIN = 0x20080000, LENGTH = 0x00008000 /* sram1, 32K */
|
||||
ram (rwx) : ORIGIN = 0x20070000, LENGTH = 0x00018000 /* sram, 96K */
|
||||
}
|
||||
|
||||
/* The stack size used by the application. NOTE: you need to adjust */
|
||||
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : 0x2000 ;
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
KEEP(*(.vectors .vectors.*))
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.glue_7t) *(.glue_7)
|
||||
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
|
||||
/* Support C constructors, and C destructors in both user code
|
||||
and the C library. This also provides support for C++ code. */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.init))
|
||||
. = ALIGN(4);
|
||||
__preinit_array_start = .;
|
||||
KEEP (*(.preinit_array))
|
||||
__preinit_array_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__init_array_start = .;
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
__init_array_end = .;
|
||||
|
||||
. = ALIGN(0x4);
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*crtend.o(.ctors))
|
||||
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
__fini_array_start = .;
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
__fini_array_end = .;
|
||||
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*crtend.o(.dtors))
|
||||
|
||||
. = ALIGN(4);
|
||||
_efixed = .; /* End of text section */
|
||||
} > rom
|
||||
|
||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||
PROVIDE_HIDDEN (__exidx_start = .);
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
} > rom
|
||||
PROVIDE_HIDDEN (__exidx_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
|
||||
.relocate : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.ramfunc .ramfunc.*);
|
||||
*(.data .data.*);
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} > ram
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sbss = . ;
|
||||
_szero = .;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
_ezero = .;
|
||||
} > ram
|
||||
|
||||
/* stack section */
|
||||
.stack (NOLOAD):
|
||||
{
|
||||
. = ALIGN(8);
|
||||
_sstack = .;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(8);
|
||||
_estack = .;
|
||||
} > ram
|
||||
|
||||
. = ALIGN(4);
|
||||
_end = . ;
|
||||
}
|
193
arch/at91sam3x8e/startup.c
Normal file
193
arch/at91sam3x8e/startup.c
Normal file
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <ardix/string.h>
|
||||
#include <arch/at91sam3x8e/interrupt.h>
|
||||
|
||||
/* from flash.ld */
|
||||
extern uint32_t _sfixed; /* fixed area start */
|
||||
extern uint32_t _efixed; /* fixed area end */
|
||||
extern uint32_t _etext; /* program (.text) end */
|
||||
extern uint32_t _srelocate; /* relocate (.data) start */
|
||||
extern uint32_t _erelocate; /* relocate end */
|
||||
extern uint32_t _szero; /* zero area (.bss) start */
|
||||
extern uint32_t _ezero; /* zero area end */
|
||||
extern uint32_t _sstack; /* stack start */
|
||||
extern uint32_t _estack; /* stack end */
|
||||
|
||||
/* implementation in init/main.c */
|
||||
void do_bootstrap(void);
|
||||
|
||||
void __isr_reset(void)
|
||||
{
|
||||
/* copy .data to sram */
|
||||
memmove(
|
||||
&_etext,
|
||||
&_srelocate,
|
||||
(size_t)&_erelocate - (size_t)&_srelocate
|
||||
);
|
||||
/* clear .bss */
|
||||
memset(&_szero, 0, (size_t)&_ezero - (size_t)&_szero);
|
||||
|
||||
/* start the Kernel */
|
||||
do_bootstrap();
|
||||
|
||||
/* halt (this should never be reached) */
|
||||
while (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default ISR for unimplemented interrupts.
|
||||
* This will halt the system.
|
||||
*/
|
||||
void __isr_stub(void)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_nmi(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_hard_fault(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_mem_fault(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_bus_fault(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_usage_fault(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_svc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_debug_mon(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_pend_sv(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_sys_tick(void);
|
||||
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_supc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_rstc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_rtc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_rtt(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_wdt(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_pmc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_efc0(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_efc1(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_uart(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_smc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_pioa(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_piob(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_pioc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_piod(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_usart0(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_usart1(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_usart2(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_usart3(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_hsmci(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_twi0(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_twi1(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_spi0(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_ssc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc0(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc1(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc2(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc3(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc4(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc5(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc6(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc7(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_tc8(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_pwm(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_adc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_dacc(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_dmac(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_uotghs(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_trng(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_emac(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_can0(void);
|
||||
__attribute__((weak, alias("__isr_stub"))) void __isr_can1(void);
|
||||
|
||||
__attribute__((section(".vectors")))
|
||||
const void *exception_table[] = {
|
||||
&_estack, /* initial SP value (stack grows down) */
|
||||
&__isr_reset, /* reset vector */
|
||||
NULL, /* reserved */
|
||||
&__isr_hard_fault, /* hard fault */
|
||||
&__isr_mem_fault, /* hemory management fault */
|
||||
&__isr_bus_fault, /* bus fault */
|
||||
&__isr_usage_fault, /* usage fault */
|
||||
NULL, /* reserved */
|
||||
NULL, /* reserved */
|
||||
NULL, /* reserved */
|
||||
NULL, /* reserved */
|
||||
&__isr_svc, /* SVC call (used for syscalls) */
|
||||
&__isr_debug_mon, /* reserved for debug */
|
||||
NULL, /* reserved */
|
||||
&__isr_pend_sv, /* PendSV */
|
||||
&__isr_sys_tick, /* SysTick (used by the scheduler) */
|
||||
|
||||
/*
|
||||
* Ok I am REALLY tired of writing out mnemonics.
|
||||
* Just have a look at include/arch/at91sam3x8e.h for details.
|
||||
*/
|
||||
&__isr_rstc,
|
||||
&__isr_rtc,
|
||||
&__isr_rtt,
|
||||
&__isr_wdt,
|
||||
&__isr_pmc,
|
||||
&__isr_efc0,
|
||||
&__isr_efc1,
|
||||
&__isr_uart,
|
||||
&__isr_smc,
|
||||
NULL, /* reserved */
|
||||
&__isr_pioa,
|
||||
&__isr_piob,
|
||||
&__isr_pioc,
|
||||
&__isr_piod,
|
||||
NULL, /* reserved */
|
||||
NULL, /* reserved */
|
||||
&__isr_usart0,
|
||||
&__isr_usart1,
|
||||
&__isr_usart2,
|
||||
&__isr_usart3,
|
||||
&__isr_hsmci,
|
||||
&__isr_twi0,
|
||||
&__isr_twi1,
|
||||
&__isr_spi0,
|
||||
NULL, /* reserved */
|
||||
&__isr_ssc,
|
||||
&__isr_tc0,
|
||||
&__isr_tc1,
|
||||
&__isr_tc2,
|
||||
&__isr_tc3,
|
||||
&__isr_tc4,
|
||||
&__isr_tc5,
|
||||
&__isr_tc6,
|
||||
&__isr_tc7,
|
||||
&__isr_tc8,
|
||||
&__isr_pwm,
|
||||
&__isr_adc,
|
||||
&__isr_dacc,
|
||||
&__isr_dmac,
|
||||
&__isr_uotghs,
|
||||
&__isr_trng,
|
||||
&__isr_emac,
|
||||
&__isr_can0,
|
||||
&__isr_can1,
|
||||
};
|
188
include/arch/at91sam3x8e/interrupt.h
Normal file
188
include/arch/at91sam3x8e/interrupt.h
Normal file
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/** Reset interrupt handler */
|
||||
void __isr_reset(void);
|
||||
/** Non-maskable interrupt handler */
|
||||
void __isr_nmi(void);
|
||||
/** Hard fault inerrupt handler */
|
||||
void __isr_hard_fault(void);
|
||||
/** Memory management fault interrupt handler */
|
||||
void __isr_mem_fault(void);
|
||||
/** Bus fault interrupt handler */
|
||||
void __isr_bus_fault(void);
|
||||
/** Usage fault (illegal instruction) interrupt handler */
|
||||
void __isr_usage_fault(void);
|
||||
/** SVC interrupt handler */
|
||||
void __isr_svc(void);
|
||||
/** Debug handler (reserved) */
|
||||
void __isr_debug_mon(void);
|
||||
/** Pending SV interrupt handler */
|
||||
void __isr_pend_sv(void);
|
||||
/** SysTick interrupt handler */
|
||||
void __isr_sys_tick(void);
|
||||
|
||||
/** Supply Controller (0) interrupt handler */
|
||||
void __isr_supc(void);
|
||||
/** Reset Controller (1) interrupt handler */
|
||||
void __isr_rstc(void);
|
||||
/** Real-time Clock (2) interrupt handler */
|
||||
void __isr_rtc(void);
|
||||
/** Real-time Timer (3) interrupt handler */
|
||||
void __isr_rtt(void);
|
||||
/** Watchdog Timer (4) interrupt handler */
|
||||
void __isr_wdt(void);
|
||||
/** Power Management Controller (5) interrupt handdler */
|
||||
void __isr_pmc(void);
|
||||
/** Embedded Flash Controller 0 (6) interrupt handler */
|
||||
void __isr_efc0(void);
|
||||
/** Embedded Flash Controller 1 (7) interrupt handler */
|
||||
void __isr_efc1(void);
|
||||
/** Universal Asynchronous Receiver Transmitter (8) interrupt handler */
|
||||
void __isr_uart(void);
|
||||
/** Static Memory Controller (9) interrupt handler */
|
||||
void __isr_smc(void);
|
||||
/** Parallel I/O Controller A (11) interrupt handler */
|
||||
void __isr_pioa(void);
|
||||
/** Parallel I/O Controller B (12) interrupt handler */
|
||||
void __isr_piob(void);
|
||||
/** Parallel I/O Controller C (13) interrupt handler */
|
||||
void __isr_pioc(void);
|
||||
/** Parallel I/O Controller D (14) interrupt handler */
|
||||
void __isr_piod(void);
|
||||
/** Universal Synchronous/Asynchronous Receiver Transmitter 0 (17) interrupt handler */
|
||||
void __isr_usart0(void);
|
||||
/** Universal Synchronous/Asynchronous Receiver Transmitter 1 (18) interrupt handler */
|
||||
void __isr_usart1(void);
|
||||
/** Universal Synchronous/Asynchronous Receiver Transmitter 2 (19) interrupt handler */
|
||||
void __isr_usart2(void);
|
||||
/** Universal Synchronous/Asynchronous Receiver Transmitter 3 (20) interrupt handler */
|
||||
void __isr_usart3(void);
|
||||
/** Multimedia Card Interface (21) interrupt handler */
|
||||
void __isr_hsmci(void);
|
||||
/** Two-Wire Interface 0 (22) interrupt handler */
|
||||
void __isr_twi0(void);
|
||||
/** Two-Wire Interface 1 (23) interrupt handler */
|
||||
void __isr_twi1(void);
|
||||
/** Serial Peripheral Interface 0 (24) interrupt handler */
|
||||
void __isr_spi0(void);
|
||||
/** Synchronous Serial Controller (26) interrupt handler */
|
||||
void __isr_ssc(void);
|
||||
/** Timer/Counter 0 (27) interrupt handler */
|
||||
void __isr_tc0(void);
|
||||
/** Timer/Counter 1 (28) interrupt handler */
|
||||
void __isr_tc1(void);
|
||||
/** Timer/Counter 2 (29) interrupt handler */
|
||||
void __isr_tc2(void);
|
||||
/** Timer/Counter 3 (30) interrupt handler */
|
||||
void __isr_tc3(void);
|
||||
/** Timer/Counter 4 (31) interrupt handler */
|
||||
void __isr_tc4(void);
|
||||
/** Timer/Counter 5 (32) interrupt handler */
|
||||
void __isr_tc5(void);
|
||||
/** Timer/Counter 6 (33) interrupt handler */
|
||||
void __isr_tc6(void);
|
||||
/** Timer/Counter 7 (34) interrupt handler */
|
||||
void __isr_tc7(void);
|
||||
/** Timer/Counter 8 (35) interrupt handler */
|
||||
void __isr_tc8(void);
|
||||
/** Pulse Width Modulation Controller (36) interrupt handler */
|
||||
void __isr_pwm(void);
|
||||
/** Analog to Digital Converter Controller (37) interrupt handler */
|
||||
void __isr_adc(void);
|
||||
/** Digital to Analog Converter Controller (38) interrupt handler */
|
||||
void __isr_dacc(void);
|
||||
/** Direct Memory Access Controller (39) interrupt handler */
|
||||
void __isr_dmac(void);
|
||||
/** USB OTG High Speed (40) interrupt handler */
|
||||
void __isr_uotghs(void);
|
||||
/** True Random Number Generator (41) interrupt handler */
|
||||
void __isr_trng(void);
|
||||
/** Ethernet MAC (42) interrupt handler */
|
||||
void __isr_emac(void);
|
||||
/** Controller Area Network 0 (43) interrupt handler */
|
||||
void __isr_can0(void);
|
||||
/** Controller Area Network 1 (44) interrupt handler */
|
||||
void __isr_can1(void);
|
||||
|
||||
/**
|
||||
* Interrupt numbers for sam3x8e
|
||||
*/
|
||||
enum irqno {
|
||||
IRQNO_NMI = -14,
|
||||
IRQNO_MEM_FAULT = -12,
|
||||
IRQNO_BUS_FAULT = -11,
|
||||
IRQNO_USAGE_FAULT = -10,
|
||||
IRQNO_SVC_CALL = -5,
|
||||
IRQNO_DEBUG = -4,
|
||||
IRQNO_PEND_SV = -2,
|
||||
IRQNO_SYS_TICK = -1,
|
||||
|
||||
IRQNO_SUPC = 0,
|
||||
IRQNO_RSTC = 1,
|
||||
IRQNO_RTC = 2,
|
||||
IRQNO_RTT = 3,
|
||||
IRQNO_WDT = 4,
|
||||
IRQNO_PMC = 5,
|
||||
IRQNO_EFC0 = 6,
|
||||
IRQNO_EFC1 = 7,
|
||||
IRQNO_UART = 8,
|
||||
IRQNO_SMC = 9,
|
||||
IRQNO_POIA = 11,
|
||||
IRQNO_PIOB = 12,
|
||||
IRQNO_PIOC = 13,
|
||||
IRQNO_PIOD = 14,
|
||||
IRQNO_USART0 = 17,
|
||||
IRQNO_USART1 = 18,
|
||||
IRQNO_USART2 = 19,
|
||||
IRQNO_USART3 = 20,
|
||||
IRQNO_HSMCI = 21,
|
||||
IRQNO_TWI0 = 22,
|
||||
IRQNO_TWI1 = 23,
|
||||
IRQNO_SPI0 = 24,
|
||||
IRQNO_SSC = 26,
|
||||
IRQNO_TC0 = 27,
|
||||
IRQNO_TC1 = 28,
|
||||
IRQNO_TC2 = 29,
|
||||
IRQNO_TC3 = 30,
|
||||
IRQNO_TC4 = 31,
|
||||
IRQNO_TC5 = 32,
|
||||
IRQNO_TC6 = 33,
|
||||
IRQNO_TC7 = 34,
|
||||
IRQNO_TC8 = 35,
|
||||
IRQNO_PWM = 36,
|
||||
IRQNO_ADC = 37,
|
||||
IRQNO_DACC = 38,
|
||||
IRQNO_DMAC = 39,
|
||||
IRQNO_UOTGHS = 40,
|
||||
IRQNO_TRNG = 41,
|
||||
IRQNO_EMAC = 42,
|
||||
IRQNO_CAN0 = 43,
|
||||
IRQNO_CAN1 = 44,
|
||||
};
|
38
include/stdbool.h
Normal file
38
include/stdbool.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef true
|
||||
#define true ((bool)1)
|
||||
#endif /* true */
|
||||
|
||||
#ifndef false
|
||||
#define false ((bool)0)
|
||||
#endif /* false */
|
56
include/stddef.h
Normal file
56
include/stddef.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ardix/types.h>
|
||||
|
||||
#ifndef offsetof
|
||||
/**
|
||||
* Calculate the byte offset of a struct member relative to the struct itself.
|
||||
*
|
||||
* @param type: The structure type.
|
||||
* @param member: The member inside the struct to the offset of.
|
||||
* @returns The offset of `member` reelative to `type`, casted to a `size_t`.
|
||||
*/
|
||||
#define offsetof(type, member) ((size_t)&((type *)0)->member)
|
||||
#endif /* offsetof */
|
||||
|
||||
#ifndef NULL
|
||||
/** The `NULL` pointer. */
|
||||
#define NULL ((void *)0)
|
||||
#endif /* NULL */
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef __always_inline
|
||||
/**
|
||||
* Force a method to always be inlined by the compiler.
|
||||
* Do not use this for functions exceeding one or two lines.
|
||||
*/
|
||||
#define __always_inline inline __attribute__((always_inline))
|
||||
#endif /* __always_inline */
|
99
include/stdint.h
Normal file
99
include/stdint.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* signed integer types
|
||||
*/
|
||||
|
||||
#ifdef __INT8_TYPE__
|
||||
typedef __INT8_TYPE__ int8_t;
|
||||
#else
|
||||
/** Signed 8-bit integer. */
|
||||
typedef signed char int8_t;
|
||||
#endif /* __INT8_TYPE__ */
|
||||
|
||||
#ifdef __INT16_TYPE__
|
||||
typedef __INT16_TYPE__ int16_t;
|
||||
#else
|
||||
/** Signed 16-bit integer. */
|
||||
typedef signed int int16_t;
|
||||
#endif /* __INT16_TYPE__ */
|
||||
|
||||
#ifdef __INT32_TYPE__
|
||||
typedef __INT32_TYPE__ int32_t;
|
||||
#else
|
||||
/** Signed 32-bit integer. */
|
||||
typedef signed long int int32_t;
|
||||
#endif /* __INT32_TYPE__ */
|
||||
|
||||
/*
|
||||
* unsigned integer types
|
||||
*/
|
||||
|
||||
#ifdef __UINT8_TYPE__
|
||||
typedef __UINT8_TYPE__ uint8_t;
|
||||
#else
|
||||
/** Unsigned 8-bit integer. */
|
||||
typedef unsigned char uint8_t;
|
||||
#endif /* __UINT8_TYPE__ */
|
||||
|
||||
#ifdef __UINT16_TYPE__
|
||||
typedef __UINT16_TYPE__ uint16_t;
|
||||
#else
|
||||
/** Unsigned 16-bit integer. */
|
||||
typedef unsigned int uint16_t;
|
||||
#endif /* __UINT16_TYPE__ */
|
||||
|
||||
#ifdef __UINT32_TYPE__
|
||||
typedef __UINT32_TYPE__ uint32_t;
|
||||
#else
|
||||
/** Unsigned 32-bit integer. */
|
||||
typedef unsigned long int uint32_t;
|
||||
#endif /* __UINT32_TYPE__ */
|
||||
|
||||
typedef uint8_t bool;
|
||||
|
||||
/*
|
||||
* integer limits
|
||||
*/
|
||||
|
||||
#define CHAR_MAX ((char)0x7f)
|
||||
#define CHAR_MIN (CHAR_MAX + 1)
|
||||
#define UCHAR_MAX ((unsigned char)0xff)
|
||||
#define UCHAR_MIN ((unsigned char)0x00)
|
||||
|
||||
#define INT_MAX ((int)0x7fff)
|
||||
#define INT_MIN (INT_MAX + 1)
|
||||
#define UINT_MAX ((unsigned int)0xffff)
|
||||
#define UINT_MIN ((unsigned int)0x0000)
|
||||
|
||||
#define LONG_MAX ((long)0x7fffffff)
|
||||
#define LONG_MIN (LONG_MAX + 1)
|
||||
#define ULONG_MAX ((unsigned long)0xffffffff)
|
||||
#define ULONG_MIN ((unsigned long)0x00000000)
|
27
init/main.c
27
init/main.c
|
@ -25,10 +25,33 @@
|
|||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* Core init routine.
|
||||
*
|
||||
* This is invoked from the startup code (usually) located in
|
||||
* arch/<architecture>/startup.c.
|
||||
*/
|
||||
int main(void)
|
||||
void do_bootstrap(void)
|
||||
{
|
||||
return 0;
|
||||
/* We'll just let the LED blink for now */
|
||||
uint32_t *piob_enable_reg = (uint32_t *)0x400E1000;
|
||||
uint32_t *piob_output_enable_reg = (uint32_t *)0x400E1010;
|
||||
uint32_t *piob_output_data_reg = (uint32_t *)0x400E1030;
|
||||
|
||||
*piob_enable_reg = 0xffffffff;
|
||||
*piob_output_enable_reg = 0xffffffff;
|
||||
uint32_t state = 0;
|
||||
|
||||
int count = 0;
|
||||
while (true)
|
||||
{
|
||||
if (count++ != 100000)
|
||||
continue;
|
||||
state = ~state;
|
||||
*piob_output_data_reg = state;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue