📄 sema.c
字号:
/**
*** Copyright (c) 2001 Equator Technologies, Inc.
**/
//*********************************************************************
//
// File: sema.c :
//
// Example program showing how to interact synchronize the vlx threads
// with vliw threads. The vliw polls a semaphore cleared by the vlx.
// (initial value is non-zero, vliw waits for it to be zeroed).
//
//*********************************************************************
#define _CONFIG_PRINTFS
#define SEMA_TIMEOUT_CYCLES 1000
#define S_PASS 0
#define S_FAIL_SEMA 1
#define S_FAIL_DATA 2
#define S_FAIL_OTHER 3
//
// Example program showing how to interact with the I/O side of the VLX
//
#include <eti/ds.h>
#include <mm.h>
#include <eti/vlx.h>
#include <eti/mapca/vlxm_piomap.h>
#include "util.h"
#include "vsema_vlx.h" // pick up the VLX binary labels
#include "common.h"
//----------------------------------
//
// Global Variables
//
//----------------------------------
extern VLX_BIN vsema; // vlx binary struct
PVLX_BIN vlxBin = &vsema; // pointer to vlx binary struct
//----------------------------------
//
// main()
//
//----------------------------------
main()
{
//
// Declarations
//
int i,j;
int succeeded=S_PASS;
SCODE status;
volatile unsigned short* pVlMemI;
volatile unsigned short* pVlMemD0;
volatile unsigned short* pVlMemD1;
volatile unsigned short* pVlMemSema;
volatile unsigned short* pVlMemStatus;
//
// Code
//
kprintf("\nIn main()...\n");
pVlMemI = (volatile unsigned short *) VlxLookupCM1();
pVlMemD0 = (volatile unsigned short *) (pVlMemI + _VLMEM_DATA0_OFFSET_SHORT);
pVlMemD1 = (volatile unsigned short *) (pVlMemI + _VLMEM_DATA1_OFFSET_SHORT);
#ifdef _CONFIG_VLX_C
kprintf("VLX C configuration...\n");
pVlMemSema = (volatile unsigned short *) (pVlMemI + VLXLAB_vsema__sema);
pVlMemStatus = (volatile unsigned short *) (pVlMemI + VLXLAB_vsema__status);
#else
kprintf("VLX ASM configuration...\n");
pVlMemSema = (volatile unsigned short *) (pVlMemI + VLXLAB_vsema_D0_SEMA);
pVlMemStatus = (volatile unsigned short *) (pVlMemI + VLXLAB_vsema_D0_STATUS);
#endif
kprintf("\npVlMemI = 0x%lx\n", pVlMemI );
kprintf("pVlMemD0 = 0x%lx\n", pVlMemD0 );
kprintf("pVlMemD1 = 0x%lx\n", pVlMemD1 );
kprintf("pVlMemSema = 0x%lx\n", pVlMemSema );
kprintf("pVlMemStatus = 0x%lx\n", pVlMemStatus );
#ifdef _CONFIG_VLX_C
kprintf("VLXLAB_vsema__sema = 0x%lx\n", VLXLAB_vsema__sema );
kprintf("VLXLAB_vsema__status = 0x%lx\n", VLXLAB_vsema__status );
#else
kprintf("VLXLAB_vsema__D0_SEMA = 0x%lx\n", VLXLAB_vsema_D0_SEMA );
kprintf("VLXLAB_vsema__D0_STATUS = 0x%lx\n", VLXLAB_vsema_D0_STATUS );
#endif
//
// Initialize Vlmem Semaphore
//
#ifdef _CONFIG_VLX_C
vlxBin->Binary[ VLXLAB_vsema__sema >> 2 ] = 0xF;
#else
vlxBin->Binary[ VLXLAB_vsema_D0_SEMA >> 2 ] = 0xF;
#endif
//
// Load Vlx Binary from DRAM to VlMem
//
status = VlxLoadBinaryByValue(
vlxBin, // binary struct ptr
((vlxBin->BinaryByteLength + 1) >> 1), // # of 16-bit words to xfer
VLXLAB_vsema_PCSTART, // xfer from start of binary
0, // ...CM1 offset
VLX_LOAD_PIO // Xfer using PIO writes
);
if (status==S_ERROR) {
kprintf("ERROR : VlxLoadBinaryByValue returned S_ERROR\n");
exit(1);
}
// Printout sema before VlxKick()
kprintf("\nBefore Kicking Vlx...\n");
kprintf("\n*pVlMemSema = 0x%x\n", *pVlMemSema );
kprintf("\n*pVlMemStatus = 0x%x\n", *pVlMemStatus );
//
// Kick the Vlx so it starts processing
//
kprintf("\nReset and Kick Vlx...\n");
VlxResetPC(); // this makes the starting PC for the VLx be 0.
VlxKick(); // this turns on the VLx clock.
//
// Semaphore Polling Loop
//
kprintf("\nWaiting for vlx to clear semaphore...\n");
i=0;
while(*(volatile unsigned short*)pVlMemSema != 0) {
for (j=0;j<100;j++);
if( i++ > SEMA_TIMEOUT_CYCLES ) break;
}
//
// Check for time-out
//
kprintf("*pVlMemSema = 0x%x\n", *pVlMemSema );
if ( i > SEMA_TIMEOUT_CYCLES ) {
kprintf("ERROR...semaphore timed out, resume.\n");
succeeded = S_FAIL_SEMA;
} else {
kprintf("...semaphore cleared, resume.\n");
}
//
// Tell the VLx the show is over
//
kprintf("\nHalt Vlx...\n");
VlxStop(); // turns off the VLx clock
if (succeeded==S_PASS) {
kprintf("\nPASSED!!\n\n");
} else {
kprintf("\nFAILED!! Try again...\n\n");
}
kprintf("\nStatus : %d\n", succeeded);
kprintf("\nend\n");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -