some question about source code

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
XXzzz
Posts: 15
Joined: Wed Dec 20, 2017 8:14 am
Has thanked: 3 times
Been thanked: 1 time

some question about source code

Post by XXzzz »

when i reading the source code ,i have some question about the object oriented in chibios.
the struct BMP085Driver have four members,and there have some methods in the vmt.

Code: Select all

static BMP085Driver BMP085D1;
/**
 * @brief   BMP085 driver structure.
 */
struct BMP085Driver {
  /** @brief BaseSensor Virtual Methods Table.                              */
  const struct BaseSensorVMT      *vmt_basesensor;
  /** @brief BaseBarometer Virtual Methods Table.                           */
  const struct BaseBarometerVMT   *vmt_basebarometer;
  /** @brief BaseThermometer Virtual Methods Table.                         */
  const struct BaseThermometerVMT *vmt_basethermometer;
  _bmp085_data;
};

so the main.c invoke the macro 'barometerReadRaw'

Code: Select all

#define barometerReadRaw(ip, dp)                                              \
        (ip)->vmt->read_raw(ip, dp)
       
 typedef struct {
  /** @brief Virtual Methods Table.*/
  const struct BaseBarometerVMT *vmt;
  _base_barometer_data
} BaseBarometer;

so these class ,like this

Code: Select all

struct
{
   instance_offset
   parent_methods
   parent_data
   children_methods
   children_data
}children

ithink we can get instance throw the macro 'objGetInstance'

Code: Select all

#define objGetInstance(type, ip)                                            \
  (type)(((size_t)(ip)) - (ip)->vmt->instance_offset)


so the question is :
1. i can't find the place where invoke the macro
2. the 'barometerReadRaw' is (ip)->vmt->read_raw(ip, dp) but in the BMP085Driver we have three vmt,how it works?
3. where can get the chibios oo model ..
4. maybe the detail of the answer is complicated , give me some advice about learning the oo in c model will be beter.

and thanks for your help.
XXzzz
Posts: 15
Joined: Wed Dec 20, 2017 8:14 am
Has thanked: 3 times
Been thanked: 1 time

Re: some question about source code

Post by XXzzz »

this code is in the CHIBIOS182->testex->STM32F4XX->I2C-BMP085
maybe my problem description is not very accurate,
thanks for your help again
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: some question about source code

Post by Giovanni »

Hi,

I think that driver is not updated to the latest model, probably a misunderstanding between the maintainers. If you want to understand the OO model please look at one of the updated drivers, lps22hb.h for example.

This is a proper example:

Code: Select all

struct LPS22HBDriver {
  /** @brief Virtual Methods Table.*/
  const struct LPS22HBVMT   *vmt;
  /** @brief Base barometer interface.*/
  BaseBarometer             baro_if;
  /** @brief Base thermometer interface.*/
  BaseThermometer           thermo_if;
  _lps22hb_data
};


The model allows for multiple inheritance, both methods and data can be inherited. the object starts with its own VMT then it includes instances of the inherited ancestors entirely, both VMTs and data, at the end there is the object's own data.

The first field of the various VMTs is the offset to the object start address, this way the object base address can be recalculated knowing any interface pointer.

Giovanni
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: some question about source code

Post by tfAteba »

Hi all,

Giovanni is right, the driver is not updated, I'm really sorry for that.

I'm not at home this weekend, I'm in travel, so I will manage that on Monday.

I hope that you can wait that time.

Thanks for you understanding.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: some question about source code

Post by tfAteba »

Hello,

I just want to said that I have just updated the code, but I still need to make some test before to push it to the svn repo.

I will do that tomorrow if all the test are fine.

Thanks.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: some question about source code

Post by tfAteba »

Hello,

Work is in progress, I have some troubles to resolve, It didn't work at the first time.

Thanks for your patience.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: some question about source code

Post by tfAteba »

Hi All,

The demo Is still not working.

So Marco can you take a look please and tell me if you see something wrong?

Thanks in advance.
Attachments
bmp085.zip
(1.3 MiB) Downloaded 624 times
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: some question about source code

Post by RoccoMarco »

Hello there,
I am going to take a look to it. Please look forward for a reply. Thanks for your effort in code maintenance.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: some question about source code

Post by tfAteba »

Hello Marco,

Thanks you for your help too :) . I hope we can manage that by combining our effort.

This week I will also continue to look in my side.

Thanks a lot.
Post Reply