I want to add a piece of code for watchdog timer within my source code so that the board resets automatically when programs hangs. I am using Mediatek Linkit One board.
You can create a function that "Feeds the dog" in an appropriate place in your program. When the dog isn't fed, the watchdog timer will elapse and reset the program. Look at the microcontroller documentation to see how this is implemented. Generally the Watch Dog timer will need to be configured correctly (with appropriate pre-scaler values), enabled, and then cleared periodically before the timer expires. The API References from mediatek labs doesn't look like it gives you access to this lower level functionalitybut the SOC Processor technical brief for the ARMyEJ-S does include a Watchdog timer (p.8) which is the only mention. If you can't find an answer to this in the documentation then I would contact them and ask for it directly and put some pressure on their developers (as it has already been requested in their forum.)
I have no idea what a Mediatek Linkit One board is (and you didn't provide a link), but, in general, you can't. If your program hangs how will the watchdog code be executed?
Watchdogs usually have to be implemented in hardware - either internally by a section of the CPU that runs independently of the user program or, if that can't be done, an external watchdog is employed. Your program would reset the external watchdog periodically by sending a pulse. If the external watchdog doesn't see a transition within a certain time then a reset is generated.