git subrepo clone https://github.com/libopencm3/libopencm3.git
subrepo: subdir: "libopencm3" merged: "88e91c9a7cce" upstream: origin: "https://github.com/libopencm3/libopencm3.git" branch: "master" commit: "88e91c9a7cce" git-subrepo: version: "0.4.3" origin: "???" commit: "???"
This commit is contained in:
45
libopencm3/lib/lm3s/Makefile
Normal file
45
libopencm3/lib/lm3s/Makefile
Normal file
@@ -0,0 +1,45 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This library is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU Lesser General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This library is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public License
|
||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
LIBNAME = libopencm3_lm3s
|
||||
SRCLIBDIR ?= ..
|
||||
|
||||
CC = $(PREFIX)gcc
|
||||
AR = $(PREFIX)ar
|
||||
TGT_CFLAGS = -Os \
|
||||
-Wall -Wextra -Wimplicit-function-declaration \
|
||||
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
||||
-Wundef -Wshadow \
|
||||
-I../../include -fno-common \
|
||||
-mcpu=cortex-m3 -mthumb $(FP_FLAGS) -Wstrict-prototypes \
|
||||
-ffunction-sections -fdata-sections -MD -DLM3S
|
||||
TGT_CFLAGS += $(DEBUG_FLAGS)
|
||||
TGT_CFLAGS += $(STANDARD_FLAGS)
|
||||
# ARFLAGS = rcsv
|
||||
ARFLAGS = rcs
|
||||
|
||||
OBJS += assert.o
|
||||
OBJS += gpio.o
|
||||
OBJS += rcc.o
|
||||
OBJS += usart.o
|
||||
OBJS += vector.o
|
||||
|
||||
VPATH += ../cm3
|
||||
|
||||
include ../Makefile.include
|
||||
52
libopencm3/lib/lm3s/gpio.c
Normal file
52
libopencm3/lib/lm3s/gpio.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/** @defgroup gpio_file General Purpose I/O
|
||||
|
||||
@brief <b>LM3S General Purpose I/O</b>
|
||||
|
||||
@ingroup LM3Sxx
|
||||
|
||||
@version 1.0.0
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2011
|
||||
Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
|
||||
@date 10 March 2013
|
||||
|
||||
LGPL License Terms @ref lgpl_license
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**@{*/
|
||||
|
||||
#include <libopencm3/lm3s/gpio.h>
|
||||
|
||||
void gpio_set(uint32_t gpioport, uint8_t gpios)
|
||||
{
|
||||
/* ipaddr[9:2] mask the bits to be set, hence the array index */
|
||||
GPIO_DATA(gpioport)[gpios] = 0xff;
|
||||
}
|
||||
|
||||
void gpio_clear(uint32_t gpioport, uint8_t gpios)
|
||||
{
|
||||
GPIO_DATA(gpioport)[gpios] = 0;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
77
libopencm3/lib/lm3s/rcc.c
Normal file
77
libopencm3/lib/lm3s/rcc.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/** @defgroup rcc_file RCC Controller
|
||||
|
||||
@brief <b>LM3S RCC Controller</b>
|
||||
|
||||
@ingroup LM3Sxx
|
||||
|
||||
@version 1.0.0
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2015
|
||||
Daniele Lacamera \<root at danielinux dot net\>
|
||||
|
||||
@date 21 November 2015
|
||||
|
||||
LGPL License Terms @ref lgpl_license
|
||||
*/
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2015 Daniele Lacamera <root@danielinux.net>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <libopencm3/lm3s/rcc.h>
|
||||
#include <libopencm3/cm3/sync.h>
|
||||
|
||||
int rcc_clock_setup_in_xtal_8mhz_out_50mhz(void)
|
||||
{
|
||||
uint32_t rcc = RCC_RESET_VALUE;
|
||||
uint32_t rcc2 = RCC2_RESET_VALUE;
|
||||
|
||||
/* Stage 0: Reset values applied */
|
||||
RCC_CR = rcc;
|
||||
RCC2_CR = rcc2;
|
||||
__dmb();
|
||||
|
||||
/* Stage 1: Reset Oscillators and select configured values */
|
||||
RCC_CR = RCC_SYSDIV_50MHZ | RCC_PWMDIV_64 | RCC_XTAL_8MHZ_400MHZ | RCC_USEPWMDIV;
|
||||
RCC2_CR = (4 - 1) << RCC2_SYSDIV2_SHIFT;
|
||||
__dmb();
|
||||
|
||||
/* Stage 2: Power on oscillators */
|
||||
rcc &= ~RCC_OFF;
|
||||
rcc2 &= ~RCC2_OFF;
|
||||
RCC_CR = rcc;
|
||||
RCC2_CR = rcc2;
|
||||
__dmb();
|
||||
|
||||
/* Stage 3: Set USESYSDIV */
|
||||
rcc |= RCC_BYPASS | RCC_USESYSDIV;
|
||||
RCC_CR = rcc;
|
||||
__dmb();
|
||||
|
||||
/* Stage 4: Wait for PLL raw interrupt */
|
||||
while ((RCC_RIS & RIS_PLLLRIS) == 0)
|
||||
;
|
||||
|
||||
/* Stage 5: Disable bypass */
|
||||
rcc &= ~RCC_BYPASS;
|
||||
rcc2 &= ~RCC2_BYPASS;
|
||||
RCC_CR = rcc;
|
||||
RCC2_CR = rcc2;
|
||||
__dmb();
|
||||
return 0;
|
||||
}
|
||||
88
libopencm3/lib/lm3s/usart.c
Normal file
88
libopencm3/lib/lm3s/usart.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2013 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
* Copyright (C) 2015 Daniele Lacamera <root at danielinux.net>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/lm3s/usart.h>
|
||||
|
||||
void usart_send(uint32_t usart, uint16_t data)
|
||||
{
|
||||
USART_DR(usart) = data;
|
||||
}
|
||||
|
||||
uint16_t usart_recv(uint32_t usart)
|
||||
{
|
||||
return USART_DR(usart) & 0xff;
|
||||
}
|
||||
|
||||
void usart_send_blocking(uint32_t usart, uint16_t data)
|
||||
{
|
||||
while (!usart_is_send_ready(usart));
|
||||
usart_send(usart, data);
|
||||
}
|
||||
|
||||
bool usart_is_recv_ready(uint32_t usart)
|
||||
{
|
||||
return ((USART_FR(usart) & USART_FR_RXFE) == 0);
|
||||
}
|
||||
|
||||
bool usart_is_send_ready(uint32_t usart)
|
||||
{
|
||||
return ((USART_FR(usart) & USART_FR_BUSY) == 0);
|
||||
}
|
||||
|
||||
uint16_t usart_recv_blocking(uint32_t usart)
|
||||
{
|
||||
while (!usart_is_recv_ready(usart));
|
||||
return usart_recv(usart);
|
||||
}
|
||||
|
||||
void usart_enable_rx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IM(usart) |= USART_IM_RX;
|
||||
}
|
||||
|
||||
void usart_enable_tx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IM(usart) |= USART_IM_TX;
|
||||
}
|
||||
|
||||
void usart_disable_rx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IM(usart) &= (~USART_IM_RX);
|
||||
}
|
||||
|
||||
void usart_disable_tx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IM(usart) &= (~USART_IM_TX);
|
||||
}
|
||||
|
||||
void usart_clear_rx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IC(usart) |= USART_IC_RX;
|
||||
}
|
||||
|
||||
void usart_clear_tx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IC(usart) |= USART_IC_TX;
|
||||
}
|
||||
|
||||
bool usart_get_interrupt_source(uint32_t usart, uint32_t flag)
|
||||
{
|
||||
return ((USART_RIS(usart) & flag) != 0);
|
||||
}
|
||||
Reference in New Issue
Block a user