I was wondering why would there be an issue with stack space if more code is wrote in an ISR than in the main function.
Stack space is probably not the primary concern for an ISR. An ISR should be as simple and fast as possible in order to minimise latency, so it shouldn't need a large stack anyway. If you have to do any non-trivial processing, your ISR should enqueue a task to run on a regular thread later to complete the job (sometimes called top-half and bottom-half). This could be achieved with a condition variable, semaphore, or message queue (to name a few IPC mechanisms). So if an ISR is using a lot of stack, it may be an indication that it's trying to do too much processing during a timing-critical scheduling period.
Also, many systems (e.g. RTOS) require you to declare the stack size for threads and ISRs.
I wish to call a few different functions from the callback. If this callback is actually called from an ISR, is calling more functions from the ISR a problem?
Only in so far as calling other functions from an ISR should be minimised as discussed above. You can call other functions, but you should defer as much as possible to run after the ISR has returned to the kernel scheduler (and unmasked interrupts!).
Also - beware of race conditions! Careful use of mutexes is necessary to protect shared state.
As I call each function, will this allow me extra stack space because each function has its own maximum stack size? This I find a bit confusing.
No - a function doesn't have its own stack size - threads do. For ISRs, it depends on the OS. Calling each function will consume more stack space though (based on the call nesting level).
I always thought that functions and ISRs can use as much stack stack space as they like up to the complete allocated stack.
Yes, but the stack is per-thread, not per-process like the heap. Using a large amount of stack space could be a sign of a design issue: allocating large objects on the stack rather than the heap, too many nested function calls, etc.
Does it mean the main function has a larger portion of the stack than others.
No, since the stack is per thread. A main
function will be at the bottom of the application's call stack, but it may consume a small or a large amount of stack, depending only on its local variables.
Some good reading: