Monday, July 29, 2019

infinite times execution using functions


#include <stdio.h>

void proc_task1();
void proc_task2();
void proc_task3();


int main()
{
    printf("\r\nit is inside main\r\n\n");
    proc_task1();
   

    return 0;
}

//proc_task1
void proc_task1()
{
    printf("\r\nit is inside proc_task1\r\n\n");
    proc_task2();
}

//proc_task2
void proc_task2()
{
    printf("\r\nit is inside proc_task2\r\n\n");
    proc_task3();
   
}

//proc_task3
void proc_task3()
{
    printf("\r\nit is inside proc_task3\r\n\n");
    proc_task1();
   
}





read the data from UART in QUECTEL MC60

/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of Quectel Co., Ltd. 2013
*
*****************************************************************************/
/*****************************************************************************
 *
 * Filename:
 * ---------
 *   example_gpio.c
 *
 * Project:
 * --------
 *   OpenCPU
 *
 * Description:
 * ------------
 *   This example demonstrates how to program a GPIO pin in OpenCPU.
 *   This example choose PINNAME_STATUS pin as GPIO.
 *
 *   All debug information will be output through DEBUG port.
 *
 *   The "Enum_PinName" enumeration defines all the GPIO pins.
 *
 * Usage:
 * ------
 *   Compile & Run:
 *
 *     Set "C_PREDEF=-D __EXAMPLE_GPIO__" in gcc_makefile file. And compile the
 *     app using "make clean/new".
 *     Download image bin to module to run.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 *----------------------------------------------------------------------------
 *
 ****************************************************************************/
#ifdef __UART_TASK__
#include "ql_trace.h"
#include "ql_system.h"
#include "ql_gpio.h"
#include "ql_stdlib.h"
#include "ql_error.h"
#include "ql_uart.h"
#include "ril.h"
#include "ril_util.h"
#include "ql_type.h"
#include "ql_trace.h"
#include "ql_stdlib.h"
#include "ril_gps.h"
#include "ql_gnss.h"
#include "Nema_pro.h"



#define DEBUG_ENABLE 1
#if DEBUG_ENABLE > 0
#define DEBUG_PORT  UART_PORT1
#define DBG_BUF_LEN   512
static char DBG_BUFFER[DBG_BUF_LEN];
#define APP_DEBUG(FORMAT,...) {\
    Ql_memset(DBG_BUFFER, 0, DBG_BUF_LEN);\
    Ql_sprintf(DBG_BUFFER,FORMAT,##__VA_ARGS__); \
    if (UART_PORT2 == (DEBUG_PORT)) \
    {\
        Ql_Debug_Trace(DBG_BUFFER);\
    } else {\
        Ql_UART_Write((Enum_SerialPort)(DEBUG_PORT), (u8*)(DBG_BUFFER), Ql_strlen((const char *)(DBG_BUFFER)));\
    }\
}
#else
#define APP_DEBUG(FORMAT,...)
#endif

#define SERIAL_RX_BUFFER_LEN  2048
static u8 m_RxBuf_Uart[SERIAL_RX_BUFFER_LEN];


void proc_task1(s32 TaskId);

void proc_task2(s32 TaskId);
void proc_task3();


s32 Ql_UART_Write(Enum_SerialPort port, u8* data, u32 writeLen );


static s32 ReadSerialPort(Enum_SerialPort port, /*[out]*/u8* pBuffer, /*[in]*/u32 bufLen)
{
    s32 rdLen = 0;
    s32 rdTotalLen = 0;
    if (NULL == pBuffer || 0 == bufLen)
    {
        return -1;
    }
    Ql_memset(pBuffer, 0x0, bufLen);
    while (1)
    {
        rdLen = Ql_UART_Read(port, pBuffer + rdTotalLen, bufLen - rdTotalLen);
        if (rdLen <= 0)  // All data is read out, or Serial Port Error!
        {
            break;
        }
        rdTotalLen += rdLen;
        // Continue to read...
    }
    if (rdLen < 0) // Serial Port Error!
    {
        APP_DEBUG("<--Fail to read from port[%d]-->\r\n", port);
        return -99;
    }
    return rdTotalLen;
}


static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara)
{
s32 iRet = 0;
   //APP_DEBUG("\r\n it is inside callback_UART Handler\r\n");
   switch (msg)
   {
    case EVENT_UART_READY_TO_READ:
   {
   char* p = NULL;
   s32 totalBytes = ReadSerialPort(port, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));
   if (totalBytes <= 0)
   {
APP_DEBUG("totalBytes = %d.\r\n",totalBytes);
   break;
   }

   APP_DEBUG("given i/p : %s\r\n",m_RxBuf_Uart);

 
   proc_task3();
 
   //APP_DEBUG("Invalid command...\r\n");
   }break;

   case EVENT_UART_READY_TO_WRITE:
   {
   //...
   }break;

   default:
   break;
   }
   
}


/************************************************************************/
/* The entrance for this example application                            */
/************************************************************************/
void proc_main_task(s32 taskId)
{
    s32 ret;
    ST_MSG msg;

    // Register & open UART port
    ret = Ql_UART_Register(UART_PORT1, CallBack_UART_Hdlr, NULL);
    if (ret < QL_RET_OK)
    {
        Ql_Debug_Trace("Fail to register serial port[%d], ret=%d\r\n", UART_PORT1, ret);
    }
    ret = Ql_UART_Open(UART_PORT1, 115200, FC_NONE);
    if (ret < QL_RET_OK)
    {
        Ql_Debug_Trace("Fail to open serial port[%d], ret=%d\r\n", UART_PORT1, ret);
    }
   
    APP_DEBUG("\r\n<-- OpenCPU: UART TASK EXECUTION-->\r\n");

   
     proc_task1(taskId);

    // Start message loop of this task
    while (TRUE)
    {
        Ql_OS_GetMessage(&msg);
        switch(msg.message)
        {
        case MSG_ID_USER_START:
            break;
        default:
            break;
        }
    }
}



//SUB TASK 1
void proc_task1(s32 TaskId)
{

APP_DEBUG("\r\n<-- IT IS INSIDE PROC_TASK1-->\r\n");
Ql_UART_Write(UART_PORT1, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));
proc_task2(TaskId);

}

//SUBTASK2
void proc_task2(s32 TaskId)
{

APP_DEBUG("\r\n<-- IT IS INSIDE PROC_TASK2-->\r\n");
Ql_UART_Write(UART_PORT1, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));

}

void proc_task3()
{

APP_DEBUG("\r\n<-- IT IS INSIDE PROC_TASK3-->\r\n");
Ql_UART_Write(UART_PORT1, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));

}




#endif //__EXAMPLE_GPIO__



python class topic video