|
|
|
|
tnkernel-PIC24-dsPIC-2-3-1-src.zip |
|
This ZIP archive contains: |
|
| |
- A TNKernel port for the Microchip PIC24/dsPIC microprocessors source code (for the MPLAB C30 v.2.05 compiler)
- The examples (include the projects for PIC24FJ128 and dsPIC33FJ128 microprocessors)
|
|
|
TNKernel was successfully ported to the Microchip (c) 16-bit microprocessors - PIC24 and dsPIC33 series.
1. The port description
A significant changes of the TNKernel
source files structure for the PIC24F/dsPIC port have been performed. All sources
were rearranges according to the principle one function - one file and
compiled as a library. At the linking stage of the application creating, linker takes from the library and includes in the
application's output file a code only of those functions which are used
in the project. It provides a significant decreasing of the ROM (FLASH) usage, what is
important for the PIC24/dsPIC.
The memory for the internal TNKernel data structures is also defined in the separate files.
This is a file names templates:
cm_xxxx.c/h - common
dq_xxxx.c/h - data queues
ev_xxxx.c/h - events
mp_xxxx.c/h - memory pools
mx_xxxx.c/h - mutexes
sm_xxxx.c/h - semaphores
sy_xxxx.c/h - system
ts_xxxx.c/h - tasks
port_xxxx.c/h/a - portable
After char '_', all files names (except port parts) include:
xx_defs.h - definitions
xx_extr.h - global function prototypes
xx_dat.c - data memory structures declarations
xx_fnc_xxxx.c - functions without arguments checking
xx_fce_xxxx.c - functions with arguments checking
xx_rtn_xxxx.c - internal function
The port part includes files:
port_a_extr.h - global function prototypes ( ASM-language implemented )
port_c_extr.h - global function prototypes ( C-language implemented )
port_c_defs.h - definitions( C-language )
port_af_xxxx.s - functions ( ASM-language implemented )
port_cf_xxxx.c - functions ( C-language implemented )
For the port, the single file tnkernel.h is used. If a debugging is enabled, files xx_defs.h are also in use.
2. The changes in the file tnkernel.h
- all base types are defined
- maximal types values are defined in the standard header file <limits.h>
- magic numbers for the tasks, semaphores, events, etc. are placed in the corresponding xx_defs.h files
- TN_TASK macro has been added - it decreases stack usage with the CGG attribute __attribute__((no return))
- TN_DEBUG macro has been added - it defines at the debugging to show the user the contents of the TCB, etc.
- TN_NO_ERROR_CHECKING macro has been added - to use functions without arguments checking
3. The changes in the API
- the function tn_start_system() in the port has an arguments
void tn_start_system(TN_UWORD * timer_task_stack,
TN_UWORD timer_task_stack_size,
TN_UWORD * idle_task_stack,
TN_UWORD idle_task_stack_size,
void (*app_in_cb)(void),
void (*cpu_int_en)(void),
void (*idle_user_cb)(void)
);
where:
timer_task_stack - timer task stack bottom address
timer_task_stack_size - number of timer task stack elements (not bytes)
idle_task_stack - idle task stack bottom address
idle_task_stack_size - number of idle task stack elements (not bytes)
app_in_cb - the address of the
tn_app_init() function
cpu_int_en - the address of the
tn_cpu_int_enable() function
idle_user_cb - idle task
callback function. This is the address of a function declared as:
void task_func (void * param)
The Idle task body function
looks like this:
void tn_idle_task_func (void *par)
{
for(;;)
{
idle_user_func_callback();
tn_idle_count++;
}
}
Here idle_user_func_callback() is an idle_user_cb
parameter of the tn_start_system().
- A functions tn_sys_enter_critical() and tn_sys_exit_critical() has been added
- In the functions tn_start_system() and tn_task_create(), a parameter task_stack_start
must point to the stack bottom (origin). The PIC24/dsPIC stack grows from
the low to the high memory addresses. For instance, if the task
stack array is defined as unsigned int xxx_xxx[task_stack_size] (in C-language notation), then the task_stack_start parameter has to be defined as &xxx_xxx[0].
4. Interrupts - PIC24
has a hardware control of the stack overflow, and at the context
switching, the SPLIM register is also saved. - The file tnkernel.inc includes assembly macroes for the prologue and epilogue code of the context switching.
All interrupts that have to use TNKernel functions, should be processed like this:
__INT0Interrupt:
TN_INTERRUPT_PROLOGUE
call _INT0_IRQ_Service
TN_INTERRUPT_EPILOGUE where: INT0_IRQ_Service() - C-language function with actual interrupt handler code
When interrupts are disabled by the kernel, the only interrupts
with priority 1-6 are actually blocked; interrupt with priority 7
should be never used for the TNKernel services.
|