When we yawn, it's not just a heads up that we're tired, it's also a way for the body to refresh the brain and lower nervous tension.
Have you ever been almost asleep when you suddenly feel a big jerk? These are spasms produced by the body to 'resuscitate' it. When we're really tired our breathing goes way down, the body 'believes' we're going to die, and gives us a little shock.