Quectel OpenCPU Watchdog Application Note V1.0
Quectel OpenCPU Watchdog Application Note V1.0
Application Note
Rev. OpenCPU_Watchdog_Application_Note_V1.0
Date: 2014-11-14
www.quectel.com
GSM/GPRS Module Series
OpenCPU Watchdog Application Note
Our aim is to provide customers with timely and comprehensive service. For any
assistance, please contact our company headquarters:
l
http://www.quectel.com/support/salesupport.aspx
t e
For technical support, to report documentation errors, please visit:
c l
http://www.quectel.com/support/techsupport.aspx
u e t ia
GENERAL NOTES
n
QUECTEL OFFERS THIS INFORMATION AS A SERVICE TO ITS CUSTOMERS. THE INFORMATION
PROVIDED IS BASED UPON CUSTOMERS REQUIREMENTS. QUECTEL MAKES EVERY EFFORT
Q ide
TO ENSURE THE QUALITY OF THE INFORMATION IT MAKES AVAILABLE. QUECTEL DOES NOT
MAKE ANY WARRANTY AS TO THE INFORMATION CONTAINED HEREIN, AND DOES NOT ACCEPT
ANY LIABILITY FOR ANY INJURY, LOSS OR DAMAGE OF ANY KIND INCURRED BY USE OF OR
f
RELIANCE UPON THE INFORMATION. ALL INFORMATION SUPPLIED HEREIN IS SUBJECT TO
CHANGE WITHOUT PRIOR NOTICE.
COPYRIGHT
o n
THIS INFORMATION CONTAINED HERE IS PROPRIETARY TECHNICAL INFORMATION OF
C
QUECTEL CO., LTD. TRANSMITTABLE, REPRODUCTION, DISSEMINATION AND EDITING OF THIS
DOCUMENT AS WELL AS UTILIZATION OF THIS CONTENTS ARE FORBIDDEN WITHOUT
PERMISSION. OFFENDERS WILL BE HELD LIABLE FOR PAYMENT OF DAMAGES. ALL RIGHTS
ARE RESERVED IN THE EVENT OF A PATENT GRANT OR REGISTRATION OF A UTILITY MODEL
OR DESIGN.
Copyright Quectel Wireless Solutions Co., Ltd. 2014. All rights reserved.
History
Revision Date
t elAuthor Description
c l
1.0 2014-11-14 Stanley YONG Initial
u e t ia
Q ide n
n f
Co
Contents
1 Introduction .......................................................................................................................................... 6
l
2.2. Software Principle ................................................................................................................... 10
2.3. Duty Time and Feed Watchdog............................................................................................... 11
t e
3 API Functions ..................................................................................................................................... 12
c l
3.1. QI_WTD_Init ............................................................................................................................ 12
3.2. QI_WTD_Start ......................................................................................................................... 13
e ia
3.3. Ql_WTD_Feed ........................................................................................................................ 13
t
3.4. Ql_WTD_Stop ......................................................................................................................... 14
u n
4 Program Watchdog ............................................................................................................................ 15
4.1. For Single Task App ................................................................................................................ 15
Q ide
4.2. For Multitasks App ................................................................................................................... 16
5 Appendix A Reference....................................................................................................................... 17
n f
Co
Table Index
t el
e c ia l
u n t
Q ide
n f
Co
Figure Index
t el
e c ia l
u n t
Q ide
n f
Co
1 Introduction
This document mainly introduces the OpenCPU watchdog solution, API functions and how to program the
watchdog as well.
t el
e c ia l
u n t
Q ide
n f
Co
el
2.1. Hardware Reference Design
c t l
The following sketch map demonstrates the hardware principle.
POWER
u e t ia VBAT
n
MOSFET VBAT
Switch
Q ide
OpenCPU
Module
Discharge
f
MOSFET Control Signal Circuit
n
Startup
Circuit PWRKEY
o
Watchdog Watchdog output
GPIO
t el
e c ia l
u n t
Figure 2: Hardware Reference Design for Watchdog
Q ide
In the schematic, the watchdog chip TPS3823-33DBVR is used. The watchdog chip must have the
timeout of at least 1.6 seconds. The following table lists the recommended components.
n f
Table 1: Recommended Components
o
Location Part No. Descriptions Vendor
C
IC PROCESSOR SUPERVISORY CIRCUITS
U2 TPS3823-33DBVR TI
SOT23-5 RO
PMOSFET -12V 4A 45mOHM @VGS=-2.5V
Q1 SI2333CDS-T1-GE3 VISHAY
SOT23
MOSFET N-Channel Vds=20V Id=6A SOT-23
Q4 SE2306 WILLAS
RO
NPN 50V 100mA R1=4.7K R2=47K
Q2, Q3 DTC143ZEBTL Rohm
EMT3F RO
e c a l
Combined with Figure 2, when 4V2 is powered on, after VDD becomes higher than VIT and a delay of td
t i
time, RESET will be pulled high. Then VBAT will supply the module and the module is turned on by
u
startup circuit. Thereafter, the module will output pulse to feed TPS3823-33DBVR and keep RESET high
n
all along, and the TPS3823-33DBVR will monitor VDD all the time. Meanwhile, when VDD drops below
Q ide
the threshold voltage VIT, or TPS3823-33DBVR does not receive pulse during tt(out), RESET will be pulled
down.
f
NOTES
n
1. The watchdog chip must have the timeout of at least 1.6 seconds.
2. The jumper J1 will be shorted out when downloading firmware to module on the production line.
o
3. Pay attention to the position of decoupling capacitor C6, it must be put in front of MOSFET switch Q1,
otherwise, it will cause a big dropout in VBAT that triggers watchdog reset.
C
4. It would be better to feed watchdog in the bootloader, because the time between power on and
Operating System start is long and the watchdog will be reset during this time.
l
Physical WDI GPIO
Manager ...
Watchdog
e
App subtask n creates logic watchdog:
t
wtd_idn=Ql_WTD_Start(intervaln)
c l
Ql_WTD_Feed(wtd_id)
u e t ia
n
Figure 4: Software Principle for Watchdog Solution
Q ide
The watchdog solution consists of three primary elements:
External Physical Watchdog: An external watchdog chip, monitors whether the OpenCPU App
f
works normally or not, and it will reset the module when some App task gets stuck. App needs to call
n
Ql_WTD_Init() to initialize the external watchdog in any task.
Logic Watchdog: One or more software watchdogs, serves for App tasks. Each task may create a
o
logic watchdog using the API function Ql_WTD_Start().
Watchdog Manager: The software agent of external watchdog, which manages and monitors one or
C
more logic watchdogs and feeds the external watchdog through a GPIO.
NOTES
1. The interval for feeding external watchdog should be two thirds or less of the overflow-time of the
watchdog chip. E.g.: If the overflow-time of the external watchdog is 1.6s, then it would be better
when the feeding interval is set to 1s; if the overflow-time of the external watchdog is 3s, then it would
be better that the feeding interval is set to 2s.
2. The interval for feeding logic watchdog should be at least twice as long as the interval for feeding
external watchdog. The interval for feeding logic watchdog is not that sensitive. You can set it to a
long time, such as 30s, 1min, etc. This interval value should be decided according to the load of the
task.
t el
2.3. Duty Time and Feed Watchdog
c a l
Besides the time that App runs, the external watchdog works in the boot course, App FOTA upgrade
e i
course and the production course as well. So the external watchdog has to be fed in whole working
t
period.
u n
The following table lists the working time of the external watchdog and the feeding owner.
Q ide
Table 2: Owner for Feeding External Watchdog
f
Period Owner for Feeding
n
Booting Core system
o
App Running App
C
Upgrading App By FOTA Core system
For the Booting and Upgrading App by FOTA course, developer just needs to specify the GPIO in
custom_sys_cfg.c which is designed to connect to the external watchdog.
3 API Functions
Developer may call Ql_WTD_Init() to initialize the external watchdog in any task, including specifying the
I/O pin and feeding interval for external watchdog. The API function Ql_WTD_Start() is used to start a
logic watchdog, and Ql_WTD_Feed() may feed the logic watchdog.
l
Once App program calls Ql_WTD_Init(), it must also call Ql_WTD_Start(), or the external watchdog will
overflow.
c t e l
a
3.1. QI_WTD_Init
u e t i
This function initializes watchdog manager, which is responsible for feeding the external watchdog. It can
n
specify the I/O pin and feeding interval.
Q ide
The interval for feeding external watchdog should be two thirds or less of the overflow-time of the
watchdog chip.
f
Prototype
n
s32 Ql_WTD_Init(s32 resetMode, Enum_PinName wtdPin, u32 interval);
Co
Parameters
resetMode:
[in] Must be zero.
wtdPin:
[in] I/O pin that connects to the WDI pin of external watchdog chip.
interval:
[in] The interval for feeding external watchdog. Unit: ms.
Return Value
3.2. QI_WTD_Start
The function starts a logic watchdog with the specified interval. If needed, every task may call this function
to start a logic watchdog service.
The interval for feeding logic watchdog should be at least twice as long as the interval for feeding external
watchdog. The interval for feeding logic watchdog is not that sensitive. You can set it to a long time, such
as 30s, 1min, and etc. And the interval value should be decided according to the load of the task.
Prototype
l
s32 Ql_WTD_Start(u32 interval);
c t e l
Parameters
e a
interval:
t i
[in] The interval for feeding the logic watchdog. Unit: ms.
u n
Return Value
Q ide
This function returns a watchdog ID if succeeds.
QL_RET_ERR_PARAM, invalid parameter.
n f
3.3. Ql_WTD_Feed
o
This function feeds the logic watchdog which is started by Ql_WTD_Start().
C
Prototype
Parameters
wtdID:
[in] Watchdog ID, which is returned by Ql_WTD_Start().
Return Value
None.
3.4. Ql_WTD_Stop
Prototype
Parameters
l
wtdID:
e
[in] Watchdog ID, which is returned by Ql_WTD_Start().
t l
Return Value
c a
None.
u e n t i
Q ide
n f
Co
4 Program Watchdog
The following codes show how to program watchdog in one task and multitasks.
el
void proc_main_task(s32 TaskId)
t
{
l
ST_MSG msg;
c
s32 wtdId;
e t ia
//Init watchdog, GPIO0, 1s interval for external watchdog (suppose that the overflow-timer of external
u
watchdog is 1.6s).
n
Ql_WTD_Init(1, PINNAME_GPIO0, 1000);
Q ide
//Start a logic watchdog service in main task, the max. interval is 5s
wtdId = Ql_WTD_Start(5*1000);
f
//Register & start a timer to feed the logic watchdog.
n
Ql_Timer_Register(TIMER_ID_WTD1, callback_onTimer, & wtdId);
Ql_Timer_Start(TIMER_ID_WTD1, 3000, TRUE); //The real feeding interval is 3s.
o
while (TRUE)
C
{
Ql_memset(&msg, 0x0, sizeof(ST_MSG));
Ql_OS_GetMessage(&msg);
switch(msg.message)
{
//
default:
break;
}
}
}
Ql_WTD_Feed(*((s32*)param));
}
Based on the case one task, developer just needs to start a new logic watchdog service in multitask, and
start a timer to feed the watchdog periodically.
l
{
ST_MSG msg;
t e
s32 wtdId;
c l
//Start a logic watchdog service in subtask, the timeout is 10s.
e a
wtdId = Ql_WTD_Start(10 * 1000);
u t i
//Register & start a timer to feed the logic watchdog
n
Ql_Timer_Register(TIMER_ID_WTD2, callback_onTimer, &wtdId);
Q ide
Ql_Timer_Start(TIMER_ID_WTD2, 8 * 1000, TRUE); //The real interval of feeding watchdog is 8s.
while (TRUE)
{
f
Ql_memset(&msg, 0x0, sizeof(ST_MSG));
Ql_OS_GetMessage(&msg);
n
switch(msg.message)
o
{
//...
C
default:
break;
}
}
}
5 Appendix A Reference
Abbreviation Description
l
App OpenCPU Application
t e
API Application Programming Interface
c l
FOTA Firmware Over The Air
e ia
GPIO General Purpose Input Output
u n t
External Watchdog The external hardware watchdog chip
Q ide
The software agent of external watchdog, which manages one or more logic
Watchdog Manager
watchdogs.
Logic Watchdog The software watchdog that serves for App task.
n f
Co