This project is a kernel initially made for ATmega 640.
Download project
The number of threads maximum 254 or limited with the ram memory dimension.
Description:
- This kernel was designed to use all the processing power of an microcontroller, in the case when on a device are used more microcontrollers each one with different functions and they (microcontrollers) don't work at maximum capacity, and it can facilitate tremendously the job of an programator who wants to implement more functions in only one microcontroller.
- On this kernel, more programs totally independently can work simultaneously (in the same time), the only thing that is affect is the processing power on each one.
- This programs can communicate between them using the name ( string 16 Chars ) of the program and/or the address of program in Flash obtained from one ping to the name of program for idle-section of program, so if we update a program or a driver, it will replace the old one with the new one without actualizing the remaining programs (the programs who were not updated) to the new address of the new program, the address of new program is declared in the installed programs table.
- When a program starts to run the kernel reads from the program haw much memory ram to give him, the kernel assigns to the program the memory ram demanded rounded of form 128 in 128 Bytes (if a program needs 0 (zero) memory ram the kernel will not assign ram memory to that program; if a program needs 1-128 Bytes memory ram the kernel will assign 128 Bytes ram memory to that program; if a program needs 129-256 Bytes memory ram the kernel will assign 256 Bytes ram memory to that program) but when the program is running it can change the dimension of the memory ram assigned, according to the memory ram he needs, by "handing in an application" to the kernel demanding a change of memory ram assigned.
- If a program requests to the kernel to open a program the kernel can open it, the kernel is checking if that program is already open, if that program is open, the kernel reads if that program can be open again, if it can be open again it will be open like a new thread independently from the previous and it will give a order number (the first open program will have the number of order 0 (zero), the second program open will have the number of order 1 etc.) this value it will be return to the program who requested the open to the program to make the difference between the open threads with the same ID. If the requested program can't be open many times, the program who demanded the open of the program will receive an error the program can't be open because is already open. (This function is incomplete implemented.)
- At the end of a program, the kernel is taking care of deleting the cluster of memory ram occupied by the program (the memory ram that this program occupied can be used by future open program) and immediately the kernel will compact the table in which are kept the principals dates of each open program.
- A program can be force closed by the kernel if there is an stack overflow error, the program can request the kernel to be closed or the kernel receive the close command from another program, and the program who will be closed can save the working dates and after that sending the close command to the kernel.
- The open programs divide the processing power equally, but there is the case when a program is in idle, in this case the program will sent to the kernel a interrupt command, the processing power remain between the time when the demand of interrupt and the time of interrupt is equally divided to the running programs.
- For each program the kernel assigns an cluster of memory ram of 128 octets because when the program is interrupted the kernel to save 32 registry, stank counter and 93 Bytes from the stank occupied by the program, before returning in the interrupted program the kernel will restore the contents of 32 registry ,the stank and counter of the stank and the stank.
- The memory ram for each program begins from an virtual address 0 (zero) in the registry Z where is the address of the head cluster of the memory ram assigned, if a program wants to find out the address of the head cluster memory ram assigned it can appeal a routine from the kernel to give him the address (in this way, using an artifice we can use the direct address knowing that the cluster memory ram used starts at the head address +2).
- System Timers: They were integrated to can make data processing and to an exact time and for software pause in lock delays, system timer have 128 steps/sec, so we can create software with the exact time of the external Quartz of 32768Hz
(Still working at kernel.)
This kernel can be adapted on any microcontroller ATmega with the some little modifications.
Here is an description to use this kernel
This kernel is a fully dynamic kernel, all files to use this kernel is in virtual ram memory
One bug is present in this kernel because is not possible to close one program if run minimum 3 threads, if one thread is closed if is running one or two thread this kernel will freeze.
For eliminate this error please use 3 ghost threads like this:
_____________________________________________________________
Ghost programs ( these programs no consume processing power )
Ldi Yl,Low(Ghost1*2)
Ldi Yh,High(Ghost1*2)
Call LauchProgram
Ldi Yl,Low(Ghost2*2)
Ldi Yh,High(Ghost2*2)
Call LauchProgram
Ldi Yl,Low(Ghost2*2)
Ldi Yh,High(Ghost2*2)
Call LauchProgram
User programs ( this programs is a user programs lached in startup )
Ldi Yl,Low(Program1*2)
Ldi Yh,High(Program1*2)
Call LauchProgram
;**********************************************************
Sei
;**********************************************************
IdleKernel:
Wdr
Rjmp IdleKernel
;**********************************************************
---------------------------------------------------------------------------------------
Ghost1:
.Db "Ghost1",255,255,255,255,255,255,255,255,255,255
.Dw EndGhost1-Ghost1
.Dw 0
.Dw 0
Ghost1Startup:
Call IntrerupereThreadLaCerere
Rjmp Ghost1Startup
EndGhost1:
---------------------------------------------------------------------------------------
Ghost2:
.Db "Ghost2",255,255,255,255,255,255,255,255,255,255
.Dw EndGhost2-Ghost2
.Dw 0
.Dw 0
Ghost2Startup:
Call IntrerupereThreadLaCerere
Rjmp Ghost2Startup
EndGhost2:
---------------------------------------------------------------------------------------
Ghost3:
.Db "Ghost3",255,255,255,255,255,255,255,255,255,255
.Dw EndGhost3-Ghost3
.Dw 0
.Dw 0
Ghost3Startup:
Call IntrerupereThreadLaCerere
Rjmp Ghost3Startup
EndGhost3:
_____________________________________________________________
With this sequences is launched one program:
Ldi Yl,Low(Program1*2)
Ldi Yh,High(Program1*2)
Call LauchProgram
With this sequences is created the resources of ram but until this sequences the program is not launched, the program is launched after kernel scan the table of start programs.
_____________________________________________________________
Here is a simple thread to run on this kernel:
Program1:
.Db "ProgramTest1",255,255,255,255;Here is a string with maxim 16 char ( this is the name of task ) this string is necessarily to end with 255 int8
.Dw EndProgram1-Program1;Here is a int16 dimension of the program
.Dw 63; Here is a int16 ( how ram to assign to this thread )
.Dw 0;Here is a int16 constant divided in Boolean that describe the configuration thread
;Vectors ( links ) for routines in program
Program1Startup:;Here jump the kernel until the all resources is reserved for this thread, here is start of thread
Rjmp Program1Startup_
Until start link , is the links of routines of this thread ( for this example , no links )
...
...
...
...
...
...
...
...
;End of vectors and begin of program routines, no chase in this example
Program1Startup_:
Lds R17,DDRH;\
Sbr R17,1<<2;Here is the configuration section for this thread, here is configurations of all port and resources used by this thread
Sts DDRH,R17;/
Program1Startup__:; Here is the main of this thread
Ldi R16,16
Rcall SlepS
Cli
Lds R17,PORTH
Sbr R17,1<<2;
Sts PORTH,R17
Sei
Rcall SlepS
Cli
Lds R17,PORTH
Cbr R17,1<<2 ;
Sts PORTH,R17
Sei ;If is used ( Jmp CloseProgram ) this thread is closed ( killed )
Program1Startup___:
Call IntrerupereThreadLaCerere;Here is interrupt request from the thread, because this thread no longer needs processing power
Rjmp Program1Startup___;After the kernel restore this thread go again to interrupt request
EndProgram1:
_____________________________________________________________
For read and write to ram memory with errors capture use these sequences:
Rcall GetRamAdressForCurentThreadInZ;Read file adress ( here is the head of ram file assigned to this thread )
Ldi Xl,Low( Offset in file )
Ldi Xh,High( Offset in file );In X is offset of byte in file
Ldi R16,'A';In R16 is byte to write
Call WriteToVirtualRamFile
Rjmp ErrorOutOfVirtualMemory;This routine is return here if is a out of file error this jump es used by user to capture this error
;Or here if no error encountred
Call ReadFromVirtualRamFile; In R16 is byte result
Rjmp ErrorOutOfVirtualMemory;This routine is return here if is a out of file error this jump es used by user to capture this error
;Or here if no error encountred
_____________________________________________________________
For read and write to ram memory with no errors capture use these sequences:
Rcall GetRamAdressForCurentThreadInZ;Read file adress ( here is the head of ram file assigned to this thread )
Ldi Xl,Low( Offset in file )
Ldi Xh,High( Offset in file );In X is offset of byte in file
Ldi R16,'A';In R16 is byte to write
Call WriteToVirtualRamFile
Nop
Call ReadFromVirtualRamFile; In R16 is byte result
Nop
_____________________________________________________________
For read and write to ram memory with errors capture and autoextend ram memory space if is detected an out of file error use these sequences:
Rcall GetRamAdressForCurentThreadInZ;Read file adress ( here is the head of ram file assigned to this thread )
Ldi Xl,Low( Offset in file )
Ldi Xh,High( Offset in file );In X is offset of byte in file
Ldi R16,'A';In R16 is byte to write
ReturnFromExtendFile:
Call WriteToVirtualRamFile
Rjmp ErrorOutOfVirtualMemoryExtendFile;This routine is return here if is a out of file error this jump es used by user to capture this error
;Or here if no error encountred
Call ReadFromVirtualRamFile; In R16 is byte result
Nop
---------------------------------------------------------------------------------------
ErrorOutOfVirtualMemoryExtendFile:
Rcall ModifyVirtualRamFileDimension
Rjmp ReturnFromExtendFile
_____________________________________________________________
3 comentarii:
For support post a comment.
Hi,
Is there a readme or tutorial ?
How can i integrate the kernel with my Robotic Routines written in C ?
How do i create/destroy tasks ?
The program stucks in line 122 of KernelV03Atmega64.asm: "Call LaunchProgram".
"The program stucks in line 122 of KernelV03Atmega64.asm: "Call LaunchProgram"."
This project works fine in AVR Studio 4.16.
Open included library and take a look on code :)
Line 122 is a blank line, and no possible to generate one error.
This kernel is created to run only asm threads because work with virtual ram memory.In future i wont to create one kernel to work with entire programs created like standalone programs.
Post a Comment