33 FD_DCG(
"KinetisCodeGenerator(" <<
this <<
")::KinetisCodeGenerator()");
38 FD_DCG(
"KinetisCodeGenerator(" <<
this <<
")::~KinetisCodeGenerator()");
44 FD_DCG(
"KinetisCodeGenerator::Clear()");
60 FD_DCG(
"KinetisCodeGenerator::DoReadTargetConfiguration()");
65 if(rTr.ExistsBegin(
"KinetisOutputControl")) {
66 rTr.ReadBegin(
"KinetisOutputControl",token);
68 rTr.ReadEnd(
"KinetisOutputControl");
70 if(rTr.ExistsBegin(
"KinetisInputControl")) {
71 rTr.ReadBegin(
"KinetisInputControl",token);
73 rTr.ReadEnd(
"KinetisInputControl");
79 FD_DCG(
"KinetisCodeGenerator::DoWriteTargetConfiguration()");
84 token.SetEmpty(
"KinetisOutputControl");
87 token.SetEmpty(
"KinetisInputControl");
108 FD_DCG(
"KinetisCodeGenerator(" <<
this <<
")::DoCompile()");
115 FD_DCG(
"KinetisCodeGenerator(" <<
this <<
")::DoGenerate()");
119 Comment(
"************************************************");
120 Comment(
"CodeGenerator: Target Kinetis K20 uController ");
121 Comment(
"************************************************");
135 Output() <<
"}; /* end function " <<
mPrefix <<
"cyclic() */";
145 Comment(
"************************************************");
146 Comment(
"CodeGenerator: Generated Code Ends Here ");
147 Comment(
"************************************************");
152 std::string KinetisCodeGenerator::ParseLiteralPort(
const std::string& lport) {
154 if((lport.size()<6) || (lport.size()>7))
return res;
155 if(lport.substr(0,4)!=
"PORT")
return res;
156 char port = lport[4];
157 if((port <
'A') || (port >
'E'))
return res;
158 int pin = lport[5] -
'0';
159 if((pin <0) || (pin > 9))
return res;
161 int pin2 = lport[6] -
'0';
162 if((pin2 <0) || (pin2 > 9))
return res;
165 if(pin >=32)
return res;
175 bool outexists=
false;
176 std::map<char, std::set< int > > outbits;
180 if(!ait->second.mSetClr)
continue;
181 std::string portpin=ParseLiteralPort(ait->second.mAddress);
183 FCG_ERR(
"KinetisCodeGenerator::InitialisePorts(): unkown output port [" << ait->second.mAddress <<
"]");
184 outbits[portpin[0]].insert(portpin[1]);
188 bool inpexists=
false;
189 std::map<char, std::set< int > > inpbits;
193 std::string portpin=ParseLiteralPort(lit->second.mAddress);
194 if(portpin==
"")
continue;
195 inpbits[portpin[0]].insert(portpin[1]);
201 if( !(outexists || inpexists) )
return;
203 Comment(
"************************************************");
204 Comment(
"* initialise input/output pins *");
205 Comment(
"************************************************");
210 std::map<char, std::set< int > >::iterator oit = outbits.begin();
211 for(;oit!= outbits.end(); ++oit) {
212 std::set< int >::iterator bit= oit->second.begin();
213 for(;bit!=oit->second.end();++bit) {
218 bit= oit->second.begin();
219 for(;bit!=oit->second.end();++bit)
222 Output() <<
"GPIO" << oit->first <<
"_PDDR |= " << WordConstant(msk) <<
";";
228 std::map<char, std::set< int > >::iterator iit = inpbits.begin();
229 for(;iit!= inpbits.end(); ++iit) {
230 std::set< int >::iterator bit= iit->second.begin();
231 for(;bit!=iit->second.end();++bit) {
243 void KinetisCodeGenerator::RunActionSet(
const std::string& address) {
244 std::string portpin=ParseLiteralPort(address);
246 FCG_ERR(
"KinetisCodeGenerator::RunAction(): unkown output port [" << address <<
"]");
247 Output() <<
"GPIO" << portpin[0] <<
"_PSOR = ( 1L << " << int(portpin[1]) <<
" );";
250 void KinetisCodeGenerator::RunActionClr(
const std::string& address) {
251 std::string portpin=ParseLiteralPort(address);
253 FCG_ERR(
"KinetisCodeGenerator::RunAction(): unkown output port [" << address <<
"]");
254 Output() <<
"GPIO" << portpin[0] <<
"_PCOR = ( 1L << " << int(portpin[1]) <<
" );";
261 std::string portpin=ParseLiteralPort(address);
263 std::string res =
"( GPIO" + std::string(1,portpin[0]) +
"_PDIR & ( 1L << " + ToStringInteger(portpin[1]) +
" ) )";
267 std::string res = address;
#define FAUDES_REGISTERCODEGENERATOR(ftype, ctype)
Class registration macro.
Code-generator for Freescale Kinetis microcontrollers.
virtual void LineFeed(int lines=1)
LineFeed (convenience support for derived classes)
LineIterator LinesEnd()
Access to line records by iterator.
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
virtual void IndentInc()
Indentation (convenience support for derived classes)
int mWordSize
compressed boolean capacity of target type word
LineIterator LinesBegin()
Access to line records by iterator.
int mIntegerSize
compressed boolean capacity of target type integer
virtual std::ostream & Output(void)
Output stream.
static std::string VersionString(void)
Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
virtual void IndentDec()
Indentation (convenience support for derived classes)
ActionAddressIterator ActionAddressesEnd()
Access to action addresses by iterator.
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
ActionAddressIterator ActionAddressesBegin()
Access to action addresses by iterator.
unsigned long word_t
Code-generator internal data type of target words.
Abstract expression; see also Absstract_Addresses.
virtual void DoGenerateDeclarations(void)
cut-and-paste template for code snippet assembly
virtual void DoGenerateResetCode(void)
cut-and-paste template for code snippet assembly
virtual void LiteralAppend(void)
Cosmetic: append literally from configuration.
std::map< std::string, bitarray_rec > mBitarrays
Record of all declared bit-arrays.
std::string mIntegerType
target data type for integer
virtual void DoGenerateCyclicCode(void)
cut-and-paste template for code snippet assembly
std::string mWordType
target data type for word
virtual void LiteralPrepend(void)
Cosmetic: prepend literally from configuration data.
std::string mPrefix
universal prefix (pseudo name space)
Implementation of code primitives by generic C-code.
void DoCompile(void)
add my preferences to DoCompile
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
virtual void Comment(const std::string &text)
Target comments (see EmbeddedcCodeGenerator for consistent reimplementation pattern)
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
virtual void Clear(void)
Clear all data.
virtual void DecrementTimers(void)
re-implemented/additional code blocks
Target Freescale Kinetis micro-controllers (K20)
std::string mKinetisInputControl
Kinetis code options.
std::string mKinetisOutputControl
Kinetis code options.
virtual ~KinetisCodeGenerator(void)
virtual void DoReadTargetConfiguration(TokenReader &rTr)
reimplemented/additional code blocks
virtual void InitialisePorts(void)
reimplemented/additional code blocks
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
void DoCompile(void)
add my preferences to DoCompile
void DoGenerate(void)
protected version of generate
KinetisCodeGenerator(void)