[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] const struct in program memory
From: |
avr-libc-devel |
Subject: |
Re: [avr-libc-dev] const struct in program memory |
Date: |
Mon, 17 Jun 2019 12:38:16 +0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 |
You certainly can use PROGMEM (or the newer __flash) on structs in
program memory. But you need to use the right methods to access the
data. Can you post a short sample code that you tried but which did not
work?
typedef struct {
uint16_t int_part;
uint8_t frac_part;
float fl_part;
} __attribute__ ((packed)) bw_data;
const bw_data bw_tab[] PROGMEM;
const bw_data bw_tab[] PROGMEM = {
[BW_7_8] = { //7.81
.int_part = 7,
.frac_part = 81,
.fl_part = 7.81f,
},
.... skip ....
}
float symbols_time_ms(const param_t *const par, const uint8_t symbols_num){
float temp;
temp = 1 << (par->sf + 6); //2^SF
temp = (float) temp * (float) symbols_num /
bw_tab[par->bw].fl_part;
return temp;
}
------------------
When I call the function symbols_time_ms (), the result is incorrect if
the PROGMEM modifier is uncommented.
Thank you very much for your answer and attention to my question.