Aman Shaikh
Published

Compact GPRS module programming (A9G)

Tutorial on programming A9G with C.

AdvancedProtip4 hours2,773
Compact GPRS module programming (A9G)

Things used in this project

Hardware components

Ai Thinker A9G
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
SparkFun FTDI Basic Breakout - 5V
SparkFun FTDI Basic Breakout - 5V
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1

Software apps and online services

VS Code
Microsoft VS Code
Windows 10
Microsoft Windows 10

Story

Read more

Code

App code

C/C++
This is the code which was uploaded to the module in the Tutorial
#include "stdint.h"
#include "stdbool.h"
#include "api_os.h"
#include "api_event.h"
#include "api_debug.h"

#define AppMain_TASK_STACK_SIZE    (1024 * 2)
#define AppMain_TASK_PRIORITY      1 
HANDLE mainTaskHandle  = NULL;
HANDLE otherTaskHandle = NULL;


void LoopTask(void *pData)
{
    uint64_t count = 0;
    while(1)
    {
        ++count;
        if(count == 3000)
        {
            count = 0;
            Trace(1,"Test Test");
            OS_Sleep(1000);
            Trace(1,"Test Test2");
        }
    }
}
void EventDispatch(API_Event_t* pEvent)
{
    switch(pEvent->id)
    {
        case API_EVENT_ID_POWER_ON:
            break;
        case API_EVENT_ID_NO_SIMCARD:
            break;
        case API_EVENT_ID_NETWORK_REGISTERED_HOME:
        case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
            break;
        default:
            break;
    }
}


void AppMainTask(void *pData)
{
    API_Event_t* event=NULL;
    
    otherTaskHandle = OS_CreateTask(LoopTask ,
        NULL, NULL, AppMain_TASK_STACK_SIZE, AppMain_TASK_PRIORITY, 0, 0, "ohter Task");
        
    while(1)
    {
        if(OS_WaitEvent(mainTaskHandle, &event, OS_TIME_OUT_WAIT_FOREVER))
        {
            EventDispatch(event);
            OS_Free(event->pParam1);
            OS_Free(event->pParam2);
            OS_Free(event);
        }
    }
}
void app_Main(void)
{
    mainTaskHandle = OS_CreateTask(AppMainTask ,
        NULL, NULL, AppMain_TASK_STACK_SIZE, AppMain_TASK_PRIORITY, 0, 0, "init Task");
    OS_SetUserMainHandle(&mainTaskHandle);
}

Blinky

C/C++
Program to blinks the inbuilt led in A9G board
#include "api_hal_gpio.h"
#include "stdint.h"
#include "stdbool.h"
#include "api_debug.h"
#include "api_os.h"
#include "api_hal_pm.h"
#include "api_os.h"
#include "api_event.h"


#define AppMain_TASK_STACK_SIZE    (1024 * 2)
#define AppMain_TASK_PRIORITY      1 
HANDLE mainTaskHandle  = NULL;
HANDLE otherTaskHandle = NULL;
HANDLE blinkTaskHandle = NULL;


void blinkTask(){

    static GPIO_LEVEL ledBlue = GPIO_LEVEL_LOW;

    GPIO_config_t gpioLedBlue ={
        .mode = GPIO_MODE_OUTPUT,
        .pin = GPIO_PIN28,
        .defaultLevel = GPIO_LEVEL_LOW
    };
    for(uint8_t i=0; i<POWER_TYPE_MAX;i++){
        PM_PowerEnable(i,true);
        
    }

    for(int i=0 ; i<GPIO_PIN_MAX ; ++i){
        gpioLedBlue.pin = i;
        GPIO_Init(gpioLedBlue);
    }

    while(1){
        ledBlue = (ledBlue==GPIO_LEVEL_HIGH)?GPIO_LEVEL_LOW:GPIO_LEVEL_HIGH;
        gpioLedBlue.pin = 28;
        GPIO_SetLevel(gpioLedBlue,ledBlue);
        Trace(1,"led power is %d",ledBlue);
        OS_Sleep(1000);
    }
}

void LoopTask(void *pData){
    uint8_t counter = 0;

    while(1){
        Trace(1,"counter %d",counter);
        OS_Sleep(1000);
        counter++;
        if(counter == 5){
            counter = 0;
        }
    }
}

void EventDispatch(API_Event_t* pEvent)
{
    switch(pEvent->id)
    {
        case API_EVENT_ID_POWER_ON:
            break;
        case API_EVENT_ID_NO_SIMCARD:
            break;
        case API_EVENT_ID_NETWORK_REGISTERED_HOME:
        case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
            break;
        default:
            break;
    }
}



void TestMainTask (void *pData){
    API_Event_t* event = NULL;

    otherTaskHandle = OS_CreateTask(
        LoopTask,
        NULL,
        NULL,
        AppMain_TASK_STACK_SIZE,
        AppMain_TASK_PRIORITY,
        0,
        0,
        "other task"
    );

    blinkTaskHandle = OS_CreateTask(
        blinkTask,
        NULL,
        NULL,
        AppMain_TASK_STACK_SIZE,
        AppMain_TASK_PRIORITY,
        0,
        0,
        "blink task"
    );



    while(1){
        if(OS_WaitEvent(mainTaskHandle,&event,OS_TIME_OUT_WAIT_FOREVER)){
            
            EventDispatch(event);
            OS_Free(event->pParam1);
            OS_Free(event->pParam2);
            OS_Free(event);
        
        }
    }
}


void Test_Main(void){
    mainTaskHandle = OS_CreateTask(TestMainTask,
    NULL,
    NULL,
    AppMain_TASK_STACK_SIZE,AppMain_TASK_PRIORITY,0,0,"init Task");
    OS_SetUserMainHandle(&mainTaskHandle);

}

Credits

Aman Shaikh

Aman Shaikh

5 projects • 2 followers
I am a passionate Embedded hardware and Software developer. I have 4 years of experience. Working beneath the surface is where I thrive.

Comments