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.
149 lines
3.2 KiB
149 lines
3.2 KiB
#include <vxWorks.h>
|
|
#include <vsbConfig.h>
|
|
#include <stdio.h>
|
|
#include <moduleLib.h>
|
|
#include <usrLib.h>
|
|
#include <cacheLib.h>
|
|
#include <sysSymTbl.h>
|
|
#include <fcntl.h>
|
|
#include <hwif/vxbus/vxBus.h>
|
|
|
|
#include "config.h"
|
|
#include "vxbFtGpio.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 */
|
|
extern int lfsLowRawWrite(unsigned long offset, const char *buffer, int size);
|
|
extern void gpioIsrSetTest (UINT32 gpio, UINT32 pin);
|
|
int bspLoadUserApp()
|
|
{
|
|
SEGMENT_ID seg;
|
|
SYMBOL_DESC symDesc;
|
|
struct stat stbuf;
|
|
MODULE_ID module = ld(1, 0, USER_APP_PATH);
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
|
|
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, 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\r\n");
|
|
if (pos <= 0) {
|
|
pos = VXWORKS_POS;
|
|
}
|
|
status = lfsLowRawWrite(pos, 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
|
|
|
|
/* GPIO1_A4 */
|
|
int bspSm1553bIrqConnect(void *data, void (*isr)(void *data))
|
|
{
|
|
VXB_DEVICE_ID pDev;
|
|
FT_GPIO_DRVCTRL * pCtrl;
|
|
|
|
pDev = vxbInstByNameFind("ftGpio", 1);
|
|
if (pDev == NULL) {
|
|
return ERROR;
|
|
}
|
|
pCtrl = pDev->pDrvCtrl;
|
|
pCtrl->gpioISRSet(pDev, 4, isr, data);
|
|
return OK;
|
|
}
|
|
|
|
int mw(unsigned long addr, unsigned int val)
|
|
{
|
|
volatile unsigned int long *ptr = (volatile unsigned long *)(addr);
|
|
|
|
*ptr = val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|