the stay awake thing is bugging you eh? 
the arduous meditation practices of a buddhist monk, linked with light diet and no exercise = fatigue most of the time.
Bodhidharma introduced exercise to increase vitality and strengt in the monks so they could endure their fastidious meditation periods which lasted a very long time.
Bodhidharma also brought Ch’an with him, which in practice is a difficult undertaking. The mind wanders when it lacks purpose or intention. THis same lacking of purpose and intention leads to boredom and distraction.
Bodhidharma also reputedly introduced the drinking of tea to the monks in order to maintain alertness when in stillness which is part of what Ch’an is.
The exercises introduced where from Dhayana practice (dhayana is sanskrit version of word Ch’an which is zen in japanese and better known as such)
Dhayana practice was not entirely unknown in China before the coming of Bodhidharma, but it was not widely known and it was not widely spread through the large institution that was the buddhist monastic order system which reinged supreme across china in that time (500 ad or so with spikes before and after depending on which warlord was running the show and how threatened they were by religious power)
It could be said that Dhayana exercises were mixed in with martial practice at a much later time when there were troubles, peasant uprisings and of course the well storied tale of the 300 year reign of the Qing dynasty which sprouted all sorts of underground secret military societies.
The Tang dynasty which is pre ming (by quite a few years) was said to be a golden era for chinese martial arts with even greater developments being made later in the Ming dynasty by the Shaolin Order. It is during the Ming dynasty that we hear about the tales of the saving of the emperor and the theft of horses and the emperor granting the monks teh right to eat meat and drink wine… Many of the tales of shaolin and it’s prowess as a place were one could develop kungfu take place in this dynasty.
In the dynasty that follows, the Qing dynasty, we hear more incredible tales of rebels and shaolin monks who aid them in their quest to defeat the Qing. Here we see the time of teh Hung society, the white lotus society and various other groups who are criminal at the time but nevertheless soldiers, scholars, warriors, monks, fishmongers you name it and they were to be found looking for a way to defeat the usurpers and to restore China to the Chinese. Afterall, are we not only men? 
Anyway, you’re gonna hear a lot of things about origins of martial arts and you’re gonna hear some stuff that will really make you go wtf?? lol
take it in stride and with a grain of salt where necessary. can’t rush understanding afterall. It only comes with time and effort.