//============================================================================== // // AVRcard - Monitor // //============================================================================== // // This firmware source code is for free. You can redistribute, copy and // modify it. It is distributed in the hope that it will be useful, // but without any warranty. // // Check the applications section of www.avrcard.com for updates and further // information on this project. // // Have fun. // // Hans Kallen, www.avrcard.com, August 2003 // //============================================================================== // // Version Date Author Changes // ------- ---------- ------- ------------------------------ // 1.1 01.05.2003 HK Initial public release // // Compiler // -------- // AVRco Rev. 5.35 or higher (by www.e-lab.de) // //////////////////////////////////////////////////////////////////////////////// program monitor_sample; {$NOSHADOW} { $W+ Warnings} {Warnings off} Device = mega128, VCC=5; Import SysTick, SerPort, SerPort2, I2Cport, FileSystem, ADCPort; From SerPort import SerPortSelect; // used for serial port selection From System import Processes, Pipes, Longword, Float; Define ProcClock = 16000000; {Hertz} StackSize = 32, iData; FrameSize = 32, iData; Systick = 2; Scheduler = iData; SerPort = 19200, Stop1; TxBuffer = 100,iData; RxBuffer = 100,iData; SerPort2 = 19200, Stop1; TxBuffer2 = 100,iData; RxBuffer2 = 100,iData; I2Cport = PortD; I2Cdat = 1; I2Cclk = 0; // !!! defines below used for user specific monitor functions in this file only !!! // !!! as well as imports above corresponding to them !!! //--------------------------------------------------------------------------------- FileBuffer = iData; FileHandles = 1, iData; Disk_A = 32; // max kBytes according hardware SecTrk_A = 128; // must allways be the same value ! ADCchans = 8, iData; ADCpresc = 8; uses monitor, fm24c256; Implementation {$IDATA} {--------------------------------------------------------------} { Type Declarations } type {--------------------------------------------------------------} { Const Declarations } const // define user specific commands // !!! mId must start with 1 as mId 0 is used for help text output !!! structconst commandArray : array[0..10] of TMonitorCommand = ((mId: 1; mText: 'cf'), // create file (mId: 2; mText: 'df'), // delete file (mId: 3; mText: 'wf'), // write text to file (mId: 4; mText: 'rf'), // read file content (mId: 5; mText: 'fseek'), // read file content at specific address (mId: 6; mText: 'fdump'), // file hex dump (mId: 7; mText: 'dir'), // show files on virtual disk (mId: 8; mText: 'disk'), // show free virtual disk space (mId: 9; mText: 'format'), // format virtual disk) (mId: 10; mText: 'vref'), // set reference voltage for adc (mId: 11; mText: 'adc')); // show input voltage at adc ports {--------------------------------------------------------------} { Var Declarations } {$IDATA} var ff : file of byte; vRef : float; {--------------------------------------------------------------} { functions } function monFileOpen(name : string[15]) : boolean; //-------------------------------------------------------------- begin if FileOpen(ff, name) then return(true); else writeln(serout, 'open file of ' + name + ' failed'); endif; return(false); end; procedure monHelpText; //-------------------------------------------------------------- begin writeln(serout, 'cf : create file'); writeln(serout, 'df : delete file'); writeln(serout, 'wf : write text to file'); writeln(serout, 'rf : read file content'); writeln(serout, 'fseek : read file content at specific address'); writeln(serout, 'fdump : file hex dump'); writeln(serout, 'dir : show files on virtual disk'); writeln(serout, 'disk : show free virtual disk space'); writeln(serout, 'format : format virtual disk'); writeln(serout, 'vref : set reference voltage for adc'); writeln(serout, 'adc : read voltages at adc ports'); end; process UserMonitor(100, 100: iData); //-------------------------------------------------------------- var c : char; mId,count,bInput : byte; lw,res : longword; text : string[15]; begin waitpipe(monUserCommand); mId := piperecv(monUserCommand); case mId of 0 : monHelpText; | 1 : writeln(serout); write(serout, '> filename:'); monGetString(@text,15); writeln(serout); if FileCreate(text) then writeln(serout, text + ' created'); else writeln(serout, 'file create failed'); endif; | 2 : writeln(serout); write(serout, '> filename:'); monGetString(@text,15); writeln(serout); if FileDelete(text) then writeln(serout, text + ' deleted'); else writeln(serout, 'file delete failed'); endif; | 3 : writeln(serout); write(serout, '> filename:'); monGetString(@text,15); writeln(serout); if monFileOpen(text) then writeln(serout, '> text(end with ):'); repeat c:= SerInp; if c = #13 then break; endif; write(serout, c); Filewrite(ff, c); until c = #13; FileClose(ff); writeln(serout); endif; | 4 : writeln(serout); write(serout, '> filename:'); monGetString(@text,15); writeln(serout); if monFileOpen(text) then while not EndOfFile(ff) do FileRead(ff, c); write(serout, c); endwhile; FileClose(ff); writeln(serout); endif; | 5 : writeln(serout); write(serout, '> filename:'); monGetString(@text,15); writeln(serout); write(serout, '> read pos(hex byte):'); lw:= Longword(monGetHexByte); writeln(serout); if monFileOpen(text) then res:= FileSeek(ff, lw); if EndOfFile(ff) then writeln(serout, 'EOF'); endif; if res = lw then writeln(serout, 'read at:' + LongToStr(res)); While not EndOfFile(ff) do FileRead(ff, c); write(serout, c); endwhile; else writeln(serout, 'nothing found'); endif; FileClose(ff); writeln(serout); endif; | 6 : writeln(serout); write(serout, '> filename:'); monGetString(@text,15); if monFileOpen(text) then writeln(serout); writeln(serout, text + 'file open'); count:= 0; while not EndOfFile(ff) do FileRead(ff, bInput); write(serout, ByteToHex(bInput) + ' '); if count = 15 then writeln(serout); count:= 0; else inc(count); endif; endwhile; FileClose(ff); writeln(serout); endif; | 7 : writeln(serout); if FileFirst(text, '*.*') then writeln(serout, text); while FileNext(text) do writeln(serout, text + ' '); endwhile; else writeln(serout, 'no files found'); endif; | 8 : writeln(serout); Write (serout, 'free diskspace = '); writeln(serout, IntToStr(DiskFree('A')) + ' kBytes'); | 9 : writeln(serout); if DiskFormat('A') then writeln(serout, 'format done'); else writeln(serout, 'format failed'); endif; | 10: writeln(serout); write(serout, '> voltage(x.xx):'); monGetString(@text,15); vRef := strtofloat(text); | 11: writeln(serout); writeln(serout, 'VRef = ' + floattostr(vRef:4:2) + 'V'); for count := 1 to 8 do writeln(serout, 'ADC' + bytetostr(count) + ' = ' + floattostr(vRef / $3ff * float(getAdc(count) and $3ff):4:2) + 'V'); endfor; | endcase; resume(Monitor); // !!! this must be done as the main monitor process will not continue working instead !!! end; {--------------------------------------------------------------} { Main Program } {$IDATA} begin vRef := 5.00; // default reference voltage (internal) monAttachCommandArray(@commandArray[0],11); // attach user specific monitor commands (see declaration section) framNumDevices(1); // notify the fram module about number of devices connected on i2c bus !!! FileSysReset; // reset file system EnableInts; start_processes; loop endloop; end monitor_sample.