LM3S9B96的EPI總線(xiàn)的HB16模式配置
EPI工作模式:
- 同步動(dòng)態(tài)隨機(jī)訪(fǎng)問(wèn)存儲(chǔ)器(SDRAM)模式:支持16位寬的SDRAM,最高達(dá)到50MHZ,復(fù)用地址與數(shù)據(jù)管腳。
- 主機(jī)總線(xiàn)(HB)模式:傳統(tǒng)的8/16位微控制器總線(xiàn)接口,可兼容PIC,8051,AVR等單片機(jī)??稍L(fǎng)問(wèn)SRAM,NORFLSH其他的并行總線(xiàn)設(shè)備,非復(fù)用下尋址能力達(dá)到1MB,復(fù)用模式下尋址可以達(dá)到256MB
- 通用模式:可以通CPLD或者FPGA進(jìn)行快速的數(shù)據(jù)交換,數(shù)據(jù)寬度可以達(dá)到32位,數(shù)據(jù)速率可以達(dá)到150MB/S.
- 并行GPIO模式:1到32位,必須經(jīng)由FIFO輸入輸出,速度可控。
- 用SysCtlClockSet設(shè)置系統(tǒng)時(shí)鐘
- 用SysCtlPeripheralEnable開(kāi)GPIO口時(shí)鐘
- 用GPIOPinConfigure將GPIO口配置成EPIO功能
- 用GPIOPinTypeEPI配置GPIO口為EPI模式
- 用EPIDividerSet設(shè)置EPI時(shí)鐘
- 用位段方式HWREG(EPI_O_CFG)配置EPI為HB16模式
- 用位段方式HWREG(EPI_O_HB16CFG)配置讀選通信號(hào)RDn(低電平有效), 最長(zhǎng)等待時(shí)間(可以永遠(yuǎn)掛起), 寫(xiě)等待態(tài)(無(wú)等待態(tài)), 讀等待態(tài)(1個(gè)等待態(tài)),字節(jié)選擇配置(數(shù)據(jù)按照16位寬度讀寫(xiě)), 主機(jī)并行總線(xiàn)的子模式(ADNOMUX子模式)
- 用位段方式HWREG(EPI_O_HB16CFG2)配置字訪(fǎng)問(wèn)模式(使能字訪(fǎng)問(wèn)模式), 雙片選波特率(相同波特率), 片選配置(EPI0S30用作片選信號(hào)CSn)
- 用位段方式HWREG(EPI_O_ADDRMAP)配置片外外設(shè)空間大小64kB(低地址范圍0x0000~0xFFFF),片外外設(shè)基地址(0xA000 0000)
- 至此,初始化完畢,就可以使用讀寫(xiě)數(shù)據(jù)了
- 指向外設(shè)基地址0xA000 0000處的指針:g_pusEPIPER = (unsigned short *)0xA0000000;
- 向外設(shè)地址0處寫(xiě)ffff: *g_pusEPIPER = 0xfffc;設(shè)1個(gè)變量接收讀取的數(shù)據(jù):usDI16 = *g_pusEPIPER; // 從外設(shè)基地址0xA000 0000處讀16位數(shù)據(jù)
//*****************************************************************************
// 頭文件包含區(qū)
//*****************************************************************************
#include "inc/lm3s9b96.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_types.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"
#include "driverlib/ethernet.h"
#include "driverlib/flash.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/watchdog.h"
#include "driverlib/epi.h"
#include "utils/locator.h"
#include "utils/lwiplib.h"
#include "utils/uartstdio.h"
#include "utils/ustdlib.h"
#include "grlib/grlib.h"
#include "httpserver_raw/httpd.h"
#include "drivers/kitronix320x240x16_ssd2119_8bit.h"
#include "drivers/set_pinout.h"
//*****************************************************************************
// 數(shù)據(jù)類(lèi)型定義區(qū)
//*****************************************************************************
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
//*****************************************************************************
// 宏定義區(qū)
//*****************************************************************************
/* Defines for setting up the system clock -----------------------------------*/
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)
#define SYSTICKUS (1000000 / SYSTICKHZ)
#define SYSTICKNS (1000000000 / SYSTICKHZ)
/* 在lm3s9b96.h中定義 --------------------------------------------------------*/
#define EPI_O_CFG 0x400D0000
#define EPI_O_HB16CFG 0x400D0010
#define EPI_O_HB16CFG2 0x400D0014
#define EPI_O_ADDRMAP 0x400D001c
#define EPI_O_BAUD 0x400D0004
#define EPI_PORTC_PINS (GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_5 | GPIO_PIN_4)
#define EPI_PORTD_PINS (GPIO_PIN_3 | GPIO_PIN_2)
#define EPI_PORTE_PINS (GPIO_PIN_1 | GPIO_PIN_0)
#define EPI_PORTF_PINS (GPIO_PIN_5 | GPIO_PIN_4)
#define EPI_PORTG_PINS (GPIO_PIN_7 | GPIO_PIN_1 | GPIO_PIN_0)
#define EPI_PORTH_PINS (GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2 |
GPIO_PIN_1 | GPIO_PIN_0)
#define EPI_PORTJ_PINS (GPIO_PIN_6 | GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0)
//*****************************************************************************
// 全局變量定義區(qū)
//*****************************************************************************
volatile WORD usDI16 = 0x0000;
static volatile WORD *g_pusEPIPER;
//*****************************************************************************
// 函數(shù)聲明區(qū)
//*****************************************************************************
extern void fs_init(void);
extern void fs_tick(unsigned long ulTickMS);
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void __error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
//*****************************************************************************
//
// 系統(tǒng)時(shí)鐘初始化函數(shù)
//
//*****************************************************************************
void SysClk_Init(void)
{
// 配置系統(tǒng)主時(shí)鐘, 使用外部晶振16M.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
}
//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************
int main(void)
{
// 系統(tǒng)時(shí)鐘初始化為16MHz
SysClk_Init();
// 使能A~J管腳
// PinoutSet();
// 開(kāi)總中斷
IntMasterEnable();
// The EPI0 peripheral must be enabled for use
SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0);
// EPI0 is used with multiple pins on Port C, E, F, G, H, J
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
GPIOPadConfigSet(GPIO_PORTC_BASE, EPI_PORTC_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
// GPIOPadConfigSet(GPIO_PORTD_BASE, EPI_PORTD_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTE_BASE, EPI_PORTE_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTF_BASE, EPI_PORTF_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTG_BASE, EPI_PORTG_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTH_BASE, EPI_PORTH_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTJ_BASE, EPI_PORTJ_PINS, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIODirModeSet(GPIO_PORTC_BASE, EPI_PORTC_PINS, GPIO_DIR_MODE_HW);
// GPIODirModeSet(GPIO_PORTD_BASE, EPI_PORTD_PINS, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTE_BASE, EPI_PORTE_PINS, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTF_BASE, EPI_PORTF_PINS, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTG_BASE, EPI_PORTG_PINS, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTH_BASE, EPI_PORTH_PINS, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTJ_BASE, EPI_PORTJ_PINS, GPIO_DIR_MODE_HW);
// configures the internal pin muxes to set the EPI pins for use with EPI
GPIOPinConfigure(GPIO_PH3_EPI0S0);
GPIOPinConfigure(GPIO_PH2_EPI0S1);
GPIOPinConfigure(GPIO_PC4_EPI0S2);
GPIOPinConfigure(GPIO_PC5_EPI0S3);
GPIOPinConfigure(GPIO_PC6_EPI0S4);
GPIOPinConfigure(GPIO_PC7_EPI0S5);
GPIOPinConfigure(GPIO_PH0_EPI0S6);
GPIOPinConfigure(GPIO_PH1_EPI0S7);
GPIOPinConfigure(GPIO_PE0_EPI0S8);
GPIOPinConfigure(GPIO_PE1_EPI0S9);
GPIOPinConfigure(GPIO_PH4_EPI0S10);
GPIOPinConfigure(GPIO_PH5_EPI0S11);
GPIOPinConfigure(GPIO_PF4_EPI0S12);
GPIOPinConfigure(GPIO_PG0_EPI0S13);
GPIOPinConfigure(GPIO_PG1_EPI0S14);
GPIOPinConfigure(GPIO_PF5_EPI0S15);
GPIOPinConfigure(GPIO_PJ0_EPI0S16);
GPIOPinConfigure(GPIO_PJ1_EPI0S17);
GPIOPinConfigure(GPIO_PJ2_EPI0S18);
GPIOPinConfigure(GPIO_PJ3_EPI0S19);
// GPIOPinConfigure(GPIO_PD2_EPI0S20);
// GPIOPinConfigure(GPIO_PD3_EPI0S21);
// GPIOPinConfigure(GPIO_PB5_EPI0S22);
// GPIOPinConfigure(GPIO_PB4_EPI0S23);
GPIOPinConfigure(GPIO_PE2_EPI0S24);
GPIOPinConfigure(GPIO_PE3_EPI0S25);
GPIOPinConfigure(GPIO_PJ4_EPI0S28);
GPIOPinConfigure(GPIO_PJ5_EPI0S29);
GPIOPinConfigure(GPIO_PJ6_EPI0S30);
GPIOPinConfigure(GPIO_PG7_EPI0S31);
// Configure the GPIO pins for EPI mode
GPIOPinTypeEPI(GPIO_PORTC_BASE, EPI_PORTC_PINS);
GPIOPinTypeEPI(GPIO_PORTE_BASE, EPI_PORTE_PINS);
GPIOPinTypeEPI(GPIO_PORTF_BASE, EPI_PORTF_PINS);
GPIOPinTypeEPI(GPIO_PORTG_BASE, EPI_PORTG_PINS);
GPIOPinTypeEPI(GPIO_PORTH_BASE, EPI_PORTH_PINS);
GPIOPinTypeEPI(GPIO_PORTJ_BASE, EPI_PORTJ_PINS);
// Sets the clock divider for the EPI module. EPIClock = SysClk.
EPIDividerSet(EPI0_BASE, 0);
// Sets the usage mode of the EPI module. EPI_MODE_HB16
HWREG(EPI_O_CFG) = (1 << 4) | 0x1;
// 讀選通信號(hào)RDn(低電平有效), 最長(zhǎng)等待時(shí)間(可以永遠(yuǎn)掛起), 寫(xiě)等待態(tài)(無(wú)等待態(tài)), 讀等待態(tài)(1個(gè)等待態(tài))
// 字節(jié)選擇配置(數(shù)據(jù)按照16位寬度讀寫(xiě)), 主機(jī)并行總線(xiàn)的子模式(ADNOMUX子模式)
HWREG(EPI_O_HB16CFG) = (1 << 20) | (0x00 << 8) | (0x01 << 4) | (1 << 0);
// 字訪(fǎng)問(wèn)模式(使能字訪(fǎng)問(wèn)模式), 雙片選波特率(相同波特率), 片選配置(EPI0S30用作片選信號(hào)CSn)
HWREG(EPI_O_HB16CFG2) = (1 << 31) | (0x01 << 24);
// 片外外設(shè)空間大小64kB(低地址范圍0x0000~0xFFFF),片外外設(shè)基地址(0xA000 0000)
HWREG(EPI_O_ADDRMAP) = (0x5 << 4);
/* 初始化完畢,就可以使用讀取數(shù)據(jù)了 ----------------------------------------*/
// 指向外設(shè)基地址0xA000 0000處的指針
g_pusEPIPER = (unsigned short *)0xA0000000;
// 從外設(shè)基地址0xA0000000處,讀取16位數(shù)據(jù)
usDI16 = *g_pusEPIPER;
usDI16 = ~usDI16;
// Loop forever. All the work is done in interrupt handlers.
while (1)
{
}
}
//*****************************************************************************
//
// Required by lwIP library to support any host-related timer functions.
//
//*****************************************************************************
void lwIPHostTimerHandler(void)
{
}
//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void SysTickIntHandler(void)
{
// Call the lwIP timer handler.
lwIPTimer(SYSTICKMS);
// Run the file system tick handler.
fs_tick(SYSTICKMS);
}
評(píng)論