Skip to content

Commit

Permalink
Working on v1.0.0:
Browse files Browse the repository at this point in the history
1. Added panic to pcounter.c.
2. Found and fixed wrong PROC_LRES_PROCESSING (closes #16).
  • Loading branch information
Anonimous committed Jan 13, 2016
1 parent dee48ad commit 46c0357
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 97 deletions.
27 changes: 4 additions & 23 deletions kernel/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,10 @@ sMMM+........................-hmMo/ds oMo`.-o :h s:`h` `Nysd.-Ny-h:......
bgrt_prio_t bgrt_index_search(bgrt_index_t index)
{
bgrt_prio_t prio = (bgrt_prio_t)0;
#ifdef BGRT_CONFIG_USE_O1_SEARCH
/*
Binary search.
Takes O(LOG2(BGRT_BITS_IN_INDEX_T)) time always, as BGRT_BITS_IN_INDEX_T is fixed, then it's O(1).
*/
bgrt_index_t upper = ~(bgrt_index_t)0, lower = ~(bgrt_index_t)0, middle;
bgrt_prio_t step = (bgrt_prio_t)BGRT_BITS_IN_INDEX_T;
while( step )
{
step>>=1; // Bisection
middle = lower>>step;
if( index & upper & middle )
{
lower = middle;
}
else
{
upper = ~middle;
prio += step;
}
}
#else
#ifndef BGRT_CONFIG_USER_SEARCH
/*
Linear search.
Time limitation is O(BGRT_BITS_IN_INDEX_T), which is also O(1).
Time limitation is O(BGRT_BITS_IN_INDEX_T), which is O(1).
*/
bgrt_index_t mask = (bgrt_index_t)1;
while( mask )
Expand All @@ -113,6 +92,8 @@ bgrt_prio_t bgrt_index_search(bgrt_index_t index)
prio++;
mask<<=1;
}
#else
BGRT_CONFIG_USER_SEARCH(prio); //User defined search procedure
#endif
return prio;
}
37 changes: 30 additions & 7 deletions kernel/pcounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ void bgrt_pcounter_init(bgrt_pcounter_t * pcounter)
// Increment
void bgrt_pcounter_inc(bgrt_pcounter_t * pcounter, bgrt_prio_t prio)
{
pcounter->counter[prio]++;

if( BGRT_CONFIG_CNT_MAX > pcounter->counter[prio] )
{
pcounter->counter[prio]++;
}
else
{
while(1);//Panic!!!
}
pcounter->index |= ((bgrt_index_t)1)<<prio;
}
// Decrement
Expand All @@ -98,37 +106,52 @@ bgrt_index_t bgrt_pcounter_dec(bgrt_pcounter_t * pcounter, bgrt_prio_t prio)

mask = ((bgrt_index_t)1)<<prio;

if(pcounter->counter[prio])
if( pcounter->counter[prio] )
{
pcounter->counter[prio]--;
}
else
{
while(1);//Panic!!!
}

if(pcounter->counter[prio] == (bgrt_cnt_t)0)
{
pcounter->index &= ~mask;
}

return pcounter->index & mask;
}
// Multiple increment
void bgrt_pcounter_plus(bgrt_pcounter_t * pcounter, bgrt_prio_t prio, bgrt_cnt_t count)
{
pcounter->index |= ((bgrt_index_t)1)<<prio;
pcounter->counter[prio] += count;

if( BGRT_CONFIG_CNT_MAX - pcounter->counter[prio] > count )
{
pcounter->counter[prio] += count;
}
else
{
while(1);//Panic
}
}
// Multiple decrement
bgrt_index_t bgrt_pcounter_minus(bgrt_pcounter_t * pcounter, bgrt_prio_t prio, bgrt_cnt_t count)
{
bgrt_index_t mask;
mask = ((bgrt_index_t)1)<<prio;
if( pcounter->counter[prio] <= count )
if( pcounter->counter[prio] < count )
{
pcounter->index &= ~mask;
pcounter->counter[prio] = (bgrt_cnt_t)0;
while(1);//Panic
}
else
{
pcounter->counter[prio] -= count;
}

if( (bgrt_cnt_t)0 == pcounter->counter[prio] )
{
pcounter->index &= ~mask;
}
return pcounter->index & mask;
}
2 changes: 1 addition & 1 deletion kernel/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void _bgrt_pctrl_propagate( BGRT_PCTRL_PROP_ARGS )
else
{
// Finish process wakeup
_bgrt_pctrl_proc_run( proc, BGRT_PROC_STATE_SYNC_READY );
_bgrt_pctrl_proc_run_high( proc, BGRT_PROC_STATE_SYNC_READY );
}

BGRT_SPIN_FREE( proc );
Expand Down
1 change: 1 addition & 0 deletions tests/arch/avr/gcc-vsmp/bugurt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef unsigned char bgrt_st_t;
// may be available, so bgrt_cnt_t can be
// unsigned char or unsigned short.
// Unsigned short is enough.
#define BGRT_CONFIG_CNT_MAX (0xff)
typedef unsigned short bgrt_cnt_t;

// You can specify any volatile unsigned type here.
Expand Down
4 changes: 2 additions & 2 deletions tests/arch/avr/gcc/avr-test.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<CodeBlocks_workspace_file>
<Workspace title="Workspace">
<Project filename="sched/sched.cbp" />
<Project filename="proc/proc.cbp" active="1" />
<Project filename="sync/sync.cbp" />
<Project filename="proc/proc.cbp" />
<Project filename="sync/sync.cbp" active="1" />
</Workspace>
</CodeBlocks_workspace_file>
2 changes: 1 addition & 1 deletion tests/arch/avr/gcc/bugurt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef unsigned char bgrt_st_t;
// may be available, so bgrt_cnt_t can be
// unsigned char or unsigned short.
// Unsigned short is enough.
#define BGRT_CONFIG_CNT_MAX (255)
typedef unsigned short bgrt_cnt_t;

// You can specify any volatile unsigned type here.
Expand All @@ -69,7 +70,6 @@ typedef unsigned char bgrt_syscall_t;
///=================================================================
// BuguRTOS behavior compilation flags, edit carefully!!!
///=================================================================
#define BGRT_CONFIG_USE_O1_SEARCH
#define BGRT_CONFIG_HARD_RT
#define BGRT_CONFIG_USER_IDLE
#define BGRT_CONFIG_PREEMPTIVE_KERNEL
Expand Down
24 changes: 12 additions & 12 deletions tests/arch/avr/gcc/sched/sched.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="../../../../../arch/avr/gcc/bugurt_port.c" open="0" top="0" tabpos="6">
<Cursor position="8344" topLine="137" />
<Cursor position="8481" topLine="137" />
</File>
<File name="../../../../../arch/avr/gcc/bugurt_port.h" open="0" top="0" tabpos="3">
<Cursor position="7844" topLine="0" />
Expand All @@ -16,32 +16,32 @@
<File name="../../../../../kernel/bugurt.h" open="0" top="0" tabpos="6">
<Cursor position="7758" topLine="123" />
</File>
<File name="../../../../../kernel/crit_sec.c" open="0" top="0" tabpos="4">
<File name="../../../../../kernel/crit_sec.c" open="1" top="0" tabpos="4">
<Cursor position="6098" topLine="75" />
</File>
<File name="../../../../../kernel/crit_sec.h" open="0" top="0" tabpos="3">
<Cursor position="163" topLine="93" />
</File>
<File name="../../../../../kernel/index.c" open="0" top="0" tabpos="10">
<File name="../../../../../kernel/index.c" open="1" top="0" tabpos="10">
<Cursor position="163" topLine="1" />
</File>
<File name="../../../../../kernel/index.h" open="0" top="0" tabpos="7">
<Cursor position="6336" topLine="75" />
</File>
<File name="../../../../../kernel/item.c" open="0" top="0" tabpos="12">
<File name="../../../../../kernel/item.c" open="1" top="0" tabpos="12">
<Cursor position="163" topLine="83" />
</File>
<File name="../../../../../kernel/item.h" open="0" top="0" tabpos="4">
<Cursor position="7281" topLine="96" />
</File>
<File name="../../../../../kernel/kernel.c" open="0" top="0" tabpos="4">
<File name="../../../../../kernel/kernel.c" open="1" top="0" tabpos="4">
<Cursor position="6362" topLine="78" />
</File>
<File name="../../../../../kernel/kernel.h" open="0" top="0" tabpos="5">
<Cursor position="9551" topLine="145" />
</File>
<File name="../../../../../kernel/pcounter.c" open="0" top="0" tabpos="4">
<Cursor position="6099" topLine="74" />
<Cursor position="6892" topLine="98" />
</File>
<File name="../../../../../kernel/pcounter.h" open="0" top="0" tabpos="6">
<Cursor position="6710" topLine="81" />
Expand All @@ -52,20 +52,20 @@
<File name="../../../../../kernel/pitem.h" open="0" top="0" tabpos="8">
<Cursor position="9318" topLine="178" />
</File>
<File name="../../../../../kernel/proc.c" open="1" top="0" tabpos="2">
<File name="../../../../../kernel/proc.c" open="0" top="0" tabpos="2">
<Cursor position="6484" topLine="80" />
</File>
<File name="../../../../../kernel/proc.h" open="1" top="0" tabpos="3">
<Cursor position="25889" topLine="532" />
<Cursor position="7415" topLine="386" />
</File>
<File name="../../../../../kernel/sched.c" open="0" top="0" tabpos="6">
<Cursor position="10222" topLine="197" />
<Cursor position="9773" topLine="184" />
</File>
<File name="../../../../../kernel/sched.h" open="0" top="0" tabpos="5">
<Cursor position="10263" topLine="190" />
</File>
<File name="../../../../../kernel/sync.c" open="1" top="1" tabpos="1">
<Cursor position="9360" topLine="968" />
<File name="../../../../../kernel/sync.c" open="1" top="0" tabpos="1">
<Cursor position="19578" topLine="442" />
</File>
<File name="../../../../../kernel/sync.h" open="0" top="0" tabpos="3">
<Cursor position="15814" topLine="298" />
Expand All @@ -89,7 +89,7 @@
<Cursor position="8240" topLine="85" />
</File>
<File name="../test_func.c" open="0" top="0" tabpos="2">
<Cursor position="2047" topLine="77" />
<Cursor position="2017" topLine="77" />
</File>
<File name="../test_func.h" open="0" top="0" tabpos="1">
<Cursor position="15" topLine="0" />
Expand Down
66 changes: 33 additions & 33 deletions tests/arch/avr/gcc/sync/sync.depend
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# depslib dependency file v1.0
1450335151 source:/home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_port.c
1452096986 source:/home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_port.c
<bugurt.h>

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_port.h
1452096986 /home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_port.h

1451650945 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/bugurt.h
1452096987 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/bugurt.h
<bugurt_config.h>
"index.h"
"item.h"
Expand All @@ -21,79 +21,79 @@
"syscall.h"
<user_syscall.h>

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/index.h
1452096987 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/index.h

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/item.h
1452096987 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/item.h

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/xlist.h
1452096989 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/xlist.h

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pitem.h
1452096988 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pitem.h

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pcounter.h
1452096988 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pcounter.h

1451651899 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/crit_sec.h
1452096987 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/crit_sec.h

1451969774 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/proc.h
1452096988 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/proc.h

1450330794 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sched.h
1452096988 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sched.h

1450335440 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/kernel.h
1452096987 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/kernel.h

1451650498 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sync.h
1452096988 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sync.h

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/timer.h
1452096989 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/timer.h

1451654345 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/syscall.h
1452096988 /home/anon/BuguRTOS/0.8.x/bugurtos/kernel/syscall.h

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_port_asm.S
1452096986 source:/home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_port_asm.S
<avr/io.h>

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_proc_stack_init.c
1452096986 source:/home/anon/BuguRTOS/0.8.x/bugurtos/arch/avr/gcc/bugurt_proc_stack_init.c
<bugurt.h>

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/crit_sec.c
1452096987 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/crit_sec.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/index.c
1452698647 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/index.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/item.c
1452096987 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/item.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/kernel.c
1452096987 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/kernel.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pcounter.c
1452698110 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pcounter.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pitem.c
1452096988 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/pitem.c
"bugurt.h"

1450329681 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/proc.c
1452096988 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/proc.c
"bugurt.h"

1451967735 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sched.c
1452096988 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sched.c
"bugurt.h"

1451979172 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sync.c
1452705125 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/sync.c
"bugurt.h"

1450956484 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/syscall.c
1452096988 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/syscall.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/timer.c
1452096988 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/timer.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/xlist.c
1452096989 source:/home/anon/BuguRTOS/0.8.x/bugurtos/kernel/xlist.c
"bugurt.h"

1449750701 source:/home/anon/BuguRTOS/0.8.x/bugurtos/tests/arch/avr/gcc/test_func.c
1452063578 source:/home/anon/BuguRTOS/0.8.x/bugurtos/tests/arch/avr/gcc/test_func.c
<test_func.h>

1451979599 source:/home/anon/BuguRTOS/0.8.x/bugurtos/tests/main/bsync/main.c
1452708958 source:/home/anon/BuguRTOS/0.8.x/bugurtos/tests/main/bsync/main.c
<test_func.h>

1449826226 /home/anon/BuguRTOS/0.8.x/bugurtos/tests/arch/avr/gcc/bugurt_config.h
1452697441 /home/anon/BuguRTOS/0.8.x/bugurtos/tests/arch/avr/gcc/bugurt_config.h
<avr/io.h>
<avr/interrupt.h>
<avr/pgmspace.h>
Expand All @@ -103,7 +103,7 @@
<avr/interrupt.h>
<avr/pgmspace.h>

1449750701 /home/anon/BuguRTOS/0.8.x/bugurtos/tests/arch/avr/gcc/test_func.h
1452063578 /home/anon/BuguRTOS/0.8.x/bugurtos/tests/arch/avr/gcc/test_func.h
<bugurt.h>
<util/delay.h>

0 comments on commit 46c0357

Please sign in to comment.