Wiz-IO / Arduino-Quectel-M66

Arduino port for Quectel M66 GPRS modules ( OpenCPU based )
12 stars 4 forks source link

Details on APIs #1

Open ajaybhargav opened 5 years ago

ajaybhargav commented 5 years ago

Can you share some details on following APIs?

unsigned int api_getRandomSeed(void); unsigned int api_getMicro(void); void api_delayMicro(unsigned int us);

I see that they are inside the static library that you have. But how are they implemented? or I believe you're calling a function inside the ROM code, maybe you can give me the name of that function?

Thanks in advance, Ajay Bhargav

Wiz-IO commented 5 years ago

Hi

Functions is version dependent get with reverse engineering

define DEF_hal_gpt_delay_us (0x08115328 + 1)

typedef hal_gpt_status_t (*HAL_GPT_DELAY_US_FUNCTION)(uint32_t us); HAL_GPT_DELAY_US_FUNCTION HAL_GPT_DELAY_US = (HAL_GPT_DELAY_US_FUNCTION) DEF_hal_gpt_delay_us; void api_delay_us(uint32_t us) { HAL_GPT_DELAY_US(us); }

hal_gpt_status_t hal_gpt_get_free_run_count(hal_gpt_clock_source_t clock_source, uint32_t *count); uint32_t api_get_micro(void) { uint32_t count; hal_gpt_get_free_run_count(HAL_GPT_CLOCK_SOURCE_1M, &count); return count; }

uint32_t cissys_rand(int a1, uint32_t SEED, int a3); uint32_t api_get_random(void) { return cissys_rand(0, 1, 0); }

Wiz-IO commented 5 years ago

ups - this is for BC66 but "the way" is the same

ajaybhargav commented 5 years ago

Thanks a lot! yes I get it, its totally version dependent. do you get accurate delay with this? or accurate count when you do getMicro?

Wiz-IO commented 5 years ago

accurate as ARM-GSM ... is based of MCU_TOPSM, maybe is SysTick counter

ajaybhargav commented 5 years ago

Does M66 has similar function? what is the name of the function in core?

Wiz-IO commented 5 years ago

All GSM modules is not accurate for microseconds


#define  HW_WRITE(ptr,data)             (*(ptr) = (data))
#define  HW_READ(ptr)                   (*(ptr))

#define MCU_TOPSM_base                  (0xA0180000)
#define TOPSM_base                      MCU_TOPSM_base

#define USCNT_CON                       (volatile kal_uint32 *)(TOPSM_base+0x0080)
#define F32K_FM                         (volatile kal_uint32 *)(TOPSM_base+0x0084)
#define USCNTI_VAL                      (volatile kal_uint32 *)(TOPSM_base+0x0088)
#define USCNT_FREQ                      (1000000)
#define USCNT_TO_FRAME(sus)             (((sus)*58161)>>28) /* Error rate: 0.0000266% */
#define USCNT_TO_QBIT(us)               (((us)*1109)>>10)  /*Error rate: 1 qbit error per 3000 qbits, allowd max log duration: 4s */
#define USCNT_WRAP                      0xFFFFFFFF

#define ust_get_current_time()          ((HW_READ(USCNTI_VAL))?(HW_READ(USCNTI_VAL)):(HW_READ(USCNTI_VAL)))
#define ust_get_duration(prev, cur)     USCNT_TO_QBIT((((cur) >= (prev))? (((cur) - (prev))): ((USCNT_WRAP - (prev) + (cur)))))

unsigned int api_getMicro(void) {
    return ust_get_current_time();
}

void api_delayMicro(unsigned int us) {
    kal_uint32 t1, t2, zerocount = 0xffff;
    if (us) {
        t1 = ust_get_current_time();
        do {
            t2 = ust_get_current_time();
            if (t1 == t2) {
                zerocount--;
            } else if (ust_get_duration(t1, t2) >= (us)) {
                break;
            } else {
                continue;
            }
        } while (zerocount);
    }
}
ajaybhargav commented 5 years ago

Well we do not expect them to be exact but atleast something is there.

I may be wrong but whats the point of doing this? ((HW_READ(USCNTI_VAL))?(HW_READ(USCNTI_VAL)):(HW_READ(USCNTI_VAL)))

You will always get the same value or am I missing something?

Wiz-IO commented 5 years ago

read register USCNTI_VAL defines is from Mediatek SDK

ajaybhargav commented 5 years ago

No my question was... you are reading the same value in if and else both. Why if condition is kept there? any reason for that?

Wiz-IO commented 5 years ago

:) ask Mediatek - it is copy/paste from Mediatek header

ajaybhargav commented 5 years ago

secret... Well the source I saw 😄

#define ust_get_current_time() HW_READ(USCNTI_VAL)

Maybe you can edit that now? 😉

Wiz-IO commented 5 years ago

for Arduino port is "hard" - I must pack new archive

Wiz-IO commented 5 years ago

BTW: GPIO latency is more 25 uSec

ajaybhargav commented 5 years ago

I also did Arduino thing myself. Its working but needs lot of work, so I dropped. Maybe will start again in future, coz of closed source issues sharing is a problem.

For GPIO, you can use direct register access. If you have MTK source then just look for the register set and directly do read/write. I have used it myself and results are great.

Wiz-IO commented 5 years ago

yes but M66 is old module :) and look port for PlatformIO https://github.com/Wiz-IO/platform-quectel

ajaybhargav commented 5 years ago

I know but in India NB-IoT modules will take some more time to come. Looks like everyone is waiting for 2G to saturate enough or they want to make money out of it 😄 Great work all over!! 👍

Wiz-IO commented 5 years ago

here in Bulgaria... and Europe is the same

ajaybhargav commented 5 years ago

I have a friend from Bulgaria (Plovdiv). This is going off topic so... I should close the issue as my query is resolved 😜

ajaybhargav commented 5 years ago

I have one more query regarding Socket API: int api_soc_getsockopt(unsigned char s, unsigned int option, void val, unsigned char size); int api_soc_setsockopt(unsigned char s, unsigned int option, void val, unsigned char size);

so the first parameter I can give the same that I get from Ql_soc_create?

Wiz-IO commented 5 years ago

OpenCPU not support get/set sockopt yes - first is socket the original is: kal_int8 soc_getsockopt(kal_int8 s, kal_uint32 option, void *val, kal_uint8 val_size);

Wiz-IO commented 5 years ago

https://github.com/Wiz-IO/Arduino-Quectel-M66/blob/master/libraries/Ethernet/src/gprsClient.cpp#L129

mojtabaarbabi commented 3 weeks ago

Screenshot 2024-10-06 231243

hello please help