You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
296 lines
7.0 KiB
296 lines
7.0 KiB
#include <vxWorks.h>
|
|
#include <vsbConfig.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <moduleLib.h>
|
|
#include <usrLib.h>
|
|
#include <cacheLib.h>
|
|
#include <ioLib.h>
|
|
#include <sysSymTbl.h>
|
|
#include <fcntl.h>
|
|
#include <logLib.h>
|
|
#include <hwif/vxbus/vxBus.h>
|
|
#include <hwif/util/vxbParamSys.h>
|
|
#include "config.h"
|
|
#include "ft2000-4.h"
|
|
#include "vxbFtGpio.h"
|
|
#include "ubootenv/libuboot.h"
|
|
#if defined(INCLUDE_IPFTPS)
|
|
#include <ipcom_sysvar.h>
|
|
#include <ipcom_sock.h>
|
|
#include <ipftps.h>
|
|
#endif
|
|
|
|
#define VXWORKS_POS (0x400000)
|
|
#define USER_APP_PATH "/tffs0/UserApp.out"
|
|
|
|
/* externs */
|
|
IMPORT int lfsLowRawWrite(unsigned long offset, const char *buffer, int size);
|
|
IMPORT unsigned int uenvGetUint(const char *varname);
|
|
IMPORT int uenvInit();
|
|
IMPORT void lfsDevRegister(void);
|
|
IMPORT void vxbSpiRawDevRegister(void);
|
|
IMPORT void sysMsDelay(UINT delay);
|
|
IMPORT void sysUsDelay(int us);
|
|
/* bsp glue functions */
|
|
|
|
void bspPinMuxInitialize(void)
|
|
{
|
|
/*
|
|
* pin_mux (SPI0):
|
|
* spi0_csn0_pad: spi0_csn0 gpio1_porta_5
|
|
* spi0_sck_pad: spi0_sck gpio1_porta_6
|
|
* spi0_so_pad: spi0_so gpio1_porta_7
|
|
* spi0_si_pad: spi0_si gpio1_portb_0
|
|
*/
|
|
unsigned int reg = readl(PIN_DEMUX_BASE + REG208);
|
|
reg &= ~((0x3 << 16) | (0x3 << 12) | (0x3 << 8) | (0x3 << 4));
|
|
writel(reg, PIN_DEMUX_BASE + REG208);
|
|
|
|
/*
|
|
* pin_mux (SPI1):
|
|
* uart_2_rxd_pad: uart_2_rxd spi1_csn0 gpio0_portb_5
|
|
* uart_2_txd_pad: uart_2_txd spi1_sck hda_sdi1
|
|
* uart_3_rxd_pad: uart_3_rxd spi1_so hda_sdi2
|
|
* uart_3_txd_pad: uart_3_txd spi1_si hda_sdi3
|
|
*/
|
|
/* SPI1 */
|
|
reg = readl(PIN_DEMUX_BASE + REG210);
|
|
reg &= ~0xf;
|
|
reg |= 0x9; /* spi1_csn0 */
|
|
writel(reg, PIN_DEMUX_BASE + REG210);
|
|
|
|
reg = readl(PIN_DEMUX_BASE + REG214);
|
|
reg &= ~((0xf << 28) | (0xf << 24) | (0xf << 20));
|
|
reg |= (0x9 << 28) | (0x9 << 24) | (0x9 << 20); /* enable pullup */
|
|
writel(reg, PIN_DEMUX_BASE + REG214);
|
|
|
|
/*
|
|
* GPIO1_B7: SM2130_MR
|
|
* GPIO0_B6: SM2130_ACKIRQ
|
|
* GPIO0_B7: SM2130_READY
|
|
*
|
|
* qspi_csn1_pad: qspi_csn1 gpio1_portb_7
|
|
* qspi_csn2_pad: spi_csn2 spi1_csn1 gpio0_portb_6
|
|
* qspi_csn3_pad: qspi_csn3 spi1_csn2 gpio0_portb_7
|
|
*/
|
|
reg = readl(PIN_DEMUX_BASE + REG214);
|
|
reg &= ~((0x3 << 12) | (0x3 << 8) | (0x3 << 4));
|
|
reg |= (0x1 << 12) | (0x2 << 8) | (0x2 << 4);
|
|
writel(reg, PIN_DEMUX_BASE + REG214);
|
|
/*
|
|
* GPIO1_A4: SM2130_IRQ
|
|
*
|
|
* ext_lpc_lad_1_pad: ext_lpc_lad_1 gpio1_porta_4
|
|
*/
|
|
reg = readl(PIN_DEMUX_BASE + REG218);
|
|
reg &= ~(0x3 << 8);
|
|
reg |= (0x1 << 8);
|
|
writel(reg, PIN_DEMUX_BASE + REG218);
|
|
|
|
/* GPIO0_A3, GPIO0_A5, GPIO0_A6
|
|
*
|
|
* sjtag_ntrst_pad: N gpio0_porta_3 uart_0_dsr_n
|
|
* tjtag_tdo_pad: N gpio0_porta_5 uart_0_rts_n
|
|
* tjtag_ntrst_pad: N gpio0_porta_6 uart_0_dtr_n
|
|
*/
|
|
reg = readl(PIN_DEMUX_BASE + REG200);
|
|
reg &= ~((0x3 << 12) | (0x3 << 8) | 0x3);
|
|
reg |= (1 << 12) | ( 1 << 8) | 1;
|
|
writel(reg, PIN_DEMUX_BASE + REG200);
|
|
}
|
|
|
|
void bspDriverRegiser(void)
|
|
{
|
|
#ifdef DRV_FS_LITTLEFS
|
|
lfsDevRegister();
|
|
#endif
|
|
#ifdef DRV_FTSPI
|
|
vxbSpiRawDevRegister();
|
|
#endif
|
|
}
|
|
|
|
/* {{{ 1553B IO */
|
|
|
|
/* MR: GPIO1_B7 (reset) */
|
|
void bspSm1553bReset(BOOL value)
|
|
{
|
|
VXB_DEVICE_ID pDev;
|
|
FT_GPIO_DRVCTRL * pCtrl;
|
|
|
|
pDev = vxbInstByNameFind("ftGpio", 1);
|
|
if (pDev == NULL) {
|
|
logMsg("Can't find ftGpio1\r\n", 1, 2, 3, 4, 5, 6);
|
|
return;
|
|
}
|
|
pCtrl = pDev->pDrvCtrl;
|
|
|
|
/* MR: GPIO1_B7 (reset) */
|
|
pCtrl->gpioOutput(pDev, 1, 7, value);
|
|
}
|
|
|
|
/* GPIO1_A4 */
|
|
void bspSm1553bIrqConnect(void *data, void (*isr)(void *data))
|
|
{
|
|
VXB_DEVICE_ID pDev;
|
|
FT_GPIO_DRVCTRL * pCtrl;
|
|
|
|
pDev = vxbInstByNameFind("ftGpio", 1);
|
|
if (pDev == NULL) {
|
|
logMsg("Can't find ftGpio1\r\n", 1, 2, 3, 4, 5, 6);
|
|
return;
|
|
}
|
|
pCtrl = pDev->pDrvCtrl;
|
|
|
|
/* GPIO1_A4 (irq) */
|
|
pCtrl->gpioISRSet(pDev, 4, isr, data);
|
|
}
|
|
|
|
/* GPIO0_B7: SM2130_READY */
|
|
int bspSm1553bChipReady(void)
|
|
{
|
|
VXB_DEVICE_ID pDev;
|
|
FT_GPIO_DRVCTRL * pCtrl;
|
|
|
|
pDev = vxbInstByNameFind("ftGpio", 0);
|
|
if (pDev == NULL) {
|
|
logMsg("Can't find ftGpio0\r\n", 1, 2, 3, 4, 5, 6);
|
|
return 0;
|
|
}
|
|
pCtrl = pDev->pDrvCtrl;
|
|
|
|
return pCtrl->gpioInput(pDev, 1, 7);
|
|
}
|
|
|
|
/* GPIO0_B6: M2130_ACKIRQ */
|
|
void bspSm1553bAckIrq(BOOL value)
|
|
{
|
|
VXB_DEVICE_ID pDev;
|
|
FT_GPIO_DRVCTRL * pCtrl;
|
|
|
|
pDev = vxbInstByNameFind("ftGpio", 0);
|
|
if (pDev == NULL) {
|
|
return;
|
|
}
|
|
pCtrl = pDev->pDrvCtrl;
|
|
|
|
pCtrl->gpioOutput(pDev, 1, 6, value);
|
|
/* logMsg("ackirq Sm1553b Irq\r\n", 1, 2, 3, 4, 5, 6); */
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
int bspLoadUserApp()
|
|
{
|
|
SEGMENT_ID seg;
|
|
SYMBOL_DESC symDesc;
|
|
struct stat stbuf;
|
|
MODULE_ID module;
|
|
void (*appEntry)(void) = NULL;
|
|
|
|
if (stat(USER_APP_PATH, &stbuf) != 0) {
|
|
return -1;
|
|
}
|
|
(void)stbuf;
|
|
module = ld(1, 0, USER_APP_PATH);
|
|
if (module != NULL) {
|
|
/* flush text segment */
|
|
seg = moduleSegFirst(module);
|
|
while (seg) {
|
|
if (seg->type == SEGMENT_TEXT) {
|
|
/* printf("flush: %p, size: 0x%x\r\n", seg->address, seg->size); */
|
|
cacheFlush(DATA_CACHE, seg->address, seg->size);
|
|
}
|
|
seg = moduleSegNext(seg);
|
|
}
|
|
memset(&symDesc, 0, sizeof symDesc);
|
|
symDesc.mask = SYM_FIND_BY_NAME;
|
|
symDesc.name = "AppEntry";
|
|
|
|
if (symFind(sysSymTbl, &symDesc) == OK) {
|
|
appEntry = (void (*)(void))(symDesc.value);
|
|
printf("AppEntry: %p\r\n", appEntry);
|
|
taskSpawn ("tUserApp", 100, 0, 0x10000,
|
|
(FUNCPTR) appEntry,0,0,0,0,0,0,0,0,0,0);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#if defined(__DCC__)
|
|
void usrAppInit(void)
|
|
{
|
|
uenvInit();
|
|
bspLoadUserApp();
|
|
}
|
|
#endif
|
|
|
|
int updateVxWorks(const char *file, int pos)
|
|
{
|
|
struct stat stbuf;
|
|
size_t size;
|
|
int fd, status;
|
|
unsigned char *ptr;
|
|
|
|
if (stat(file, &stbuf) != OK) {
|
|
printf("Can't stat %s\r\n", file);
|
|
return ERROR;
|
|
}
|
|
if (pos <= 0) {
|
|
pos = (int)uenvGetUint("krnaddr");
|
|
}
|
|
if (pos <= QSPI_PROTECT_SIZE) {
|
|
printf("Unknown flash offset (0x%x)\r\n", pos);
|
|
return -1;
|
|
}
|
|
size = (stbuf.st_size + 0x10000 - 1) / 0x10000;
|
|
size *= 0x10000;
|
|
ptr = malloc(size);
|
|
if (ptr == NULL) {
|
|
printf("%s: out of memory\r\n", __FUNCTION__);
|
|
return ERROR;
|
|
}
|
|
|
|
memset(ptr, 0xff, size);
|
|
|
|
fd = open(file, O_RDONLY, 0);
|
|
if (fd < 0) {
|
|
printf("%s: can't open to read\r\n", __FUNCTION__);
|
|
free(ptr);
|
|
return ERROR;
|
|
}
|
|
printf("Reading: %d bytes\r\n", stbuf.st_size);
|
|
size = read(fd, (void *)ptr, stbuf.st_size);
|
|
close(fd);
|
|
|
|
if (size != stbuf.st_size) {
|
|
printf("%s: read size mismatch %d != filesize %d\r\n", __FUNCTION__, size, stbuf.st_size);
|
|
free(ptr);
|
|
return ERROR;
|
|
}
|
|
size = (stbuf.st_size + 0x100 - 1) / 0x100;
|
|
size *= 0x100;
|
|
printf("Write to flash offset: 0x%x, len: %d\r\n", pos, stbuf.st_size);
|
|
status = lfsLowRawWrite(pos, (void *)ptr, size);
|
|
free(ptr);
|
|
printf("%s\r\n", status == OK ? "Success" : "Failed");
|
|
return status;
|
|
}
|
|
|
|
#if defined(INCLUDE_IPFTPS)
|
|
int bsp_ipftps_authenticate_nopasswd(Ipftps_session *session, char *password)
|
|
{
|
|
//printf("ftp passthor\r\n");
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
int mw(unsigned long addr, unsigned int val)
|
|
{
|
|
volatile unsigned int long *ptr = (volatile unsigned long *)(addr);
|
|
|
|
*ptr = val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|