提交 255f8b7c 编写于 作者: B Bernard Xiong

[BSP] Add BSP for Ingenic X1000 CPU

上级 bef87f8a
# RT-Thread for Ingenic X1000 porting.
\ No newline at end of file
# for module compiling
import os
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
import os
import sys
import rtconfig
from rtconfig import RTT_ROOT
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
TARGET = 'rtthread-x1000.' + rtconfig.TARGET_EXT
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CC, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT)
# make a building
DoBuilding(TARGET, objs)
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd, str(Dir('#'))]
if not GetDepend("RT_USING_DFS_ROMFS"):
SrcRemove(src, "romfs.c")
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* File : _main.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
printf("Hello RT-Thread!\n");
return 0;
}
/*
* File : mnt.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <dfs_fs.h>
int mnt_init(void)
{
#ifdef RT_USING_SDIO
rt_mmcsd_core_init();
rt_mmcsd_blk_init();
jz47xx_sdio_init();
rt_thread_delay(RT_TICK_PER_SECOND * 1);
/* mount sd card fat partition 1 as root directory */
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
{
rt_kprintf("File System initialized!\n");
}
else
{
rt_kprintf("File System initialzation failed!\n");
}
#endif
}
INIT_ENV_EXPORT(mnt_init);
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* File : board.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
#include "drv_clock.h"
#include "drv_uart.h"
#include "drv_ost.h"
extern void rt_hw_cache_init(void);
void rt_hw_board_init(void)
{
rt_hw_cache_init();
/* init hardware interrupt */
rt_hw_interrupt_init();
rt_hw_uart_init();
#ifdef RT_USING_CONSOLE
/* set console device */
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif /* RT_USING_CONSOLE */
#ifdef RT_USING_HEAP
/* init memory system */
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
rt_hw_ost_init();
}
/*
* File : board.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#ifndef _BOARD_H_
#define _BOARD_H_
#include <stdint.h>
#include "x1000.h"
#define RT_USING_JZ_X1000
// #define BOARD_PHOENIX
// #define BOARD_CANNA
#ifdef BOARD_PHOENIX
#define RT_USING_EMAC
#endif
/*********************************************************************************************************
** Clock for Board
*********************************************************************************************************/
#define BOARD_EXTAL_CLK 24000000
#define BOARD_RTC_CLK 32768
#define BOARD_CPU_CLK (1008 * 1000 * 1000UL)
/*********************************************************************************************************
** HEAP Setting
*********************************************************************************************************/
extern unsigned char __bss_start;
extern unsigned char __bss_end;
#define RT_HW_HEAP_BEGIN (void*)&__bss_end
#define RT_HW_HEAP_END (void*)(0x80000000 + 32 * 1024 * 1024)
/*********************************************************************************************************
** UART Setting
*********************************************************************************************************/
#define RT_USING_UART2
#endif
/*
* File : board_io.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <board.h>
#include <rtthread.h>
#include "drv_gpio.h"
此差异已折叠。
/*
* File : drv_clock.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#ifndef DRV_CLOCK_H_
#define DRV_CLOCK_H_
#include "board.h"
#define CPM_CPCCR (0x00)
#define CPM_CPCSR (0xd4)
#define CPM_DDRCDR (0x2c)
#define CPM_I2SCDR (0x60)
#define CPM_I2SCDR1 (0x70)
#define CPM_LPCDR (0x64)
#define CPM_MSC0CDR (0x68)
#define CPM_MSC1CDR (0xa4)
#define CPM_USBCDR (0x50)
#define CPM_MACCDR (0x54)
#define CPM_UHCCDR (0x6c)
#define CPM_SFCCDR (0x74)
#define CPM_CIMCDR (0x7c)
#define CPM_PCMCDR (0x84)
#define CPM_PCMCDR1 (0xe0)
#define CPM_MPHYC (0xe8)
#define CPM_INTR (0xb0)
#define CPM_INTRE (0xb4)
#define CPM_DRCG (0xd0)
#define CPM_CPSPPR (0x38)
#define CPM_CPPSR (0x34)
#define CPM_USBPCR (0x3c)
#define CPM_USBRDT (0x40)
#define CPM_USBVBFIL (0x44)
#define CPM_USBPCR1 (0x48)
#define CPM_CPAPCR (0x10)
#define CPM_CPMPCR (0x14)
#define CPM_LCR (0x04)
#define CPM_PSWC0ST (0x90)
#define CPM_PSWC1ST (0x94)
#define CPM_PSWC2ST (0x98)
#define CPM_PSWC3ST (0x9c)
#define CPM_CLKGR (0x20)
#define CPM_MESTSEL (0xec)
#define CPM_SRBC (0xc4)
#define CPM_ERNG (0xd8)
#define CPM_RNG (0xdc)
#define CPM_SLBC (0xc8)
#define CPM_SLPC (0xcc)
#define CPM_OPCR (0x24)
#define CPM_RSR (0x08)
#define LCR_LPM_MASK (0x3)
#define LCR_LPM_SLEEP (0x1)
#define OPCR_ERCS (0x1<<2)
#define OPCR_PD (0x1<<3)
#define OPCR_IDLE (0x1<<31)
#define cpm_inl(off) readl(CPM_BASE + (off))
#define cpm_outl(val,off) writel(val, CPM_BASE + (off))
#define cpm_test_bit(bit,off) (cpm_inl(off) & 0x1<<(bit))
#define cpm_set_bit(bit,off) (cpm_outl((cpm_inl(off) | 0x1<<(bit)),off))
#define cpm_clear_bit(bit,off) (cpm_outl(cpm_inl(off) & ~(0x1 << bit), off))
#define I2S_PRI_DIV 0xb0020030
#define PCM_PRI_DIV 0xb0030014
struct clk;
struct clk_ops {
int (*enable) (struct clk *,int);
struct clk* (*get_parent) (struct clk *);
int (*set_parent) (struct clk *,struct clk *);
uint32_t (*get_rate) (struct clk *);
int (*set_rate) (struct clk *,uint32_t);
int (*set_round_rate) (struct clk *,uint32_t);
};
struct clk {
const char *name;
uint32_t rate;
struct clk *parent;
uint32_t flags;
#define CLK_FLG_NOALLOC BIT(0)
#define CLK_FLG_ENABLE BIT(1)
#define CLK_GATE_BIT(flg) ((flg) >> 24)
#define CLK_FLG_GATE BIT(2)
#define CLK_CPCCR_NO(flg) (((flg) >> 24) & 0xff)
#define CLK_FLG_CPCCR BIT(3)
#define CLK_CGU_NO(flg) (((flg) >> 24) & 0xff)
#define CLK_FLG_CGU BIT(4)
#define CLK_PLL_NO(flg) (((flg) >> 24) & 0xff)
#define CLK_FLG_PLL BIT(5)
#define CLK_CGU_AUDIO_NO(flg) (((flg) >> 24) & 0xff)
#define CLK_FLG_CGU_AUDIO BIT(6)
#define CLK_PARENT(flg) (((flg) >> 16) & 0xff)
#define CLK_RELATIVE(flg) (((flg) >> 16) & 0xff)
#define CLK_FLG_PARENT BIT(7)
#define CLK_FLG_RELATIVE BIT(8)
struct clk_ops *ops;
int count;
int init_state;
struct clk *source;
struct clk *child;
unsigned int CLK_ID;
};
int init_all_clk(void);
struct clk *clk_get(const char *id);
int clk_enable(struct clk *clk);
int clk_is_enabled(struct clk *clk);
void clk_disable(struct clk *clk);
uint32_t clk_get_rate(struct clk *clk);
void clk_put(struct clk *clk);
int clk_set_rate(struct clk *clk, uint32_t rate);
#endif
/*
* File : drv_gpio.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_gpio.h"
#define GPIO_DEBUG 0
#if GPIO_DEBUG
#define GPIO_DBG(...) rt_kprintf(__VA_ARGS__)
#else
#define GPIO_DBG(...)
#endif
struct jz_gpio_irq_def _g_gpio_irq_tbl[GPIO_NR_PORTS] = {0};
rt_inline int _fls(int x)
{
__asm__("clz %0, %1" : "=r" (x) : "r" (x));
return 32 - x;
}
void gpio_set_func(enum gpio_port port, uint32_t pins, enum gpio_function func)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(func & 0x8 ? pins : 0, GPIO_PXINTS(port));
writel(func & 0x4 ? pins : 0, GPIO_PXMSKS(port));
writel(func & 0x2 ? pins : 0, GPIO_PXPAT1S(port));
writel(func & 0x1 ? pins : 0, GPIO_PXPAT0S(port));
writel(func & 0x8 ? 0 : pins, GPIO_PXINTC(port));
writel(func & 0x4 ? 0 : pins, GPIO_PXMSKC(port));
writel(func & 0x2 ? 0 : pins, GPIO_PXPAT1C(port));
writel(func & 0x1 ? 0 : pins, GPIO_PXPAT0C(port));
writel(func & 0x10 ? pins : 0, GPIO_PXPENC(port));
writel(func & 0x10 ? 0 : pins, GPIO_PXPENS(port));
}
void gpio_set_value(enum gpio_port port,enum gpio_pin pin,int value)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
if (value)
writel(pin, GPIO_PXPAT0S(port));
else
writel(pin, GPIO_PXPAT0C(port));
}
void gpio_enable_pull(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(pin, GPIO_PXPENC(port));
}
void gpio_disable_pull(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(pin, GPIO_PXPENS(port));
}
void gpio_ctrl_pull(enum gpio_port port, uint32_t pins,int enable)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
if (enable)
writel(pins, GPIO_PXPENC(port));
else
writel(pins, GPIO_PXPENS(port));
}
int gpio_get_value(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
return !!(readl(GPIO_PXPIN(port)) & pin);
}
int gpio_get_flag(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
return (readl(GPIO_PXFLG(port)) & pin);
}
void gpio_clear_flag(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(pin, GPIO_PXFLGC(port));
}
void gpio_direction_input(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
gpio_set_func(port,pin,GPIO_INPUT);
}
void gpio_direction_output(enum gpio_port port, enum gpio_pin pin,int value)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
gpio_set_func(port, pin, value ? GPIO_OUTPUT1 : GPIO_OUTPUT0);
}
/*********************************************************************************************************
** IRQ
*********************************************************************************************************/
void gpio_unmask_irq(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(pin, GPIO_PXMSKC(port));
}
void gpio_mask_irq(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(BIT(pin), GPIO_PXMSKS(port));
}
int gpio_set_irq_type(enum gpio_port port, enum gpio_pin pin, enum gpio_irq_type irq_type)
{
enum gpio_function func;
RT_ASSERT(IS_GPIO_ALL_PORT(port));
if (irq_type & IRQ_TYPE_PROBE)
return 0;
switch (irq_type & IRQ_TYPE_SENSE_MASK)
{
case IRQ_TYPE_LEVEL_HIGH:
func = GPIO_INT_HI;
break;
case IRQ_TYPE_LEVEL_LOW:
func = GPIO_INT_LO;
break;
case IRQ_TYPE_EDGE_RISING:
func = GPIO_INT_RE;
break;
case IRQ_TYPE_EDGE_FALLING:
func = GPIO_INT_FE;
break;
case IRQ_TYPE_EDGE_BOTH:
if (gpio_get_value(port, pin))
func = GPIO_INT_FE;
else
func = GPIO_INT_RE;
break;
default:
return -1;
}
gpio_set_func(port,pin, func);
return 0;
}
void gpio_ack_irq(enum gpio_port port, enum gpio_pin pin)
{
RT_ASSERT(IS_GPIO_ALL_PORT(port));
writel(pin, GPIO_PXFLGC(port));
}
void gpio_set_irq_callback(enum gpio_port port, enum gpio_pin pin, void (*irq_cb)(void *),void *irq_arg)
{
uint32_t pin_id;
RT_ASSERT(IS_GPIO_ALL_PORT(port));
pin_id = _fls(pin) - 1;
GPIO_DBG("port = %d,pin = %d \n",port,pin_id);
_g_gpio_irq_tbl[port].irq_cb[pin_id] = irq_cb;
_g_gpio_irq_tbl[port].irq_arg[pin_id] = irq_arg;
GPIO_DBG("set irq callback end... \n");
}
void gpio_irq_handler(int irq, void *param)
{
struct jz_gpio_irq_def *irq_def = (struct jz_gpio_irq_def *)param;
uint32_t pend,mask;
uint32_t pin_id;
enum gpio_port port = (IRQ_GPIO0 - irq);
enum gpio_pin pin;
RT_ASSERT(param != RT_NULL);
GPIO_DBG("GPIO irq handler,irq=%d\n",irq);
pend = readl(GPIO_PXFLG(port));
mask = readl(GPIO_PXMSK(port));
GPIO_DBG("port =%d pend =%08x mask =%08x\n",port,pend,mask);
pend = pend & ~mask;
while(pend)
{
pin_id = _fls(pend) - 1;
pin = 0x01 << pin_id;
GPIO_DBG("PORT%d PIN%d interrupt happened..\n",port,pin_id);
if(irq_def->irq_cb[pin_id] != RT_NULL)
{
GPIO_DBG("do irq callback...\n",port,pin);
irq_def->irq_cb[pin_id](irq_def->irq_arg[pin_id]);
}
pend &= ~(0x01 << pin_id);
gpio_ack_irq(port, pin);
}
}
int rt_hw_gpio_init(void)
{
GPIO_DBG("Install gpio interrupt source...\n");
/* install ISR */
rt_hw_interrupt_install(IRQ_GPIO0,gpio_irq_handler,&_g_gpio_irq_tbl[GPIO_PORT_A],"GPIOAINT");
rt_hw_interrupt_umask(IRQ_GPIO0);
rt_hw_interrupt_install(IRQ_GPIO1,gpio_irq_handler,&_g_gpio_irq_tbl[GPIO_PORT_B],"GPIOBINT");
rt_hw_interrupt_umask(IRQ_GPIO1);
rt_hw_interrupt_install(IRQ_GPIO2,gpio_irq_handler,&_g_gpio_irq_tbl[GPIO_PORT_C],"GPIOCINT");
rt_hw_interrupt_umask(IRQ_GPIO2);
rt_hw_interrupt_install(IRQ_GPIO3,gpio_irq_handler,&_g_gpio_irq_tbl[GPIO_PORT_D],"GPIODINT");
rt_hw_interrupt_umask(IRQ_GPIO3);
return 0;
}
INIT_BOARD_EXPORT(rt_hw_gpio_init);
/*
* File : board_gpio.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#ifndef _BOARD_GPIO_H_
#define _BOARD_GPIO_H_
#include <stdint.h>
#define GPIO_PA(n) (0*32 + n)
#define GPIO_PB(n) (1*32 + n)
#define GPIO_PC(n) (2*32 + n)
#define GPIO_PD(n) (3*32 + n)
#define GPIO_PE(n) (4*32 + n)
#define GPIO_PF(n) (5*32 + n)
#define GPIO_PG(n) (6*32 + n)
#define GPIO_PIN(n) (0x01 << n)
/*************************************************************************
* GPIO (General-Purpose I/O Ports)
*************************************************************************/
#define GPIO_PORT_OFF 0x100
#define GPIO_SHADOW_OFF 0x700
#define PXPIN 0x00 /* PIN Level Register */
#define PXINT 0x10 /* Port Interrupt Register */
#define PXINTS 0x14 /* Port Interrupt Set Register */
#define PXINTC 0x18 /* Port Interrupt Clear Register */
#define PXMSK 0x20 /* Port Interrupt Mask Reg */
#define PXMSKS 0x24 /* Port Interrupt Mask Set Reg */
#define PXMSKC 0x28 /* Port Interrupt Mask Clear Reg */
#define PXPAT1 0x30 /* Port Pattern 1 Set Reg. */
#define PXPAT1S 0x34 /* Port Pattern 1 Set Reg. */
#define PXPAT1C 0x38 /* Port Pattern 1 Clear Reg. */
#define PXPAT0 0x40 /* Port Pattern 0 Register */
#define PXPAT0S 0x44 /* Port Pattern 0 Set Register */
#define PXPAT0C 0x48 /* Port Pattern 0 Clear Register */
#define PXFLG 0x50 /* Port Flag Register */
#define PXFLGC 0x58 /* Port Flag clear Register */
#define PXOENS 0x64 /* Port Output Disable Set Register */
#define PXOENC 0x68 /* Port Output Disable Clear Register */
#define PXPEN 0x70 /* Port Pull Disable Register */
#define PXPENS 0x74 /* Port Pull Disable Set Register */
#define PXPENC 0x78 /* Port Pull Disable Clear Register */
#define PXDSS 0x84 /* Port Drive Strength set Register */
#define PXDSC 0x88 /* Port Drive Strength clear Register */
#define PZGID2LD 0xF0 /* GPIOZ Group ID to load */
#define GPIO_PXPIN(n) (GPIO_BASE + (PXPIN + (n) * GPIO_PORT_OFF)) /* PIN Level Register */
#define GPIO_PXINT(n) (GPIO_BASE + (PXINT + (n) * GPIO_PORT_OFF)) /* Port Interrupt Register */
#define GPIO_PXINTS(n) (GPIO_BASE + (PXINTS + (n) * GPIO_PORT_OFF)) /* Port Interrupt Set Register */
#define GPIO_PXINTC(n) (GPIO_BASE + (PXINTC + (n) * GPIO_PORT_OFF)) /* Port Interrupt Clear Register */
#define GPIO_PXMSK(n) (GPIO_BASE + (PXMSK + (n) * GPIO_PORT_OFF)) /* Port Interrupt Mask Register */
#define GPIO_PXMSKS(n) (GPIO_BASE + (PXMSKS + (n) * GPIO_PORT_OFF)) /* Port Interrupt Mask Set Reg */
#define GPIO_PXMSKC(n) (GPIO_BASE + (PXMSKC + (n) * GPIO_PORT_OFF)) /* Port Interrupt Mask Clear Reg */
#define GPIO_PXPAT1(n) (GPIO_BASE + (PXPAT1 + (n) * GPIO_PORT_OFF)) /* Port Pattern 1 Register */
#define GPIO_PXPAT1S(n) (GPIO_BASE + (PXPAT1S + (n) * GPIO_PORT_OFF)) /* Port Pattern 1 Set Reg. */
#define GPIO_PXPAT1C(n) (GPIO_BASE + (PXPAT1C + (n) * GPIO_PORT_OFF)) /* Port Pattern 1 Clear Reg. */
#define GPIO_PXPAT0(n) (GPIO_BASE + (PXPAT0 + (n) * GPIO_PORT_OFF)) /* Port Pattern 0 Register */
#define GPIO_PXPAT0S(n) (GPIO_BASE + (PXPAT0S + (n) * GPIO_PORT_OFF)) /* Port Pattern 0 Set Register */
#define GPIO_PXPAT0C(n) (GPIO_BASE + (PXPAT0C + (n) * GPIO_PORT_OFF)) /* Port Pattern 0 Clear Register */
#define GPIO_PXFLG(n) (GPIO_BASE + (PXFLG + (n) * GPIO_PORT_OFF)) /* Port Flag Register */
#define GPIO_PXFLGC(n) (GPIO_BASE + (PXFLGC + (n) * GPIO_PORT_OFF)) /* Port Flag clear Register */
#define GPIO_PXOENS(n) (GPIO_BASE + (PXOENS + (n) * GPIO_PORT_OFF)) /* Port Output Disable Set Register */
#define GPIO_PXOENC(n) (GPIO_BASE + (PXOENC + (n) * GPIO_PORT_OFF)) /* Port Output Disable Clear Register */
#define GPIO_PXPEN(n) (GPIO_BASE + (PXPEN + (n) * GPIO_PORT_OFF)) /* Port Pull Disable Register */
#define GPIO_PXPENS(n) (GPIO_BASE + (PXPENS + (n) * GPIO_PORT_OFF)) /* Port Pull Disable Set Register */
#define GPIO_PXPENC(n) (GPIO_BASE + (PXPENC + (n) * GPIO_PORT_OFF)) /* Port Pull Disable Clear Register */
#define GPIO_PXDSS(n) (GPIO_BASE + (PXDSS + (n) * GPIO_PORT_OFF)) /* Port Drive Strength set Register */
#define GPIO_PXDSC(n) (GPIO_BASE + (PXDSC + (n) * GPIO_PORT_OFF)) /* Port Drive Strength clear Register */
#define GPIO_PZGID2LD(n) (GPIO_BASE + (PZGID2LD + (n) * GPIO_PORT_OFF)) /* GPIOZ Group ID to load */
struct jzgpio_state {
uint32_t pxint;
uint32_t pxmsk;
uint32_t pxpat1;
uint32_t pxpat0;
uint32_t pxpen;
uint32_t pxignore;
};
enum gpio_function
{
GPIO_FUNC_0 = 0x00, //0000, GPIO as function 0 / device 0
GPIO_FUNC_1 = 0x01, //0001, GPIO as function 1 / device 1
GPIO_FUNC_2 = 0x02, //0010, GPIO as function 2 / device 2
GPIO_FUNC_3 = 0x03, //0011, GPIO as function 3 / device 3
GPIO_OUTPUT0 = 0x04, //0100, GPIO output low level
GPIO_OUTPUT1 = 0x05, //0101, GPIO output high level
GPIO_INPUT = 0x06, //0110, GPIO as input
GPIO_INT_LO = 0x08, //1000, Low Level trigger interrupt
GPIO_INT_HI = 0x09, //1001, High Level trigger interrupt
GPIO_INT_FE = 0x0a, //1010, Fall Edge trigger interrupt
GPIO_INT_RE = 0x0b, //1011, Rise Edge trigger interrupt
GPIO_INPUT_PULL = 0x16, //0001 0110, GPIO as input and enable pull
};
enum gpio_irq_type
{
IRQ_TYPE_NONE = 0x00000000,
IRQ_TYPE_EDGE_RISING = 0x00000001,
IRQ_TYPE_EDGE_FALLING = 0x00000002,
IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING),
IRQ_TYPE_LEVEL_HIGH = 0x00000004,
IRQ_TYPE_LEVEL_LOW = 0x00000008,
IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
IRQ_TYPE_SENSE_MASK = 0x0000000f,
IRQ_TYPE_DEFAULT = IRQ_TYPE_SENSE_MASK,
IRQ_TYPE_PROBE = 0x00000010,
IRQ_LEVEL = (1 << 8),
};
enum gpio_port {
GPIO_PORT_A = 0,
GPIO_PORT_B,
GPIO_PORT_C,
GPIO_PORT_D,
/* this must be last */
GPIO_NR_PORTS,
};
#define IS_GPIO_ALL_PORT(PORT) ( (PORT) < GPIO_NR_PORTS )
enum gpio_pin {
GPIO_Pin_0 = ((uint32_t)0x00000001), /* Pin 0 selected */
GPIO_Pin_1 = ((uint32_t)0x00000002), /* Pin 1 selected */
GPIO_Pin_2 = ((uint32_t)0x00000004), /* Pin 2 selected */
GPIO_Pin_3 = ((uint32_t)0x00000008), /* Pin 3 selected */
GPIO_Pin_4 = ((uint32_t)0x00000010), /* Pin 4 selected */
GPIO_Pin_5 = ((uint32_t)0x00000020), /* Pin 5 selected */
GPIO_Pin_6 = ((uint32_t)0x00000040), /* Pin 6 selected */
GPIO_Pin_7 = ((uint32_t)0x00000080), /* Pin 7 selected */
GPIO_Pin_8 = ((uint32_t)0x00000100), /* Pin 8 selected */
GPIO_Pin_9 = ((uint32_t)0x00000200), /* Pin 9 selected */
GPIO_Pin_10 = ((uint32_t)0x00000400), /* Pin 10 selected */
GPIO_Pin_11 = ((uint32_t)0x00000800), /* Pin 11 selected */
GPIO_Pin_12 = ((uint32_t)0x00001000), /* Pin 12 selected */
GPIO_Pin_13 = ((uint32_t)0x00002000), /* Pin 13 selected */
GPIO_Pin_14 = ((uint32_t)0x00004000), /* Pin 14 selected */
GPIO_Pin_15 = ((uint32_t)0x00008000), /* Pin 15 selected */
GPIO_Pin_16 = ((uint32_t)0x00010000), /* Pin 16 selected */
GPIO_Pin_17 = ((uint32_t)0x00020000), /* Pin 17 selected */
GPIO_Pin_18 = ((uint32_t)0x00040000), /* Pin 18 selected */
GPIO_Pin_19 = ((uint32_t)0x00080000), /* Pin 19 selected */
GPIO_Pin_20 = ((uint32_t)0x00100000), /* Pin 20 selected */
GPIO_Pin_21 = ((uint32_t)0x00200000), /* Pin 21 selected */
GPIO_Pin_22 = ((uint32_t)0x00400000), /* Pin 22 selected */
GPIO_Pin_23 = ((uint32_t)0x00800000), /* Pin 23 selected */
GPIO_Pin_24 = ((uint32_t)0x01000000), /* Pin 24 selected */
GPIO_Pin_25 = ((uint32_t)0x02000000), /* Pin 25 selected */
GPIO_Pin_26 = ((uint32_t)0x04000000), /* Pin 26 selected */
GPIO_Pin_27 = ((uint32_t)0x08000000), /* Pin 27 selected */
GPIO_Pin_28 = ((uint32_t)0x10000000), /* Pin 28 selected */
GPIO_Pin_29 = ((uint32_t)0x20000000), /* Pin 29 selected */
GPIO_Pin_30 = ((uint32_t)0x40000000), /* Pin 30 selected */
GPIO_Pin_31 = ((uint32_t)0x80000000), /* Pin 31 selected */
GPIO_Pin_All = ((uint32_t)0xFFFFFFFF), /* All pins selected */
};
struct jz_gpio_irq_def
{
void *irq_arg[32];
void (*irq_cb[32]) (void *param);
};
void gpio_set_func (enum gpio_port port, uint32_t pins, enum gpio_function func);
void gpio_set_value (enum gpio_port port, enum gpio_pin pin,int value);
int gpio_get_value (enum gpio_port port, enum gpio_pin pin);
int gpio_get_flag (enum gpio_port port, enum gpio_pin pin);
void gpio_clear_flag (enum gpio_port port, enum gpio_pin pin);
void gpio_direction_input (enum gpio_port port, enum gpio_pin pin);
void gpio_direction_output (enum gpio_port port, enum gpio_pin pin,int value);
void gpio_enable_pull (enum gpio_port port, enum gpio_pin pin);
void gpio_disable_pull (enum gpio_port port, enum gpio_pin pin);
void gpio_as_irq_high_level (enum gpio_port port, enum gpio_pin pin);
void gpio_as_irq_rise_edge (enum gpio_port port, enum gpio_pin pin);
void gpio_as_irq_fall_edge (enum gpio_port port, enum gpio_pin pin);
void gpio_ack_irq (enum gpio_port port, enum gpio_pin pin);
void gpio_set_irq_callback(enum gpio_port port, enum gpio_pin pin, void (*irq_cb)(void *),void *irq_arg);
#endif /* _BOARD_GPIO_H_ */
此差异已折叠。
#ifndef DRV_MMC_H__
#define DRV_MMC_H__
#include <stdint.h>
/* MSC configure */
#define MMC_MSC_INTERRUPT_ENABLE 1 /* 0: disable, 1: enable. */
//--------------------------------------------------------------------------
// MSC Registers Offset Definition
//--------------------------------------------------------------------------
#define MSC_CTRL_OFFSET ( 0x00 ) // W, 16, 0x000, MSC Control register
#define MSC_STAT_OFFSET ( 0x04 ) // R, 32, 0x00000040, MSC Status register
#define MSC_CLKRT_OFFSET ( 0x08 ) // RW, 16, 0x0000, MSC Clock Rate register
#define MSC_CMDAT_OFFSET ( 0x0C ) // RW, 32, 0x00000000, MSC Command and Data Control register
#define MSC_RESTO_OFFSET ( 0x10 ) // RW, 16, 0x0040, MSC Response Time Out register
#define MSC_RDTO_OFFSET ( 0x14 ) // RW, 16, 0xFFFF, MSC Read Time Out register
#define MSC_BLKLEN_OFFSET ( 0x18 ) // RW, 16, 0x0000, MSC Block Length register
#define MSC_NOB_OFFSET ( 0x1C ) // RW, 16, 0x0000, MSC Number of Block register
#define MSC_SNOB_OFFSET ( 0x20 ) // R, 16, 0x????, MSC Number of Successfully-transferred Blocks register
#define MSC_IMASK_OFFSET ( 0x24 ) // RW, 32, 0x000000FF, MSC Interrupt Mask register
#define MSC_IREG_OFFSET ( 0x28 ) // RW, 16, 0x2000, MSC Interrupt register
#define MSC_CMD_OFFSET ( 0x2C ) // RW, 8, 0x00, MSC Command Index register
#define MSC_ARG_OFFSET ( 0x30 ) // RW, 32, 0x00000000, MSC Command Argument register
#define MSC_RES_OFFSET ( 0x34 ) // R, 16, 0x????, MSC Response FIFO register
#define MSC_RXFIFO_OFFSET ( 0x38 ) // R, 32, 0x????????, MSC Receive Data FIFO register
#define MSC_TXFIFO_OFFSET ( 0x3C ) // W, 32, 0x????????, MSC Transmit Data FIFO register
#define MSC_LPM_OFFSET ( 0x40 ) // RW, 32, 0x00000000, MSC Low Power Mode register
#define MSC_DMAC_OFFSET ( 0x44 )
#define MSC_DMANDA_OFFSET ( 0x48 )
#define MSC_DMADA_OFFSET ( 0x4C )
#define MSC_DMALEN_OFFSET ( 0x50 )
#define MSC_DMACMD_OFFSET ( 0x54 )
#define MSC_CTRL2_OFFSET ( 0x58 )
#define MSC_RTCNT_OFFSET ( 0x5C )
//--------------------------------------------------------------------------
// MMC/SD Control Register field descriptions (MSC_CTRL)
//--------------------------------------------------------------------------
#define MSC_CTRL_CLOCK_CONTROL_MASK ( 3 << 0 )
#define MSC_CTRL_CLOCK_DONOTHING ( 0 << 0 )
#define MSC_CTRL_CLOCK_STOP ( 1 << 0 )
#define MSC_CTRL_CLOCK_START ( 2 << 0 )
#define MSC_CTRL_START_OP ( 1 << 2 )
#define MSC_CTRL_RESET ( 1 << 3 )
#define MSC_CTRL_STOP_RDWAIT ( 1 << 4 )
#define MSC_CTRL_START_RDWAIT ( 1 << 5 )
#define MSC_CTRL_EXIT_TRANSFER ( 1 << 6 )
#define MSC_CTRL_EXIT_MULTIPLE ( 1 << 7 )
#define MSC_CTRL_SEND_AS_CCSD ( 1 << 14 )
#define MSC_CTRL_SEND_CCSD ( 1 << 15 )
//--------------------------------------------------------------------------
// MSC Status Register field descriptions (MSC_STAT)
//--------------------------------------------------------------------------
#define MSC_STAT_TIME_OUT_READ ( 1 << 0 )
#define MSC_STAT_TIME_OUT_RES ( 1 << 1 )
#define MSC_STAT_CRC_WRITE_ERR_MASK ( 3 << 2 )
#define MSC_STAT_CRC_WRITE_NO_ERR ( 0 << 2 )
#define MSC_STAT_CRC_WRITE_ERR ( 1 << 2 )
#define MSC_STAT_CRC_WRITE_NO_STATUS ( 2 << 2 )
#define MSC_STAT_CRC_READ_ERR ( 1 << 4 )
#define MSC_CMDAT_RESP_FORMAT_MASK ( 7 << 0 )
#define MSC_STAT_CRC_RES_ERR ( 1 << 5 )
#define MSC_STAT_DATA_FIFO_EMPTY ( 1 << 6 )
#define MSC_STAT_DATA_FIFO_FULL ( 1 << 7 )
#define MSC_STAT_CLK_EN ( 1 << 8 )
#define MSC_STAT_IS_READWAIT ( 1 << 9 )
#define MSC_STAT_DATA_FIFO_AFULL ( 1 << 10 )
#define MSC_STAT_END_CMD_RES ( 1 << 11 )
#define MSC_STAT_DATA_TRAN_DONE ( 1 << 12 )
#define MSC_STAT_PRG_DONE ( 1 << 13 )
#define MSC_STAT_SDIO_INT_ACTIVE ( 1 << 14 )
#define MSC_STAT_IS_RESETTING ( 1 << 15 )
#define MSC_STAT_AUTO_CMD_DONE ( 1 << 31 )
//--------------------------------------------------------------------------
//MMC/SD Command and Data Control Register field descriptions (MSC_CMDAT)
//--------------------------------------------------------------------------
#define MSC_CMDAT_RESP_FORMAT_MASK ( 7 << 0 )
#define MSC_CMDAT_RESPONSE_NONE ( 0 << 0 )/* No response */
#define MSC_CMDAT_RESPONSE_R1 ( 1 << 0 )/* Format R1 and R1b */
#define MSC_CMDAT_RESPONSE_R2 ( 2 << 0 )/* Format R2 */
#define MSC_CMDAT_RESPONSE_R3 ( 3 << 0 )/* Format R3 */
#define MSC_CMDAT_RESPONSE_R4 ( 4 << 0 )/* Format R4 */
#define MSC_CMDAT_RESPONSE_R5 ( 5 << 0 )/* Format R5 */
#define MSC_CMDAT_RESPONSE_R6 ( 6 << 0 )/* Format R6 */
#define MSC_CMDAT_RESPONSE_R7 ( 7 << 0 )/* Format R7 */
#define MSC_CMDAT_DATA_EN ( 1 << 3 )
#define MSC_CMDAT_WRRD_MASK ( 1 << 4 )
#define MSC_CMDAT_WRITE ( 1 << 4 )
#define MSC_CMDAT_READ ( 0 << 4 )
#define MSC_CMDAT_STREAM_BLOCK ( 1 << 5 )
#define MSC_CMDAT_BUSY ( 1 << 6 )
#define MSC_CMDAT_INIT ( 1 << 7 )
#define MSC_CMDAT_DMA_EN ( 1 << 8 )
#define MSC_CMDAT_BUS_WIDTH_MASK ( 3 << 9 )
#define MSC_CMDAT_BUS_WIDTH_1BIT ( 0 << 9 )
#define MSC_CMDAT_BUS_WIDTH_4BIT ( 2 << 9 )
#define MSC_CMDAT_BUS_WIDTH_8BIT ( 3 << 9 )
#define MSC_CMDAT_STOP_ABORT ( 1 << 11 )
#define MSC_CMDAT_TTRG_MASK ( 3 << 12 )
#define MSC_CMDAT_TTRG_08 ( 0 << 12 )
#define MSC_CMDAT_TTRG_16 ( 1 << 12 )
#define MSC_CMDAT_TTRG_24 ( 2 << 12 )
#define MSC_CMDAT_RTRG_MASK ( 3 << 14 )
#define MSC_CMDAT_RTRG_08 ( 0 << 14 )
#define MSC_CMDAT_RTRG_16 ( 1 << 14 )
#define MSC_CMDAT_RTRG_24 ( 2 << 14 )
#define MSC_CMDAT_SEND_AS_STOP ( 1 << 16 )
#define MSC_CMDAT_SDIO_PRDT ( 1 << 17 )
#define MSC_CMDAT_READ_CEATA ( 1 << 30 )
#define MSC_CMDAT_CCS_EXPECTED ( 1 << 31 )
//--------------------------------------------------------------------------
// IRQ Number descriptions
//--------------------------------------------------------------------------
#define MSC_DATA_TRAN_DONE ( 1 << 0 )
#define MSC_PRG_DONE ( 1 << 1 )
#define MSC_END_CMD_RES ( 1 << 2 )
#define MSC_RXFIFO_RD_REQ ( 1 << 5 )
#define MSC_TXFIFO_WR_REQ ( 1 << 6 )
#define MSC_SDIO ( 1 << 7 )
#define MSC_TIME_OUT_READ ( 1 << 8 )
#define MSC_TIME_OUT_RES ( 1 << 9 )
#define MSC_CRC_WRITE_ERR ( 1 << 10 )
#define MSC_CRC_READ_ERR ( 1 << 11 )
#define MSC_CRC_RES_ERR ( 1 << 12 )
#define MSC_DATA_FIFO_EMP ( 1 << 13 )
#define MSC_DATA_FIFO_FULL ( 1 << 14 )
#define MSC_AUTO_CMD_DONE ( 1 << 15 )
#define MSC_DMAEND ( 1 << 16 )
#define MSC_BAR ( 1 << 17 )
#define MSC_BAE ( 1 << 18 )
#define MSC_BDE ( 1 << 19 )
#define MSC_BCE ( 1 << 20 )
#define MSC_WR_ALL_DONE ( 1 << 23 )
#define MSC_PIN_LEVEL ( 1 << 24 )
#define MSC_DMA_DATA_DONE ( 1 << 31 )
/* MSC Interrupts Status Register (MSC_IREG) */
#define IFLG_DMA_DATA_DONE (1 << 31)
#define IFLG_WR_ALL_DONE (1 << 23)
#define IFLG_AUTO_CMD23_DONE (1 << 30)
#define IFLG_SVS (1 << 29)
#define IFLG_PIN_LEVEL_SHF 24
#define IFLG_PIN_LEVEL_MASK (0x1f << IFLG_PIN_LEVEL_SHF)
#define IFLG_BCE (1 << 20)
#define IFLG_BDE (1 << 19)
#define IFLG_BAE (1 << 18)
#define IFLG_BAR (1 << 17)
#define IFLG_DMAEND (1 << 16)
#define IFLG_AUTO_CMD12_DONE (1 << 15)
#define IFLG_DATA_FIFO_FULL (1 << 14)
#define IFLG_DATA_FIFO_EMP (1 << 13)
#define IFLG_CRC_RES_ERR (1 << 12)
#define IFLG_CRC_READ_ERR (1 << 11)
#define IFLG_CRC_WRITE_ERR (1 << 10)
#define IFLG_TIMEOUT_RES (1 << 9)
#define IFLG_TIMEOUT_READ (1 << 8)
#define IFLG_SDIO (1 << 7)
#define IFLG_TXFIFO_WR_REQ (1 << 6)
#define IFLG_RXFIFO_RD_REQ (1 << 5)
#define IFLG_END_CMD_RES (1 << 2)
#define IFLG_PRG_DONE (1 << 1)
#define IFLG_DATA_TRAN_DONE (1 << 0)
/* MSC Low Power Mode Register (MSC_LPM) */
#define LPM_DRV_SEL_SHF 30
#define LPM_DRV_SEL_MASK (0x3 << LPM_DRV_SEL_SHF)
#define LPM_SMP_SEL (1 << 29)
#define LPM_LPM (1 << 0)
/* MSC DMA Control Register (MSC_DMAC) */
#define DMAC_MODE_SEL (1 << 7)
#define DMAC_AOFST_SHF 5
#define DMAC_AOFST_MASK (0x3 << DMAC_AOFST_SHF)
#define DMAC_AOFST_0 (0 << DMAC_AOFST_SHF)
#define DMAC_AOFST_1 (1 << DMAC_AOFST_SHF)
#define DMAC_AOFST_2 (2 << DMAC_AOFST_SHF)
#define DMAC_AOFST_3 (3 << DMAC_AOFST_SHF)
#define DMAC_ALIGNEN (1 << 4)
#define DMAC_INCR_SHF 2
#define DMAC_INCR_MASK (0x3 << DMAC_INCR_SHF)
#define DMAC_INCR_16 (0 << DMAC_INCR_SHF)
#define DMAC_INCR_32 (1 << DMAC_INCR_SHF)
#define DMAC_INCR_64 (2 << DMAC_INCR_SHF)
#define DMAC_DMASEL (1 << 1)
#define DMAC_DMAEN (1 << 0)
/* MSC DMA Command Register (MSC_DMACMD) */
#define DMACMD_IDI_SHF 24
#define DMACMD_IDI_MASK (0xff << DMACMD_IDI_SHF)
#define DMACMD_ID_SHF 16
#define DMACMD_ID_MASK (0xff << DMACMD_ID_SHF)
#define DMACMD_OFFSET_SHF 9
#define DMACMD_OFFSET_MASK (0x3 << DMACMD_OFFSET_SHF)
#define DMACMD_ALIGN_EN (1 << 8)
#define DMACMD_ENDI (1 << 1)
#define DMACMD_LINK (1 << 0)
/* Error codes */
enum mmc_result_t {
MMC_NO_RESPONSE = -1,
MMC_NO_ERROR = 0,
MMC_ERROR_OUT_OF_RANGE,
MMC_ERROR_ADDRESS,
MMC_ERROR_BLOCK_LEN,
MMC_ERROR_ERASE_SEQ,
MMC_ERROR_ERASE_PARAM,
MMC_ERROR_WP_VIOLATION,
MMC_ERROR_CARD_IS_LOCKED,
MMC_ERROR_LOCK_UNLOCK_FAILED,
MMC_ERROR_COM_CRC,
MMC_ERROR_ILLEGAL_COMMAND,
MMC_ERROR_CARD_ECC_FAILED,
MMC_ERROR_CC,
MMC_ERROR_GENERAL,
MMC_ERROR_UNDERRUN,
MMC_ERROR_OVERRUN,
MMC_ERROR_CID_CSD_OVERWRITE,
MMC_ERROR_STATE_MISMATCH,
MMC_ERROR_HEADER_MISMATCH,
MMC_ERROR_TIMEOUT,
MMC_ERROR_CRC,
MMC_ERROR_DRIVER_FAILURE,
};
struct jz47xx_sdio
{
struct rt_mmcsd_host *host;
struct rt_mmcsd_req *req;
struct rt_mmcsd_cmd *cmd;
uint32_t hw_base;
uint32_t msc_clock;
uint32_t irqno;
uint32_t flag;
struct rt_completion completion;
struct clk *clock;
struct clk *clock_gate;
int sdio_clk; /* clock for sdio */
rt_uint32_t current_status;
};
#endif /* DRV_MMC_H__ */
/*
* File : board_timer.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <stdint.h>
#include "board.h"
#include "drv_clock.h"
#include "drv_ost.h"
/**
* This is the OST timer interrupt service routine.
*/
void rt_hw_ost_handler(void)
{
/* increase a OS tick */
rt_tick_increase();
/* clear flag */
REG_OSTFR = 0;
}
void rt_hw_ost_init(void)
{
rt_uint32_t cnt, div;
struct clk *clk;
div = OST_DIV16;
cnt = BOARD_EXTAL_CLK / 16;
/* enable OST clock */
clk = clk_get("sys_ost");
clk_enable(clk);
/* Disable OST (channel 1/2) */
REG_OSTECR = 0x3;
/* clear counter */
REG_OSTCR = 0x01;
REG_OST1CNT = 0;
/* set timer data (channel 1) */
REG_OST1DFR = (cnt / RT_TICK_PER_SECOND - 1);
/* set prescale ext clk */
REG_OSTCCR = div;
/* unmask interrupt */
REG_OSTMR = 0;
/* enable OST (channel 1) */
REG_OSTESR = 0x01;
clk_put(clk);
}
/*
* File : board_timer.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#ifndef DRV_OST_H__
#define DRV_OST_H__
#define TCU_TSTR (0xF0) /* Timer Status Register,Only Used In Tcu2 Mode */
#define TCU_TSTSR (0xF4) /* Timer Status Set Register */
#define TCU_TSTCR (0xF8) /* Timer Status Clear Register */
#define TCU_TSR (0x1C) /* Timer Stop Register */
#define TCU_TSSR (0x2C) /* Timer Stop Set Register */
#define TCU_TSCR (0x3C) /* Timer Stop Clear Register */
#define TCU_TER (0x10) /* Timer Counter Enable Register */
#define TCU_TESR (0x14) /* Timer Counter Enable Set Register */
#define TCU_TECR (0x18) /* Timer Counter Enable Clear Register */
#define TCU_TFR (0x20) /* Timer Flag Register */
#define TCU_TFSR (0x24) /* Timer Flag Set Register */
#define TCU_TFCR (0x28) /* Timer Flag Clear Register */
#define TCU_TMR (0x30) /* Timer Mask Register */
#define TCU_TMSR (0x34) /* Timer Mask Set Register */
#define TCU_TMCR (0x38) /* Timer Mask Clear Register */
#define CH_TDFR(n) (0x40 + (n)*0x10) /* Timer Data Full Reg */
#define CH_TDHR(n) (0x44 + (n)*0x10) /* Timer Data Half Reg */
#define CH_TCNT(n) (0x48 + (n)*0x10) /* Timer Counter Reg */
#define CH_TCSR(n) (0x4C + (n)*0x10) /* Timer Control Reg */
#define REG_TCU_TSTR REG32(TCU_BASE + (0xF0))
#define REG_TCU_TSTSR REG32(TCU_BASE + (0xF4))
#define REG_TCU_TSTCR REG32(TCU_BASE + (0xF8))
#define REG_TCU_TSR REG32(TCU_BASE + (0x1C))
#define REG_TCU_TSSR REG32(TCU_BASE + (0x2C))
#define REG_TCU_TSCR REG32(TCU_BASE + (0x3C))
#define REG_TCU_TER REG32(TCU_BASE + (0x10))
#define REG_TCU_TESR REG32(TCU_BASE + (0x14))
#define REG_TCU_TECR REG16(TCU_BASE + (0x18))
#define REG_TCU_TFR REG32(TCU_BASE + (0x20))
#define REG_TCU_TFSR REG32(TCU_BASE + (0x24))
#define REG_TCU_TFCR REG32(TCU_BASE + (0x28))
#define REG_TCU_TMR REG32(TCU_BASE + (0x30))
#define REG_TCU_TMSR REG32(TCU_BASE + (0x34))
#define REG_TCU_TMCR REG32(TCU_BASE + (0x38))
#define REG_CH_TDFR(n) REG32(TCU_BASE + (0x40 + (n)*0x10))
#define REG_CH_TDHR(n) REG32(TCU_BASE + (0x44 + (n)*0x10))
#define REG_CH_TCNT(n) REG32(TCU_BASE + (0x48 + (n)*0x10))
#define REG_CH_TCSR(n) REG32(TCU_BASE + (0x4C + (n)*0x10))
#define TER_OSTEN (1 << 15) /* enable the counter in ost */
#define TMR_OSTM (1 << 15) /* ost comparison match interrupt mask */
#define TFR_OSTF (1 << 15) /* ost interrupt flag */
#define TSR_OSTS (1 << 15) /*the clock supplies to osts is stopped */
#define TSR_WDTS (1 << 16) /*the clock supplies to wdt is stopped */
// Register bits definitions
#define TSTR_REAL2 (1 << 18) /* only used in TCU2 mode */
#define TSTR_REAL1 (1 << 17) /* only used in TCU2 mode */
#define TSTR_BUSY2 (1 << 2) /* only used in TCU2 mode */
#define TSTR_BUSY1 (1 << 1) /* only used in TCU2 mode */
#define TCSR_CNT_CLRZ (1 << 10) /* clear counter to 0, only used in TCU2 mode */
#define TCSR_PWM_SD (1 << 9) /* shut down the pwm output only used in TCU1 mode */
#define TCSR_PWM_HIGH (1 << 8) /* selects an initial output level for pwm output */
#define TCSR_PWM_EN (1 << 7) /* pwm pin output enable */
/*********************************************************************************************************
** OST
*********************************************************************************************************/
#define REG_OSTCCR REG32(OST_BASE + 0x00)
#define REG_OSTER REG32(OST_BASE + 0x04)
#define REG_OSTCR REG32(OST_BASE + 0x08)
#define REG_OSTFR REG32(OST_BASE + 0x0C)
#define REG_OSTMR REG32(OST_BASE + 0x10)
#define REG_OST1DFR REG32(OST_BASE + 0x14)
#define REG_OST1CNT REG32(OST_BASE + 0x18)
#define REG_OST2CNTL REG32(OST_BASE + 0x20)
#define REG_OSTCNT2HBUF REG32(OST_BASE + 0x24)
#define REG_OSTESR REG32(OST_BASE + 0x34)
#define REG_OSTECR REG32(OST_BASE + 0x38)
/*
* Operating system timer module(OST) address definition
*/
#define OST_DR (0xE0)
#define OST_CNTL (0xE4)
#define OST_CNTH (0xE8)
#define OST_CSR (0xEC)
#define OST_CNTH_BUF (0xFC)
#define REG_OST_DR REG32(OST_BASE + (0xE0))
#define REG_OST_CNTL REG32(OST_BASE + (0xE4))
#define REG_OST_CNTH REG32(OST_BASE + (0xE8))
#define REG_OST_CSR REG16(OST_BASE + (0xEC))
#define REG_OST_CNTH_BUF REG32(OST_BASE + (0xFC))
/* Operating system control register(OSTCSR) */
#define OST_CSR_CNT_MD (1 << 15)
#define CSR_EXT_EN (1 << 2) /* select extal as the timer clock input */
#define CSR_RTC_EN (1 << 1) /* select rtcclk as the timer clock input */
#define CSR_PCK_EN (1 << 0) /* select pclk as the timer clock input */
#define CSR_CLK_MSK (0x7)
#define CSR_DIV1 (0x0 << 3)
#define CSR_DIV4 (0x1 << 3)
#define CSR_DIV16 (0x2 << 3)
#define CSR_DIV64 (0x3 << 3)
#define CSR_DIV256 (0x4 << 3)
#define CSR_DIV1024 (0x5 << 3)
#define CSR_DIV_MSK (0x7 << 3)
#define OST_DIV1 (0x0)
#define OST_DIV4 (0x1)
#define OST_DIV16 (0x2)
void rt_hw_ost_init(void);
#endif
/*
* File : drv_uart.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_uart.h"
struct jz_uart_s
{
rt_uint32_t hw_base;
rt_uint32_t irqno;
char name[RT_NAME_MAX];
};
static rt_err_t uart_configure (struct rt_serial_device *serial, struct serial_configure *cfg);
static rt_err_t uart_control (struct rt_serial_device *serial, int cmd, void *arg);
static int uart_putc (struct rt_serial_device *serial, char c);
static int uart_getc (struct rt_serial_device *serial);
static rt_size_t uart_dma_transmit (struct rt_serial_device *serial, const rt_uint8_t *buf, rt_size_t size, int direction);
static void uart_irq_handler (int irqno, void *param);
const struct rt_uart_ops _uart_ops =
{
uart_configure,
uart_control,
uart_putc,
uart_getc,
uart_dma_transmit
};
/*
* UART Initiation
*/
void rt_hw_uart_init(void)
{
struct rt_serial_device *serial;
struct jz_uart_s *uart;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
#ifdef RT_USING_UART1
{
static struct rt_serial_device serial1;
static struct jz_uart_s uart1;
serial = &serial1;
uart = &uart1;
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;
uart->hw_base = UART0_BASE;
uart->irqno = IRQ_UART0;
rt_hw_serial_register(serial,
"uart1",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif
#ifdef RT_USING_UART2
{
static struct rt_serial_device serial2;
static struct jz_uart_s uart2;
serial = &serial2;
uart = &uart2;
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;
uart->hw_base = UART2_BASE;
uart->irqno = IRQ_UART2;
rt_hw_serial_register(serial,
"uart2",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif
#ifdef RT_USING_UART3
{
static struct rt_serial_device serial3;
static struct jz_uart_s uart3;
serial = &serial3;
uart = &uart3;
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;
uart->hw_base = UART3_BASE;
uart->irqno = IRQ_UART3;
rt_hw_serial_register(serial,
"uart3",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif
}
/*
* UART interface
*/
static rt_err_t uart_configure (struct rt_serial_device *serial, struct serial_configure *cfg)
{
rt_uint32_t baud_div;
struct jz_uart_s * uart;
RT_ASSERT(serial != RT_NULL);
serial->config = *cfg;
uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
/* Init UART Hardware */
UART_IER(uart->hw_base) = 0; /* clear interrupt */
UART_FCR(uart->hw_base) = ~UARTFCR_UUE; /* disable UART unite */
/* Enable UART clock */
/* Set both receiver and transmitter in UART mode (not SIR) */
UART_SIRCR(uart->hw_base) = ~(SIRCR_RSIRE | SIRCR_TSIRE);
/* Set databits, stopbits and parity. (8-bit data, 1 stopbit, no parity) */
UART_LCR(uart->hw_base) = UARTLCR_WLEN_8;
/* set baudrate */
#if defined(RT_USING_JZ4750) || defined(RT_USING_JZ4755) || defined(RT_USING_JZ4760)
if(REG_CPM_CPCCR & (1UL << 30))
{
/* CPCCR.ECS = 1: clock source is EXCLK/2 */
baud_div = BOARD_EXTAL_CLK / 2 / 16 / cfg->baud_rate;
}
else
#endif
{
/* CPCCR.ECS = 0: clock source is EXCLK */
baud_div = BOARD_EXTAL_CLK / 16 / cfg->baud_rate;
}
UART_LCR(uart->hw_base) |= UARTLCR_DLAB;
UART_DLHR(uart->hw_base) = (baud_div >> 8) & 0xff;
UART_DLLR(uart->hw_base) = baud_div & 0xff;
UART_LCR(uart->hw_base) &= ~UARTLCR_DLAB;
/* Enable UART unit, enable and clear FIFO */
UART_FCR(uart->hw_base) = UARTFCR_UUE | UARTFCR_FE | UARTFCR_TFLS | UARTFCR_RFLS;
return (RT_EOK);
}
static rt_err_t uart_control (struct rt_serial_device *serial, int cmd, void *arg)
{
struct jz_uart_s * uart;
uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
/* Disable the UART Interrupt */
UART_IER(uart->hw_base) &= ~(UARTIER_RIE | UARTIER_RTIE);
rt_hw_interrupt_mask(uart->irqno);
break;
case RT_DEVICE_CTRL_SET_INT:
/* install interrupt */
rt_hw_interrupt_install(uart->irqno, uart_irq_handler,
serial, uart->name);
rt_hw_interrupt_umask(uart->irqno);
/* Enable the UART Interrupt */
UART_IER(uart->hw_base) |= (UARTIER_RIE | UARTIER_RTIE);
break;
}
return (RT_EOK);
}
static int uart_putc (struct rt_serial_device *serial, char c)
{
struct jz_uart_s* uart;
uart = serial->parent.user_data;
/* FIFO status, contain valid data */
while (!((UART_LSR(uart->hw_base) & (UARTLSR_TDRQ | UARTLSR_TEMT)) == 0x60));
/* write data */
UART_TDR(uart->hw_base) = c;
return (1);
}
static int uart_getc (struct rt_serial_device *serial)
{
struct jz_uart_s* uart = serial->parent.user_data;
/* Receive Data Available */
if (UART_LSR(uart->hw_base) & UARTLSR_DR)
{
return UART_RDR(uart->hw_base);
}
return (-1);
}
static rt_size_t uart_dma_transmit (struct rt_serial_device *serial, const rt_uint8_t *buf, rt_size_t size, int direction)
{
return (0);
}
/* UART ISR */
static void uart_irq_handler(int irqno, void *param)
{
rt_ubase_t isr;
struct rt_serial_device *serial = (struct rt_serial_device*)param;
struct jz_uart_s* uart = serial->parent.user_data;
/* read interrupt status and clear it */
isr = UART_ISR(uart->hw_base);
if (isr & UARTISR_IID_RDI) /* Receive Data Available */
{
rt_hw_serial_isr(serial,RT_SERIAL_EVENT_RX_IND);
}
if(isr & UARTISR_IID_THRI)
{
rt_hw_serial_isr(serial,RT_SERIAL_EVENT_TX_DONE);
}
}
/*
* File : board_uart.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-11-19 Urey the first version
*/
#ifndef _BOARD_UART_H_
#define _BOARD_UART_H_
/* Uart Register */
#define UART_RDR(base) REG8((base) + 0x00) /* R 8b H'xx */
#define UART_TDR(base) REG8((base) + 0x00) /* W 8b H'xx */
#define UART_DLLR(base) REG8((base) + 0x00) /* RW 8b H'00 */
#define UART_DLHR(base) REG8((base) + 0x04) /* RW 8b H'00 */
#define UART_IER(base) REG8((base) + 0x04) /* RW 8b H'00 */
#define UART_ISR(base) REG8((base) + 0x08) /* R 8b H'01 */
#define UART_FCR(base) REG8((base) + 0x08) /* W 8b H'00 */
#define UART_LCR(base) REG8((base) + 0x0C) /* RW 8b H'00 */
#define UART_MCR(base) REG8((base) + 0x10) /* RW 8b H'00 */
#define UART_LSR(base) REG8((base) + 0x14) /* R 8b H'00 */
#define UART_MSR(base) REG8((base) + 0x18) /* R 8b H'00 */
#define UART_SPR(base) REG8((base) + 0x1C) /* RW 8b H'00 */
#define UART_MCR(base) REG8((base) + 0x10) /* RW 8b H'00 */
#define UART_SIRCR(base) REG8((base) + 0x20) /* RW 8b H'00 */
/*
* Define macros for UARTIER
* UART Interrupt Enable Register
*/
#define UARTIER_RIE (1 << 0) /* 0: receive fifo "full" interrupt disable */
#define UARTIER_TIE (1 << 1) /* 0: transmit fifo "empty" interrupt disable */
#define UARTIER_RLIE (1 << 2) /* 0: receive line status interrupt disable */
#define UARTIER_MIE (1 << 3) /* 0: modem status interrupt disable */
#define UARTIER_RTIE (1 << 4) /* 0: receive timeout interrupt disable */
/*
* Define macros for UARTISR
* UART Interrupt Status Register
*/
#define UARTISR_IP (1 << 0) /* 0: interrupt is pending 1: no interrupt */
#define UARTISR_IID (7 << 1) /* Source of Interrupt */
#define UARTISR_IID_MSI (0 << 1) /* Modem status interrupt */
#define UARTISR_IID_THRI (1 << 1) /* Transmitter holding register empty */
#define UARTISR_IID_RDI (2 << 1) /* Receiver data interrupt */
#define UARTISR_IID_RLSI (3 << 1) /* Receiver line status interrupt */
#define UARTISR_FFMS (3 << 6) /* FIFO mode select, set when UARTFCR.FE is set to 1 */
#define UARTISR_FFMS_NO_FIFO (0 << 6)
#define UARTISR_FFMS_FIFO_MODE (3 << 6)
/*
* Define macros for UARTFCR
* UART FIFO Control Register
*/
#define UARTFCR_FE (1 << 0) /* 0: non-FIFO mode 1: FIFO mode */
#define UARTFCR_RFLS (1 << 1) /* write 1 to flush receive FIFO */
#define UARTFCR_TFLS (1 << 2) /* write 1 to flush transmit FIFO */
#define UARTFCR_DMS (1 << 3) /* 0: disable DMA mode */
#define UARTFCR_UUE (1 << 4) /* 0: disable UART */
#define UARTFCR_RTRG (3 << 6) /* Receive FIFO Data Trigger */
#define UARTFCR_RTRG_1 (0 << 6)
#define UARTFCR_RTRG_4 (1 << 6)
#define UARTFCR_RTRG_8 (2 << 6)
#define UARTFCR_RTRG_15 (3 << 6)
/*
* Define macros for UARTLCR
* UART Line Control Register
*/
#define UARTLCR_WLEN (3 << 0) /* word length */
#define UARTLCR_WLEN_5 (0 << 0)
#define UARTLCR_WLEN_6 (1 << 0)
#define UARTLCR_WLEN_7 (2 << 0)
#define UARTLCR_WLEN_8 (3 << 0)
#define UARTLCR_STOP (1 << 2) /* 0: 1 stop bit when word length is 5,6,7,8
1: 1.5 stop bits when 5; 2 stop bits when 6,7,8 */
#define UARTLCR_PE (1 << 3) /* 0: parity disable */
#define UARTLCR_PROE (1 << 4) /* 0: even parity 1: odd parity */
#define UARTLCR_SPAR (1 << 5) /* 0: sticky parity disable */
#define UARTLCR_SBRK (1 << 6) /* write 0 normal, write 1 send break */
#define UARTLCR_DLAB (1 << 7) /* 0: access UARTRDR/TDR/IER 1: access UARTDLLR/DLHR */
/*
* Define macros for UARTLSR
* UART Line Status Register
*/
#define UARTLSR_DR (1 << 0) /* 0: receive FIFO is empty 1: receive data is ready */
#define UARTLSR_ORER (1 << 1) /* 0: no overrun error */
#define UARTLSR_PER (1 << 2) /* 0: no parity error */
#define UARTLSR_FER (1 << 3) /* 0; no framing error */
#define UARTLSR_BRK (1 << 4) /* 0: no break detected 1: receive a break signal */
#define UARTLSR_TDRQ (1 << 5) /* 1: transmit FIFO half "empty" */
#define UARTLSR_TEMT (1 << 6) /* 1: transmit FIFO and shift registers empty */
#define UARTLSR_RFER (1 << 7) /* 0: no receive error 1: receive error in FIFO mode */
/*
* Define macros for UARTMCR
* UART Modem Control Register
*/
#define UARTMCR_DTR (1 << 0) /* 0: DTR_ ouput high */
#define UARTMCR_RTS (1 << 1) /* 0: RTS_ output high */
#define UARTMCR_OUT1 (1 << 2) /* 0: UARTMSR.RI is set to 0 and RI_ input high */
#define UARTMCR_OUT2 (1 << 3) /* 0: UARTMSR.DCD is set to 0 and DCD_ input high */
#define UARTMCR_LOOP (1 << 4) /* 0: normal 1: loopback mode */
#define UARTMCR_MCE (1 << 7) /* 0: modem function is disable */
/*
* Define macros for UARTMSR
* UART Modem Status Register
*/
#define UARTMSR_DCTS (1 << 0) /* 0: no change on CTS_ pin since last read of UARTMSR */
#define UARTMSR_DDSR (1 << 1) /* 0: no change on DSR_ pin since last read of UARTMSR */
#define UARTMSR_DRI (1 << 2) /* 0: no change on RI_ pin since last read of UARTMSR */
#define UARTMSR_DDCD (1 << 3) /* 0: no change on DCD_ pin since last read of UARTMSR */
#define UARTMSR_CTS (1 << 4) /* 0: CTS_ pin is high */
#define UARTMSR_DSR (1 << 5) /* 0: DSR_ pin is high */
#define UARTMSR_RI (1 << 6) /* 0: RI_ pin is high */
#define UARTMSR_DCD (1 << 7) /* 0: DCD_ pin is high */
/*
* Define macros for SIRCR
* Slow IrDA Control Register
*/
#define SIRCR_TSIRE (1 << 0) /* 0: transmitter is in UART mode 1: IrDA mode */
#define SIRCR_RSIRE (1 << 1) /* 0: receiver is in UART mode 1: IrDA mode */
#define SIRCR_TPWS (1 << 2) /* 0: transmit 0 pulse width is 3/16 of bit length
1: 0 pulse width is 1.6us for 115.2Kbps */
#define SIRCR_TXPL (1 << 3) /* 0: encoder generates a positive pulse for 0 */
#define SIRCR_RXPL (1 << 4) /* 0: decoder interprets positive pulse as 0 */
void rt_hw_uart_init(void);
#endif /* _BOARD_UART_H_ */
#ifndef __RTTHREAD_CFG_H__
#define __RTTHREAD_CFG_H__
// <RDTConfigurator URL="http://www.rt-thread.com/eclipse">
// <integer name="RT_NAME_MAX" description="Maximal size of kernel object name length" default="6" />
#define RT_NAME_MAX 8
// <integer name="RT_ALIGN_SIZE" description="Alignment size for CPU architecture data access" default="4" />
#define RT_ALIGN_SIZE 4
// <integer name="RT_THREAD_PRIORITY_MAX" description="Maximal level of thread priority" default="32">
// <item description="8">8</item>
// <item description="32">32</item>
// <item description="256">256</item>
// </integer>
#define RT_THREAD_PRIORITY_MAX 32
// <integer name="RT_TICK_PER_SECOND" description="OS tick per second" default="100" />
#define RT_TICK_PER_SECOND 100
// <integer name="IDLE_THREAD_STACK_SIZE" description="The stack size of idle thread" default="512" />
#define IDLE_THREAD_STACK_SIZE 1024
// <section name="RT_DEBUG" description="Kernel Debug Configuration" default="true" >
#define RT_DEBUG
// <integer name="RT_DEBUG_SCHEDULER" description="Enable scheduler debug information" default="0" />
#define RT_DEBUG_SCHEDULER 0
// <bool name="RT_USING_OVERFLOW_CHECK" description="Thread stack over flow detect" default="true" />
#define RT_USING_OVERFLOW_CHECK
// </section>
// <bool name="RT_USING_HOOK" description="Using hook functions" default="true" />
#define RT_USING_HOOK
// <section name="RT_USING_TIMER_SOFT" description="Using software timer which will start a thread to handle soft-timer" default="true" >
// #define RT_USING_TIMER_SOFT
// <integer name="RT_TIMER_THREAD_PRIO" description="The priority level of timer thread" default="4" />
#define RT_TIMER_THREAD_PRIO 4
// <integer name="RT_TIMER_THREAD_STACK_SIZE" description="The stack size of timer thread" default="512" />
#define RT_TIMER_THREAD_STACK_SIZE 512
// </section>
// <section name="IPC" description="Inter-Thread communication" default="always" >
// <bool name="RT_USING_SEMAPHORE" description="Using semaphore in the system" default="true" />
#define RT_USING_SEMAPHORE
// <bool name="RT_USING_MUTEX" description="Using mutex in the system" default="true" />
#define RT_USING_MUTEX
// <bool name="RT_USING_EVENT" description="Using event group in the system" default="true" />
#define RT_USING_EVENT
// <bool name="RT_USING_MAILBOX" description="Using mailbox in the system" default="true" />
#define RT_USING_MAILBOX
// <bool name="RT_USING_MESSAGEQUEUE" description="Using message queue in the system" default="true" />
#define RT_USING_MESSAGEQUEUE
// </section>
// <section name="MM" description="Memory Management" default="always" >
// <bool name="RT_USING_MEMPOOL" description="Using Memory Pool Management in the system" default="true" />
#define RT_USING_MEMPOOL
// <bool name="RT_USING_MEMHEAP" description="Using Memory Heap Object in the system" default="true" />
// #define RT_USING_MEMHEAP
// <bool name="RT_USING_HEAP" description="Using Dynamic Heap Management in the system" default="true" />
#define RT_USING_HEAP
// <bool name="RT_USING_SMALL_MEM" description="Optimizing for small memory" default="false" />
#define RT_USING_SMALL_MEM
// <bool name="RT_USING_SLAB" description="Using SLAB memory management for large memory" default="false" />
// #define RT_USING_SLAB
// </section>
// <section name="RT_USING_DEVICE" description="Using Device Driver Framework" default="true" >
#define RT_USING_DEVICE
// <bool name="RT_USING_SERIAL" description="Using serial frame work" default="true" />
#define RT_USING_SERIAL
// <bool name="RT_USING_SPI" description="Using SPI frame work" default="true" />
// #define RT_USING_SPI
// <bool name="RT_USING_DEVICE_IPC" description="Using IPC for device driver" default="true" />
#define RT_USING_DEVICE_IPC
// <bool name="RT_USING_SDIO" description="Using SDIO frame work for SD, MMC, SDIO wifi" default="true" />
#define RT_USING_SDIO
// <bool name="RT_USING_USB_DEVICE" description="Using USB Device Stack" default="true" />
//#define RT_USING_USB_DEVICE
// <bool name="RT_USING_USB_DEVICE" description="Using USB Device Stack" default="true" />
//#define RT_USB_DEVICE_CDC
//#define USB_VENDOR_ID 0x0483
//#define USB_PRODUCT_ID 0x5740
// </section>
// <section name="RT_USING_CONSOLE" description="Using console" default="true" >
#define RT_USING_CONSOLE
// <integer name="RT_CONSOLEBUF_SIZE" description="The buffer size for console output" default="128" />
#define RT_CONSOLEBUF_SIZE 128
// <string name="RT_CONSOLE_DEVICE_NAME" description="The device name for console" default="uart1" />
#define RT_CONSOLE_DEVICE_NAME "uart2"
// </section>
// <section name="RT_USING_FINSH" description="Using finsh as shell, which is a C-Express shell" default="true" >
#define RT_USING_FINSH
// <bool name="FINSH_USING_SYMTAB" description="Using symbol table in finsh shell" default="true" />
#define FINSH_USING_SYMTAB
// <bool name="FINSH_USING_DESCRIPTION" description="Keeping description in symbol table" default="true" />
#define FINSH_USING_DESCRIPTION
// <integer name="FINSH_THREAD_STACK_SIZE" description="The stack size for finsh thread" default="2048" />
#define FINSH_THREAD_STACK_SIZE 4096
// <bool name="FINSH_USING_MSH" description="Using module shell" default="true" />
#define FINSH_USING_MSH
// <bool name="FINSH_USING_MSH_DEFAULT" description="Using msh in default" default="true" />
#define FINSH_USING_MSH_DEFAULT
// <bool name="FINSH_USING_MSH_ONLY" description="Only using msh" default="true" />
// #define FINSH_USING_MSH_ONLY
// </section>
// <section name="LIBC" description="C Runtime library setting" default="always" >
// <bool name="RT_USING_LIBC" description="Using C library" default="true" />
#define RT_USING_LIBC
// <bool name="RT_USING_PTHREADS" description="Using POSIX threads library" default="true" />
#define RT_USING_PTHREADS
// <bool name="RT_USING_COMPONENTS_INIT" description="Using automatically component initialization." default="true" />
#define RT_USING_COMPONENTS_INIT
// <bool name="RT_USING_USER_MAIN" description="Using main() as user entry" default="true" />
#define RT_USING_USER_MAIN
// </section>
// <section name="RT_USING_DFS" description="Device file system" default="true" >
#define RT_USING_DFS
// <bool name="DFS_USING_WORKDIR" description="Using working directory" default="true" />
#define DFS_USING_WORKDIR
// <integer name="DFS_FILESYSTEMS_MAX" description="The maximal number of mounted file system" default="4" />
#define DFS_FILESYSTEMS_MAX 4
// <integer name="DFS_FD_MAX" description="The maximal number of opened files" default="4" />
#define DFS_FD_MAX 8
// <bool name="RT_USING_DFS_ELMFAT" description="Using ELM FatFs" default="true" />
#define RT_USING_DFS_ELMFAT
// <integer name="RT_DFS_ELM_DRIVES" description="The maximal number of drives of FatFs" default="4" />
#define RT_DFS_ELM_DRIVES 4
// <bool name="RT_DFS_ELM_REENTRANT" description="Support reentrant" default="true" />
#define RT_DFS_ELM_REENTRANT
// <integer name="RT_DFS_ELM_USE_LFN" description="Support long file name" default="0">
// <item description="Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect">0</item>
// <item description="Enable LFN with static working buffer on the BSS. Always NOT reentrant">1</item>
// <item description="Enable LFN with dynamic working buffer on the STACK">2</item>
// <item description="Enable LFN with dynamic working buffer on the HEAP">3</item>
// </integer>
#define RT_DFS_ELM_USE_LFN 3
// <integer name="RT_DFS_ELM_CODE_PAGE" description="OEM code page" default="936">
#define RT_DFS_ELM_CODE_PAGE 437
// <integer name="RT_DFS_ELM_MAX_LFN" description="Maximal size of file name length" default="256" />
#define RT_DFS_ELM_MAX_LFN 256
// <bool name="RT_USING_DFS_YAFFS2" description="Using YAFFS2" default="false" />
// #define RT_USING_DFS_YAFFS2
// <bool name="RT_USING_DFS_UFFS" description="Using UFFS" default="false" />
// #define RT_USING_DFS_UFFS
// <bool name="RT_USING_DFS_DEVFS" description="Using devfs for device objects" default="true" />
#define RT_USING_DFS_DEVFS
// <bool name="RT_USING_DFS_NFS" description="Using NFS v3 client file system" default="false" />
// #define RT_USING_DFS_NFS
// <string name="RT_NFS_HOST_EXPORT" description="NFSv3 host export" default="192.168.1.5:/" />
#define RT_NFS_HOST_EXPORT "192.168.1.5:/"
// <bool name="RT_USING_DFS_LWIP" description="Enable lwIP socket operators in file system" default="true" />
// #define RT_USING_DFS_LWIP
// </section>
// <section name="RT_USING_LWIP" description="lwip, a lightweight TCP/IP protocol stack" default="true" >
// #define RT_USING_LWIP
// <integer name="RT_LWIP_PBUF_POOL_BUFSIZE" description="the buffer size of pbuf pool" default="1500" />
#define RT_LWIP_PBUF_POOL_BUFSIZE (1536)
// <bool name="RT_LWIP_ICMP" description="Enable ICMP protocol" default="true" />
#define RT_LWIP_ICMP
// <bool name="RT_LWIP_IGMP" description="Enable IGMP protocol" default="false" />
// #define RT_LWIP_IGMP
// <bool name="RT_LWIP_UDP" description="Enable UDP protocol" default="true" />
#define RT_LWIP_UDP
// <bool name="RT_LWIP_TCP" description="Enable TCP protocol" default="true" />
#define RT_LWIP_TCP
// <bool name="RT_LWIP_DNS" description="Enable DNS protocol" default="true" />
#define RT_LWIP_DNS
// <integer name="RT_LWIP_TCP_PCB_NUM" description="Maximal number of simultaneously active TCP connections" default="5" />
#define RT_LWIP_TCP_PCB_NUM 8
// <integer name="RT_LWIP_TCP_SND_BUF" description="TCP sender buffer size" default="8192" />
#define RT_LWIP_TCP_SND_BUF 8192
// <integer name="RT_LWIP_TCP_WND" description="TCP receive window" default="8192" />
#define RT_LWIP_TCP_WND 8192
// <bool name="RT_LWIP_SNMP" description="Enable SNMP protocol" default="false" />
// #define RT_LWIP_SNMP
// <bool name="RT_LWIP_DHCP" description="Enable DHCP client to get IP address" default="false" />
#define RT_LWIP_DHCP
// <integer name="RT_LWIP_TCPTHREAD_PRIORITY" description="the thread priority of TCP thread" default="128" />
#define RT_LWIP_TCPTHREAD_PRIORITY 12
// <integer name="RT_LWIP_TCPTHREAD_MBOX_SIZE" description="the mail box size of TCP thread to wait for" default="32" />
#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8
// <integer name="RT_LWIP_TCPTHREAD_STACKSIZE" description="the thread stack size of TCP thread" default="4096" />
#define RT_LWIP_TCPTHREAD_STACKSIZE 4096
// <integer name="RT_LWIP_ETHTHREAD_PRIORITY" description="the thread priority of ethnetif thread" default="144" />
#define RT_LWIP_ETHTHREAD_PRIORITY 14
// <integer name="RT_LWIP_ETHTHREAD_MBOX_SIZE" description="the mail box size of ethnetif thread to wait for" default="8" />
#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8
// <integer name="RT_LWIP_ETHTHREAD_STACKSIZE" description="the stack size of ethnetif thread" default="512" />
#define RT_LWIP_ETHTHREAD_STACKSIZE 512
// <ipaddr name="RT_LWIP_IPADDR" description="IP address of device" default="192.168.1.30" />
#define RT_LWIP_IPADDR0 192
#define RT_LWIP_IPADDR1 168
#define RT_LWIP_IPADDR2 10
#define RT_LWIP_IPADDR3 222
// <ipaddr name="RT_LWIP_GWADDR" description="Gateway address of device" default="192.168.1.1" />
#define RT_LWIP_GWADDR0 192
#define RT_LWIP_GWADDR1 168
#define RT_LWIP_GWADDR2 10
#define RT_LWIP_GWADDR3 1
// <ipaddr name="RT_LWIP_MSKADDR" description="Mask address of device" default="255.255.255.0" />
#define RT_LWIP_MSKADDR0 255
#define RT_LWIP_MSKADDR1 255
#define RT_LWIP_MSKADDR2 255
#define RT_LWIP_MSKADDR3 0
// </section>
// </RDTConfigurator>
#define RT_USING_CPU_FFS
#define RT_CFG_MAX_DMA_CHANNELS 8
#endif
import os
# toolchains options
ARCH ='mips'
CPU ='xburst'
CROSS_TOOL ='gcc'
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = r'../..'
if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')
if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = r'c:/embStudio/tools/mips-2015.11/bin'
else:
print 'Please make sure your toolchains is GNU GCC!'
exit(0)
if os.getenv('RTT_EXEC_PATH'):
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
BUILD = 'debug'
if PLATFORM == 'gcc':
# toolchains
PREFIX = 'mips-sde-elf-'
CC = PREFIX + 'gcc'
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'elf'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -mips32 -msoft-float'
CFLAGS = DEVICE + ' -EL -G0 -mno-abicalls -fno-pic -fno-builtin -fno-exceptions -ffunction-sections -fomit-frame-pointer'
AFLAGS = ' -c' + DEVICE + ' -EL -x assembler-with-cpp'
LFLAGS = DEVICE + ' -EL -Wl,--gc-sections,-Map=rtthread_x1000.map,-cref,-u,Reset_Handler -T x1000_ram.lds'
CPATH = ''
LPATH = ''
if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'
CXXFLAGS = CFLAGS
DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n'
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
/*
* File : x1000_ram.lds
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* 2015-12-12 bernard first version
*/
OUTPUT_FORMAT("elf32-tradlittlemips", "elf32-tradlittlemips", "elf32-tradlittlemips")
OUTPUT_ARCH(mips)
MEMORY
{
/* 16M SDRAM */
DRAM : ORIGIN = 0x80800000, LENGTH = 0x01800000
/* 16K SRAM */
IRAM : ORIGIN = 0x80000000, LENGTH = 0x00004000
}
ENTRY(_start)
SECTIONS
{
. = 0x80800000 ;
.start :
{
*(.start);
} > DRAM
. = ALIGN(4);
.text :
{
*(.text) /* remaining code */
*(.text.*) /* remaining code */
*(.rodata) /* read-only data (constants) */
*(.rodata*)
*(.glue_7)
*(.glue_7t)
*(.gnu.linkonce.t*)
/* section information for finsh shell */
. = ALIGN(4);
__fsymtab_start = .;
KEEP(*(FSymTab))
__fsymtab_end = .;
. = ALIGN(4);
__vsymtab_start = .;
KEEP(*(VSymTab))
__vsymtab_end = .;
. = ALIGN(4);
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)))
__rt_init_end = .;
. = ALIGN(4);
. = ALIGN(4);
_etext = .;
} > DRAM
.eh_frame_hdr :
{
*(.eh_frame_hdr)
*(.eh_frame_entry)
} > DRAM
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } > DRAM
. = ALIGN(4);
.data :
{
*(.data)
*(.data.*)
*(.data1)
*(.data1.*)
. = ALIGN(8);
_gp = ABSOLUTE(.); /* Base of small data */
*(.sdata)
*(.sdata.*)
} > DRAM
. = ALIGN(4);
_iramat = .;
.iram : AT(_iramat)
{
_iramstart = .;
*(.vectors.1);
. = 0x100;
*(.vectors.2);
. = 0x180;
*(.vectors.3);
. = 0x200;
*(.vectors.4);
*(.vectors);
*(.icode);
*(.irodata);
*(.idata);
KEEP(*(.vectors*))
_iramend = .;
} > IRAM
_iramcopy = LOADADDR(.iram);
.sbss :
{
__bss_start = .;
*(.sbss)
*(.sbss.*)
*(.dynsbss)
*(.scommon)
} > DRAM
.bss :
{
*(.bss)
*(.bss.*)
*(.dynbss)
*(COMMON)
__bss_end = .;
} > DRAM
_end = .;
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
* Symbols in the DWARF debugging sections are relative to the beginning
* of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.S')
CPPPATH = [cwd]
group = DefineGroup('CPU', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* File : cache.c
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include "../xburst/cache.h"
#include <board.h>
#define CACHE_SIZE 16*1024
#define CACHE_LINE_SIZE 32
#define KSEG0 0x80000000
#define K0_TO_K1() \
do { \
unsigned long __k0_addr; \
\
__asm__ __volatile__( \
"la %0, 1f\n\t" \
"or %0, %0, %1\n\t" \
"jr %0\n\t" \
"nop\n\t" \
"1: nop\n" \
: "=&r"(__k0_addr) \
: "r" (0x20000000) ); \
} while(0)
#define K1_TO_K0() \
do { \
unsigned long __k0_addr; \
__asm__ __volatile__( \
"nop;nop;nop;nop;nop;nop;nop\n\t" \
"la %0, 1f\n\t" \
"jr %0\n\t" \
"nop\n\t" \
"1: nop\n" \
: "=&r" (__k0_addr)); \
} while (0)
#define INVALIDATE_BTB() \
do { \
unsigned long tmp; \
__asm__ __volatile__( \
".set mips32\n\t" \
"mfc0 %0, $16, 7\n\t" \
"nop\n\t" \
"ori %0, 2\n\t" \
"mtc0 %0, $16, 7\n\t" \
"nop\n\t" \
".set mips2\n\t" \
: "=&r" (tmp)); \
} while (0)
#define SYNC_WB() __asm__ __volatile__ ("sync")
#define cache_op(op,addr) \
__asm__ __volatile__( \
" .set noreorder \n" \
" .set mips32\n\t \n" \
" cache %0, %1 \n" \
" .set mips0 \n" \
" .set reorder" \
: \
: "i" (op), "m" (*(unsigned char *)(addr)))
void __icache_invalidate_all(void)
{
unsigned int i;
K0_TO_K1();
asm volatile (".set noreorder\n"
".set mips32\n\t"
"mtc0\t$0,$28\n\t"
"mtc0\t$0,$29\n"
".set mips0\n"
".set reorder\n");
for (i=KSEG0;i<KSEG0+CACHE_SIZE;i+=CACHE_LINE_SIZE)
cache_op(Index_Store_Tag_I, i);
K1_TO_K0();
INVALIDATE_BTB();
}
void __dcache_writeback_all(void)
{
unsigned int i;
for (i=KSEG0;i<KSEG0+CACHE_SIZE;i+=CACHE_LINE_SIZE)
cache_op(Index_Writeback_Inv_D, i);
SYNC_WB();
}
void rt_hw_cache_init(void)
{
__dcache_writeback_all();
__icache_invalidate_all();
}
/*
* File : cache.h
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#ifndef __CACHE_H__
#define __CACHE_H__
/*
* Cache Operations
*/
#define Index_Invalidate_I 0x00
#define Index_Writeback_Inv_D 0x01
#define Index_Invalidate_SI 0x02
#define Index_Writeback_Inv_SD 0x03
#define Index_Load_Tag_I 0x04
#define Index_Load_Tag_D 0x05
#define Index_Load_Tag_SI 0x06
#define Index_Load_Tag_SD 0x07
#define Index_Store_Tag_I 0x08
#define Index_Store_Tag_D 0x09
#define Index_Store_Tag_SI 0x0A
#define Index_Store_Tag_SD 0x0B
#define Create_Dirty_Excl_D 0x0d
#define Create_Dirty_Excl_SD 0x0f
#define Hit_Invalidate_I 0x10
#define Hit_Invalidate_D 0x11
#define Hit_Invalidate_SI 0x12
#define Hit_Invalidate_SD 0x13
#define Fill 0x14
#define Hit_Writeback_Inv_D 0x15
/* 0x16 is unused */
#define Hit_Writeback_Inv_SD 0x17
#define Hit_Writeback_I 0x18
#define Hit_Writeback_D 0x19
/* 0x1a is unused */
#define Hit_Writeback_SD 0x1b
/* 0x1c is unused */
/* 0x1e is unused */
#define Hit_Set_Virtual_SI 0x1e
#define Hit_Set_Virtual_SD 0x1f
void rt_hw_cache_init(void);
#endif
/*
* File : cache_init.S
* Change Logs:
* Date Author Notes
* 2010-05-17 swkyer first version
*/
#include "../common/mips.inc"
#include "../common/mipsregs.h"
#include "../common/stackframe.h"
.text
.set noreorder
.globl cache_init
.ent cache_init
cache_init:
.set noreorder
mtc0 zero, CP0_TAGLO
move t0, a0 // cache total size
move t1, a1 // cache line size
li t2, 0x80000000
addu t3, t0, t2
_cache_init_loop:
cache 8, 0(t2) // icache_index_store_tag
cache 9, 0(t2) // dcache_index_store_tag
addu t2, t1
bne t2, t3, _cache_init_loop
nop
mfc0 t0, CP0_CONFIG
li t1, 0x7
not t1
and t0, t0, t1
or t0, 0x3 // cacheable, noncoherent, write-back, write allocate
mtc0 t0, CP0_CONFIG
jr ra
nop
.set reorder
.end cache_init
/*
* File : context_gcc.S
* Change Logs:
* Date Author Notes
* 2010-05-17 swkyer first version
* 2010-09-11 bernard port to Jz4755
*/
#include "../common/mips.inc"
#include "../common/stackframe.h"
#include "stack.h"
.section ".text", "ax"
.set noreorder
/*
* rt_base_t rt_hw_interrupt_disable()
*/
.globl rt_hw_interrupt_disable
rt_hw_interrupt_disable:
mfc0 v0, CP0_STATUS
and v1, v0, 0xfffffffe
mtc0 v1, CP0_STATUS
jr ra
nop
/*
* void rt_hw_interrupt_enable(rt_base_t level)
*/
.globl rt_hw_interrupt_enable
rt_hw_interrupt_enable:
mtc0 a0, CP0_STATUS
jr ra
nop
/*
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
* a0 --> from
* a1 --> to
*/
.globl rt_hw_context_switch
rt_hw_context_switch:
mtc0 ra, CP0_EPC
SAVE_ALL
sw sp, 0(a0) /* store sp in preempted tasks TCB */
lw sp, 0(a1) /* get new task stack pointer */
RESTORE_ALL_AND_RET
/*
* void rt_hw_context_switch_to(rt_uint32 to)/*
* a0 --> to
*/
.globl rt_hw_context_switch_to
rt_hw_context_switch_to:
lw sp, 0(a0) /* get new task stack pointer */
RESTORE_ALL_AND_RET
/*
* void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
*/
.globl rt_thread_switch_interrupt_flag
.globl rt_interrupt_from_thread
.globl rt_interrupt_to_thread
.globl rt_hw_context_switch_interrupt
rt_hw_context_switch_interrupt:
la t0, rt_thread_switch_interrupt_flag
lw t1, 0(t0)
nop
bnez t1, _reswitch
nop
li t1, 0x01 /* set rt_thread_switch_interrupt_flag to 1 */
sw t1, 0(t0)
la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
sw a0, 0(t0)
_reswitch:
la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
sw a1, 0(t0)
jr ra
nop
.globl system_dump
/*
* void rt_hw_context_switch_interrupt_do(rt_base_t flag)
*/
.globl rt_interrupt_enter
.globl rt_interrupt_leave
.globl mips_irq_handle
mips_irq_handle:
SAVE_ALL
mfc0 t0, CP0_CAUSE
mfc0 t1, CP0_STATUS
and t0, t1
andi t0, 0xff00
beqz t0, spurious_interrupt
nop
/* let k0 keep the current context sp */
move k0, sp
/* switch to kernel stack */
li sp, SYSTEM_STACK
jal rt_interrupt_enter
nop
jal rt_interrupt_dispatch
nop
jal rt_interrupt_leave
nop
/* switch sp back to thread's context */
move sp, k0
/*
* if rt_thread_switch_interrupt_flag set, jump to
* rt_hw_context_switch_interrupt_do and don't return
*/
la k0, rt_thread_switch_interrupt_flag
lw k1, 0(k0)
beqz k1, spurious_interrupt
nop
sw zero, 0(k0) /* clear flag */
nop
/*
* switch to the new thread
*/
la k0, rt_interrupt_from_thread
lw k1, 0(k0)
nop
sw sp, 0(k1) /* store sp in preempted tasks's TCB */
la k0, rt_interrupt_to_thread
lw k1, 0(k0)
nop
lw sp, 0(k1) /* get new task's stack pointer */
j spurious_interrupt
nop
spurious_interrupt:
RESTORE_ALL_AND_RET
.set reorder
/*
* File : cpu.c
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-07-09 Bernard first version
* 2010-09-11 Bernard add CPU reset implementation
*/
#include <rtthread.h>
#include <board.h>
/**
* @addtogroup Ingenic
*/
/*@{*/
/**
* this function will reset CPU
*
*/
void rt_hw_cpu_reset()
{
/* open the watch-dog */
REG_WDT_TCSR = WDT_TCSR_EXT_EN;
REG_WDT_TCSR |= WDT_TCSR_PRESCALE_1024;
REG_WDT_TDR = 0x03;
REG_WDT_TCNT = 0x00;
REG_WDT_TCER |= WDT_TCER_TCEN;
rt_kprintf("reboot system...\n");
while (1);
}
/**
* this function will shutdown CPU
*
*/
void rt_hw_cpu_shutdown()
{
rt_kprintf("shutdown...\n");
while (1);
}
/**
* This function finds the first bit set (beginning with the least significant bit)
* in value and return the index of that bit.
*
* Bits are numbered starting at 1 (the least significant bit). A return value of
* zero from any of these functions means that the argument was zero.
*
* @return return the index of the first bit set. If value is 0, then this function
* shall return 0.
*/
int __rt_ffs(int value)
{
return __builtin_ffs(value);
}
/*@}*/
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
* File : stack.h
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#ifndef __STACK_H__
#define __STACK_H__
#define SYSTEM_STACK 0x80003fe8 /* the kernel system stack address */
#endif
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册