Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12603 Discussions

Nios V i2c ALT_AVALON_I2C_STATUS_CODE

andy25
New Contributor I
813 Views

altera_avalon_i2c.h defines:

typedef alt_u32 ALT_AVALON_I2C_STATUS_CODE;

 

Which is an unsigned type, which is a problem because the errors are all negative.

This compiles with a warning:

   ALT_AVALON_I2C_STATUS_CODE status = alt_avalon_i2c_master_tx(
         i2c_dev,
         txbuffer,
         2,
         ALT_AVALON_I2C_NO_INTERRUPTS
   );
   if (status == ALT_AVALON_I2C_ERROR) {
      uart.println("error");
   }
main.cpp:221:15: warning: comparison of integer expressions of different signedness: 'ALT_AVALON_I2C_STATUS_CODE' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  221 |    if (status == ALT_AVALON_I2C_ERROR) {

 

 

And a switch(status) errors:

freertos_bsp/drivers/inc/altera_avalon_i2c.h:102:33: error: narrowing conversion of '-1' from 'int' to 'long unsigned int' [-Wnarrowing]
  102 | #define ALT_AVALON_I2C_ERROR (-1)

 

 

Please change  ALT_AVALON_I2C_STATUS_CODE to a signed type.

 

-Andy

 

0 Kudos
8 Replies
EBERLAZARE_I_Intel
771 Views

Hi,


Thanks for the feedback, let me verify it on our side.


0 Kudos
EBERLAZARE_I_Intel
734 Views

Hi,


Could you share your design that faced this error? That would be helpful.


0 Kudos
andy25
New Contributor I
720 Views

Not easily.  But I can tell you how to recreate it pretty easy.

1) create a platform designer with a NiosV and an i2c master.  Just enough to generate the .socpinfo file, you dont need anything in quartus.

2) create a default hal bsp, make sure altera_avalon_i2c is being included.

3) create an app, add this to your CMakeLists.txt:

 

target_compile_options(app.elf PRIVATE
   -fno-exceptions
   -fno-common
   -fno-rtti
   -fvisibility=hidden
   -fvisibility-inlines-hidden
   -D_FORTIFY_SOURCE=2
   -fstack-protector
   -Wall
   -Wextra
   -Wshadow
   -Wdouble-promotion
   -Wnon-virtual-dtor
   -Wcast-align
   -Wunused
   -Wundef
   -Woverloaded-virtual
   -Wpedantic
   -Wconversion # warn on type conversions that may lose data
   -Wsign-conversion
   -Wnull-dereference
   -Wformat=2
   -Wmisleading-indentation
   -Wduplicated-cond
   -Wduplicated-branches
   -Wlogical-op
)

 

 

4) In your main add something like:

 

   ALT_AVALON_I2C_DEV_t *i2c_dev = alt_avalon_i2c_open(IPMB_0_I2C_MASTER_NAME);

   if (i2c_dev == nullptr)
   {
      uart.println("Error: Cannot find /dev/i2c_0");
      return;
   }

   // set remote address
   alt_avalon_i2c_master_target_set(i2c_dev, addr);

   ALT_AVALON_I2C_STATUS_CODE status = alt_avalon_i2c_master_tx(
         i2c_dev,
         txbuffer,
         numValues,
         ALT_AVALON_I2C_NO_INTERRUPTS
   );
    // this gives warnings
   if (status == ALT_AVALON_I2C_SUCCESS) {
      uart.println("send success (staus = %d)", status);
   }
   // this errors
   switch(status) {
      case ALT_AVALON_I2C_SUCCESS:
         uart.println("send success (staus = %d)", status);
         break;
   }

 

 

0 Kudos
EBERLAZARE_I_Intel
655 Views

Hi,


Thanks a lot for the inputs, I will test and channel this to our internal team as feedback.


0 Kudos
EBERLAZARE_I_Intel
570 Views

Hi,


I got it, just to confirm again, is this warning is on the FreeRTOS? Did you see same warning on the Altera HAL?


0 Kudos
andy25
New Contributor I
541 Views

In the steps posed above:

   Step 2) create a default hal bsp

 

Its in HAL. 

0 Kudos
EBERLAZARE_I_Intel
500 Views

Hi,


Reason I ask was because in the initial post, it was calling out the "freertos_bsp" folder regarding the switch(status) error.


0 Kudos
EBERLAZARE_I_Intel
433 Views

Hi,


Thanks again, this feedback have been channeled to our internal team.


I now transition this thread to community support. If you have a new question, Please login to ‘https://supporttickets.intel.com’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.



p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.


0 Kudos
Reply