25.12.2013 Aufrufe

Gecko3 - CCC Event Weblog

Gecko3 - CCC Event Weblog

Gecko3 - CCC Event Weblog

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

E. Quellcode<br />

#include ” s p i . h”<br />

#include ”m25p16 . h”<br />

#include ” i i c e x t c h i p c o m . h”<br />

27 #define w r i t e n o k 1 // d e f i n i t i o n f o r w r i t e s t a t e<br />

#define w r i t e o k 0 // d e f i n i t i o n f o r w r i t e s t a t e<br />

#define f i l e s i z e 130952 // f i l e s i z e f o r XC3S200 ( important : you must<br />

a d j u s t t h i s s i z e f o r o t h e r d e v i c e s )<br />

#define highaddr memory range 0 x01 // 1 stand f o r t h e high address range in t h e SPI<br />

Flash<br />

32 extern BOOL f l a s h r d e n ;<br />

extern BOOL new cfg ; // d e t e c t a new c o n f i g u r a t i o n<br />

extern unsigned long s p i f l a s h a d d r e s s ; // memory a d r e s s from SPI Flash<br />

BOOL w r i t e s t a t u s = 1 ; // s e t w r i t e s t a t e on not ok<br />

37 unsigned int o f f s e t ; // o f f s e t f o r w r i t e t r a n s a c t i o n<br />

// unsigned i n t r e a d s t a t u s ;<br />

void s p i f l a s h i n i t ( void )<br />

{<br />

42 // Set Port A s e t t i n g s f o r SPI Flash communication<br />

OEA |= 0 x01 ; // Port A b i t 0 output f o r SCLK<br />

OEA |= 0 x02 ; // Port A b i t 1 output f o r MOSI<br />

OEA &= 0xFB ; // Port A b i t 2 i n p u t f o r MISO<br />

OEA |= 0 x08 ; // Port A b i t 3 output f o r SPI CS F<br />

47 }<br />

void s p i f l a s h w r ( void )<br />

{<br />

WORD count , i ;<br />

52 i f ( s w i t c h r d ( ) == highaddr memory range )<br />

{<br />

l e d w r (0 x06 ) ;<br />

s p i f l a s h a d d r e s s = 0 x100000 ;<br />

}<br />

57 while ( ! ( EP2468STAT & bmEP2EMPTY) ) // check EP2 EMPTY( busy ) b i t in EP2468STAT (SFR) ,<br />

core s e t ’ s t h i s b i t when FIFO i s empty<br />

{<br />

// Autopointer source a d r e s s<br />

AUTOPTRH1 = MSB( &EP2FIFOBUF ) ;<br />

AUTOPTRL1 = LSB( &EP2FIFOBUF ) ;<br />

62<br />

count = (EP2BCH 256) // i f i n p u t d a t a l o n g e r than 257 Bytes<br />

{<br />

o f f s e t = count − 2 5 4 ; // we must c a l c u l a t e t h e o f f s e t<br />

// e . g . t h e EP2 FIFO c ontent ( count ) i s 280 b y t e s , t h e o f f s e t<br />

i s 26<br />

// and t h e for −l o op ( writePageProgram ( ) ) r e p e a t 254 times<br />

77 // two b y t e send t h e startPageProgramm ( ) and<br />

lastPageProgramm ( ) f u n c t i o n s<br />

} else<br />

{<br />

o f f s e t = 2 ; // i f i n p u t d a t a s h o r t e r , t h e o f f s e t i s two because we<br />

78 Matthias Zurbrügg, Christoph Zimmermann

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!