Download - Wouter van Ooijen Mail: [email protected] Sheets en info: voti.nl/hvu/2TPRJ6

Transcript
Page 1: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

12TPRJ6 – hardware en ontwikkelomgeving

Wouter van OoijenMail: [email protected]

Sheets en info:www.voti.nl/hvu/2TPRJ6

De hardware en ontwikkelomgeving voor 2TPRJ6

Page 2: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

22TPRJ6 – hardware en ontwikkelomgeving

Even iets heel anders:

2TPRJ4• voor wie het aftekenen van de opdracht geeft gemist: herkansing in de volgende toest/organiatieperiode (datum komt tzt op mijn 2TPRJ4 pagina)• voor (bijna) iedereen: je moet je inschrijven, anders kan ik je geen cijfer geven!

Page 3: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

32TPRJ6 – hardware en ontwikkelomgeving

Philips ARM2106 microcontroller (64k RAM, 128k FLASH)

voeding uit USB (geen USB communicatie) LCD 2x16 char (HD44780-compatible) klein luidsprekertje 16 schakelaars, uitlezen via schuifregisters 8 LEDjes, aansturen via schuifregister parallel JTAG programming interface (McGraigor) RS232 serial interface connector voor uitbreidingen

Page 4: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

42TPRJ6 – hardware en ontwikkelomgeving

Page 5: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

52TPRJ6 – hardware en ontwikkelomgeving

Dit is de setting voor JTAG

Page 6: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

62TPRJ6 – hardware en ontwikkelomgeving

(sorry, volgende week pas…)

aansturing voor een LEGO motortje aansluiting van een (twee?) hall sensoren

Page 7: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

72TPRJ6 – hardware en ontwikkelomgeving

Page 8: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

82TPRJ6 – hardware en ontwikkelomgeving

Page 9: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

92TPRJ6 – hardware en ontwikkelomgeving

Page 10: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

102TPRJ6 – hardware en ontwikkelomgeving

Page 11: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

112TPRJ6 – hardware en ontwikkelomgeving

PSPAD editor GNU assmbler/C/C++ compiler Insight debugger MAC_MOT TCP-to-parallel JTAG

interface C++ BSP (board support package)

Voorlopig werken jullie uitsluitend in RAM.

Page 12: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

122TPRJ6 – hardware en ontwikkelomgeving

// The BSP class is a monad: you can create as many instances as you like,// but they will effectively all be the same instance.class C_BSP {public:

// initialise is done automatically at startup, but it might be usefull // lateron (for instance after a power failure or another glitch) void Init( void );

C_Busy * Busy; C_Interrupts * Interrupts; C_Timer * Timer; C_Pins * Pins; C_LCD * LCD; C_Keyboard * Keyboard; C_LEDs * LEDs;

C_BSP( void );

private: void Create( void );};

Page 13: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

132TPRJ6 – hardware en ontwikkelomgeving

class C_Busy {public:

// initialise is done automatically at startup, but it might be sefull // lateron (for instance after a power failure or another glitch) void Init( void );

// wait N us void WaitUs( int N );

// wait n ms void WaitMs( int N );

private: C_Busy( void ); void Create( void ); friend class C_BSP;};

Page 14: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

142TPRJ6 – hardware en ontwikkelomgeving

class C_Interrupts {public: void Init( void );

void RawEnable( void ); void RawDisable( void );

bool IsEnabled( void );

void UninterruptableBegin( void ); void UninterruptableEnd( void );

int UninterruptableCount( void );

private: ...};

Page 15: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

152TPRJ6 – hardware en ontwikkelomgeving

class C_Timer {public: void Init( void );

// schedule the specified function each millisecond // only one function can be scheduled, scheduling a new // function disables the previous one. void Schedule( void (*f)( void ));

// return the number of 1ms Ticks since startup unsigned long int NrMillis( void );

private: ...};

Page 16: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

162TPRJ6 – hardware en ontwikkelomgeving

enum DirectionT { DirectionInput, DirectionOutput };

class C_Pins {public: void Init( void );

// set the direction of a pin void DirectionSet( unsigned char Pin, DirectionT Direction );

// get and set pin value // Set is most usefull when the pin direction is output // Get is most usefull when the pin direction is input bool Get( unsigned char Pin ); void Set( unsigned char Pin, bool Value );

private: ...};

Page 17: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

172TPRJ6 – hardware en ontwikkelomgeving

class C_LCD {public: void Init( void );

// send a HD44780 command byte to the LCD void Command( unsigned char Cmd );

// send a HD44780 data byte to the LCD void Data( unsigned char Chr );

// put the write cursor at X,Y // X = column, 1 = leftmost // Y = line number, 1 = top line void Goto( unsigned char X, unsigned char Y );

// write a char at the write cursor position, // advance the write cursor position void Write( char Chr );

// For Command() and Data() no delay is added, so the caller // is responsible for the delay(s) required by the HD44780. // For Goto() and Write() the delays are added inside the calls.

private: ...};

Page 18: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

182TPRJ6 – hardware en ontwikkelomgeving

enum KeyT { Key0 = 6, Key1 = 15, Key2 = 14, Key3 = 13, Key4 = 12, Key5 = 11, Key6 = 10, Key7 = 9, Key8 = 8, Key9 = 7, KeyA = 3, KeyB = 2, KeyC = 1, KeyD = 0, KeyStar = 5, KeySharp = 4, KeyNone = 0xFF };

class C_Keyboard {public: void Init( void );

// read the keyboard, return whether a key is pressed and if so which one KeyT Read( void );

private: ...};

Page 19: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

192TPRJ6 – hardware en ontwikkelomgeving

class C_LEDs {public: void Init( void );

// set the LEDs according to the 8 bits in Value void SetAll( unsigned char Value );

// switch the LED Nr on or off void SetOne( int Nr, bool Value );

private: ...};

Page 20: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

202TPRJ6 – hardware en ontwikkelomgeving

// The BSP class is a monad: you can create as many instances as you like,// but they will effectively all be the same instance.class C_BSP {public:

// initialise is done automatically at startup, but it might be usefull // lateron (for instance after a power failure or another glitch) void Init( void );

C_Busy * Busy; C_Interrupts * Interrupts; C_Tick1ms * Tick1ms; C_Pins * Pins; C_LCD * LCD; C_Keyboard * Keyboard; C_LEDs * LEDs;

C_BSP( void );

private: void Create( void );};

Page 21: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

212TPRJ6 – hardware en ontwikkelomgeving

LET OP!De I/O classes (LCD, Keyboard, LEDs) mogen niet uit de

interrupt (ge-schedulde timertick) aangeroepen worden. Pinnen lezen en/of schrijven mag wel.

Page 22: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

222TPRJ6 – hardware en ontwikkelomgeving

LET OP!In de huidige versie van de linker scripts worden de

allocators (initialisatie) van global objecten niet aageroepen! Gebruik dus locale objecten, evt. een global pointer naar zo’n object (of references doorgeven).

Page 23: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

232TPRJ6 – hardware en ontwikkelomgeving

De microcontroller heeft 64Kb RAM, maar daar moet alles in: code, globale data, stack. Wees dus “een beetje” zunig.

Downloaden met de JTAG gaat niet erg snel. Zuinig zijn met code werkt dus sneller! Een classe op zich kost gen code, maar het gebruik van dynamisch geheugen wel!

Page 24: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

242TPRJ6 – hardware en ontwikkelomgeving

sluit een bordje aan (parallel + USB) installeer de files uit de BSP

(BikeComputer.zip) in een lege directory let op: geen spaties in de pathname

dubbel-klik op de .ppr file build start debugger

Page 25: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

252TPRJ6 – hardware en ontwikkelomgeving

zet onder file > target settings:Target = Remote/TCPHostname = 127.0.0.1Port = 8888

(als je netjes afsluit blijft zou dit moeten blijven staan)

Page 26: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

262TPRJ6 – hardware en ontwikkelomgeving

evt. kan je breakpoints zetten of verwijderen

run

als het goed is kom je nu op een breakpoint aan het begin van main

Page 27: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

272TPRJ6 – hardware en ontwikkelomgeving

continue

Zoals het een embedded programma betaamt eindigt ons programma nooit.

stop

Page 28: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

282TPRJ6 – hardware en ontwikkelomgeving

Als je dit krijgt heb je debugger/loader niet afgesloten

Page 29: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

292TPRJ6 – hardware en ontwikkelomgeving

Als je dit krijgt moet je onder control panel > system > hardware > device manager (select view > show hidden devices) > non plug-and-pray devices > MAC_MOT > driver instellen op status = started, type = automatic

Page 30: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

302TPRJ6 – hardware en ontwikkelomgeving

Onder ‘external programs’ staat ook en

entry om de MAC_MOT driver te her-installeren.

Page 31: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

312TPRJ6 – hardware en ontwikkelomgeving

Als de die MAC_MOT driver niet kan vinden: installeer de Macraigor OCD commander (de link staat op www.voti.nl/hvu/2TPRJ6)

Page 32: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

322TPRJ6 – hardware en ontwikkelomgeving

Als het echt niet werkt: de USB aansluiting er even

uithalen om het bordje te resetten, evt ook je PC resetten.

Page 33: Wouter van Ooijen Mail:  wouter@voti.nl Sheets en info: voti.nl/hvu/2TPRJ6

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

332TPRJ6 – hardware en ontwikkelomgeving

doen• Laat de LEDs knipperen: iedere seconde

even (bv 200ms) aan• Zet ‘Hello world’ op het LCD scherm, en

iets naar keuze op de tweede regel• Tel (op de LEDs of op de LCD) het aantal

keren dat een bepaalde toest is ingedrukt (let op dender!).