2013-01-12 22:44:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \addtogroup cc2538-udma
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* \file
|
|
|
|
* Implementation of the cc2538 micro-DMA driver
|
|
|
|
*/
|
2017-09-04 14:22:34 +00:00
|
|
|
#include "contiki.h"
|
2013-01-12 22:44:42 +00:00
|
|
|
#include "dev/udma.h"
|
|
|
|
#include "dev/nvic.h"
|
|
|
|
#include "reg.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
struct channel_ctrl {
|
|
|
|
uint32_t src_end_ptr;
|
|
|
|
uint32_t dst_end_ptr;
|
|
|
|
uint32_t ctrl_word;
|
|
|
|
uint32_t unused;
|
|
|
|
};
|
|
|
|
|
|
|
|
static volatile struct channel_ctrl channel_config[UDMA_CONF_MAX_CHANNEL + 1]
|
cc2538: Move SoC data to a dedicated section to save space
Some SoC data requires huge alignments. E.g., the µDMA channel control table has
to be 1024-byte aligned. This table was simply aligned to 1024 bytes in the C
code, which had the following consequences, wasting a lot of RAM:
- As this table could be placed anywhere in .bss, there could be an alignment
gap of up to 1023 bytes between the preceding data and this table.
- The size of this table was also aligned to 1024 bytes, regardless of
UDMA_CONF_MAX_CHANNEL, making this configuration option supposed to save RAM
just useless.
- .bss was also aligned to at least 1024 bytes, creating a huge alignment gap
between .data and .bss.
Instead of relying on the compiler to force this alignment, and on the linker to
automatically place data, this change places carefully such SoC data in RAM
using the linker script. A dedicated section is created to place such SoC data
requiring huge alignments, and it is put at the beginning of the SRAM in order
to ensure a maximal alignment without any gap. In this way, the alignment of
.bss also remains normal, and the size of this table is not constrained by its
alignment, but only by its contents (i.e. by UDMA_CONF_MAX_CHANNEL).
In the case of the µDMA channel control table, the data is still zeroed by
udma_init() (instead of also being zeroed as part of .bss).
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
2013-12-19 20:30:35 +00:00
|
|
|
__attribute__ ((section(".udma_channel_control_table")));
|
2013-01-12 22:44:42 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_init()
|
|
|
|
{
|
2016-01-09 13:07:47 +00:00
|
|
|
memset((void *)&channel_config, 0, sizeof(channel_config));
|
2013-01-12 22:44:42 +00:00
|
|
|
|
|
|
|
REG(UDMA_CFG) = UDMA_CFG_MASTEN;
|
|
|
|
|
|
|
|
REG(UDMA_CTLBASE) = (uint32_t)(&channel_config);
|
|
|
|
|
2016-07-23 21:39:56 +00:00
|
|
|
NVIC_EnableIRQ(UDMA_SW_IRQn);
|
|
|
|
NVIC_EnableIRQ(UDMA_ERR_IRQn);
|
2013-01-12 22:44:42 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_set_channel_src(uint8_t channel, uint32_t src_end)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel_config[channel].src_end_ptr = src_end;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_set_channel_dst(uint8_t channel, uint32_t dst_end)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel_config[channel].dst_end_ptr = dst_end;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_set_channel_control_word(uint8_t channel, uint32_t ctrl)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel_config[channel].ctrl_word = ctrl;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_set_channel_assignment(uint8_t channel, uint8_t enc)
|
|
|
|
{
|
|
|
|
uint32_t base_chmap = UDMA_CHMAP0;
|
|
|
|
uint8_t shift;
|
|
|
|
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the address of the relevant CHMAP register */
|
|
|
|
base_chmap += (channel >> 3) * 4;
|
|
|
|
|
|
|
|
/* Calculate the shift value for the correct CHMAP register bits */
|
|
|
|
shift = (channel & 0x07);
|
|
|
|
|
|
|
|
/* Read CHMAPx value, zero out channel's bits and write the new value */
|
|
|
|
REG(base_chmap) = (REG(base_chmap) & ~(0x0F << shift)) | (enc << shift);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_enable(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG(UDMA_ENASET) |= 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_disable(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes of 0 have no effect, this no need for RMW */
|
|
|
|
REG(UDMA_ENACLR) = 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_use_alternate(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG(UDMA_ALTSET) |= 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_use_primary(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes of 0 have no effect, this no need for RMW */
|
|
|
|
REG(UDMA_ALTCLR) = 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_prio_set_high(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG(UDMA_PRIOSET) |= 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_prio_set_default(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes of 0 have no effect, this no need for RMW */
|
|
|
|
REG(UDMA_PRIOCLR) = 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_use_burst(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG(UDMA_USEBURSTSET) |= 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_use_single(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes of 0 have no effect, this no need for RMW */
|
|
|
|
REG(UDMA_USEBURSTCLR) = 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_mask_set(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG(UDMA_REQMASKSET) |= 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_mask_clr(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes of 0 have no effect, this no need for RMW */
|
|
|
|
REG(UDMA_REQMASKCLR) = 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_channel_sw_request(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG(UDMA_SWREQ) |= 1 << channel;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint8_t
|
|
|
|
udma_channel_get_mode(uint8_t channel)
|
|
|
|
{
|
|
|
|
if(channel > UDMA_CONF_MAX_CHANNEL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (channel_config[channel].ctrl_word & 0x07);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_isr()
|
|
|
|
{
|
|
|
|
/* Simply clear Channel interrupt status for now */
|
|
|
|
REG(UDMA_CHIS) = UDMA_CHIS_CHIS;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
udma_err_isr()
|
|
|
|
{
|
|
|
|
/* Stub Implementation, just clear the error flag */
|
|
|
|
REG(UDMA_ERRCLR) = 1;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/** @} */
|