Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 04, 2016, 02:53:22 02:53


Login with username, password and session length


Pages: [1]
Print
Author Topic: Writing Platform Independent Code  (Read 2392 times)
0 Members and 1 Guest are viewing this topic.
SANEMB
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 3
-Receive: 0


« on: October 27, 2009, 08:52:04 08:52 »

Hi Guys,

I am writing an program for one application in C / C++ which should run on all target controller architecture like 8051 , AVR, PIC , MSP430 or ARM7 . How could I write this Platform Independent Code.

can anyone help me on this.

Logged
sam_des
Active Member
***
Offline Offline

Posts: 221

Thank You
-Given: 47
-Receive: 111


« Reply #1 on: October 27, 2009, 07:24:10 19:24 »

Hello,

Your code can't be 100% portable across all the architectures. BUt you can maxmize your chances & minimize your work.

1) Use only ANSI C. Enable strict ANSI checking if compiler supports it.

2) Carefully seperate hardware dependent low level functions & high level functions. Low level functions must be re-written for every target, but high level functions can be reused if they follow ANSI specs.
  e.g. Accessing I2C eeprom using software I2C, you can write low level functions like i2c_start(), i2c_stop() etc for each target seperately. But you can write the high level functions like i2c_ee_read_byte(), i2c_ee_write_byte() etc. once only.

3) Don't use any compiler specific extensions. That means you may have to do some things harder way.

4) Avoid using target specific features. Like there is 'bit' type for 8051, but it may not be present for AVR or ARM. Also 8051 can access external RAM/ROM while PIC can't do that.

5) Interrupts are one of the things which have to be re-written for each target. Interrupts differ in all big & small respects in every target. Even if you write isr in C, still they won't be portable that easily.

6) Also note that when you are porting across 8,16 & 32-bit targets, your code won't be optimized. For example, for PIC/AVR, 8-bit vars are faster, but for ARM 32-bit vars are more faster. Also allocation of local data may be different. ARM, AVR use data-stack while PIC,8051 use overlays.

7) For some architectures c++ simply doesn't exist.

In my opinion it's more work that it is worth to write application which needs to be portable across so varied targets. Instead I prefer write seprate programs for each. That way it is more optimized, using full power of architecture in hand.

Hope that helpes
regards,
sam_des
Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
DarkClover
Active Member
***
Offline Offline

Posts: 170

Thank You
-Given: 36
-Receive: 60


Still alive...


« Reply #2 on: October 27, 2009, 11:19:30 23:19 »

I agree with 1) to 7), but just partial with "...Instead I prefer write seprate programs for each. That way it is more optimized, using full power of architecture in hand."

If the code project is in development state and big and complex enough it's good to write it platform independent.
Later you can decide which one is the best and fastest and in the end you just have to optimize the code only for one platform.
Logged

Not thinking means to believe what others say!
TRY & ERROR... the fundamental principle our existence is based on
SANEMB
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 3
-Receive: 0


« Reply #3 on: October 30, 2009, 06:28:18 06:28 »

Hi Sam,

I rily appreciate your time & effort.

Yes , as u said we can go for writing separate program for each architecture for the optimization. But this code is going to be written specifically for the implementation of  IEC62056  DLMS/ COSEM for Energy Meter which consists of both Single phase as well as three phase meter of various target platform such TI MSP430, Analog devices , MAXIM , ST & also other processor architecture interfaced with ASIC chips. So how i should go for it.

   
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC