Page 1 of 1

some question about source code

Posted: Thu May 31, 2018 5:05 am
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.

Re: some question about source code

Posted: Thu May 31, 2018 5:08 am
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

Re: some question about source code

Posted: Thu May 31, 2018 8:08 am
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

Re: some question about source code

Posted: Fri Jun 01, 2018 12:00 pm
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.

Re: some question about source code

Posted: Tue Jun 05, 2018 8:15 am
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.

Re: some question about source code

Posted: Wed Jun 06, 2018 8:00 am
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.

Re: some question about source code

Posted: Tue Jun 12, 2018 9:01 am
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.

Re: some question about source code

Posted: Thu Jun 14, 2018 11:39 pm
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.

Re: some question about source code

Posted: Fri Jun 15, 2018 7:41 am
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.