📄 spi.cpp
字号:
/*******************************************************************************
*
* G p s S p i D e v i c e D r i v e r
*
* Areas are are:
* 1) Initialization and deinit.
* 2) Interrupts
* 3) Data Transfers
* 4) GLL and HAL process model
* 5) Possible extensions.
*
******************************************************************************/
#include "stdafx.h"
#include <winioctl.h>
#include <windows.h>
#include <pkfuncs.h>
#include <ceddk.h> // TODO: can only be used from Platform Builder?
// ... except I patched in a kludge for <pkfuncs.h> and IsInPwrHdlr()
// #define IsInPwrHdlr() (0 != PUserKData[PWR_FLAG_OFFSET])
#include "gpioHardware.h"
#include "spiIoctl.h"
#include "spiDriver.h"
#include "gpsDeviceDriver.h"
#include "cust_debug.h"
#include "cust_hw_spi.h"
#include "oalintr.h"
#include "wit_gpiomap.h"
#include "xllp_ssp.h"
#include "xllp_ost.h"
#include "bulverde_clkmgr.h"
#include "bulverde_gpio.h"
#include "trace.h"
#include <Mmsystem.h>
#define SPI_EXPORT extern "C" __declspec(dllexport)
//using namespace SSP;
extern int rb_TestRead(void);
extern volatile DWORD* pGpsTimer; // 1 tick = 3.25 MHz = .307 usec.
extern bool GetGpsDeviceID(void); // see gpsID.cpp
SPI_EXPORT BOOL
SPI_IOControl(DWORD hOpenContext, DWORD dwCode,
PBYTE pBufIn, DWORD dwLenIn,
PBYTE pBufOut, DWORD dwLenOut,
PDWORD pdwActualOut);
#define GPS_SPI_VERSION_MAJOR 2
#define GPS_SPI_VERSION_MINOR 17
//
// GOAL: Reduce traces from 2.16 & fix statistics
// Scheme: 3.0 - interrupts
// Options: Enable stat traces; disable debugs; no prio changing;
// Don't print traces until it is time to do so.
// 1-GPIO control.
// Changes:
// Disable debugs.
// Fiddle with casting & calculations in trace.cpp when done.
// RESULTS:
// ..
// GPS_SPI_VERSION_MINOR 16
//
// GOAL: Reduce debugs from 2.15.
// Scheme: 3.0 - interrupts
// Options: Enable all trace; disable debugs; no prio changing;
// Don't print traces until it is time to do so.
// 1-GPIO control.
// Changes:
// Disable debugs.
// RESULTS:
// works.
// GPS_SPI_VERSION_MINOR 15
//
// GOAL: Debug SPI lockup problem.
// Scheme: 3.0 - interrupts
// Options: Enable all trace; enable debugs; no prio changing;
// Don't print traces until it is time to do so.
// 1-GPIO control.
// Changes:
// Try more SSP port changes: preprogram SPI clock.
// RESULTS:
// Works!
// GPS_SPI_VERSION_MINOR 14
//
// GOAL: Debug SPI lockup problem.
// Scheme: 3.0 - interrupts
// Options: Enable all trace; enable debugs; no prio changing;
// Don't print traces until it is time to do so.
// 1-GPIO control.
// Changes:
// Add sspConfig() to reprogram the SSP3 SPI port
// at init time AND at power up.
// RESULTS:
// See status of 0xFF from MR all the time, but after some
// reasonable SPI transfer time.
// GPS_SPI_VERSION_MINOR 13
//
// GOAL: Debug SPI lockup problem.
// Scheme: 3.0 - interrupts
// Options: Enable all trace; enable debugs; no prio changing;
// Don't print traces until it is time to do so.
// 1-GPIO control.
// Changes:
// Remove power-up revision ID check.
// RESULTS:
// See status of 1 from MR right away with no delay at all.
// GPS_SPI_VERSION_MINOR 12
//
// GOAL: Debug SPI lockup problem.
// Scheme: 3.0 - interrupts
// Options: Enable all trace; enable debugs; no prio changing;
// Print traces as they occur.
// 1-GPIO control.
// Changes:
// Remove power-up revision ID check.
// RESULTS:
// See SPI bus interrupted error report.
// Could be because there is a 31.803 millisecond time gap
// between line 435 and line 559. Why? In case it is related
// to full debug tracing, repeat test with tracing on, and
// full debugs, BUT no printing of traces until it is time!
// GPS_SPI_VERSION_MINOR 11
//
// GOAL: Build for 3-gpio system testing.
// Scheme: 3.0 - interrupts
// Options: Enable trace stats; disable debugs; no prio changing;
// 3-GPIO control.
// Changes:
// Add power-off handling of GPIO for VDDCORE.
// RESULTS:
// ..
// GPS_SPI_VERSION_MINOR 10
//
// GOAL: Johnson test for 1/2 hour, unsigned driver..
// Scheme: 3.0 - interrupts
// Options: Enable trace stats; disable debugs; no prio changing;
// 1-GPIO control.
// Changes:
// Same as 2.09, but don't sign the driver.
// Change statistics to stop at power-off or close.
// Performance statistics (report 287.4; really is 28.7 KB/s)
// RESULTS:
// ..
// GPS_SPI_VERSION_MINOR 9
//
// GOAL: More power-off testing.
// Scheme: 3.0 - interrupts
// Options: Enable trace stats; disable debugs; no prio changing;
// 1-GPIO control.
// Changes:
// Change statistics to stop at power-off or close.
// RESULTS:
// ..
// GPS_SPI_VERSION_MINOR 8
//
// GOAL: More power-off testing.
// Scheme: 3.0 - interrupts
// Options: Enable trace stats; disable debugs; no prio changing;
// 1-GPIO control.
// Changes:
// Return -1 upon **EVERY** SPI_Read() - due to powerdown.
// Add OPT_GPIO to the banner.
// RESULTS:
// Stops properly, but restart fails due to an SPI problem.
// OPT_GPIO works.
// GPS_SPI_VERSION_MINOR 7
//
// GOAL: Add GPIOs for RESET and VDD_CORE control.
// Scheme: 3.0 - interrupts
// Options: Enable trace; disable debugs; no prio changing.
// 3-GPIO controls.
// Changes:
// Return -1 upon **EVERY** SPI_Read() - due to powerdown.
// Many GPIO programming changes for 3-gpio configuration.
// Add Sleep(1) between enables of the GPIO.
// RESULTS:
// Device can get GPS signal.
// GPS_SPI_VERSION_MINOR 06
//
// GOAL: See why power off doesn't stop GPSCT & allow proper
// restart.
// Scheme: 3.0 - interrupts
// Options: Disable trace (stats only); disable debugs; no prio changing.
// Changes:
// Return 0 upon **EVERY** SPI_Read() - due to powerdown.
// RESULTS:
// ..
// GPS_SPI_VERSION_MINOR 05
//
// GOAL: See why power off doesn't stop GPSCT & allow proper
// restart.
// Scheme: 3.0 - interrupts
// Options: Disable trace (stats only); disable debugs; no prio changing.
// Changes:
// Return -1 upon first SPI_Read() - due to powerdown.
// RESULTS:
// Same as 2.04
// Trace the problem to missing logic in the serial HAL.
// GPS_SPI_VERSION_MINOR 04
//
// GOAL: See why power off doesn't stop GPSCT & allow proper
// restart.
// Scheme: 3.0 - interrupts
// Options: Disable trace (stats only); disable debugs; no prio changing.
// Changes:
// 2.03 - Add power-off handling error messages.
// 2.03 - Upon power-off, assert nSTANDBY signal (set to 0).
// Guard nSTANDBY with GPIO existance macro.
// Report cause for dumping the traces.
// RESULTS:
// Traces removed successfully. New deug/error reports are useful.
// Need to return -1 upon spi_read() error.
// GPS_SPI_VERSION_MINOR 03
//
// GOAL: See why power off doesn't stop GPSCT & allow proper
// restart.
// Scheme: 3.0 - interrupts
// Options: Enable trace; disable debugs; no prio changing.
// Changes:
// Add power-off handling error messages.
// Upon power-off, assert nSTANDBY signal (set to 0).
// RESULTS:
// ..
// GPS_SPI_VERSION_MINOR 02
//
// GOAL: See why the system is sluggish.
// Scheme: 3.0 - interrupts
// Options: Enable traces; disable debugs; no prio changing.
// Changes: Disable SPI priority increase.
// Add SPI priority increase to the build options.
// RESULTS:
// Very good GPS performance.
// UI is sluggish.
// ==> Consider increasing glOnEvent() timeout loop.
// GPS_SPI_VERSION_MINOR 01
//
// GOAL: Trace GPS driver activity to tune GPS driver performance
// with the SPI_DONE interrupt. See why the system is
// sluggish.
// Scheme: 3.0 - interrupts
// Options: Enable traces; disable debugs;
// Changes: Fix tracing of stats AND of the main traces.
// RESULTS:
// System still sluggish.
// Very short delay time until SPI done received (less than 500 us).
// Tracing the body of the SPI code adds 1.2% CPU load.
// See two SPI_Exchange_Bytes()/519 wait timeout
// cr1 0x13c00 sr 0xE13C (or 0xF06C)
// There doesn't seem to be any GLL problems surrounding these
// two occurrances.
//
// spi_read() called 2959 times. 173528 bytes 3123030 uSec
// spi_write() called 13090 times. 221844 bytes 15166653 uSec
// spi_interrupts 204 int_ack 203/1030
// spi transfer rate = 395372/18289683 = 211.1 KB/s
// spi_open() for 284427331 us. 6.4% of CPU time.
// GPS_SPI_VERSION_MINOR 00
//
// GOAL: Ensure GPS operation and start tuning GPS driver performance
// with the SPI_DONE interrupt.
// Scheme: 3.0 - interrupts
// Options: Enable traces (stats only); disable debugs;
// Changes: disable debugs.
// RESULTS:
// Works.
// System is sluggish.
//
// EventName=GpsEvent not in registry:
//
// SPI_Close()/698 #@(#)GpsSpiBulverde 2.00 built May 10 2006 16:55:05
// spiDone(3.0) - interrupt
// spi_read() called 926 times. 64750 bytes 764653 uSec
// spi_write() called 4266 times. 78136 bytes 5077320 uSec
// spi_interrupts 1 int_ack 0/0
// spi transfer rate = 142886/5841973 = 238.9 KB/s
// spi_open() for 115,354,495 us. 5.0% of CPU time. (about 2 minutes)
// Latency 267 ms.
//
// Repeat with EventName=GpsEvent in registry:
//
// spi_read() called 1026 times. 60474 bytes 741059 uSec
// spi_write() called 4021 times. 72962 bytes 4656274 uSec
// spi_interrupts 90 int_ack 90/288
// spi transfer rate = 133436/5397333 = 241.4 KB/s
// spi_open() for 101963181 us. 5.2% of CPU time.
// Latency 206 ms.
// GPS_SPI_VERSION_MINOR 99
//
// GOAL: See why scheme 3.0 can't receive data.
// Scheme: 3.0 - interrupts
// Options: Enable traces; enable debugs;
// Changes: Get SpiSR after the interrupt event.
// RESULTS: Works!
// GPS_SPI_VERSION_MINOR 98
//
// GOAL: See why 97 can't send data.
// Scheme: 3.0 - interrupts
// Options: Enable traces; enable debugs;
// Changes: Add \r\n to 3 messages.
// RESULTS:
// Can't seem to read any data.
// I think it is lack of spiSR update after interrupt.
// GPS_SPI_VERSION_MINOR 97
//
// GOAL: Same as 96, except disable debugs.
//
// Options: Enable traces; disable debugs;
// Enable SPI done interrupt from the Bulverde driver.
// Also test aspects of 93.
//
// RESULTS:
//
// Run with latest OS from Wistron.
// Can't seem to read any data. Constant open/close of driver
// because GPSCT exits:
//
// SPI_Open()/627 #@(#)GpsSpiBulverde 1.97 built May 5 2006 18:05:24
// spiDone(3.0) - interrupt
// SPI_IOControl(10303ff[421886155])/909 bad IO code
// SPI_Close()/656 #@(#)GpsSpiBulverde 1.97 built May 5 2006 18:05:24
// spiDone(3.0) - interrupt
// spi_read() called 327 times. 0 bytes 1209 399 uSec
// spi_write() called 5 times. 42 bytes 1810 0 uSec
// spi_interrupts 0 int_ack 0/0
// spi transfer rate = 42/1227499 = 0.3 KB/s
// spi_open() for 12648455 ms. 9.7% of CPU time.
//
// Stats seem OK.
// GPS_SPI_VERSION_MINOR 96
//
// GOAL: Unit test of the SPI DONE interrupt, so full debugging
// enabled.
//
// Options: Enable traces; Enable debugs;
// Enable SPI done interrupt from the Bulverde driver.
//
// RESULTS:
//
// Appears to work. I see the command to enable the ISR,
// the ISR, the status, and the command to disable the ISR.
//
// PROBLEMS:
//
// The OS has some hard-coded debug messages:
// SSP3:Interrupt Occur!
// InterruptDone:SSP3
// These must be removed before performance testing can
// be started.
// GPS_SPI_VERSION_MINOR 95
// Options: Enable traces; Enable debugs;
// Disabled SPI done interrupt from the Bulverde driver.
//
// RESULTS:
//
// [not built or tested]
// GPS_SPI_VERSION_MINOR 94
// Options: Enable traces; Enable debugs;
// Added SPI done interrupt from the Bulverde driver.
// Also testing aspects of 93.
//
// RESULTS:
//
// [not built or tested]
// GPS_SPI_VERSION_MINOR 93
// Options: stat summary only; Disable traces; disable debugs;
// SPI_DONE: short int-off; sleep(0) during poll.
// Fixed stats again.
//
// RESULTS:
//
// [not built or tested, but presumed to fix %f display bug.]
// GPS_SPI_VERSION_MINOR 92
// Options: stat summary only; Disable traces; disable debugs;
// SPI_DONE: short int-off; sleep(0) during poll.
// Fixed stats again.
//
// RESULTS:
//
// Better reporting, but still wrong. System is sluggish, but not too bad.
// 7.6% CPU
// 29.5 KB/sec
// Latency < 40 ms.
// GPS_SPI_VERSION_MINOR 91
// Options: stat summary only; Disable traces; disable debugs; short int-off
// Fixed %f using %d and integer arithmetic.
// Sleep(0) with a short SPI_DONE poll.
//
// RESULTS:
//
// Stats are reported wrong. Hand computing them is:
// 3.3% of the CPU
// Latency very low (less than 50 ms)
// 21.2 KB/sec thruput.
//
// GPS_SPI_VERSION_MINOR 90
// Options: stat summary only; Disable traces; disable debugs; long int-off
// Added report of just the read/write statistics.
//
// RESULTS:
//
// Works, but stats can't pringt %f
// GPS_SPI_VERSION_MINOR 89
// Options: Enable stats; Disable traces; disable debugs; long int-off
// Fix \n\r for stats.
//
// RESULTS:
// 4.1% of CPU for reads & writes
// 29 KB/sec thruput
// less than 50 latency.
// CPU very responsive.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -