Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DDRO_Farrari by
Revision 10:95e9932f7990, committed 2014-02-25
- Comitter:
- josewang
- Date:
- Tue Feb 25 02:14:41 2014 +0000
- Parent:
- 9:cbb692f51e0f
- Commit message:
- Read from ram buffer and print
Changed in this revision
--- a/EasyBMP.cpp Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,612 +0,0 @@
-/*************************************************
-* *
-* EasyBMP Cross-Platform Windows Bitmap Library *
-* *
-* Author: Paul Macklin *
-* email: macklin01@users.sourceforge.net *
-* support: http://easybmp.sourceforge.net *
-* *
-* file: EasyBMP.cpp *
-* date added: 03-31-2006 *
-* date modified: 12-01-2006 *
-* version: 1.06 *
-* *
-* License: BSD (revised/modified) *
-* Copyright: 2005-6 by the EasyBMP Project *
-* *
-* description: Actual source file *
-* *
-*************************************************/
-
-#include "EasyBMP.h"
-
-/* These functions are defined in EasyBMP_DataStructures.h */
-
-int ceildiv(int n, int d)
-{
- return 1 + ((n - 1) / d);
-}
-
-int IntPow( int base, int exponent )
-{
- int i;
- int output = 1;
- for( i=0 ; i < exponent ; i++ )
- { output *= base; }
- return output;
-}
-
-BMFH::BMFH()
-{
- bfType = 19778;
- bfReserved1 = 0;
- bfReserved2 = 0;
-}
-
-BMIH::BMIH()
-{
- biPlanes = 1;
- biCompression = 0;
- biXPelsPerMeter = DefaultXPelsPerMeter;
- biYPelsPerMeter = DefaultYPelsPerMeter;
- biClrUsed = 0;
- biClrImportant = 0;
-}
-
-
-/* These functions are defined in EasyBMP_BMP.h */
-
-unsigned char BMP::GetPixel( int i, int j ) const
-{
- if(PixelsBW[i / 32][j] & ( 0x1 << (31 - i % 32))){
- return 1; // white
- }else{
- return 0; // black
- }
-}
-
-bool BMP::SetPixel( int i, int j )
-{
- PixelsR[i / 32][j] |= ( 0x1 << (31 - i % 32));
- return true;
-}
-
-BMP::BMP()
-{
- Width = 1;
- Height = 1;
- BitDepth = 24;
- PixelsBW = new unsigned int* [1];
- PixelsBW[0] = new unsigned int [1];
- PixelsR = new unsigned int* [1];
- PixelsR[0] = new unsigned int [1];
-
- Colors = NULL;
-
- XPelsPerMeter = 0;
- YPelsPerMeter = 0;
-
- MetaData1 = NULL;
- SizeOfMetaData1 = 0;
- MetaData2 = NULL;
- SizeOfMetaData2 = 0;
-}
-
-
-BMP::~BMP()
-{
- int i;
- for(i=0;i<ceildiv(Width,32);i++)
- { delete [] PixelsBW[i]; }
- delete [] PixelsBW;
-
- for(i=0;i<ceildiv(Width,32);i++)
- { delete [] PixelsR[i]; }
- delete [] PixelsR;
-
- if( Colors )
- { delete [] Colors; }
-
- if( MetaData1 )
- { delete [] MetaData1; }
- if( MetaData2 )
- { delete [] MetaData2; }
-}
-
-// int BMP::TellBitDepth( void ) const
-int BMP::TellBitDepth( void )
-{ return BitDepth; }
-
-// int BMP::TellHeight( void ) const
-int BMP::TellHeight( void )
-{ return Height; }
-
-// int BMP::TellWidth( void ) const
-int BMP::TellWidth( void )
-{ return Width; }
-
-// int BMP::TellNumberOfColors( void ) const
-int BMP::TellNumberOfColors( void )
-{
- int output = IntPow( 2, BitDepth );
- return output;
-}
-
-bool BMP::SetBitDepth( int NewDepth )
-{
- using namespace std;
- if( NewDepth != 1 && NewDepth != 4)
- {
- return false;
- }
-
- BitDepth = NewDepth;
- if( Colors )
- { delete [] Colors; }
- int NumberOfColors = IntPow( 2, BitDepth );
-
- { Colors = new RGBApixel [NumberOfColors]; }
- { CreateStandardColorTable(); }
-
- return true;
-}
-
-bool BMP::SetSize(int NewWidth , int NewHeight )
-{
- using namespace std;
- if( NewWidth <= 0 || NewHeight <= 0 )
- {
- return false;
- }
-
- int i,j;
-
- for(i=0;i<ceildiv(Width,32);i++)
- { delete [] PixelsBW[i]; }
- delete [] PixelsBW;
-
- for(i=0;i<ceildiv(Width,32);i++)
- { delete [] PixelsR[i]; }
- delete [] PixelsR;
-
- Width = NewWidth;
- Height = NewHeight;
- PixelsBW = new unsigned int* [ ceildiv(Width,32) ];
- PixelsR = new unsigned int* [ ceildiv(Width,32) ];
-
- for(i=0;i<ceildiv(Width,32);i++){
- PixelsBW[i] = new unsigned int [ Height ];
- PixelsR[i] = new unsigned int [ Height ];
- for( j=0 ; j < Height ; j++ ){
- PixelsBW[i][j] = 0;
- PixelsR[i][j] = 0;
- }
- }
-
- return true;
-}
-#include<iostream>
-
-bool BMP::WriteToFile( const char* FileName )
-{
-
- using namespace std;
-
- cout << "called" << endl;
- if( !EasyBMPcheckDataSize() )
- {
- return false;
- }
-
- FILE* fp = fopen( FileName, "wb" );
-
-
- if( fp == NULL )
- {
- cout << "can't write\r\n" << endl;
- fclose( fp );
- return false;
- }
-
- // some preliminaries
-
- double dBytesPerPixel = ( (double) BitDepth ) / 8.0;
- double dBytesPerRow = dBytesPerPixel * (Width+0.0);
- dBytesPerRow = ceil(dBytesPerRow);
-
- int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4;
- if( BytePaddingPerRow == 4 )
- { BytePaddingPerRow = 0; }
-
- double dActualBytesPerRow = dBytesPerRow + BytePaddingPerRow;
-
- double dTotalPixelBytes = Height * dActualBytesPerRow;
-
- double dPaletteSize = 0;
- if( BitDepth == 1 || BitDepth == 4)
- { dPaletteSize = IntPow(2,BitDepth)*4.0; }
-
- double dTotalFileSize = 14 + 40 + dPaletteSize + dTotalPixelBytes;
-
- // write the file header
-
- BMFH bmfh;
- bmfh.bfSize = (ebmpDWORD) dTotalFileSize;
- bmfh.bfReserved1 = 0;
- bmfh.bfReserved2 = 0;
- bmfh.bfOffBits = (ebmpDWORD) (14+40+dPaletteSize);
-
- fwrite( (char*) &(bmfh.bfType) , sizeof(ebmpWORD) , 1 , fp );
- fwrite( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1 , fp );
- fwrite( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1 , fp );
- fwrite( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp );
-
- // write the info header
-
- BMIH bmih;
- bmih.biSize = 40;
- bmih.biWidth = Width;
- bmih.biHeight = Height;
- bmih.biPlanes = 1;
- bmih.biBitCount = BitDepth;
- bmih.biCompression = 0;
- bmih.biSizeImage = (ebmpDWORD) dTotalPixelBytes;
- if( XPelsPerMeter )
- { bmih.biXPelsPerMeter = XPelsPerMeter; }
- else
- { bmih.biXPelsPerMeter = DefaultXPelsPerMeter; }
- if( YPelsPerMeter )
- { bmih.biYPelsPerMeter = YPelsPerMeter; }
- else
- { bmih.biYPelsPerMeter = DefaultYPelsPerMeter; }
-
- bmih.biClrUsed = 0;
- bmih.biClrImportant = 0;
-
- // indicates that we'll be using bit fields for 16-bit files
- if( BitDepth == 16 )
- { bmih.biCompression = 3; }
-
- fwrite( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp );
- fwrite( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp);
- fwrite( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp);
-
- // write the palette
- if( BitDepth == 1 || BitDepth == 4 )
- {
- int NumberOfColors = IntPow(2,BitDepth);
-
- // if there is no palette, create one
- if( !Colors )
- {
- if( !Colors )
- { Colors = new RGBApixel [NumberOfColors]; }
- CreateStandardColorTable();
- }
-
- int n;
- for( n=0 ; n < NumberOfColors ; n++ )
- { fwrite( (char*) &(Colors[n]) , 4 , 1 , fp ); }
- }
-
- // write the pixels
- int j;
- {
- ebmpBYTE* Buffer;
- int BufferSize = (int) ( (Width*BitDepth)/8.0 );
- while( 8*BufferSize < Width*BitDepth )
- { BufferSize++; }
- while( BufferSize % 4 )
- { BufferSize++; }
-
- Buffer = new ebmpBYTE [BufferSize];
- for( j=0 ; j < BufferSize; j++ )
- { Buffer[j] = 0; }
-
- j=Height-1;
-
- while( j > -1 )
- {
- bool Success = false;
- if( BitDepth == 4 )
- { Success = Write4bitRow( Buffer, BufferSize, j ); }
- if( Success )
- {
- int BytesWritten = (int) fwrite( (char*) Buffer, 1, BufferSize, fp );
- if( BytesWritten != BufferSize )
- { Success = false; }
- }
- if( !Success )
- {
- j = -1;
- }
- j--;
- }
-
- delete [] Buffer;
- }
-
- cout << "done " << endl;
- fclose(fp);
- return true;
-}
-
-bool BMP::ReadFromFile( const char* FileName )
-{
- using namespace std;
- if( !EasyBMPcheckDataSize() )
- {
- return false;
- }
-
- FILE* fp = fopen( FileName, "rb" );
- if( fp == NULL )
- {
-
- SetBitDepth(1);
- SetSize(1,1);
- return false;
- }
-
- // read the file header
-
- BMFH bmfh;
- bool NotCorrupted = true;
-
- NotCorrupted &= SafeFread( (char*) &(bmfh.bfType) , sizeof(ebmpWORD), 1, fp);
-
- bool IsBitmap = false;
-
- if( bmfh.bfType == 19778 )
- { IsBitmap = true; }
-
- if( !IsBitmap )
- {
- fclose( fp );
- return false;
- }
-
- NotCorrupted &= SafeFread( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1, fp);
- NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1, fp);
- NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1, fp);
- NotCorrupted &= SafeFread( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp);
-
- // read the info header
-
- BMIH bmih;
-
- NotCorrupted &= SafeFread( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1, fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1, fp);
-
- NotCorrupted &= SafeFread( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp);
- NotCorrupted &= SafeFread( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp);
-
- // a safety catch: if any of the header information didn't read properly, abort
- // future idea: check to see if at least most is self-consistent
-
- if( !NotCorrupted )
- {
- SetSize(1,1);
- SetBitDepth(1);
- fclose(fp);
- return false;
- }
-
- XPelsPerMeter = bmih.biXPelsPerMeter;
- YPelsPerMeter = bmih.biYPelsPerMeter;
-
- // set the bit depth
-
- int TempBitDepth = (int) bmih.biBitCount;
- if( TempBitDepth != 1 && TempBitDepth != 4 )
- {
- SetSize(1,1);
- SetBitDepth(1);
- fclose(fp);
- return false;
- }
- SetBitDepth( (int) bmih.biBitCount );
-
- // set the size
-
- if( (int) bmih.biWidth <= 0 || (int) bmih.biHeight <= 0 )
- {
- SetSize(1,1);
- SetBitDepth(1);
- fclose(fp);
- return false;
- }
- SetSize( (int) bmih.biWidth , (int) bmih.biHeight );
-
- // some preliminaries
-
- double dBytesPerPixel = ( (double) BitDepth ) / 8.0;
- double dBytesPerRow = dBytesPerPixel * (Width+0.0);
- dBytesPerRow = ceil(dBytesPerRow);
-
- int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4;
- if( BytePaddingPerRow == 4 )
- { BytePaddingPerRow = 0; }
-
- // skip blank data if bfOffBits so indicates
-
- int BytesToSkip = bmfh.bfOffBits - 54;;
- if( BitDepth == 16 && bmih.biCompression == 3 )
- { BytesToSkip -= 3*4; }
- if( BytesToSkip < 0 )
- { BytesToSkip = 0; }
- if( BytesToSkip > 0 && BitDepth != 16 )
- {
- ebmpBYTE* TempSkipBYTE;
- TempSkipBYTE = new ebmpBYTE [BytesToSkip];
- SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp);
- delete [] TempSkipBYTE;
- }
-
- // This code reads 1, 4, 8, 24, and 32-bpp files
- // with a more-efficient buffered technique.
-
- int j;
- if( BitDepth != 16 )
- {
- int BufferSize = (int) ( (Width*BitDepth) / 8.0 );
- while( 8*BufferSize < Width*BitDepth )
- { BufferSize++; }
- while( BufferSize % 4 )
- { BufferSize++; }
- ebmpBYTE* Buffer;
- Buffer = new ebmpBYTE [BufferSize];
- j= Height-1;
- while( j > -1 )
- {
- int BytesRead = (int) fread( (char*) Buffer, 1, BufferSize, fp );
- if( BytesRead < BufferSize )
- {
- j = -1;
- }
- else
- {
- bool Success = false;
- if( BitDepth == 1 )
- { Success = Read1bitRow( Buffer, BufferSize, j ); }
- if( !Success )
- {
- j = -1;
- }
- }
- j--;
- }
- delete [] Buffer;
- }
- fclose(fp);
- return true;
-}
-
-bool BMP::CreateStandardColorTable( void )
-{
- using namespace std;
- if( BitDepth != 1 && BitDepth != 4)
- {
- return false;
- }
-
- if( BitDepth == 1 )
- {
- int i;
- for( i=0 ; i < 2 ; i++ )
- {
- Colors[i].Red = i*255;
- Colors[i].Green = i*255;
- Colors[i].Blue = i*255;
- Colors[i].Alpha = 0;
- }
- return true;
- }
-
- for(int i=0; i<16; i++){
- Colors[i].Red = 0;
- Colors[i].Blue = 0;
- Colors[i].Green = 0;
- Colors[i].Alpha = 0;
- }
-
- Colors[1].Red = 255;
-
- Colors[15].Red = 255;
- Colors[15].Blue = 255;
- Colors[15].Green = 255;
-
- return true;
-}
-
-bool SafeFread( char* buffer, int size, int number, FILE* fp )
-{
- using namespace std;
- int ItemsRead;
- if( feof(fp) )
- { return false; }
- ItemsRead = (int) fread( buffer , size , number , fp );
- if( ItemsRead < number )
- { return false; }
- return true;
-}
-
-#include<iostream>
-bool BMP::Read1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row )
-{
- using namespace std;
- if( Width > 8*BufferSize )
- { return false; }
-
- int i=0;
- for(i=0; i < BufferSize; i++){
- PixelsBW[i/4][Row] |= Buffer[i] << (8 * (3 - i%4));
- }
- return true;
-}
-
-bool BMP::Write4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row )
-{
- int PositionWeights[2] = {16,1};
-
- int i=0;
- int j;
- int k=0;
- if( Width > 2*BufferSize )
- { return false; }
- while( i < Width )
- {
- j=0;
- int Index = 0;
- while( j < 2 && i < Width )
- {
- int closest = 0; // black
- if(PixelsBW[i / 32][Row] & ( 0x1 << (31 - i % 32))){
- closest = 15; // white
- }
- if(PixelsR[i / 32][Row] & ( 0x1 << (31 - i % 32))){
- closest = 1; // red
- }
- Index += ( PositionWeights[j]* closest );
- i++; j++;
- }
- Buffer[k] = (ebmpBYTE) Index;
- k++;
- }
- return true;
-}
-
-bool EasyBMPcheckDataSize( void )
-{
- using namespace std;
- bool ReturnValue = true;
- if( sizeof( ebmpBYTE ) != 1 )
- {
- ReturnValue = false;
- }
- if( sizeof( ebmpWORD ) != 2 )
- {
- ReturnValue = false;
- }
- if( sizeof( ebmpDWORD ) != 4 )
- {
- ReturnValue = false;
- }
- return ReturnValue;
-}
--- a/EasyBMP.h Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +0,0 @@
-/*************************************************
-* *
-* EasyBMP Cross-Platform Windows Bitmap Library *
-* *
-* Author: Paul Macklin *
-* email: macklin01@users.sourceforge.net *
-* support: http://easybmp.sourceforge.net *
-* *
-* file: EasyBMP.h *
-* date added: 01-31-2005 *
-* date modified: 12-01-2006 *
-* version: 1.06 *
-* *
-* License: BSD (revised/modified) *
-* Copyright: 2005-6 by the EasyBMP Project *
-* *
-* description: Main include file *
-* *
-*************************************************/
-
-//#include <iostream>
-#include <cmath>
-#include <cctype>
-#include <cstring>
-
-#include "mbed.h"
-
-#ifndef EasyBMP
-#define EasyBMP
-//static LocalFileSystem local("local");
-
-#include "pinout.h"
-
-#include <cstdio>
-
-
-#ifndef _DefaultXPelsPerMeter_
-#define _DefaultXPelsPerMeter_
-#define DefaultXPelsPerMeter 3780
-// set to a default of 96 dpi
-#endif
-
-#ifndef _DefaultYPelsPerMeter_
-#define _DefaultYPelsPerMeter_
-#define DefaultYPelsPerMeter 3780
-// set to a default of 96 dpi
-#endif
-
-
-int IntPow( int base, int exponent );
-int ceildiv(int n, int d);
-
-#ifndef _EasyBMP_Defined_WINGDI
-#define _EasyBMP_Defined_WINGDI
- typedef unsigned char ebmpBYTE;
- typedef unsigned short ebmpWORD;
- typedef unsigned int ebmpDWORD;
-#endif
-
-#ifndef _EasyBMP_DataStructures_h_
-#define _EasyBMP_DataStructures_h_
-
-
-// it's easier to use a struct than a class
-// because we can read/write all four of the bytes
-// at once (as we can count on them being continuous
-// in memory
-
-typedef struct RGBApixel {
- ebmpBYTE Blue;
- ebmpBYTE Green;
- ebmpBYTE Red;
- ebmpBYTE Alpha;
-} RGBApixel;
-
-class BMFH{
-public:
- ebmpWORD bfType;
- ebmpDWORD bfSize;
- ebmpWORD bfReserved1;
- ebmpWORD bfReserved2;
- ebmpDWORD bfOffBits;
-
- BMFH();
-};
-
-class BMIH{
-public:
- ebmpDWORD biSize;
- ebmpDWORD biWidth;
- ebmpDWORD biHeight;
- ebmpWORD biPlanes;
- ebmpWORD biBitCount;
- ebmpDWORD biCompression;
- ebmpDWORD biSizeImage;
- ebmpDWORD biXPelsPerMeter;
- ebmpDWORD biYPelsPerMeter;
- ebmpDWORD biClrUsed;
- ebmpDWORD biClrImportant;
-
- BMIH();
-};
-
-#endif
-
-#ifndef _EasyBMP_BMP_h_
-#define _EasyBMP_BMP_h_
-
-
-bool SafeFread( char* buffer, int size, int number, FILE* fp );
-bool EasyBMPcheckDataSize( void );
-
-class BMP
-{private:
-
- char BitDepth;
- short Width;
- short Height;
-
- RGBApixel* Colors;
- short XPelsPerMeter;
- short YPelsPerMeter;
-
- ebmpBYTE* MetaData1;
- short SizeOfMetaData1;
- ebmpBYTE* MetaData2;
- short SizeOfMetaData2;
-
- bool Read1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row );
- bool Write4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row );
-
- public:
-
- unsigned int** PixelsBW;
- unsigned int** PixelsR;
-
- int TellBitDepth( void );
- int TellWidth( void );
- int TellHeight( void );
- int TellNumberOfColors( void );
-
- BMP();
- ~BMP();
-
- unsigned char GetPixel( int i, int j ) const;
- bool SetPixel( int i, int j);
-
- bool CreateStandardColorTable( void );
-
- bool SetSize( int NewWidth, int NewHeight );
- bool SetBitDepth( int NewDepth );
- bool WriteToFile( const char* FileName );
- bool ReadFromFile( const char* FileName );
-
-};
-
-#endif
-
-
-#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/GPIOInterrupt.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -0,0 +1,84 @@
+/*
+ * Implementations of two threads created in main.cpp.
+ * One thread is used for handling core read/write request, the other thread is for sending an acknowledge interrupt.
+ *
+ * Written by Zimin Wang
+ *
+ */
+#include "mbed.h"
+#include "rtos.h"
+#include "jtag.h"
+#include "mmap.h"
+#include "GPIOInterrupt.h"
+#include "basic_io.h"
+#include "signal.h"
+
+#define PRINT_REQ (0U)
+#define SCAN_REQ (1U)
+
+// interrupt pins
+static InterruptIn req_intr(p15);
+// p16 is used to send an IRQ1 to core.
+static DigitalOut ack_intr(p16);
+
+void enable_GPIO_intr(void (*handler)(void)) {
+ req_intr.rise(handler);
+ req_intr.mode(PullDown);
+}
+
+void disable_GPIO_intr(void) {
+ req_intr.disable_irq();
+ return;
+}
+
+
+// GPIO_out should be put in main loop. When an output request interrupt from chip occurs,
+// this function read output data from chip and print data. Then it sends an output acknowledge
+// signal to unblock task in the chip.
+// When there is no output request interrupt it returns quietly.
+void listen_req(void const *args) {
+ static bool init = true;
+
+ JTAG *pJtag = (JTAG *)args;
+ while (1) {
+ Thread::signal_wait(SIG_COREREQ);
+ if (init) {
+ // inittialize jtag
+ pJtag->reset();
+ pJtag->leaveState();
+ pJtag->PowerupDAP();
+ init = false;
+ }
+ // check whether it's a print request or scan request
+ unsigned int type = pJtag->readMemory(IO_TYPE);
+ if (type == PRINT_REQ) {
+ // read message from JTAG
+ term_printf(pJtag);
+ } else if (type == SCAN_REQ) {
+ term_scanf(pJtag);
+ } else {
+ mbed_printf("Unknown request type: %u\r\n", type);
+ continue;
+ }
+ // generate an acknowledge interrupt signal
+ ack_intr = 1;
+ ack_intr = 0;
+ }
+}
+
+
+/*
+// GPIO_in should be put in main loop. When an input request interrupt from chip occurs,
+// this functino read user input and write user input to the chip. Then it sends an input
+// acknowledge interrupt to unblock task in the chip.
+// When there is no input request interrupt it returns quietly.
+void GPIO_in(void const *args) {
+ while (1) {
+ mbed_printf("Enter GPIO in.\r\n");
+ // generate interrupt signal
+ in_ack = 1;
+ in_ack = 0;
+ Thread::wait(4000);
+ }
+}
+*/
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GPIOInterrupt.h Tue Feb 25 02:14:41 2014 +0000 @@ -0,0 +1,26 @@ +/* + * Written by Zimin Wang + * + */ +#ifndef GPIO_INTERRUPT_H_ +#define GPIO_INTERRUPT_H_ + +#include <InterruptIn.h> + +// enable and disable interrupt from GPIO +extern void enable_GPIO_intr(void (*handler)(void)); +extern void disable_GPIO_intr(void); + +// GPIO_out should be put in main loop. When an output request interrupt from chip occurs, +// this function read output data from chip and print data. Then it sends an output acknowledge +// signal to unblock task in the chip. +// When there is no output request interrupt it returns quietly. +extern void listen_req(void const *args); + +// GPIO_in should be put in main loop. When an input request interrupt from chip occurs, +// this functino read user input and write user input to the chip. Then it sends an input +// acknowledge interrupt to unblock task in the chip. +// When there is no input request interrupt it returns quietly. +//extern void GPIO_in(void const *args); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_io.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -0,0 +1,189 @@
+/*
+ * Implementation of a family of print and scan functions
+ *
+ * Written by Zimin Wang
+ */
+#include <stdarg.h>
+#include <stdio.h>
+#include "mbed.h"
+#include "rtos.h"
+#include "mmap.h"
+#include "signal.h"
+#include "pinout.h"
+#include "basic_io.h"
+
+#define TERMBUF_SIZE (256)
+
+// mutex to serialize terminal read and write so that input/output won't be interleaved
+static Mutex term_write_mutex;
+static Mutex term_read_mutex;
+// mutex to lock ram buffer
+static Mutex rambuf_mutex;
+
+// buffer for read from or write to terminal
+static char term_txbuffer[TERMBUF_SIZE];
+static char term_rxbuffer[TERMBUF_SIZE];
+
+// Each time we can only read/write 4 bytes of data from/to ram buffer through JTAG
+static union byte_chunk_union {
+ unsigned int word;
+ char bytes[4];
+} byte_chunk;
+
+
+// Actual function called when read from or write to terminal.
+// Send buffer to stdout.
+static void term_sendbuffer(const char *buffer, size_t size);
+// Read stdin and write a maximum of size bytes data to buffer.
+static void term_readbuffer(char *buffer, size_t size);
+
+
+int mbed_printf(const char *format, ...) {
+ int size;
+ va_list args;
+
+ va_start(args, format);
+ size = mbed_vprintf(format, args);
+ va_end(args);
+
+ return size;
+}
+
+int mbed_vprintf(const char *format, va_list args) {
+ int size;
+
+ // tx_line is in critical section. We need a mutex to protect it.
+ term_write_mutex.lock();
+ size = vsnprintf(term_txbuffer, TERMBUF_SIZE, format, args);
+ term_sendbuffer(term_txbuffer, TERMBUF_SIZE);
+ term_write_mutex.unlock();
+
+ return size;
+}
+
+// prompt user to input data from terminal
+int mbed_scanf(const char *format, ...) {
+ int size;
+ va_list args;
+
+ va_start(args, format);
+ size = mbed_vscanf(format, args);
+ va_end(args);
+
+ return size;
+}
+
+int mbed_vscanf(const char *format, va_list args) {
+ int size;
+
+ // rx_line is in critical section, we need a mutex to protect it.
+ term_read_mutex.lock();
+ term_readbuffer(term_rxbuffer, TERMBUF_SIZE);
+ size = vsscanf(term_rxbuffer, format, args);
+ term_read_mutex.unlock();
+ return size;
+}
+
+int term_printf(JTAG *pJtag) {
+ // acquire locks
+ rambuf_mutex.lock();
+ term_write_mutex.lock();
+ // read data from ram buffer
+ char *cp = term_txbuffer;
+ bool finished = false;
+ int len = 0;
+ for (unsigned int i = RAMBUF_BEGIN; i < RAMBUF_END; i += 4) {
+ byte_chunk.word = pJtag->readMemory(i);
+ for (int j = 0; j < 4; ++j) {
+ if (byte_chunk.bytes[j] != '\0') {
+ *cp++ = byte_chunk.bytes[j];
+ ++len;
+ }
+ else {
+ finished = true;
+ break;
+ }
+ }
+ if (finished)
+ break;
+ }
+ *cp = '\0';
+
+ term_sendbuffer(term_txbuffer, TERMBUF_SIZE);
+ // release locks
+ term_write_mutex.unlock();
+ rambuf_mutex.unlock();
+ return len;
+}
+
+int term_scanf(JTAG *pJtag) {
+ // acquire locks
+ rambuf_mutex.lock();
+ term_read_mutex.lock();
+ // read from terminal and write to ram buffer
+ term_readbuffer(term_rxbuffer, RAMBUF_SIZE);
+ char *cp = term_rxbuffer;
+ bool finished = false;
+ int len = 0;
+ for (int i = RAMBUF_BEGIN; i < RAMBUF_END; i+= 4) {
+ for (int j = 0; j < 4; ++j) {
+ if (*cp) {
+ byte_chunk.bytes[j] = *cp++;
+ ++len;
+ } else {
+ byte_chunk.bytes[j] = '\0';
+ finished = true;
+ }
+ }
+ pJtag->writeMemory(i, byte_chunk.word);
+ if (finished)
+ break;
+ }
+ // release locks
+ term_read_mutex.unlock();
+ rambuf_mutex.unlock();
+ return len;
+}
+
+void debug_print(JTAG *pJtag) {
+ // print the content of ram buffer
+ unsigned int value;
+ for (unsigned int i = RAMBUF_BEGIN; i < RAMBUF_END; i+=4) {
+ value = pJtag->readMemory(i);
+ mbed_printf("%08x\r\n", value);
+ }
+ value = pJtag->readMemory(IO_TYPE);
+ mbed_printf("%8x\r\n", value);
+}
+
+static void term_sendbuffer(const char *buffer, size_t size) {
+ int i;
+
+ i = 0;
+ while (i < size) {
+ if (buffer[i] != '\0' && pc.writeable()) {
+ pc.putc(buffer[i++]);
+ } else if (buffer[i] == '\0') {
+ break;
+ }
+ }
+ return;
+}
+
+static void term_readbuffer(char *buffer, size_t size) {
+ int i;
+ char temp;
+
+ i = 0;
+ while (i < size-1) { // save for null character
+ if (pc.readable()) {
+ temp = pc.getc();
+ if (temp == '\r')
+ break;
+ else
+ buffer[i++] = temp;
+ }
+ }
+ buffer[i] = '\0';
+ return;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/basic_io.h Tue Feb 25 02:14:41 2014 +0000 @@ -0,0 +1,36 @@ +/* + * A family of print and scan functions. + * + * Written by Zimin Wang. + */ + +#ifndef BASIC_IO_H +#define BASIC_IO_H + +#include <stdarg.h> +#include "jtag.h" + +// IO functions to read/write data from/to terminal to mbed program. +// These functions are used as a replacement to pc.printf() and pc.scanf() +extern int mbed_printf(const char *format, ...); +extern int mbed_scanf(const char *format,...); +extern int mbed_vprintf(const char *format, va_list args); +extern int mbed_vscanf(const char *format, va_list args); + +// IO functions to read from ram buffer within Cortex-M3 core and write to peripherals of the testboard, +// or read data from peripherals of the testboard and write them to the ram buffer of Cortex-M3 core. +// foo_printf below reads from ram buffer and write data to peripheral "foo". +// foo_scanf below reads from peripheral "foo" and write data to ram buffer. +extern int term_printf(JTAG *pJtag); +extern int term_scanf(JTAG *pJtag); +extern int xbee_printf(const char *format, ...); +extern int xbee_scanf(const char *format, ...); +extern int usb_printf(const char *format, ...); +extern int usb_scanf(const char *format, ...); +extern int inet_printf(const char *format, ...); +extern int inet_scanf(const char *format, ...); + +// read from ram buffer and print for debug use +extern void debug_print(JTAG *pJtag); + +#endif \ No newline at end of file
--- a/board_test.cpp Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-#include "board_test.h"
-
-
-void mem_test(JTAG &jtag)
-{
-
- jtag.PowerupDAP();
- unsigned int base = 0x10000000;
- unsigned int size = 2000;
- unsigned int* data;
- data = new unsigned int[size];
-
- for(unsigned int i=0; i<size; i++){
- data[i] = i;
- }
-
- pc.printf("Performing memWrite\r\n");
- jtag.memWrite(base, data, size);
-
- pc.printf("Checking memWrite\r\n");
- for(unsigned int i=0; i<size; i++){
- unsigned int d = jtag.readMemory(base + i*4);
- //pc.printf("MEM[%X] = %X\r\n", i, d);
- if(d != i){
- pc.printf("MEMERROR: MEM[%X] = %X\r\n", i, d);
- }
- }
-
- jtag.writeMemory(base + 4*20, 0xdeadbeef);
-
- pc.printf("Performing memRead\r\n");
- jtag.memRead(base, data, size, true, true);
-
- pc.printf("Mem test done\r\n");
- delete data;
-
-}
-
-void lcd_test()
-{
-
- lcd_default();
- wait(1);
-
- lcd_printf("Initial Power On");
- wait(1);
- lcd_clear( );
- wait(1);
-
- lcd_goto( LINE4_BEGIN );
- lcd_printf("Line 4");
- wait(1);
- lcd_goto( LINE2_BEGIN );
- lcd_printf("Line 2");
- wait(1);
-
- lcd_clear_line( 4);
- lcd_home();
- lcd_printf("Line 1");
- lcd_clear();
- wait(1);
-
- lcd_printf("ABCDEF");
- wait(1);
- lcd_backspace(); lcd_backspace(); lcd_backspace();
- wait(1);
- lcd_cursor_left(); lcd_cursor_left(); lcd_cursor_left();
- lcd_printf("def");
- wait(1);
- lcd_cursor_right(); lcd_cursor_right(); lcd_cursor_right();
- lcd_printf("abc");
- wait(1);
- lcd_clear();
- wait(1);
-
- lcd_goto( LINE1_BEGIN ); lcd_printf("LINE1");
- lcd_goto( LINE2_BEGIN ); lcd_printf("LINE2");
- lcd_goto( LINE3_BEGIN ); lcd_printf("LINE3");
- lcd_goto( LINE4_BEGIN ); lcd_printf("LINE4");
- wait(1);
-
- int i=0;
- while(1) {
- lcd_set_contrast( (5*i)%50 );
- lcd_backlight_level( i%8 );
-
- lcd_shift_right(); wait_ms(50);
- lcd_shift_right(); wait_ms(50);
- lcd_shift_right(); wait_ms(50);
- lcd_shift_right(); wait_ms(50);
- lcd_shift_right(); wait_ms(50);
- lcd_shift_right(); wait_ms(50);
- lcd_shift_right(); wait_ms(50);
-
- lcd_shift_left(); wait_ms(50);
- lcd_shift_left(); wait_ms(50);
- lcd_shift_left(); wait_ms(50);
- lcd_shift_left(); wait_ms(50);
- lcd_shift_left(); wait_ms(50);
- lcd_shift_left(); wait_ms(50);
- lcd_shift_left(); wait_ms(50);
-
- i++;
- wait_ms(100);
- }
-}
-
-
-void i2ctest(){
-
- char data[4] = "abc";
- int A = 0;
- for (A = 0; A<=0xFF; A++) {
- if (lcd.write(A,data,3,false)==0) {
- pc.printf (" GOT LCD %X\r\n", A);
- }
- }
-
-}
-
-void analog_test()
-{
-
- power_chan(ADVDD, 0.10);
- wait(POWER_UP_TIME);
- power_chan(PADVDD, 0.15);
- wait(POWER_UP_TIME);
- power_chan(DVDD, 0.20);
- wait(POWER_UP_TIME);
- power_chan(ADVDD2, 0.25);
- wait(POWER_UP_TIME);
- power_chan(COREVDD, 0.30);
- wait(POWER_UP_TIME);
- power_chan(DVDD2, 0.35);
- wait(POWER_UP_TIME);
- power_chan(SENSORVDD, 0.40);
- wait(POWER_UP_TIME);
- power_chan(SENSORLOWVDD, 0.45);
- wait(POWER_UP_TIME);
- power_chan(SENSORSTRESSVDD, 0.50);
- wait(POWER_UP_TIME);
- power_chan(CLOCKVDD, 0.55);
- wait(POWER_UP_TIME);
- power_chan(MEM1VDD, 0.60);
- wait(POWER_UP_TIME);
- power_chan(MEM2VDD, 0.65);
- wait(POWER_UP_TIME);
- power_chan(PLLAVDD, 0.70);
- wait(POWER_UP_TIME);
- power_chan(RING_OSC_NBIAS, 0.75);
- power_indicator = 1;
-}
-
-void scan_set_test()
-{
-
- rotate_chain();
- rotate_chain();
- int g = get_scan_bits("PLL_LFTUNE");
- pc.printf("initially %d\r\n", g); // should be 0
-
- set_scan_bits("PLL_LFTUNE", 27);
- rotate_chain();
- load_chip();
-
- //load_chain();
- rotate_chain();
-
-
- g = get_scan_bits("PLL_LFTUNE");
- pc.printf("then %d\r\n", g); // should be 27
-
- pc.printf("The 13th line of range is %d\r\n", get_binline_by_num("/local/Prange.txt", 13));
-
-}
-
-void jtag_test()
-{
- JTAG jtag;
- for(char ii=0x0; ii<=0xf; ii++){
- jtag.setIR(ii);
-
- //jtag.leaveState();
- jtag.setState('d');
-
- int rett = jtag.shiftBits(0xdeadbeef >> 1, 32);
- jtag.leaveState();
- pc.printf("ii %x, rett %x\r\n", ii, rett);
-
-}
-
-}
-void pll_test()
-{
- scan_pll(1, 1, 126, 1, 12, 32);
- unsigned long long freq = calc_pll_freqs(1, 1, 126, 1, 12, 32);
- freq = freq / 1000000; // in MHz
- int fMHz = freq;
-
- pc.printf("pll freq: %d MHz", fMHz);
-
- set_scan_bits("use_scan", 1);
- set_scan_bits("PLL_RESET", 1);
- set_scan_bits("intclk_source", 2);
- set_scan_bits("extclk_source", 1);
- set_scan_bits("ext_div_by", 10);
- rotate_chain();
- load_chip();
-
- set_scan_bits("PLL_RESET", 0);
- rotate_chain();
- load_chip();
-
- PORESETn = 1;
- CORERESETn = 1;
- set_scan_bits("RESET_scan", 1);
- set_scan_bits("CORERESET_scan", 1);
-
-}
\ No newline at end of file
--- a/board_test.h Tue Feb 11 21:36:52 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#include "mbed.h" -#include "dac.h" -#include "pinout.h" -#include "scan.h" -#include "pll.h" -#include "lcd.h" -#include "jtag.h" - -void analog_test(); -void scan_set_test(); -void lcd_test(); -void mem_test(JTAG &jtag); \ No newline at end of file
--- a/clock.cpp Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#include "clock.h"
-
-float ext_freq(DigitalIn* clk_pin)
-{
- bool last = false;
- unsigned int count = 0;
-
- Timer t;
- t.start();
- for(int i=0; i<100000; i++){
- bool clkval = *clk_pin;
- if(clkval && !last){
- count++;
- }
- last = clkval;
- }
- float time = t.read();
- t.stop();
- if(count < 1000){
- dual_printf("Clk read inaccurate");
- pc.printf("Clk count %d\r\n", count);
- }
- //pc.printf("T: %f\r\nC: %i\r\n", time, count);
-
- return count / time;
-}
\ No newline at end of file
--- a/clock.h Tue Feb 11 21:36:52 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -#include "mbed.h" -#include "lcd.h" -#include "pinout.h" - -float ext_freq(DigitalIn* clk_pin); \ No newline at end of file
--- a/dac.h Tue Feb 11 21:36:52 2014 +0000 +++ b/dac.h Tue Feb 25 02:14:41 2014 +0000 @@ -1,3 +1,6 @@ +#ifndef DAC_H_ +#define DAC_H_ + #include "mbed.h" #include "pinout.h" @@ -14,4 +17,6 @@ #define CHAN_G 0x36 #define CHAN_H 0x37 -void power_chan(char i2caddr, char chan, float voltage); +extern void power_chan(char i2caddr, char chan, float voltage); + +#endif
--- a/jtag.cpp Tue Feb 11 21:36:52 2014 +0000
+++ b/jtag.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -2,7 +2,8 @@
#include "mbed.h"
#include "pinout.h"
#include "mmap.h"
-#include "lcd.h"
+#include "panic.h"
+#include "basic_io.h"
using namespace std;
@@ -32,7 +33,7 @@
if(readdata[j-1] != word) {
mismatch++;
if(print) {
- pc.printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, readdata[j-1]);
+ mbed_printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, readdata[j-1]);
}
}
}
@@ -43,7 +44,7 @@
if(readdata[j-1] != word) {
mismatch++;
if(print) {
- pc.printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, readdata[j-1]);
+ mbed_printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, readdata[j-1]);
}
}
}
@@ -58,7 +59,7 @@
void JTAG::memWrite(unsigned int baseaddr, unsigned int writedata[], int size, bool zero)
{
if(zero){
- pc.printf("Called with %x, %x\r\n", baseaddr, size);
+ mbed_printf("Called with %x, %x\r\n", baseaddr, size);
}
writeBanksel(0);
writeAPACC(0x23000052, AP_CSW);
@@ -111,8 +112,7 @@
writeMemory(address, value);
value = readMemory(address);
if (! ((value & DHCSR_C_HALT) && (value & DHCSR_C_DEBUGEN)) ) {
- pc.printf("cannot halt the core, check DHCSR...\r\n");
- return -1;
+ panic("cannot halt the core, check DHCSR...\r\n");
}
// dual_printf("Reading Program HEX");
@@ -120,8 +120,7 @@
FILE *fp = fopen("/local/program.txt", "r");
// pc.printf("Program open\r\n");
if (fp == NULL) {
- pc.printf("Error in open /local/program.txt\r\n");
- return -1;
+ panic("Error in open /local/program.txt\r\n");
}
// Similar to MemWrite here
@@ -158,7 +157,7 @@
fscanf(fp, "%X", &d);
if(d != word) {
mismatch++;
- pc.printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, d);
+ mbed_printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, d);
}
}
if(!feof(fp)){
@@ -167,14 +166,13 @@
fscanf(fp, "%X", &d);
if(d != word) {
mismatch++;
- pc.printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, d);
+ mbed_printf("Mismatch line %x, was %x, expected %x\r\n", j-1, word, d);
}
}
addr = addr + 1024*4;
}
if(mismatch) {
- dual_printf("Mem Load Failed");
- return -1;
+ panic("Mem Load Failed");
}
fclose(fp);
@@ -265,40 +263,45 @@
writeDPACC(0x12345678, DP_SELECT);
int rd = readDPACC(DP_SELECT);
if(rd != 0x12000070) {
- pc.printf("DP SELECT %x", rd);
- exit(1);
+ //pc.printf("DP SELECT %x", rd);
+ //exit(1);
+ panic("DP SELECT %x", rd);
}
writeDPACC(0xedcba987, DP_SELECT);
rd = readDPACC(DP_SELECT);
if(rd != 0xed000080) {
- pc.printf("DP SELECT %x", rd);
- exit(1);
+ //pc.printf("DP SELECT %x", rd);
+ //exit(1);
+ panic("DP SELECT %x", rd);
}
writeDPACC(0x10000000, DP_CTRLSTAT);
rd = readDPACC(DP_CTRLSTAT);//////////////////////////////////////////////////////////////
if(rd != 0x30000000) {
- pc.printf("DP CTRL %x", rd);
- exit(1);
+ //pc.printf("DP CTRL %x", rd);
+ //exit(1);
+ panic("DP CTRL %x", rd);
}
writeDPACC(0x40000000, DP_CTRLSTAT);
rd = readDPACC(DP_CTRLSTAT);
if(rd != 0xc0000000) {
- pc.printf("DP CTRL %x", rd);
- exit(1);
+ //pc.printf("DP CTRL %x", rd);
+ //exit(1);
+ panic("DP CTRL %x", rd);
}
writeDPACC(0x50000000, DP_CTRLSTAT);
rd = readDPACC(DP_CTRLSTAT);
if(rd != 0xf0000000) {
- pc.printf("DP CTRL %x", rd);
- exit(1);
+ //pc.printf("DP CTRL %x", rd);
+ //exit(1);
+ panic("DP CTRL %x", rd);
}
writeBanksel(0xf);
rd = readAPACC(AP_IDR);
if(rd != 0x24770011) {
- pc.printf("AP IDR %x", rd);
- exit(1);
+ //pc.printf("AP IDR %x", rd);
+ //exit(1);
+ panic("AP IDR %x", rd);
}
- //dual_printf("DAP Activated");
}
// --------------------------------
@@ -310,8 +313,9 @@
setState('i');
char one = shiftBits(A, 4);
if(one != 1) {
- dual_printf("ERROR: JTAG IR");
- pc.printf("Got %x instead of 1\r\n", one);
+ //dual_printf("ERROR: JTAG IR");
+ //pc.printf("Got %x instead of 1\r\n", one);
+ panic("ERROR: JTAG IR. Got %x instead of 1\r\n", one);
}
leaveState();
}
@@ -437,9 +441,10 @@
} else if(okstat == 2) {
// Got OK/FAULT
} else {
- dual_printf("invalid OK Stat");
+ //dual_printf("invalid OK Stat");
leaveState();
- exit(1);
+ //exit(1);
+ panic("%s\r\n", "invalid OK Stat");
}
}
--- a/jtag.h Tue Feb 11 21:36:52 2014 +0000
+++ b/jtag.h Tue Feb 25 02:14:41 2014 +0000
@@ -7,6 +7,9 @@
// DHCSR: Debug Halting Control and Status Register.
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/CEGCJAHJ.html
+#ifndef JTAG_H
+#define JTAG_H
+
#define DHCSR_ADDR 0xE000EDF0
#define DCRSR_ADDR 0xE000EDF4
@@ -81,8 +84,7 @@
#define SW_DP_ACK_WAIT 2
#define SW_DP_ACK_FAULT 4
-#ifndef JTAG_H
-#define JTAG_H
+
class JTAG
{
--- a/lcd.cpp Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,207 +0,0 @@
-#include "mbed.h"
-#include "lcd.h"
-
-int lcdlinenum;
-
-void dual_printf(char* a){
- pc.printf(a);
- pc.printf("\r\n");
-
- lcd_clear_line(lcdlinenum);
-
- lcd_printf(a);
- if(lcdlinenum > 3){
- lcdlinenum = 1;
- }else{
- lcdlinenum++;
- }
-}
-
-/********************************************************************
- lcd default
-********************************************************************/
-void lcd_default()
-{
- lcdlinenum = 1;
- lcd.frequency(10000);
- lcd_clear();
- lcd_set_contrast( 40 );
- lcd_backlight_level( 8 );
- lcd_cursor_blink(1);
-}
-/********************************************************************
- lcd clear
-********************************************************************/
-void lcd_clear()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x51;
- lcd.write(LCDADDR, data, 2, false);
- wait_ms(2);
-}
-/********************************************************************
- lcd home
-********************************************************************/
-void lcd_home()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x46;
- lcd.write(LCDADDR, data, 2, false);
- wait_ms(2);
-}
-
-void lcd_printf(char* message){
- lcd.write(LCDADDR, message, strlen(message), false);
-}
-
-/********************************************************************
- clear one line of display
-********************************************************************/
-void lcd_clear_line(unsigned int line)
-{
- switch (line){
- case 1:
- lcd_goto( LINE1_BEGIN );
- lcd_printf(" ");
- lcd_goto( LINE1_BEGIN );
- break;
- case 2:
- lcd_goto( LINE2_BEGIN );
- lcd_printf(" ");
- lcd_goto( LINE2_BEGIN );
- break;
- case 3:
- lcd_goto( LINE3_BEGIN );
- lcd_printf(" ");
- lcd_goto( LINE3_BEGIN );
- break;
- case 4:
- lcd_goto( LINE4_BEGIN );
- lcd_printf(" ");
- lcd_goto( LINE4_BEGIN );
- break;
- default:
- break;
- }
- wait_ms(5);
-}
-
-void lcd_cursor_blink(bool blink){
- char data[10];
- data[0] = 0xFE;
- if(blink){
- data[1] = 0x4b;
- }else{
- data[1] = 0x4c;
- }
-
- lcd.write(LCDADDR, data, 2, false);
-
- wait_ms(2);
-}
-
-/********************************************************************
- lcd cursor goto
-********************************************************************/
-void lcd_goto(unsigned int position)
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x45;
- data[2] = position;
- lcd.write(LCDADDR, data, 3, false);
-
- wait_ms(2);
-}
-/********************************************************************
- lcd set contrast
-********************************************************************/
-void lcd_set_contrast(unsigned int level)
-{
- if(level > 50){ level = 50; }
-
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x52;
- data[2] = level;
- lcd.write(LCDADDR, data, 3, false);
-
- wait_ms(10);
-}
-/********************************************************************
- lcd set backlight level
-********************************************************************/
-void lcd_backlight_level(unsigned int level)
-{
- if(level > 8){ level = 8; }
-
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x53;
- data[2] = level;
- lcd.write(LCDADDR, data, 3, false);
-
- wait_ms(2);
-}
-/********************************************************************
- lcd set backlight level
-********************************************************************/
-void lcd_shift_right()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x56;
- lcd.write(LCDADDR, data, 2, false);
-
- wait_ms(1);
-}
-/********************************************************************
- lcd set backlight level
-********************************************************************/
-void lcd_shift_left()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x55;
- lcd.write(LCDADDR, data, 2, false);
-
- wait_ms(1);
-}
-/********************************************************************
- lcd set backlight level
-********************************************************************/
-void lcd_cursor_right()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x4A;
- lcd.write(LCDADDR, data, 2, false);
-
- wait_ms(1);
-}
-/********************************************************************
- lcd set backlight level
-********************************************************************/
-void lcd_cursor_left()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x49;
- lcd.write(LCDADDR, data, 2, false);
-
- wait_ms(1);
-}
-/********************************************************************
- lcd set backlight level
-********************************************************************/
-void lcd_backspace()
-{
- char data[10];
- data[0] = 0xFE;
- data[1] = 0x4E;
- lcd.write(LCDADDR, data, 2, false);
-
- wait_ms(1);
-}
\ No newline at end of file
--- a/lcd.h Tue Feb 11 21:36:52 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ - //******************************************************************* - // * October, 2012 - // * Definitions for I2C LCD program - // * - // * - // * - /******************************************************************** - function protocol: - 0xFE, 0x41 - display on - 0xFE, 0x42 - display off - 0xFE, 0x45 - set cursor position - 0xFE, 0x46 - home cursor - 0xFE, 0x47 - underline cursor on - 0xFE, 0x48 - underline cursor off - 0xFE, 0x49 - move cursor left 1 space - 0xFE, 0x4A - move cursor right 1 space - 0xFE, 0x4B - blinking cursor on - 0xFE, 0x4C - blinking curson off - 0xFE, 0x4E - back space. - 0xFE, 0x51 - clear screen - 0xFE, 0x52 - set contrast (1-50) - 0xFE, 0x53 - set backlight brightness (1-16) - 0xFE, 0x54 - load custom characters - - 0xFE, 0x55 - move screen left 1 space - 0xFE, 0x56 - move screen right 1 space - - 0xFE, 0x61 - change BAUD rate (1 - 8) - 0xFE, 0x62 - change I2C address (0-255) - 0xFE, 0x70 - display version number - 0xFE, 0x71 - display RS232 BAUD rate - 0xFE, 0x72 - display I2C address - 0xFE, 0xFE - send next byte to command register - ********************************************************************/ - #include "mbed.h" - #include "pinout.h" - - // I2C Addr Pin - #define LCDADDR 0x50 - - #define LINE1_BEGIN 0x00 - #define LINE2_BEGIN 0x40 - #define LINE3_BEGIN 0x14 - #define LINE4_BEGIN 0x54 - - #define LINE1_END 0x13 - #define LINE2_END 0x53 - #define LINE3_END 0x27 - #define LINE4_END 0x67 - - // proto type functions - void dual_printf(char* a); - void lcd_default(); - void lcd_clear(); - void lcd_home(); - void lcd_clear_line(unsigned int line); - void lcd_goto(unsigned int position); - void lcd_set_contrast(unsigned int level); - void lcd_backlight_level(unsigned int level); - void lcd_shift_right(); - void lcd_shift_left(); - void lcd_cursor_right(); - void lcd_cursor_left(); - void lcd_backspace(); - void lcd_cursor_blink(bool blink); - void lcd_printf(char* message); \ No newline at end of file
--- a/main.cpp Tue Feb 11 21:36:52 2014 +0000
+++ b/main.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -1,56 +1,40 @@
-#include <InterruptIn.h>
#include "mbed.h"
-#include "dac.h"
-#include "board_test.h"
-#include "scan.h"
+#include "rtos.h"
#include "power.h"
#include "pinout.h"
#include "pll.h"
-#include "lcd.h"
#include "jtag.h"
#include "mmap.h"
-#include "clock.h"
-#include "EasyBMP.h"
+#include "GPIOInterrupt.h"
+#include "basic_io.h"
+#include "panic.h"
#include "main.h"
-#include "serialIO.h"
+#include "signal.h"
-InterruptIn GPIO_int(GPIO_int_pin);
-JTAG *pJtag;
+// pointer to thread
+Thread *thread_ptr;
-void trigger() {
- for (int i = 0; i < 2; ++i) {
- sprintf(tx_line, "hex is: %08x\r\n", pJtag->readMemory(0x24000110 + i * 4));
- send_line();
- }
-}
+void init_hw(void);
+void req_intr_handler(void);
+void print_rambuffer(void const *args);
int main()
{
- float core_volt = 1;
-
- //wdt.kick(20.0);
- pc.printf("Begin FFT\r\n");
- power_down();
- power_up(core_volt); // Power Up Chip
- pc.printf("Powered up!\r\n");
-
- PORESETn = 0;
- CORERESETn = 0;
- wait_us(100);
- PORESETn = 1;
- CORERESETn = 1;
-
+ init_hw();
+
JTAG jtag;
- pJtag = &jtag;
// We check if JTAG works well by checking idcode returned by issuing a test instruction and read result idcode back.
int idcode = jtag.readID();
if(idcode != 0x4ba00477) {
- pc.printf("ERROR: IDCode %X\r\n", idcode);
- wait(2);
- power_down();
- return -1;
+ panic("ERROR: IDCode %X\r\n", idcode);
}
- pc.printf("IDCode %X\r\n", idcode);
+
+ // create working threads first
+ Thread core_handler(listen_req, (void *)(&jtag));
+ Thread debugThread(print_rambuffer, (void *)(&jtag));
+ thread_ptr = &core_handler;
+ // enable GPIO interrupt
+ enable_GPIO_intr(&req_intr_handler);
jtag.reset();
jtag.leaveState();
@@ -62,79 +46,71 @@
power_core(1);
set_pll_frequency (200, jtag);
- // attach new interrupt handler
- pc.attach(&Tx_interrupt, Serial::TxIrq);
- pc.attach(&Rx_interrupt, Serial::RxIrq);
// Begin to load program
- sprintf(tx_line, "Begining loading program.\r\n");
- send_line();
+ mbed_printf("Begining loading program.\r\n");
if (jtag.loadProgram()) {
- sprintf(tx_line, "Load Failed!\r\n");
- send_line();
+ mbed_printf("Load Failed!\r\n");
} else {
+ mbed_printf("Load Succeed!\r\n");
CORERESETn = 0;
- CORERESETn = 1;
- wait(0.2);
- jtag.reset();
- jtag.leaveState();
- jtag.PowerupDAP();
+ CORERESETn = 1;
+ char line[80];
- sprintf(tx_line, "JTAG initialization finished.\r\n");
- send_line();
- // Enable interrupt from GPIO. Each time when an GPIO interrupt happens, we read an unsigned int
- // from a certain address of cortex-m3 through JTAG-DP
- GPIO_int.rise(&trigger);
- GPIO_int.mode(PullDown);
while (1) {
- sprintf(tx_line, "Type 'quit' to quit. Press any key to continue.\r\n");
- send_line();
- read_line();
- if (strncmp(rx_line, "quit", 80) == 0)
+
+ mbed_printf("Type 'quit' to quit.\r\n");
+ mbed_scanf("%s", line);
+ if (strncmp(line, "quit", 80) == 0)
break;
+ else if (strncmp(line, "debug", 80) == 0)
+ debugThread.signal_set(SIG_DEBUG);
+
}
+
}
-
- sprintf(tx_line, "Powering Down\r\n");
- send_line();
+
+ core_handler.terminate();
+ thread_ptr = NULL;
+ jtag.reset();
+
+ mbed_printf("Powering Down\r\n");
power_down();
- sprintf(tx_line, "Done.\r\n");
- send_line();
+ mbed_printf("Done.\r\n");
while (1)
;
}
-void DDRO_Sensor(JTAG &jtag)
-{
- /**********************enable****************************************/
- jtag.writeMemory(ddro_syn_en, 0xffffffff);
- jtag.writeMemory(ddro_inv_en, 0xffffffff);
- /**********************set ref_clk and samp_clk**********************/
- jtag.writeMemory(ddro_ref_src, 0x00000002);
- /**********************write threshold*******************************/
- jtag.writeMemory(ddro_threshold, 100000);
- //jtag.writeMemory(0xe000e104, 0x000000ff); // enable interrupts
+void init_hw(void) {
+ float core_volt = 1;
+ power_down();
+ power_up(core_volt); // Power Up Chip
+ mbed_printf("Powered up!\r\n");
+
+ PORESETn = 0;
+ CORERESETn = 0;
+ wait_us(100);
+ PORESETn = 1;
+ CORERESETn = 1;
+}
- for (int ro_id=3;ro_id<=15;ro_id++) {
- pc.printf("RO %d\r\n ", ro_id-2);
- jtag.writeMemory(ddro_samp_src, ro_id);
- jtag.writeMemory(ddro_start, 0);
- int meas1 = jtag.readMemory(ddro_count);
- pc.printf("Counter starts at: %d ", meas1);
- jtag.writeMemory(ddro_start, 1);
- wait_us(50000);
- jtag.writeMemory(ddro_start, 0);
- meas1 = jtag.readMemory(ddro_count);
- pc.printf("ends at: %d\r\n", meas1);
-
- jtag.writeMemory(ddro_samp_src, ro_id);
- jtag.writeMemory(ddro_start, 0);
- meas1 = jtag.readMemory(ddro_count);
- pc.printf("Counter starts at: %d ", meas1);
- jtag.writeMemory(ddro_start, 1);
- wait_us(50000);
- jtag.writeMemory(ddro_start, 0);
- meas1 = jtag.readMemory(ddro_count);
- printf("ends at: %d\r\n", meas1);
+void req_intr_handler(void) {
+ if (thread_ptr)
+ thread_ptr->signal_set(SIG_COREREQ);
+ return;
+}
+
+void print_rambuffer(void const *args) {
+ static bool init = true;
+ JTAG *pJtag = (JTAG *)args;
+ while (1) {
+ Thread::signal_wait(SIG_DEBUG);
+ if (init) {
+ pJtag->reset();
+ pJtag->leaveState();
+ pJtag->PowerupDAP();
+ init = false;
+ }
+ debug_print(pJtag);
}
}
--- a/main.h Tue Feb 11 21:36:52 2014 +0000 +++ b/main.h Tue Feb 25 02:14:41 2014 +0000 @@ -22,6 +22,4 @@ }; Watchdog wdt; -void DDRO_Sensor(JTAG &jtag); -int check_FFT_Freq(JTAG &jtag, int fMHz); #endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Feb 25 02:14:41 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#f88660a9bed1
--- a/mbed.bld Tue Feb 11 21:36:52 2014 +0000 +++ b/mbed.bld Tue Feb 25 02:14:41 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/869cf507173a \ No newline at end of file
--- a/mmap.cpp Tue Feb 11 21:36:52 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -#include "mmap.h"
--- a/mmap.h Tue Feb 11 21:36:52 2014 +0000 +++ b/mmap.h Tue Feb 25 02:14:41 2014 +0000 @@ -1,9 +1,19 @@ +#ifndef MMAP_H_ +#define MMAP_H_ + // SRAM Limits #define IMEM_MIN 0x00000000 #define IMEM_MAX 0x00010000 #define DMEM_MIN 0x20000000 #define DMEM_MAX 0x2002C000 +// ram buffer for data transmission between mbed and cortex-m3 +// read from IO_TYPE to check whether the request is print or scan request +#define RAMBUF_BEGIN (0x24000100) +#define RAMBUF_END (0x2400017C) +#define RAMBUF_SIZE ((RAMBUF_END - RAMBUF_BEGIN)*4) +#define IO_TYPE (0x2400017C) + // Redefine Imem addr from 0x10000000 to 0x00000000 #define set_imem 0x44000008 @@ -258,3 +268,5 @@ #define dmem_CRE 0x441001f0 #define dmem_RR 0x441001f4 #define dmem_RRE 0x441001f8 + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/panic.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -0,0 +1,25 @@
+/*
+ * Written by Zimin Wang
+ *
+ */
+#include "mbed.h"
+#include "pinout.h"
+#include "power.h"
+#include "panic.h"
+#include "basic_io.h"
+
+// When error happens, print error message, power down the core and terminate
+void panic(const char *format, ...)
+{
+ // print error message
+ va_list args;
+ va_start(args, format);
+
+ mbed_vprintf(format, args);
+ va_end(args);
+
+ wait(2);
+ power_down();
+
+ exit(1);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/panic.h Tue Feb 25 02:14:41 2014 +0000 @@ -0,0 +1,11 @@ +/* + * Written by Zimin Wang + * + */ +#ifndef PANIC_H_ +#define PANIC_H_ + +// When some error happens, print error message and terminate +extern void panic(const char *format, ...); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pinout.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+#include "pinout.h"
+
+LocalFileSystem local("local");
+Serial pc(USBTX, USBRX);//tx, rx => for debugging purposes
+
+// TI DAC7578 interface
+//static BusOut CLR_BAR(p5, p7);
+//static BusOut LDAC_BAR(p6, p8);
+I2C dac_i2c(p9, p10); //sda, scl
+
+I2C lcd(p9, p10);
+
+// LED Indicators
+DigitalOut power_indicator (LED1);
+DigitalOut power_error_indicator (LED4);
+DigitalOut wait_indicator (LED2);
+
+// To Chip
+DigitalOut PORESETn(p11);
+DigitalOut CORERESETn(p12);
+
+// From Chip
+DigitalIn HCLK_div_down(p5);
+DigitalIn RO_clock_out(p6);
+
+// GPIO to/from Chip
+//static BusInOut GPIO(p7, p16, p15);
+
+// Analog in from amplifier (for power measurement)
+AnalogIn meas_sen(p17);
+AnalogIn meas_mem2(p18);
+AnalogIn meas_mem1(p19);
+AnalogIn meas_core(p20);
+DigitalOut gain_ctrl(p8);
+
+// Scan
+DigitalOut scan_data_in(p30);
+DigitalOut scan_phi(p29);
+DigitalOut scan_phi_bar(p13);
+DigitalOut scan_load_chain(p14);
+DigitalOut scan_load_chip(p26);
+DigitalIn scan_data_out(p25);
+
+// JTAG
+DigitalOut TCK(p24);
+DigitalOut TMS(p23);
+DigitalOut TDI(p22);
+DigitalIn TDO(p21);
\ No newline at end of file
--- a/pinout.h Tue Feb 11 21:36:52 2014 +0000
+++ b/pinout.h Tue Feb 25 02:14:41 2014 +0000
@@ -1,53 +1,54 @@
#ifndef PINOUT_H
#define PINOUT_H
-static LocalFileSystem local("local");
-static Serial pc(USBTX, USBRX);//tx, rx => for debugging purposes
+extern LocalFileSystem local;
+extern Serial pc;
// TI DAC7578 interface
-//static BusOut CLR_BAR(p5, p7);
-//static BusOut LDAC_BAR(p6, p8);
-static I2C dac_i2c(p9, p10); //sda, scl
+//extern BusOut CLR_BAR(p5, p7);
+//extern BusOut LDAC_BAR(p6, p8);
+extern I2C dac_i2c; //sda, scl
-static I2C lcd(p9, p10);
+extern I2C lcd;
// LED Indicators
-static DigitalOut power_indicator (LED1);
-static DigitalOut power_error_indicator (LED4);
-static DigitalOut wait_indicator (LED2);
+extern DigitalOut power_indicator;
+extern DigitalOut power_error_indicator;
+extern DigitalOut wait_indicator;
// To Chip
-static DigitalOut PORESETn(p11);
-static DigitalOut CORERESETn(p12);
+extern DigitalOut PORESETn;
+extern DigitalOut CORERESETn;
// From Chip
-static DigitalIn HCLK_div_down(p5);
-static DigitalIn RO_clock_out(p6);
+extern DigitalIn HCLK_div_down;
+extern DigitalIn RO_clock_out;
// GPIO to/from Chip
-//static BusInOut GPIO(p7, p16, p15);
+//extern BusInOut GPIO(p7, p16, p15);
#define GPIO_int_pin (p15)
+#define GPIO_ack_pin (p16)
// Analog in from amplifier (for power measurement)
-static AnalogIn meas_sen(p17);
-static AnalogIn meas_mem2(p18);
-static AnalogIn meas_mem1(p19);
-static AnalogIn meas_core(p20);
-static DigitalOut gain_ctrl(p8);
+extern AnalogIn meas_sen;
+extern AnalogIn meas_mem2;
+extern AnalogIn meas_mem1;
+extern AnalogIn meas_core;
+extern DigitalOut gain_ctrl;
// Scan
-static DigitalOut scan_data_in(p30);
-static DigitalOut scan_phi(p29);
-static DigitalOut scan_phi_bar(p13);
-static DigitalOut scan_load_chain(p14);
-static DigitalOut scan_load_chip(p26);
-static DigitalIn scan_data_out(p25);
+extern DigitalOut scan_data_in;
+extern DigitalOut scan_phi;
+extern DigitalOut scan_phi_bar;
+extern DigitalOut scan_load_chain;
+extern DigitalOut scan_load_chip;
+extern DigitalIn scan_data_out;
// JTAG
-static DigitalOut TCK(p24);
-static DigitalOut TMS(p23);
-static DigitalOut TDI(p22);
-static DigitalIn TDO(p21);
+extern DigitalOut TCK;
+extern DigitalOut TMS;
+extern DigitalOut TDI;
+extern DigitalIn TDO;
#define POWER_UP_TIME 0.01
--- a/pll.cpp Tue Feb 11 21:36:52 2014 +0000
+++ b/pll.cpp Tue Feb 25 02:14:41 2014 +0000
@@ -77,6 +77,7 @@
return strtol(value, NULL, 2);
}
+/*
void scan_pll(unsigned int prediv, unsigned int multint_upper, unsigned int multint,
unsigned int range_upper, unsigned int rangea, unsigned int rangeb){
@@ -97,7 +98,7 @@
set_scan_bits("PLL_RANGEA", range_upper << 5 | rangea);
set_scan_bits("PLL_RANGEB", range_upper << 5 | rangeb);
}
-
+*/
void jtag_pll(JTAG &jtag, unsigned int prediv, unsigned int multint_upper, unsigned int multint,
unsigned int range_upper, unsigned int rangea, unsigned int rangeb){
--- a/pll.h Tue Feb 11 21:36:52 2014 +0000 +++ b/pll.h Tue Feb 25 02:14:41 2014 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" -#include "scan.h" +//#include "scan.h" #include "pinout.h" #include "jtag.h" #include "mmap.h"
--- a/scan.cpp Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-#include "scan.h"
-#include "lcd.h"
-
-
-void scan_clear()
-{
- dual_printf("Clearing Scan Bits");
- scan_data_in = 0;
- scan_load_chain = 0;
- scan_phi = 1;
- scan_phi_bar = 1;
- scan_load_chip = 1;
-
- // 0 all inputs again
- scan_phi = 0;
- scan_phi_bar = 0;
- scan_load_chip = 0;
-}
-
-void scan_init()
-{
- scan_clear();
-
- //pc.printf("Opening Scan File\r\n");
- FILE *fp = fopen("/local/scan.txt", "r");
- if(!fp){
- dual_printf("ERROR: scan file not found");
- }
- //pc.printf("Scan File Open\r\n");
- {
- unsigned int high = 0;
- unsigned int low = 0;
- char sig_name[255];
-
- // First pass through file to find number of variables, length of chain, and longest var name
- int n = 0;
- while (!feof(fp)) {
- fscanf(fp, "%d:%d %s", &high, &low, sig_name);
- n++;
- }
- rewind(fp);
- scan_num_vars = n;
- scan_length = high + 1;
- pc.printf("Scan chain length %d, %d variables\r\n", scan_length, scan_num_vars);
-
- // Declare dynamic memory using sizes just found
- scan_bits = new char[scan_length];
- scan_out = new char[scan_length];
- for(int i=0; i<scan_length; i++) {
- scan_bits[i] = 0;
- scan_out[i] = 0;
- }
-
- scan_highs = new int[scan_num_vars];
- scan_lows = new int[scan_num_vars];
- scan_names = new char*[scan_num_vars];
-
- n = 0;
- while (!feof(fp)) {
- fscanf(fp, "%d:%d %s", &high, &low, sig_name);
-
- scan_highs[n] = high;
- scan_lows[n] = low;
- scan_names[n] = new char[strlen(sig_name)+1];
- strcpy(scan_names[n], sig_name);
- //pc.printf("Read line signal %s, h=%i, l=%i\r\n", scan_names[n], scan_highs[n], scan_lows[n]);
- n++;
- }
- }
- //pc.printf("Closing Scan File\r\n");
- fclose(fp);
- //pc.printf("File Scan Closed\r\n");
-}
-
-int get_var_idx(char* varname)
-{
- for(int i=0; i<scan_num_vars; i++) {
- if(!strcmp(varname, scan_names[i])) {
- return i;
- }
- }
- dual_printf("ERROR - INVALID SCAN VARIABLE");
- dual_printf(varname);
- return -1;
-}
-
-void set_scan_bits(char* varname, unsigned int value)
-{
- int idx = get_var_idx(varname);
-
- int j=0;
- for(int i=scan_lows[idx]; i<=scan_highs[idx]; i++) {
- scan_bits[i] = (value & (1 << j)) >> j;
- j++;
- }
-}
-
-unsigned int get_scan_bits(char* varname){
- int idx = get_var_idx(varname);
- unsigned int value = 0;
-
- int j = 0;
- for(int i=scan_lows[idx]; i<=scan_highs[idx]; i++) {
- value = value | (scan_out[i] << j);
- j++;
- }
-
- return value;
-}
-
-void load_chip()
-{
- scan_load_chip = 1;
- scan_load_chip = 0;
-}
-
-void load_chain()
-{
- scan_load_chain = 1;
- scan_phi = 1;
- scan_phi = 0;
- scan_phi_bar = 1;
- scan_phi_bar = 0;
- scan_load_chain = 0;
-}
-
-void rotate_chain()
-{
- for(int i=0; i<scan_length; i++) {
- scan_data_in = scan_bits[i];
- scan_out[i] = scan_data_out;
- scan_phi = 1;
- scan_phi = 0;
- scan_phi_bar = 1;
- scan_phi_bar = 0;
- }
-}
\ No newline at end of file
--- a/scan.h Tue Feb 11 21:36:52 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#include "mbed.h" -#include "pinout.h" - -#ifndef SCAN_H -#define SCAN_H - -static char* scan_bits; -static char* scan_out; -static int scan_length; - -static int* scan_highs; -static int* scan_lows; -static char** scan_names; -static int scan_num_vars; - -void scan_clear(); -void scan_init(); -int get_var_idx(char* varname); -void set_scan_bits(char* varname, unsigned int value); -unsigned int get_scan_bits(char* varname); -void load_chip(); -void load_chain(); -void rotate_chain(); - -#endif \ No newline at end of file
--- a/serialIO.cpp Tue Feb 11 21:36:52 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-#include "mbed.h"
-#include "pinout.h"
-#include "serialIO.h"
-
-// buffer for TX and RX
-char tx_buffer[buffer_size];
-char rx_buffer[buffer_size];
-// buffer for sscanf and sprintf
-char tx_line[80];
-char rx_line[80];
-
-// index marking the begin/end of rx_buffer and tx_buffer
-volatile int tx_out = 0;
-volatile int tx_in = 0;
-volatile int rx_out = 0;
-volatile int rx_in = 0;
-
-// Copy tx line buffer to large tx buffer for tx interrupt routine
-void send_line() {
- int i;
- char temp_char;
- bool empty;
- i = 0;
-// Start Critical Section - don't interrupt while changing global buffer variables
- NVIC_DisableIRQ(USB_IRQn);
- empty = (tx_in == tx_out);
- while ((i==0) || (tx_line[i-1] != '\n')) {
-// Wait if buffer full
- if (((tx_in + 1) % buffer_size) == tx_out) {
-// End Critical Section - need to let interrupt routine empty buffer by sending
- NVIC_EnableIRQ(USB_IRQn);
- while (((tx_in + 1) % buffer_size) == tx_out) {
- }
-// Start Critical Section - don't interrupt while changing global buffer variables
- NVIC_DisableIRQ(USB_IRQn);
- }
- tx_buffer[tx_in] = tx_line[i];
- i++;
- tx_in = (tx_in + 1) % buffer_size;
- }
- if (pc.writeable() && (empty)) {
- temp_char = tx_buffer[tx_out];
- tx_out = (tx_out + 1) % buffer_size;
-// Send first character to start tx interrupts, if stopped
- pc.putc(temp_char);
- }
-// End Critical Section
- NVIC_EnableIRQ(USB_IRQn);
- return;
-}
-
-// Interupt Routine to write out data to serial port
-void Tx_interrupt() {
-// Loop to fill more than one character in UART's transmit FIFO buffer
-// Stop if buffer empty
- while ((pc.writeable()) && (tx_in != tx_out)) {
- pc.putc(tx_buffer[tx_out]);
- tx_out = (tx_out + 1) % buffer_size;
- }
- return;
-}
-
-// Read a line from the large rx buffer from rx interrupt routine
-void read_line() {
- int i;
- i = 0;
-// Start Critical Section - don't interrupt while changing global buffer variables
- NVIC_DisableIRQ(USB_IRQn);
-// Loop reading rx buffer characters until end of line character
- while ((i==0) || (rx_line[i-1] != '\r')) {
-// Wait if buffer empty
- if (rx_in == rx_out) {
-// End Critical Section - need to allow rx interrupt to get new characters for buffer
- NVIC_EnableIRQ(USB_IRQn);
- while (rx_in == rx_out) {
- }
-// Start Critical Section - don't interrupt while changing global buffer variables
- NVIC_DisableIRQ(USB_IRQn);
- }
- rx_line[i] = rx_buffer[rx_out];
- i++;
- rx_out = (rx_out + 1) % buffer_size;
- }
-// End Critical Section
- NVIC_EnableIRQ(USB_IRQn);
- rx_line[i-1] = 0;
- return;
-}
-
-// Interupt Routine to read in data from serial port
-void Rx_interrupt() {
-// Loop just in case more than one character is in UART's receive FIFO buffer
-// Stop if buffer full
- while ((pc.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
- rx_buffer[rx_in] = pc.getc();
-// Uncomment to Echo to USB serial to watch data flow
-// monitor_device.putc(rx_buffer[rx_in]);
- rx_in = (rx_in + 1) % buffer_size;
- }
- return;
-}
--- a/serialIO.h Tue Feb 11 21:36:52 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#ifndef SERIALIO_H -#define SERIALIO_H - -#include "pinout.h" - -const int buffer_size = 255; - -extern char rx_line[]; -extern char tx_line[]; -// functions for sending data -extern void send_line(); -extern void Tx_interrupt(); -// functions for receiving data -extern void read_line(); -extern void Rx_interrupt(); -#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/signal.h Tue Feb 25 02:14:41 2014 +0000 @@ -0,0 +1,11 @@ +#ifndef SIGNAL_H_ +#define SIGNAL_H_ + +// core send a print or scan request to mbed +#define SIG_COREREQ (0x1) +//#define SIG_TERMREAD (0x1) + +// user type debug, wake up a thread to print content of ram buffer for debug +#define SIG_DEBUG (0x2) + +#endif \ No newline at end of file
