TNeo  BETA v1.08-11-g97e5a6d
Functions
tn_arch.h File Reference

Detailed Description

Architecture-dependent routines declaration.

Definition in file tn_arch.h.

Go to the source code of this file.

Functions

void tn_arch_int_dis (void)
 Unconditionally disable system interrupts. More...
 
void tn_arch_int_en (void)
 Unconditionally enable interrupts. More...
 
TN_UWord tn_arch_sr_save_int_dis (void)
 Disable system interrupts and return previous value of status register, atomically. More...
 
void tn_arch_sr_restore (TN_UWord sr)
 Restore previously saved status register. More...
 
TN_UWord tn_arch_sched_dis_save (void)
 Disable kernel scheduler and return previous state. More...
 
void tn_arch_sched_restore (TN_UWord sched_state)
 Restore state of the kernel scheduler. More...
 
TN_UWord_tn_arch_stack_init (TN_TaskBody *task_func, TN_UWord *stack_low_addr, TN_UWord *stack_high_addr, void *param)
 Should put initial CPU context to the provided stack pointer for new task and return current stack pointer. More...
 
int _tn_arch_inside_isr (void)
 Should return 1 if system ISR is currently running, 0 otherwise. More...
 
int _tn_arch_is_int_disabled (void)
 Should return 1 if system interrupts are currently disabled, 0 otherwise. More...
 
void _tn_arch_context_switch_pend (void)
 Called whenever we need to switch context from one task to another. More...
 
void _tn_arch_context_switch_now_nosave (void)
 Called whenever we need to switch context to new task, but don't save current context. More...
 
void _tn_arch_sys_start (TN_UWord *int_stack, TN_UWord int_stack_size)
 Performs first context switch to the first task (_tn_next_task_to_run is already set to needed task). More...
 

Function Documentation

◆ tn_arch_int_dis()

void tn_arch_int_dis ( void  )

Unconditionally disable system interrupts.

Refer to the section Interrupt types for details on what is system interrupt.

◆ tn_arch_int_en()

void tn_arch_int_en ( void  )

Unconditionally enable interrupts.

Refer to the section Interrupt types for details on what is system interrupt.

◆ tn_arch_sr_save_int_dis()

TN_UWord tn_arch_sr_save_int_dis ( void  )

Disable system interrupts and return previous value of status register, atomically.

Refer to the section Interrupt types for details on what is system interrupt.

See also
tn_arch_sr_restore()

◆ tn_arch_sr_restore()

void tn_arch_sr_restore ( TN_UWord  sr)

Restore previously saved status register.

Parameters
srstatus register value previously from tn_arch_sr_save_int_dis()
See also
tn_arch_sr_save_int_dis()

◆ tn_arch_sched_dis_save()

TN_UWord tn_arch_sched_dis_save ( void  )

Disable kernel scheduler and return previous state.

Returns
Scheduler state to be restored later by tn_arch_sched_restore().

◆ tn_arch_sched_restore()

void tn_arch_sched_restore ( TN_UWord  sched_state)

Restore state of the kernel scheduler.

See tn_arch_sched_dis_save().

Parameters
sched_stateValue returned from tn_arch_sched_dis_save()

◆ _tn_arch_stack_init()

TN_UWord* _tn_arch_stack_init ( TN_TaskBody task_func,
TN_UWord stack_low_addr,
TN_UWord stack_high_addr,
void *  param 
)

Should put initial CPU context to the provided stack pointer for new task and return current stack pointer.

When resulting context gets restored by _tn_arch_context_switch_now_nosave() or _tn_arch_context_switch_pend(), the following conditions should be met:

  • Interrupts are enabled;
  • Return address is set to tn_task_exit(), so that when task body function returns, tn_task_exit() gets automatially called;
  • Argument 0 contains param pointer
Parameters
task_funcPointer to task body function.
stack_low_addrLowest address of the stack, independently of the architecture stack implementation
stack_high_addrHighest address of the stack, independently of the architecture stack implementation
paramUser-provided parameter for task body function.
Returns
current stack pointer (top of the stack)

◆ _tn_arch_inside_isr()

int _tn_arch_inside_isr ( void  )

Should return 1 if system ISR is currently running, 0 otherwise.

Refer to the section Interrupt types for details on what is system ISR.

◆ _tn_arch_is_int_disabled()

int _tn_arch_is_int_disabled ( void  )

Should return 1 if system interrupts are currently disabled, 0 otherwise.

Refer to the section Interrupt types for details on what is system interrupt.

◆ _tn_arch_context_switch_pend()

void _tn_arch_context_switch_pend ( void  )

Called whenever we need to switch context from one task to another.

This function typically does NOT switch context; it merely pends it, that is, it sets appropriate interrupt flag. If current level is an application level, interrupt is fired immediately, and context gets switched. Otherwise (if some ISR is currently running), context switch keeps pending until all ISR return.

Preconditions:

  • interrupts are enabled;
  • _tn_curr_run_task points to currently running (preempted) task;
  • _tn_next_task_to_run points to new task to run.

Actions to perform in actual context switching routine:

  • save context of the preempted task to its stack;
  • if preprocessor macro _TN_ON_CONTEXT_SWITCH_HANDLER is non-zero, call _tn_sys_on_context_switch(_tn_curr_run_task, _tn_next_task_to_run);.
  • set _tn_curr_run_task to _tn_next_task_to_run;
  • restore context of the newly activated task from its stack.
See also
_tn_curr_run_task
_tn_next_task_to_run

◆ _tn_arch_context_switch_now_nosave()

void _tn_arch_context_switch_now_nosave ( void  )

Called whenever we need to switch context to new task, but don't save current context.

This happens:

This function doesn't need to pend context switch, it switches context immediately.

Preconditions:

  • interrupts are disabled;
  • _tn_next_task_to_run is already set to needed task.

Actions to perform:

  • if preprocessor macro _TN_ON_CONTEXT_SWITCH_HANDLER is non-zero, call _tn_sys_on_context_switch(_tn_curr_run_task, _tn_next_task_to_run);.
  • set _tn_curr_run_task to _tn_next_task_to_run;
  • restore context of the newly activated task from its stack.
See also
_tn_curr_run_task
_tn_next_task_to_run

◆ _tn_arch_sys_start()

void _tn_arch_sys_start ( TN_UWord int_stack,
TN_UWord  int_stack_size 
)

Performs first context switch to the first task (_tn_next_task_to_run is already set to needed task).

Typically, this function just calls _tn_arch_context_switch_now_nosave(), but it also can perform any architecture-dependent actions first, if needed.