├── .cproject ├── .gitattributes ├── .gitignore ├── .project ├── .settings ├── language.settings.xml ├── org.eclipse.cdt.codan.core.prefs ├── org.eclipse.cdt.core.prefs └── org.eclipse.cdt.managedbuilder.core.prefs ├── app ├── inc │ ├── edm_config.h │ └── edm_def.h └── src │ ├── app_pthread.c │ ├── app_rtt.c │ └── app_ucos.c ├── cache ├── cache.c └── cache.h ├── elog ├── LICENSE ├── README.md ├── inc │ ├── elog.h │ └── elog_cfg.h ├── port │ └── elog_port.c └── src │ ├── elog.c │ ├── elog_async.c │ ├── elog_buf.c │ └── elog_utils.c ├── refresher └── rt-thread │ ├── refresher.c │ └── refresher.h └── thread_pool ├── pthread ├── pthread_pool.c └── pthread_pool.h ├── rt-thread ├── drivers │ ├── board.c │ └── board.h ├── inc │ ├── rtdebug.h │ ├── rtdef.h │ ├── rthw.h │ ├── rtm.h │ ├── rtservice.h │ └── rtthread.h ├── libcpu │ └── sim │ │ └── win32 │ │ ├── cpu_port.c │ │ └── cpu_port.h ├── rtconfig.h ├── rtthread_pool.c ├── rtthread_pool.h └── src │ ├── clock.c │ ├── device.c │ ├── idle.c │ ├── ipc.c │ ├── irq.c │ ├── kservice.c │ ├── mem.c │ ├── memheap.c │ ├── mempool.c │ ├── module.c │ ├── module.h │ ├── object.c │ ├── scheduler.c │ ├── slab.c │ ├── thread.c │ └── timer.c ├── ucos2 ├── arch │ ├── app_cfg.h │ ├── os_cfg.h │ ├── os_cpu.h │ └── os_cpu_c.c └── source │ ├── os_core.c │ ├── os_flag.c │ ├── os_globle.c │ ├── os_mbox.c │ ├── os_men.c │ ├── os_mutex.c │ ├── os_q.c │ ├── os_sem.c │ ├── os_task.c │ ├── os_time.c │ └── ucos_ii.h ├── ucosii ├── Ports │ ├── app_cfg.h │ ├── cpu_core.h │ ├── os_cfg.h │ ├── os_cpu.h │ └── os_cpu_c.c └── Source │ ├── os_core.c │ ├── os_flag.c │ ├── os_mbox.c │ ├── os_mem.c │ ├── os_mutex.c │ ├── os_q.c │ ├── os_sem.c │ ├── os_task.c │ ├── os_time.c │ ├── os_tmr.c │ ├── ucos_ii.c │ └── ucos_ii.h └── ucosiii ├── App ├── Exec.c ├── Radian.c ├── Random.c ├── Stack.c └── main.c ├── Include ├── bsp.h ├── cpu.h ├── cpu_cfg.h ├── cpu_core.h ├── cpu_def.h ├── includes.h ├── lib_def.h ├── os.h ├── os_cfg.h ├── os_cfg_app.h ├── os_cpu.h ├── os_type.h ├── pc.h └── system.h ├── Ports ├── bsp.c ├── cpu_core.c ├── os_cpu_c.c └── pc.c └── uCOS-III ├── os_cfg_app.c ├── os_core.c ├── os_dbg.c ├── os_flag.c ├── os_int.c ├── os_mem.c ├── os_msg.c ├── os_mutex.c ├── os_pend_multi.c ├── os_prio.c ├── os_q.c ├── os_sem.c ├── os_stat.c ├── os_task.c ├── os_tick.c ├── os_time.c ├── os_tmr.c └── os_var.c /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.S text 4 | *.asm text 5 | *.c text 6 | *.cc text 7 | *.cpp text 8 | *.cxx text 9 | *.h text 10 | *.htm text 11 | *.html text 12 | *.in text 13 | *.ld text 14 | *.m4 text 15 | *.mak text 16 | *.mk text 17 | *.py text 18 | *.rb text 19 | *.s text 20 | *.sct text 21 | *.sh text 22 | *.txt text 23 | *.xml text 24 | Makefile text 25 | AUTHORS text 26 | COPYING text 27 | 28 | *.LZO -text 29 | *.Opt -text 30 | *.Uv2 -text 31 | *.ewp -text 32 | *.eww -text 33 | *.vcproj -text 34 | *.bat -text 35 | *.dos -text 36 | *.icf -text 37 | *.inf -text 38 | *.ini -text 39 | *.sct -text 40 | *.xsd -text 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /RVMDK/Output 2 | /Debug 3 | /Release 4 | /EWARM/Debug 5 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | EasyDataManager 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?name? 14 | 15 | 16 | 17 | org.eclipse.cdt.make.core.append_environment 18 | true 19 | 20 | 21 | org.eclipse.cdt.make.core.buildArguments 22 | 23 | 24 | 25 | org.eclipse.cdt.make.core.buildCommand 26 | make 27 | 28 | 29 | org.eclipse.cdt.make.core.buildLocation 30 | ${workspace_loc:/EasyDataManager/Debug} 31 | 32 | 33 | org.eclipse.cdt.make.core.contents 34 | org.eclipse.cdt.make.core.activeConfigSettings 35 | 36 | 37 | org.eclipse.cdt.make.core.enableAutoBuild 38 | false 39 | 40 | 41 | org.eclipse.cdt.make.core.enableCleanBuild 42 | true 43 | 44 | 45 | org.eclipse.cdt.make.core.enableFullBuild 46 | true 47 | 48 | 49 | org.eclipse.cdt.make.core.stopOnError 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.useDefaultBuildCmd 54 | true 55 | 56 | 57 | 58 | 59 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 60 | full,incremental, 61 | 62 | 63 | 64 | 65 | 66 | org.eclipse.cdt.core.cnature 67 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 68 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 69 | 70 | 71 | -------------------------------------------------------------------------------- /.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.settings/org.eclipse.cdt.codan.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.cdt.codan.checkers.errnoreturn=Warning 3 | org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} 4 | org.eclipse.cdt.codan.checkers.errreturnvalue=Error 5 | org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 6 | org.eclipse.cdt.codan.checkers.noreturn=Error 7 | org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} 8 | org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error 9 | org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 10 | org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error 11 | org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 12 | org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning 13 | org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 14 | org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error 15 | org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 16 | org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning 17 | org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},no_break_comment\=>"no break",last_case_param\=>true,empty_case_param\=>false} 18 | org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning 19 | org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()} 20 | org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error 21 | org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 22 | org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning 23 | org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true} 24 | org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error 25 | org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 26 | org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error 27 | org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 28 | org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error 29 | org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 30 | org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error 31 | org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 32 | org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error 33 | org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 34 | org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error 35 | org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 36 | org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error 37 | org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 38 | org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info 39 | org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} 40 | org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning 41 | org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 42 | org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error 43 | org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 44 | org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error 45 | org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 46 | org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error 47 | org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 48 | org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning 49 | org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 50 | org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning 51 | org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 52 | org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning 53 | org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>()} 54 | org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning 55 | org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},paramNot\=>false} 56 | org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning 57 | org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},else\=>false,afterelse\=>false} 58 | org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error 59 | org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 60 | org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning 61 | org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} 62 | org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning 63 | org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} 64 | org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning 65 | org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")} 66 | org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error 67 | org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 68 | -------------------------------------------------------------------------------- /.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/MINGW_HOME/delimiter=; 3 | environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/MINGW_HOME/operation=replace 4 | environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/MINGW_HOME/value=C\:\\mingw-w64 5 | environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/append=true 6 | environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/appendContributed=true 7 | -------------------------------------------------------------------------------- /.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/CPATH/delimiter=; 3 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/C_INCLUDE_PATH/delimiter=; 5 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/C_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/append=true 7 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/appendContributed=true 8 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/LIBRARY_PATH/delimiter=; 9 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/LIBRARY_PATH/operation=remove 10 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/append=true 11 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.514594119/appendContributed=true 12 | -------------------------------------------------------------------------------- /app/inc/edm_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: EasyDataManager config file 7 | * Created on: 2013-11-15 8 | */ 9 | 10 | #ifndef EDM_CONFIG_H_ 11 | #define EDM_CONFIG_H_ 12 | 13 | /* Thread poll used platform.Only one */ 14 | //#define EDM_USING_PTHREAD 15 | #define EDM_USING_RTT 16 | //#define EDM_USING_UCOS 17 | 18 | #define EDM_DEBUG 1 19 | 20 | #define EDM_LOG_LVL ELOG_LVL_DEBUG 21 | 22 | #endif /* EDM_CONFIG_H_ */ 23 | -------------------------------------------------------------------------------- /app/inc/edm_def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: all definition in this library 7 | * Created on: 2013-11-10 8 | */ 9 | 10 | #ifndef _EDM_DEF_H_ 11 | #define _EDM_DEF_H_ 12 | 13 | #include "edm_config.h" 14 | 15 | /** 16 | * Log default configuration for EasyLogger. 17 | * NOTE: Must defined before including the and after including the . 18 | */ 19 | #if !defined(LOG_TAG) 20 | #define LOG_TAG "edm" 21 | #endif 22 | #undef LOG_LVL 23 | #if defined(EDM_LOG_LVL) 24 | #define LOG_LVL EDM_LOG_LVL 25 | #endif 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #define EDM_VERSION "4.0.1" 33 | 34 | #endif /* _EDM_DEF_H_ */ 35 | -------------------------------------------------------------------------------- /app/src/app_pthread.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/app/src/app_pthread.c -------------------------------------------------------------------------------- /app/src/app_rtt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : application.c 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2009-01-05 Bernard the first version 13 | */ 14 | 15 | #define LOG_TAG "app" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "cache.h" 23 | #include "refresher.h" 24 | 25 | extern int rt_application_init(void); 26 | 27 | extern rt_uint8_t *heap; 28 | 29 | /** 30 | * This function will startup RT-Thread RTOS. 31 | */ 32 | void rtthread_startup(void) 33 | { 34 | /* init board */ 35 | rt_hw_board_init(); 36 | 37 | /* show version */ 38 | rt_show_version(); 39 | 40 | /* init tick */ 41 | rt_system_tick_init(); 42 | 43 | /* init kernel object */ 44 | rt_system_object_init(); 45 | 46 | /* init timer system */ 47 | rt_system_timer_init(); 48 | 49 | #ifdef RT_USING_HEAP 50 | /* init memory system */ 51 | rt_system_heap_init((void *)heap, (void *)&heap[RT_HEAP_SIZE - 1]); 52 | #endif 53 | 54 | /* init scheduler system */ 55 | rt_system_scheduler_init(); 56 | 57 | /* init all device */ 58 | #ifdef RT_USING_DEVICE 59 | rt_device_init_all(); 60 | #endif 61 | /* init application */ 62 | rt_application_init(); 63 | 64 | /* init timer thread */ 65 | rt_system_timer_thread_init(); 66 | 67 | /* init idle thread */ 68 | rt_thread_idle_init(); 69 | 70 | /* start scheduler */ 71 | rt_system_scheduler_start(); 72 | 73 | /* never reach here */ 74 | return ; 75 | } 76 | 77 | void *valueChangedListener1(void *arg) { 78 | pCacheData data = (pCacheData)arg; 79 | log_d("this is valueChangedListener1,the data %s was changed", data->name); 80 | rt_thread_delay(1); 81 | return NULL; 82 | } 83 | 84 | void *valueChangedListener2(void *arg) { 85 | pCacheData data = (pCacheData)arg; 86 | log_d("this is valueChangedListener2,the data %s was changed", data->name); 87 | rt_thread_delay(1); 88 | return NULL; 89 | } 90 | 91 | void testCache(void){ 92 | Cache cache; 93 | uint16_t valueTemp[CACHE_LENGTH_MAX]; 94 | uint32_t cacheLength, cacheSize; 95 | initCache(&cache, "cache", 4, 512); 96 | valueTemp[0] = 0; 97 | valueTemp[1] = 1; 98 | valueTemp[2] = 2; 99 | valueTemp[3] = 3; 100 | //test add data 101 | cache.add(&cache,"Temp",1,valueTemp,valueChangedListener1); 102 | cache.add(&cache,"Pressure",2,valueTemp,valueChangedListener2); 103 | cache.add(&cache,"Humidity",3,valueTemp,NULL); 104 | cache.add(&cache,"PM2.5",4,valueTemp,NULL); 105 | //test get data 106 | cache.getSize(&cache,&cacheLength,&cacheSize); 107 | cache.get(&cache,"Temp",valueTemp); 108 | cache.get(&cache,"Pressure",valueTemp); 109 | cache.get(&cache,"Humidity",valueTemp); 110 | cache.get(&cache,"PM2.5",valueTemp); 111 | //test delete data 112 | cache.del(&cache,"Temp"); 113 | cache.del(&cache,"Pressure"); 114 | cache.del(&cache,"Humidity"); 115 | cache.del(&cache,"PM2.5"); 116 | cache.del(&cache,"PM2.5"); 117 | cache.get(&cache,"PM2.5",valueTemp); 118 | //test valueChangedListener 119 | cache.add(&cache,"PM2.5",4,valueTemp,valueChangedListener1); 120 | cache.add(&cache,"Pressure",2,valueTemp,valueChangedListener2); 121 | valueTemp[0] = 3; 122 | valueTemp[1] = 2; 123 | valueTemp[2] = 1; 124 | valueTemp[3] = 0; 125 | cache.set(&cache,"Pressure",valueTemp); 126 | cache.set(&cache,"PM2.5",valueTemp); 127 | cache.get(&cache,"PM2.5",valueTemp); 128 | cache.getSize(&cache,&cacheLength,&cacheSize); 129 | //test destroy cache 130 | rt_thread_delay(1000); 131 | cache.pool->delAll(cache.pool); 132 | cache.pool->destroy(cache.pool); 133 | } 134 | 135 | void testCachePerformance(uint32_t dataTotalNum){ 136 | long i, lastTime; 137 | uint16_t valueTemp[CACHE_LENGTH_MAX]; 138 | Cache cache; 139 | char dataName[] = "0000000000000000000\0"; 140 | valueTemp[0] = 0; 141 | valueTemp[1] = 1; 142 | valueTemp[2] = 2; 143 | valueTemp[3] = 3; 144 | printf("Start test cache performance using %d data, please wait...\n", dataTotalNum); 145 | initCache(&cache, "cache", 4, 512); 146 | lastTime = rt_tick_get(); 147 | for (i = 0; i < dataTotalNum; i++) { 148 | ltoa(i, dataName, 10); 149 | cache.add(&cache, dataName, 1, valueTemp, NULL); 150 | } 151 | printf("1.Test cache add data finish.This system can add %ld data to cache in 1s.\n",dataTotalNum*1000/(rt_tick_get() - lastTime)); 152 | lastTime = rt_tick_get(); 153 | for(i = 0 ;i < dataTotalNum;i++){ 154 | ltoa(i,dataName,10); 155 | cache.set(&cache,dataName,valueTemp); 156 | } 157 | printf("2.Test cache set data finish.This system can set %ld data value in 1s.\n",dataTotalNum*1000/(rt_tick_get() - lastTime)); 158 | lastTime = rt_tick_get(); 159 | for(i = 0 ;i < dataTotalNum;i++){ 160 | ltoa(i,dataName,10); 161 | cache.get(&cache,dataName,valueTemp); 162 | } 163 | printf("3.Test cache get data finish.This system can get %ld data value in 1s.\n",dataTotalNum*1000/(rt_tick_get() - lastTime)); 164 | lastTime = rt_tick_get(); 165 | for(i = 0 ;i < dataTotalNum;i++){ 166 | ltoa(i,dataName,10); 167 | cache.del(&cache,dataName); 168 | } 169 | printf("4.Test cache delete data finish.This system can delete %ld data value in 1s.\n",dataTotalNum*1000/(rt_tick_get() - lastTime)); 170 | 171 | } 172 | 173 | void tempRefreshProcess(void *arg){ 174 | log_d("Temp refresh is process"); 175 | rt_thread_delay(13); 176 | } 177 | 178 | void pressureRefreshProcess(void *arg){ 179 | log_d("Pressure refresh is process"); 180 | rt_thread_delay(20); 181 | } 182 | 183 | void testRefresher(){ 184 | #ifdef EDM_USING_RTT 185 | Refresher refresher; 186 | initRefresher(&refresher, 1024, 5, 50); 187 | refresher.add(&refresher, "Temp", 8, 2, -1, false, 512, tempRefreshProcess); 188 | refresher.add(&refresher, "Pressure", 10, 4, -1, false, 512, pressureRefreshProcess); 189 | // refresher.add(&refresher,"Temp",8,2,4,true,512,tempRefreshProcess); 190 | // refresher.add(&refresher,"Pressure",10,4,4,true,512,pressureRefreshProcess); 191 | rt_thread_delay(2000); 192 | log_d("change period and priority "); 193 | refresher.setPeriodAndPriority(&refresher, "Pressure", 1, 1); 194 | rt_thread_delay(2000); 195 | log_d("setTimes"); 196 | refresher.setTimes(&refresher, "Pressure", 1); 197 | rt_thread_delay(2000); 198 | log_d("will delete job"); 199 | refresher.del(&refresher, "Temp"); 200 | log_d("retry delete job"); 201 | refresher.del(&refresher, "Temp"); 202 | log_d("delete all jobs"); 203 | refresher.delAll(&refresher); 204 | refresher.destroy(&refresher); 205 | rt_thread_delay(2000); 206 | #endif 207 | } 208 | 209 | void thread_entry_SysMonitor(void* parameter) { 210 | uint8_t i = 0; 211 | 212 | /* EasyLogger library initialize */ 213 | elog_init(); 214 | elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL & ~ELOG_FMT_P_INFO); 215 | elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_ALL & ~ELOG_FMT_P_INFO); 216 | elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_ALL & ~ELOG_FMT_P_INFO); 217 | elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME); 218 | elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_P_INFO)); 219 | elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_P_INFO)); 220 | elog_set_filter_lvl(ELOG_LVL_VERBOSE); 221 | // elog_set_text_color_enabled(true); 222 | /* start EasyLogger */ 223 | elog_start(); 224 | 225 | testCache(); 226 | 227 | testRefresher(); 228 | 229 | // testCachePerformance(20000); 230 | for (i = 0; i < 3; i++) { 231 | log_d("hello, world"); 232 | rt_thread_delay(1000); 233 | } 234 | exit(0); 235 | } 236 | 237 | int rt_application_init() { 238 | rt_thread_t tid; 239 | tid = rt_thread_create("SysMonitor2", thread_entry_SysMonitor, RT_NULL, 4096, 4, 20); 240 | if (tid != RT_NULL) 241 | rt_thread_startup(tid); 242 | 243 | return 0; 244 | } 245 | 246 | int main(void) 247 | { 248 | /* close printf buffer */ 249 | setbuf(stdout, NULL); 250 | 251 | /* disable interrupt first */ 252 | rt_hw_interrupt_disable(); 253 | 254 | /* startup RT-Thread RTOS */ 255 | rtthread_startup(); 256 | 257 | return 0; 258 | } 259 | 260 | 261 | /*@}*/ 262 | -------------------------------------------------------------------------------- /app/src/app_ucos.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/app/src/app_ucos.c -------------------------------------------------------------------------------- /cache/cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: process and manage the cache data 7 | * Created on: 2013-10-31 8 | * Note: Cache > CacheData=Data > Value in logic 9 | */ 10 | 11 | #define LOG_TAG "edm.cache" 12 | 13 | #include "cache.h" 14 | 15 | static pCacheData hasData(pCache const cache, const char* name); 16 | static CacheErrCode addData(pCache const cache, const char* name, 17 | uint8_t length, uint16_t* value, 18 | void* (*valueChangedListener)(void *arg)); 19 | static CacheErrCode delData(pCache const cache, const char* name); 20 | static CacheErrCode getValue(pCache const cache, const char* name, 21 | uint16_t* value); 22 | static CacheErrCode setValue(pCache const cache, const char* name, 23 | uint16_t* value); 24 | static CacheErrCode getSize(pCache const cache, uint32_t* length, 25 | uint32_t* size); 26 | 27 | /** 28 | * This function will initialize cache model. 29 | * 30 | * @param cache the cache pointer 31 | * @param name the cache name 32 | * @param maxThreadNum the cache use max threads number in thread pool 33 | * @param threadStackSize the thread stack size in thread pool 34 | * 35 | * @return error code 36 | */ 37 | CacheErrCode initCache(pCache const cache, const char* name, uint8_t maxThreadNum, 38 | uint32_t threadStackSize) { 39 | CacheErrCode errorCode = CACHE_NO_ERR; 40 | 41 | if ((name == NULL) || (strlen(name) > CACHE_NAME_MAX)) { 42 | log_i("the name of %s can not be create for list", name); 43 | errorCode = CACHE_NAME_ERROR; 44 | } else { 45 | strcpy(cache->name, name); 46 | } 47 | cache->has = hasData; 48 | cache->add = addData; 49 | cache->del = delData; 50 | cache->get = getValue; 51 | cache->set = setValue; 52 | cache->getSize = getSize; 53 | cache->dataHead = NULL; 54 | cache->dataTail = NULL; 55 | /* initialize the thread pool */ 56 | cache->pool = (pThreadPool) malloc(sizeof(ThreadPool)); 57 | assert(cache->pool != NULL); 58 | initThreadPool(cache->pool, "cache", maxThreadNum, threadStackSize); 59 | return errorCode; 60 | } 61 | 62 | /** 63 | * This function will find the data in CacheData list. 64 | * 65 | * @param cache the cache pointer 66 | * @param name the name of CacheData 67 | * 68 | * @return the CacheData point which has found,If not found will return NULL. 69 | */ 70 | static pCacheData hasData(pCache const cache, const char* name) { 71 | pCacheData data = cache->dataHead; 72 | 73 | assert((name != NULL) && (strlen(name) <= CACHE_NAME_MAX)); 74 | //this cache is null 75 | if (cache->dataHead == NULL) { 76 | log_d("the %s's data list is NULL,find data fail", cache->name); 77 | return NULL; 78 | } 79 | /* search the data from list*/ 80 | for (;;) { 81 | if (!strcmp(data->name, name)) { 82 | return data; 83 | } else { 84 | if (data->next == NULL) {/* list tail */ 85 | log_d("could not find %s", name); 86 | break; 87 | } 88 | data = data->next; 89 | } 90 | } 91 | return NULL; 92 | } 93 | 94 | /** 95 | * This function will add CacheData to list. 96 | * 97 | * @param cache the cache pointer 98 | * @param name the name of CacheData 99 | * @param length the value length 100 | * @param value the value point 101 | * @param valueChangedListener the changed value's callback function 102 | * 103 | * @return error code 104 | */ 105 | static CacheErrCode addData(pCache const cache, const char* name, uint8_t length, 106 | uint16_t* value, void* (*valueChangedListener)(void *arg)) { 107 | CacheErrCode errorCode = CACHE_NO_ERR; 108 | pCacheData data; 109 | /* lock the thread pool synchronized lock */ 110 | cache->pool->lock(cache->pool); 111 | 112 | data = (pCacheData) malloc(sizeof(CacheData)); 113 | assert(data != NULL); 114 | 115 | if (hasData(cache, name) != NULL) {/* the data must not exist in list */ 116 | log_d("the name of %s data is already exist in cache data list", name); 117 | errorCode = CACHE_NAME_ERROR; 118 | } else { 119 | strcpy(data->name, name); 120 | } 121 | 122 | if (errorCode == CACHE_NO_ERR) { 123 | if (length > CACHE_LENGTH_MAX) { 124 | log_d("the name %s is too long,can't add to list", name); 125 | errorCode = CACHE_LENGTH_ERROR; 126 | } else { 127 | data->length = length; 128 | } 129 | } 130 | 131 | if (errorCode == CACHE_NO_ERR) { 132 | /* malloc data value space */ 133 | data->value = (uint16_t*) malloc(length * sizeof(uint16_t)); 134 | assert(data->value != NULL); 135 | memcpy(data->value, value, length * sizeof(uint16_t)); 136 | data->valueChangedListener = valueChangedListener; 137 | data->next = NULL; 138 | /* if list is NULL ,then head node is equal of tail node*/ 139 | if (cache->dataHead == NULL) { 140 | cache->dataHead = cache->dataTail = data; 141 | } else if ((cache->dataHead == cache->dataTail) /* the list has one node */ 142 | && (cache->dataHead != NULL)) { 143 | cache->dataHead->next = data; 144 | cache->dataTail = data; 145 | } else { /* the list has more than one node*/ 146 | cache->dataTail->next = data; 147 | cache->dataTail = data; 148 | } 149 | log_d("add %s to data list is success", name); 150 | } else if (errorCode != CACHE_NO_ERR) { 151 | free(data); 152 | data = NULL; 153 | } 154 | /* unlock the thread pool synchronized lock */ 155 | cache->pool->unlock(cache->pool); 156 | return errorCode; 157 | } 158 | 159 | /** 160 | * This function will delete the data from CacheData list. 161 | * 162 | * @param cache the cache pointer 163 | * @param name the cache data name 164 | * 165 | * @return error code 166 | */ 167 | static CacheErrCode delData(pCache const cache, const char* name) { 168 | CacheErrCode errorCode = CACHE_NO_ERR; 169 | pCacheData data = cache->dataHead, dataTemp; 170 | /* lock the thread pool synchronized lock */ 171 | cache->pool->lock(cache->pool); 172 | 173 | assert((name != NULL) && (strlen(name) <= CACHE_NAME_MAX)); 174 | /* check cache initialize */ 175 | if (cache->dataHead == NULL) { 176 | log_d("the %s's data list is NULL,delete data fail", cache->name); 177 | errorCode = CACHE_NO_VALUE; 178 | } 179 | /* search the data from list*/ 180 | if (errorCode == CACHE_NO_ERR) { 181 | if (strcmp(data->name, name)) { /* list head */ 182 | for (;;) { 183 | if (data->next == NULL) {/* list tail */ 184 | log_d("could not find %s", name); 185 | errorCode = CACHE_NAME_ERROR; 186 | break; 187 | } else { 188 | if (!strcmp(data->next->name, name)) { 189 | break; 190 | } else { 191 | data = data->next; 192 | } 193 | } 194 | } 195 | } 196 | } 197 | if (errorCode == CACHE_NO_ERR) { 198 | /* delete data is head node */ 199 | if (data == cache->dataHead) { 200 | /* the list has one node */ 201 | if ((cache->dataHead == cache->dataTail) 202 | && (cache->dataHead != NULL)) { 203 | cache->dataHead = cache->dataTail = NULL; 204 | } else { /* the list has more than one node*/ 205 | cache->dataHead = data->next; 206 | } 207 | } else if (data->next == cache->dataTail) {/* delete data is tail node */ 208 | cache->dataTail = data; 209 | cache->dataTail->next = NULL; 210 | data = data->next; /* data will be freed in the end */ 211 | } else { 212 | dataTemp = data->next; 213 | data->next = data->next->next; 214 | data = dataTemp; /* data will be freed in the end */ 215 | } 216 | free(data->value); 217 | data->value = NULL; 218 | free(data); 219 | data = NULL; 220 | dataTemp = NULL; 221 | log_d("delete %s data node is success", name); 222 | } 223 | /* unlock the thread pool synchronized lock */ 224 | cache->pool->unlock(cache->pool); 225 | return errorCode; 226 | } 227 | 228 | /** 229 | * This function will get the value from CacheData list. 230 | * 231 | * @param cache the cache pointer 232 | * @param name the cache data name 233 | * @param value the value which has getted 234 | * 235 | * @return error code 236 | */ 237 | static CacheErrCode getValue(pCache const cache, const char* name, uint16_t* value) { 238 | CacheErrCode errorCode = CACHE_NO_ERR; 239 | pCacheData data; 240 | uint8_t i; 241 | uint16_t* dataValue; 242 | /* the data must exist in list */ 243 | if ((data = hasData(cache, name)) == NULL) { 244 | errorCode = CACHE_NAME_ERROR; 245 | } 246 | /* return the value */ 247 | if (errorCode == CACHE_NO_ERR) { 248 | dataValue = data->value; 249 | for (i = 0; i < data->length; i++) { 250 | log_d("get %s value%d is %d ", data->name, i, *(dataValue)); 251 | *(value++) = *(dataValue++); 252 | } 253 | } 254 | 255 | return errorCode; 256 | } 257 | 258 | /** 259 | * This function will set the value in CacheData list. 260 | * 261 | * @param cache the cache pointer 262 | * @param name the cache data name 263 | * @param value the value which will set 264 | * 265 | * @return error code 266 | */ 267 | static CacheErrCode setValue(pCache const cache, const char* name, uint16_t* value) { 268 | CacheErrCode errorCode = CACHE_NO_ERR; 269 | pCacheData data = cache->dataHead; 270 | uint8_t i, isValueChanged = false; 271 | uint16_t* dataValue; 272 | /* the data must exist in list */ 273 | if ((data = hasData(cache, name)) == NULL) { 274 | errorCode = CACHE_NAME_ERROR; 275 | } else { /* set the value */ 276 | dataValue = data->value; 277 | for (i = 0; i < data->length; i++) { 278 | log_d("set %s value%d is %d", data->name, i, *(value)); 279 | if (*(dataValue) != *(value)) { 280 | isValueChanged = true; 281 | } 282 | *(dataValue++) = *(value++); 283 | } 284 | } 285 | /* If value was changed.Execution valueChangedListener */ 286 | if ((isValueChanged) && (data->valueChangedListener != NULL)) { 287 | cache->pool->addTask(cache->pool, data->valueChangedListener, data); 288 | } 289 | return errorCode; 290 | } 291 | 292 | /** 293 | * This function will get the CacheData list total length. 294 | * 295 | * @param cache the cache pointer 296 | * @param length the total length of list 297 | * 298 | * @return error code 299 | */ 300 | static CacheErrCode getSize(pCache const cache, uint32_t* length, uint32_t* size) { 301 | CacheErrCode errorCode = CACHE_NO_ERR; 302 | pCacheData data = cache->dataHead; 303 | *length = 0; 304 | *size = 0; 305 | for (;;) { 306 | if (data == NULL) { 307 | log_d("the %s's length is %d,size is %ld", cache->name, *length, 308 | *size); 309 | break; 310 | } else { 311 | (*length)++; 312 | (*size) += data->length * sizeof(uint16_t); 313 | data = data->next; 314 | } 315 | } 316 | if ((*length) == 0) 317 | errorCode = CACHE_NOT_INIT; 318 | return errorCode; 319 | } 320 | -------------------------------------------------------------------------------- /cache/cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: process and manage the cache data 7 | * Created on: 2013-10-31 8 | * Note: Cache > CacheData=Data > Value in logic 9 | */ 10 | 11 | #ifndef CACHE_H_ 12 | #define CACHE_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #if defined(EDM_USING_PTHREAD) 21 | #include "pthread_pool.h" 22 | #elif defined(EDM_USING_RTT) 23 | #include "rtthread_pool.h" 24 | #endif 25 | 26 | #define CACHE_NAME_MAX 32 /**< CacheData max name length */ 27 | #define CACHE_LENGTH_MAX 64 /**< value max length */ 28 | 29 | /* Cache error code */ 30 | typedef enum{ 31 | CACHE_NO_ERR, /**< no error */ 32 | CACHE_NAME_ERROR, /**< CacheData name has error */ 33 | CACHE_INDEX_ERROR, /**< value index has error */ 34 | CACHE_LENGTH_ERROR, /**< value length has error */ 35 | CACHE_NO_VALUE, /**< value not find */ 36 | CACHE_ILL_ARG, /**< illegal argument */ 37 | CACHE_NOT_INIT, /**< cache not initialize */ 38 | CACHE_NO_SPACE, /**< not enough space */ 39 | }CacheErrCode; 40 | 41 | /* CacheData is the dynamic cache data's property. */ 42 | typedef struct _CacheData{ 43 | char name[CACHE_NAME_MAX+1]; /**< the name of CacheData, the end of name is include '\0' */ 44 | uint8_t length; /**< value length */ 45 | uint16_t* value; /**< the value pointer*/ 46 | void* (*valueChangedListener)(void *arg); /**< it will call when the CacheData's value has changed */ 47 | struct _CacheData* next; /**< point to next CacheData */ 48 | } CacheData, *pCacheData; 49 | 50 | /* Cache supply functions set and CacheData list for app */ 51 | typedef struct _Cache { 52 | /** 53 | * This function will find the data in CacheData list. 54 | * 55 | * @param cache the cache pointer 56 | * @param name the name of CacheData 57 | * 58 | * @return the CacheData point which has found,If not found will return NULL. 59 | */ 60 | pCacheData (*has)(struct _Cache* const cache, const char* name); 61 | /** 62 | * This function will add CacheData to list. 63 | * 64 | * @param cache the cache pointer 65 | * @param name the name of CacheData 66 | * @param length the value length 67 | * @param value the value point 68 | * @param valueChangedListener the changed value's callback function 69 | * 70 | * @return error code 71 | */ 72 | CacheErrCode (*add)(struct _Cache* const cache, const char* name, 73 | uint8_t length, uint16_t* value, 74 | void* (*valueChangedListener)(void *arg)); 75 | /** 76 | * This function will delete the data from CacheData list. 77 | * 78 | * @param cache the cache pointer 79 | * @param name the cache data name 80 | * 81 | * @return error code 82 | */ 83 | CacheErrCode (*del)(struct _Cache* const cache, const char* name); 84 | /** 85 | * This function will set the value in CacheData list. 86 | * 87 | * @param cache the cache pointer 88 | * @param name the cache data name 89 | * @param value the value which will set 90 | * 91 | * @return error code 92 | */ 93 | CacheErrCode (*set)(struct _Cache* const cache, const char* name, 94 | uint16_t* value); 95 | /** 96 | * This function will get the value from CacheData list. 97 | * 98 | * @param cache the cache pointer 99 | * @param name the cache data name 100 | * @param value the value which has getted 101 | * 102 | * @return error code 103 | */ 104 | CacheErrCode (*get)(struct _Cache* const cache, const char* name, 105 | uint16_t* value); 106 | /** 107 | * This function will set the value in CacheData list. 108 | * 109 | * @param cache the cache pointer 110 | * @param name the cache data name 111 | * @param value the value which will set 112 | * 113 | * @return error code 114 | */ 115 | CacheErrCode (*getSize)(struct _Cache* const cache, uint32_t* length, 116 | uint32_t* size); 117 | char name[CACHE_NAME_MAX+1]; /**< the name of CacheData, the end of name is include '\0' */ 118 | pCacheData dataHead; 119 | pCacheData dataTail; 120 | pThreadPool pool; 121 | } Cache, *pCache; 122 | 123 | CacheErrCode initCache(pCache const cache, const char* name, uint8_t maxThreadNum, 124 | uint32_t threadStackSize); 125 | 126 | #endif /* DM_H_ */ 127 | -------------------------------------------------------------------------------- /elog/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2016 Armink (armink.ztl@gmail.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /elog/README.md: -------------------------------------------------------------------------------- 1 | # EasyLogger 2 | 3 | --- 4 | 5 | # 1. 介绍 6 | 7 | [EasyLogger](https://github.com/armink/EasyLogger)是一款超轻量级(ROM<1.6K, RAM<0.3K)、高性能的C日志库,非常适合对资源敏感的软件项目,例如:IoT产品、可穿戴设备、智能家居等等。相比log4c、zlog这些知名的C日志库,EasyLogger的功能更加简单,提供给用户的接口更少,但上手会很快,更多实用功能支持以插件形式进行动态扩展。 8 | 9 | ## 1.1 主要特性 10 | 11 | - 支持用户自定义输出方式(例如:终端、文件、数据库、串口、485、Flash...); 12 | - 日志内容可包含级别、时间戳、线程信息、进程信息等; 13 | - 日志输出被设计为线程安全的方式; 14 | - 支持多种操作系统([RT-Thread](http://www.rt-thread.org/)、UCOS、Linux、Windows...),也支持裸机平台; 15 | - 日志支持 **RAW格式** ; 16 | - 支持按 **标签** 、 **级别** 、 **关键词** 进行动态过滤; 17 | - 各级别日志支持不同颜色显示 18 | - 扩展性强,支持以插件形式扩展新功能。 19 | 20 | > 名词解释: 21 | 1、RAW格式:未经过格式化的原始日志。 22 | 2、标签:在软件中可以按照文件、模块、功能等方面,对需要打印的日志设定标签,实现日志分类。 23 | 24 | ## 1.2 插件 25 | 26 | - 1、Flash:使用[EasyFlash](https://github.com/armink/EasyFlash)库提供的Flash操作接口,可以把日志直接存储在Flash中。 27 | - 2、File(正在开发):支持文件转档、软件运行时动态加载配置文件等与文件日志输出相关功能。 28 | - 3、敬请期待…… 29 | 30 | ## 1.3 Star & Fork 31 | 32 | 后续我还会提供更多插件。也非常欢迎大家设计、开发更多实用插件和功能,一起来完善EasyLogger **([Github](https://github.com/armink/EasyLogger)|[OSChina](http://git.oschina.net/armink/EasyLogger)|[Coding](https://coding.net/u/armink/p/EasyLogger/git))** 。如果觉得这个开源项目很赞,可以点击[项目主页](https://github.com/armink/EasyLogger) 右上角的**Star**,同时把它推荐给更多有需要的朋友。 33 | 34 | # 2. 使用 35 | 36 | ### 2.1 参数配置 37 | 38 | EasyLogger拥有过滤方式、输出格式、输出开关这些属性。 39 | 40 | - 过滤方式支持按照标签、级别、关键词进行过滤; 41 | - 可以动态的开启/关闭日志的输出; 42 | - 可设定动态和静态的输出级别(静态:一级开关,通过宏定义;动态:二级开关,通过API接口)。 43 | 44 | > 注:目前参数配置及输出方式都是单例模式,即全局只支持一种配置方式。此模式下,软件会较为简单,但是无法支持复杂的输出方式。 45 | 46 | ### 2.2 输出级别 47 | 48 | 参考Android Logcat,级别最高为0(Assert),最低为5(Verbose)。 49 | 50 | ``` 51 | 0.[A]:断言(Assert) 52 | 1.[E]:错误(Error) 53 | 2.[W]:警告(Warn) 54 | 3.[I]:信息(Info) 55 | 4.[D]:调试(Debug) 56 | 5.[V]:详细(Verbose) 57 | ``` 58 | 59 | #### 2.2.1 设置不同的颜色及字体风格 60 | 61 | 各个级别日志默认颜色效果如下。用户也可以根据自己的喜好,在 `elog_cfg.h` 对各个级别日志的颜色及字体风格进行单独设置。 62 | 63 | ![TextColor](https://raw.githubusercontent.com/armink/EasyLogger/master/docs/zh/images/TextColor.png) 64 | 65 | ### 2.3 输出过滤 66 | 67 | 支持按照 **级别、标签及关键词** 进行过滤。日志内容较多时,使用过滤功能可以更快定位日志,保证日志的可读性。更多的过滤功能设置方法及细节请阅读[`\docs\zh\api\kernel.md`](https://github.com/armink/EasyLogger/blob/master/docs/zh/api/kernel.md)文档 68 | 69 | ### 2.4 输出格式 70 | 71 | 输出格式支持:级别、时间、标签、进程信息、线程信息、文件路径、行号、方法名。每种优先级别可以独立设置输出格式。 72 | 73 | > 注:默认为 **RAW格式**,RAW格式日志不支持标签过滤 74 | 75 | ### 2.5 输出方式 76 | 77 | 通过用户的移植,可以支持任何一种输出方式。只不过对于某种输出方式可能引入的新功能,需要通过插件实现,例如:文件转存,检索Flash日志等等。后期会有更多的插件开源出来。下面简单对比下部分输出方式使用场景: 78 | 79 | - 终端:方便用户动态查看,不具有存储功能; 80 | - 文件与Flash:都具有存储功能,用户可以查看历史日志。但是文件方式需要文件系统的支持,而Flash方式更加适合应用在无文件系统的小型嵌入式设备中。 81 | 82 | ### 2.6 Demo 83 | 84 | ### 2.6.1 核心功能 85 | 86 | 下图为在终端中输入命令来控制日志的输出及过滤器的设置,更加直观的展示了EasyLogger核心功能。 87 | 88 | - Demo路径:[`\demo\os\rt-thread\stm32f10x\`](https://github.com/armink/EasyLogger/tree/master/demo/os/rt-thread/stm32f10x) 89 | - API文档:[`\docs\zh\api\kernel.md`](https://github.com/armink/EasyLogger/blob/master/docs/zh/api/kernel.md) 90 | - 移植文档:[`\docs\zh\port\kernel.md`](https://github.com/armink/EasyLogger/blob/master/docs/zh/port/kernel.md) 91 | 92 | ![easylogger](https://raw.githubusercontent.com/armink/EasyLogger/master/docs/zh/images/EasyLoggerDemo.gif) 93 | 94 | ### 2.6.2 Flash Log(将日志保存到Flash中) 95 | 96 | 下图过程为通过控制台输出日志,并将输出的日志存储到Flash中。重启再读取上次保存的日志,最后清空Flash日志。 97 | 98 | - Demo路径:[`\demo\os\rt-thread\stm32f10x\`](https://github.com/armink/EasyLogger/tree/master/demo/os/rt-thread/stm32f10x) 99 | - API文档:[`\docs\zh\api\flash.md`](https://github.com/armink/EasyLogger/blob/master/docs/zh/api/flash.md) 100 | - 移植文档:[`\docs\zh\port\flash.md`](https://github.com/armink/EasyLogger/blob/master/docs/zh/port/flash.md) 101 | 102 | ![FlashLog](https://raw.githubusercontent.com/armink/EasyLogger/master/docs/zh/images/LogDemo.gif) 103 | 104 | # 3. 文档 105 | 106 | 具体内容参考[`\docs\zh\`](https://github.com/armink/EasyLogger/tree/master/docs/zh)下的文件。务必保证在 **阅读文档** 后再移植使用。 107 | 108 | # 4. 后期 109 | 110 | - 1、~~Flash存储:在[EasyFlash](https://github.com/armink/EasyFlash)中增加日志存储、读取功能,让EasyLogger与其无缝对接。使日志可以更加容易的存储在 **非文件系统** 中,~~并具有历史日检索的功能; 111 | - 2、配置文件:文件系统下的配置文件; 112 | - 3、文件转档:文件系统下支持文件按容量转档,按时间区分; 113 | - 4、日志助手:开发跨平台的日志助手,兼容Linux、Windows、Mac系统,打开助手即可查看、过滤(支持正则表达式)、排序、保存日志等。前端:[HTML5](https://zh.wikipedia.org/wiki/HTML5) + [Bootstrap](https://github.com/twbs/bootstrap) + [AngularJS](https://angularjs.org/) + [NW.js](http://www.oschina.net/p/nwjs),后端:[Rust](https://github.com/rust-lang/rust) + [iron](https://github.com/iron/iron) + [rust-websocket](https://github.com/cyderize/rust-websocket) + [serial-rs](https://github.com/dcuddeback/serial-rs); 114 | - 5、异步输出:目前日志输出与用户代码之间是同步的方式,这种方式虽然软件简单,也不存在日志覆盖的问题。但在输出速度较低的平台下,会由于增加日志功能,而降低软件运行速度。所以后期会增加 **异步输出** 方式,关键字过滤也可以放到异步输出中去; 115 | - 6、Arduino:增加Arduino lib,并提供其Demo; 116 | 117 | # 5. 许可 118 | 119 | MIT Copyright (c) armink.ztl@gmail.com 120 | -------------------------------------------------------------------------------- /elog/inc/elog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyLogger Library. 3 | * 4 | * Copyright (c) 2015-2017, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: It is an head file for this library. You can see all be called functions. 26 | * Created on: 2015-04-28 27 | */ 28 | 29 | #ifndef __ELOG_H__ 30 | #define __ELOG_H__ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* output log's level */ 42 | #define ELOG_LVL_ASSERT 0 43 | #define ELOG_LVL_ERROR 1 44 | #define ELOG_LVL_WARN 2 45 | #define ELOG_LVL_INFO 3 46 | #define ELOG_LVL_DEBUG 4 47 | #define ELOG_LVL_VERBOSE 5 48 | 49 | /* output log's level total number */ 50 | #define ELOG_LVL_TOTAL_NUM 6 51 | 52 | /* EasyLogger software version number */ 53 | #define ELOG_SW_VERSION "2.0.0" 54 | 55 | /* EasyLogger assert for developer. */ 56 | #ifdef ELOG_ASSERT_ENABLE 57 | #define ELOG_ASSERT(EXPR) \ 58 | if (!(EXPR)) \ 59 | { \ 60 | if (elog_assert_hook == NULL) { \ 61 | elog_a("elog", "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \ 62 | while (1); \ 63 | } else { \ 64 | elog_assert_hook(#EXPR, __FUNCTION__, __LINE__); \ 65 | } \ 66 | } 67 | #else 68 | #define ELOG_ASSERT(EXPR) ((void)0); 69 | #endif 70 | 71 | #ifndef ELOG_OUTPUT_ENABLE 72 | #define elog_a(tag, ...) 73 | #define elog_e(tag, ...) 74 | #define elog_w(tag, ...) 75 | #define elog_i(tag, ...) 76 | #define elog_d(tag, ...) 77 | #define elog_v(tag, ...) 78 | #else /* ELOG_OUTPUT_ENABLE */ 79 | #if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT 80 | #define elog_assert(tag, ...) \ 81 | elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 82 | #else 83 | #define elog_assert(tag, ...) 84 | #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT */ 85 | 86 | #if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR 87 | #define elog_error(tag, ...) \ 88 | elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 89 | #else 90 | #define elog_error(tag, ...) 91 | #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR */ 92 | 93 | #if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN 94 | #define elog_warn(tag, ...) \ 95 | elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 96 | #else 97 | #define elog_warn(tag, ...) 98 | #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_WARN */ 99 | 100 | #if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO 101 | #define elog_info(tag, ...) \ 102 | elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 103 | #else 104 | #define elog_info(tag, ...) 105 | #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_INFO */ 106 | 107 | #if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG 108 | #define elog_debug(tag, ...) \ 109 | elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 110 | #else 111 | #define elog_debug(tag, ...) 112 | #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG */ 113 | 114 | #if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE 115 | #define elog_verbose(tag, ...) \ 116 | elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 117 | #else 118 | #define elog_verbose(tag, ...) 119 | #endif /* ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE */ 120 | #endif /* ELOG_OUTPUT_ENABLE */ 121 | 122 | /* all formats index */ 123 | typedef enum { 124 | ELOG_FMT_LVL = 1 << 0, /**< level */ 125 | ELOG_FMT_TAG = 1 << 1, /**< tag */ 126 | ELOG_FMT_TIME = 1 << 2, /**< current time */ 127 | ELOG_FMT_P_INFO = 1 << 3, /**< process info */ 128 | ELOG_FMT_T_INFO = 1 << 4, /**< thread info */ 129 | ELOG_FMT_DIR = 1 << 5, /**< file directory and name */ 130 | ELOG_FMT_FUNC = 1 << 6, /**< function name */ 131 | ELOG_FMT_LINE = 1 << 7, /**< line number */ 132 | } ElogFmtIndex; 133 | 134 | /* macro definition for all formats */ 135 | #define ELOG_FMT_ALL (ELOG_FMT_LVL|ELOG_FMT_TAG|ELOG_FMT_TIME|ELOG_FMT_P_INFO|ELOG_FMT_T_INFO| \ 136 | ELOG_FMT_DIR|ELOG_FMT_FUNC|ELOG_FMT_LINE) 137 | 138 | /* output log's filter */ 139 | typedef struct { 140 | uint8_t level; 141 | char tag[ELOG_FILTER_TAG_MAX_LEN + 1]; 142 | char keyword[ELOG_FILTER_KW_MAX_LEN + 1]; 143 | } ElogFilter, *ElogFilter_t; 144 | 145 | /* easy logger */ 146 | typedef struct { 147 | ElogFilter filter; 148 | size_t enabled_fmt_set[ELOG_LVL_TOTAL_NUM]; 149 | bool output_enabled; 150 | bool output_lock_enabled; 151 | bool output_is_locked_before_enable; 152 | bool output_is_locked_before_disable; 153 | 154 | #ifdef ELOG_COLOR_ENABLE 155 | bool text_color_enabled; 156 | #endif 157 | 158 | }EasyLogger, *EasyLogger_t; 159 | 160 | /* EasyLogger error code */ 161 | typedef enum { 162 | ELOG_NO_ERR, 163 | } ElogErrCode; 164 | 165 | /* elog.c */ 166 | ElogErrCode elog_init(void); 167 | void elog_start(void); 168 | void elog_set_output_enabled(bool enabled); 169 | bool elog_get_output_enabled(void); 170 | void elog_set_text_color_enabled(bool enabled); 171 | bool elog_get_text_color_enabled(void); 172 | void elog_set_fmt(uint8_t level, size_t set); 173 | void elog_set_filter(uint8_t level, const char *tag, const char *keyword); 174 | void elog_set_filter_lvl(uint8_t level); 175 | void elog_set_filter_tag(const char *tag); 176 | void elog_set_filter_kw(const char *keyword); 177 | void elog_raw(const char *format, ...); 178 | void elog_output(uint8_t level, const char *tag, const char *file, const char *func, 179 | const long line, const char *format, ...); 180 | void elog_output_lock_enabled(bool enabled); 181 | extern void (*elog_assert_hook)(const char* expr, const char* func, size_t line); 182 | void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_t line)); 183 | int8_t elog_find_lvl(const char *log); 184 | const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len); 185 | 186 | #define elog_a(tag, ...) elog_assert(tag, __VA_ARGS__) 187 | #define elog_e(tag, ...) elog_error(tag, __VA_ARGS__) 188 | #define elog_w(tag, ...) elog_warn(tag, __VA_ARGS__) 189 | #define elog_i(tag, ...) elog_info(tag, __VA_ARGS__) 190 | #define elog_d(tag, ...) elog_debug(tag, __VA_ARGS__) 191 | #define elog_v(tag, ...) elog_verbose(tag, __VA_ARGS__) 192 | 193 | /** 194 | * log API short definition 195 | * NOTE: The `LOG_TAG` and `LOG_LVL` must defined before including the when you want to use log_x API. 196 | */ 197 | #if !defined(LOG_TAG) 198 | #define LOG_TAG "NO_TAG" 199 | #endif 200 | #if !defined(LOG_LVL) 201 | #define LOG_LVL ELOG_LVL_VERBOSE 202 | #endif 203 | #if LOG_LVL >= ELOG_LVL_ASSERT 204 | #define log_a(...) elog_a(LOG_TAG, __VA_ARGS__) 205 | #else 206 | #define log_a(...) ((void)0); 207 | #endif 208 | #if LOG_LVL >= ELOG_LVL_ERROR 209 | #define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) 210 | #else 211 | #define log_e(...) ((void)0); 212 | #endif 213 | #if LOG_LVL >= ELOG_LVL_WARN 214 | #define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) 215 | #else 216 | #define log_w(...) ((void)0); 217 | #endif 218 | #if LOG_LVL >= ELOG_LVL_INFO 219 | #define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) 220 | #else 221 | #define log_i(...) ((void)0); 222 | #endif 223 | #if LOG_LVL >= ELOG_LVL_DEBUG 224 | #define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) 225 | #else 226 | #define log_d(...) ((void)0); 227 | #endif 228 | #if LOG_LVL >= ELOG_LVL_VERBOSE 229 | #define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) 230 | #else 231 | #define log_v(...) ((void)0); 232 | #endif 233 | 234 | /* assert API short definition */ 235 | #if !defined(assert) 236 | #define assert ELOG_ASSERT 237 | #endif 238 | 239 | /* elog_buf.c */ 240 | void elog_buf_enabled(bool enabled); 241 | void elog_flush(void); 242 | 243 | /* elog_async.c */ 244 | void elog_async_enabled(bool enabled); 245 | size_t elog_async_get_log(char *log, size_t size); 246 | size_t elog_async_get_line_log(char *log, size_t size); 247 | 248 | /* elog_utils.c */ 249 | size_t elog_strcpy(size_t cur_len, char *dst, const char *src); 250 | size_t elog_cpyln(char *line, const char *log, size_t len); 251 | void *elog_memcpy(void *dst, const void *src, size_t count); 252 | 253 | #ifdef __cplusplus 254 | } 255 | #endif 256 | 257 | #endif /* __ELOG_H__ */ 258 | -------------------------------------------------------------------------------- /elog/inc/elog_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyLogger Library. 3 | * 4 | * Copyright (c) 2015, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: It is the configure head file for this library. 26 | * Created on: 2015-07-30 27 | */ 28 | 29 | #ifndef _ELOG_CFG_H_ 30 | #define _ELOG_CFG_H_ 31 | 32 | /* enable log output. default open this macro */ 33 | #define ELOG_OUTPUT_ENABLE 34 | /* setting static output log level */ 35 | #define ELOG_OUTPUT_LVL ELOG_LVL_VERBOSE 36 | /* enable assert check */ 37 | #define ELOG_ASSERT_ENABLE 38 | /* buffer size for every line's log */ 39 | #define ELOG_LINE_BUF_SIZE 1024 40 | /* output line number max length */ 41 | #define ELOG_LINE_NUM_MAX_LEN 5 42 | /* output filter's tag max length */ 43 | #define ELOG_FILTER_TAG_MAX_LEN 30 44 | /* output filter's keyword max length */ 45 | #define ELOG_FILTER_KW_MAX_LEN 16 46 | /* output newline sign */ 47 | #define ELOG_NEWLINE_SIGN "\n" 48 | /* enable log color */ 49 | #define ELOG_COLOR_ENABLE 50 | /* enable asynchronous output mode */ 51 | #define ELOG_ASYNC_OUTPUT_ENABLE 52 | /* buffer size for asynchronous output mode */ 53 | #define ELOG_ASYNC_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 100) 54 | /* each asynchronous output's log which must end with newline sign */ 55 | #define ELOG_ASYNC_LINE_OUTPUT 56 | /* asynchronous output mode using POSIX pthread implementation */ 57 | //#define ELOG_ASYNC_OUTPUT_USING_PTHREAD 58 | ///* enable buffered output mode */ 59 | //#define ELOG_BUFF_OUTPUT_ENABLE 60 | ///* buffer size for buffered output mode */ 61 | //#define ELOG_BUF_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 10) 62 | 63 | #endif /* _ELOG_CFG_H_ */ 64 | -------------------------------------------------------------------------------- /elog/port/elog_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyLogger Library. 3 | * 4 | * Copyright (c) 2015, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: Portable interface for each platform. 26 | * Created on: 2015-04-28 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #if defined(EDM_USING_PTHREAD) 35 | #include 36 | #if defined(WIN32) || defined(WIN64) 37 | #include 38 | #endif 39 | static pthread_mutex_t _printLock; 40 | static pthread_mutex_t* printLock = &_printLock; 41 | #elif defined(EDM_USING_RTT) 42 | #include 43 | #include 44 | static struct rt_mutex _printLock; 45 | static rt_mutex_t printLock = &_printLock; 46 | 47 | #endif 48 | 49 | #ifdef ELOG_ASYNC_OUTPUT_ENABLE 50 | static struct rt_semaphore output_notice; 51 | static void async_output(void *arg); 52 | #endif 53 | 54 | /** 55 | * EasyLogger port initialize 56 | * 57 | * @return result 58 | */ 59 | ElogErrCode elog_port_init(void) { 60 | ElogErrCode result = ELOG_NO_ERR; 61 | #if defined(EDM_USING_PTHREAD) 62 | pthread_mutex_init(printLock, NULL); 63 | 64 | #elif defined(EDM_USING_RTT) 65 | rt_mutex_init(printLock, "elog", RT_IPC_FLAG_PRIO); 66 | 67 | #endif 68 | 69 | #ifdef ELOG_ASYNC_OUTPUT_ENABLE 70 | rt_sem_init(&output_notice, "elog async", 0, RT_IPC_FLAG_PRIO); 71 | rt_thread_t async_thread = rt_thread_create("elog_async", async_output, NULL, 1024, RT_THREAD_PRIORITY_MAX - 1, 10); 72 | if (async_thread) { 73 | rt_thread_startup(async_thread); 74 | } 75 | #endif 76 | 77 | printf("Welcome to use Easy Data Manager(V%s) by armink. E-Mail: armink.ztl@gmail.com \n", EDM_VERSION); 78 | 79 | return result; 80 | } 81 | 82 | /** 83 | * output log port interface 84 | * 85 | * @param log output of log 86 | * @param size log size 87 | */ 88 | void elog_port_output(const char *log, size_t size) { 89 | /* output to terminal */ 90 | #if defined(EDM_USING_PTHREAD) 91 | printf("%.*s", size, log); 92 | #elif defined(EDM_USING_RTT) 93 | rt_kprintf("%.*s", size, log); 94 | #endif 95 | } 96 | 97 | #if defined(EDM_USING_RTT) 98 | //void rt_hw_console_output(const char *str) { 99 | // printf("%s", str); 100 | //} 101 | #endif 102 | 103 | #ifdef ELOG_ASYNC_OUTPUT_ENABLE 104 | static void async_output(void *arg) { 105 | size_t get_log_size = 0; 106 | static char poll_get_buf[ELOG_LINE_BUF_SIZE - 4]; 107 | 108 | while(true) { 109 | /* waiting log */ 110 | rt_sem_take(&output_notice, RT_WAITING_FOREVER); 111 | /* polling gets and outputs the log */ 112 | while(true) { 113 | get_log_size = elog_async_get_line_log(poll_get_buf, sizeof(poll_get_buf)); 114 | if (get_log_size) { 115 | elog_port_output(poll_get_buf, get_log_size); 116 | } else { 117 | break; 118 | } 119 | } 120 | } 121 | } 122 | 123 | void elog_async_output_notice(void) { 124 | rt_sem_release(&output_notice); 125 | } 126 | #endif 127 | 128 | /** 129 | * output lock 130 | */ 131 | void elog_port_output_lock(void) { 132 | #if defined(EDM_USING_PTHREAD) 133 | pthread_mutex_lock(printLock); 134 | 135 | #elif defined(EDM_USING_RTT) 136 | rt_mutex_take(printLock, RT_WAITING_FOREVER); 137 | #endif 138 | } 139 | 140 | /** 141 | * output unlock 142 | */ 143 | void elog_port_output_unlock(void) { 144 | #if defined(EDM_USING_PTHREAD) 145 | pthread_mutex_unlock(printLock); 146 | 147 | #elif defined(EDM_USING_RTT) 148 | rt_mutex_release(printLock); 149 | #endif 150 | } 151 | 152 | /** 153 | * get current time interface 154 | * 155 | * @return current time 156 | */ 157 | const char *elog_port_get_time(void) { 158 | static char cur_system_time[32] = { 0 }; 159 | #if defined(EDM_USING_PTHREAD) 160 | #if defined(WIN32) || defined(WIN64) 161 | SYSTEMTIME currTime; 162 | GetLocalTime(&currTime); 163 | snprintf(cur_system_time, 32, "%02d-%02d %02d:%02d:%02d.%03d ", currTime.wMonth, currTime.wDay, 164 | currTime.wHour, currTime.wMinute, currTime.wSecond, 165 | currTime.wMilliseconds); 166 | #else 167 | time_t timep; 168 | struct tm *p; 169 | time(&timep); 170 | p=localtime(&timep); 171 | if(p==NULL) { 172 | return; 173 | } 174 | snprintf(cur_system_time, 32, "%02d-%02d %02d:%02d:%02d.%03d ",p->tm_mon+1 ,p->tm_mday ,p->tm_hour ,p->tm_min,p->tm_sec); 175 | #endif 176 | 177 | #elif defined(EDM_USING_RTT) 178 | rt_snprintf(cur_system_time, 16, "tick:%010d", rt_tick_get()); 179 | #endif 180 | return cur_system_time; 181 | } 182 | 183 | /** 184 | * get current process name interface 185 | * 186 | * @return current process name 187 | */ 188 | const char *elog_port_get_p_info(void) { 189 | return ""; 190 | } 191 | 192 | /** 193 | * get current thread name interface 194 | * 195 | * @return current thread name 196 | */ 197 | const char *elog_port_get_t_info(void) { 198 | static char cur_thread_name[64] = { 0 }; 199 | #if defined(EDM_USING_PTHREAD) 200 | #if defined(WIN32) || defined(WIN64) 201 | snprintf(cur_thread_name, 64, "tid:%04ld ",GetCurrentThreadId()); 202 | #else 203 | snprintf(cur_thread_name, 64, "tid:%#x ",pthread_self()); 204 | #endif 205 | #elif defined(EDM_USING_RTT) 206 | snprintf(cur_thread_name, 64, "thread_name:%s ",rt_thread_self()->name); 207 | #endif 208 | return cur_thread_name; 209 | } 210 | -------------------------------------------------------------------------------- /elog/src/elog.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/elog/src/elog.c -------------------------------------------------------------------------------- /elog/src/elog_async.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyLogger Library. 3 | * 4 | * Copyright (c) 2016, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: Logs asynchronous output. 26 | * Created on: 2016-11-06 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #ifdef ELOG_ASYNC_OUTPUT_ENABLE 33 | #if !defined(ELOG_ASYNC_OUTPUT_BUF_SIZE) 34 | #error "Please configure buffer size for asynchronous output mode (in elog_cfg.h)" 35 | #endif 36 | 37 | #ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD 38 | #include 39 | #include 40 | #include 41 | /* thread default stack size */ 42 | #ifndef ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE 43 | #if PTHREAD_STACK_MIN > 4*1024 44 | #define ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE PTHREAD_STACK_MIN 45 | #else 46 | #define ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE (1*1024) 47 | #endif 48 | /* thread default priority */ 49 | #ifndef ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY 50 | #define ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY (sched_get_priority_max(SCHED_RR) - 1) 51 | #endif 52 | /* output thread poll get log buffer size */ 53 | #ifndef ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE 54 | #define ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE (ELOG_LINE_BUF_SIZE - 4) 55 | #endif 56 | #endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */ 57 | 58 | /* asynchronous output log notice */ 59 | static sem_t output_notice; 60 | /* asynchronous output pthread thread */ 61 | static pthread_t async_output_thread; 62 | #endif 63 | 64 | /* Initialize OK flag */ 65 | static bool init_ok = false; 66 | /* asynchronous output mode enabled flag */ 67 | static bool is_enabled = false; 68 | /* asynchronous output mode's ring buffer */ 69 | static char log_buf[ELOG_ASYNC_OUTPUT_BUF_SIZE] = { 0 }; 70 | /* log ring buffer write index */ 71 | static size_t write_index = 0; 72 | /* log ring buffer read index */ 73 | static size_t read_index = 0; 74 | /* log ring buffer full flag */ 75 | static bool buf_is_full = false; 76 | /* log ring buffer empty flag */ 77 | static bool buf_is_empty = true; 78 | 79 | extern void elog_port_output(const char *log, size_t size); 80 | extern void elog_output_lock(void); 81 | extern void elog_output_unlock(void); 82 | 83 | /** 84 | * asynchronous output ring buffer used size 85 | * 86 | * @return used size 87 | */ 88 | static size_t elog_async_get_buf_used(void) { 89 | if (write_index > read_index) { 90 | return write_index - read_index; 91 | } else { 92 | if (!buf_is_full && !buf_is_empty) { 93 | return ELOG_ASYNC_OUTPUT_BUF_SIZE - (read_index - write_index); 94 | } else if (buf_is_full) { 95 | return ELOG_ASYNC_OUTPUT_BUF_SIZE; 96 | } else { 97 | return 0; 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * asynchronous output ring buffer remain space 104 | * 105 | * @return remain space 106 | */ 107 | static size_t async_get_buf_space(void) { 108 | return ELOG_ASYNC_OUTPUT_BUF_SIZE - elog_async_get_buf_used(); 109 | } 110 | 111 | /** 112 | * put log to asynchronous output ring buffer 113 | * 114 | * @param log put log buffer 115 | * @param size log size 116 | * 117 | * @return put log size, the log which beyond ring buffer space will be dropped 118 | */ 119 | static size_t async_put_log(const char *log, size_t size) { 120 | size_t space = 0; 121 | 122 | space = async_get_buf_space(); 123 | /* no space */ 124 | if (!space) { 125 | size = 0; 126 | goto __exit; 127 | } 128 | /* drop some log */ 129 | if (space <= size) { 130 | size = space; 131 | buf_is_full = true; 132 | } 133 | 134 | if (write_index + size < ELOG_ASYNC_OUTPUT_BUF_SIZE) { 135 | memcpy(log_buf + write_index, log, size); 136 | write_index += size; 137 | } else { 138 | memcpy(log_buf + write_index, log, ELOG_ASYNC_OUTPUT_BUF_SIZE - write_index); 139 | memcpy(log_buf, log + ELOG_ASYNC_OUTPUT_BUF_SIZE - write_index, 140 | size - (ELOG_ASYNC_OUTPUT_BUF_SIZE - write_index)); 141 | write_index += size - ELOG_ASYNC_OUTPUT_BUF_SIZE; 142 | } 143 | 144 | buf_is_empty = false; 145 | 146 | __exit: 147 | 148 | return size; 149 | } 150 | 151 | #ifdef ELOG_ASYNC_LINE_OUTPUT 152 | /** 153 | * Get line log from asynchronous output ring buffer. 154 | * It will copy all log when the newline sign isn't find. 155 | * 156 | * @param log get line log buffer 157 | * @param size line log size 158 | * 159 | * @return get line log size, the log size is less than ring buffer used size 160 | */ 161 | size_t elog_async_get_line_log(char *log, size_t size) { 162 | size_t used = 0, cpy_log_size = 0; 163 | /* lock output */ 164 | elog_output_lock(); 165 | used = elog_async_get_buf_used(); 166 | 167 | /* no log */ 168 | if (!used || !size) { 169 | goto __exit; 170 | } 171 | /* less log */ 172 | if (used <= size) { 173 | size = used; 174 | } 175 | 176 | if (read_index + size < ELOG_ASYNC_OUTPUT_BUF_SIZE) { 177 | cpy_log_size = elog_cpyln(log, log_buf + read_index, size); 178 | read_index += cpy_log_size; 179 | } else { 180 | cpy_log_size = elog_cpyln(log, log_buf + read_index, ELOG_ASYNC_OUTPUT_BUF_SIZE - read_index); 181 | if (cpy_log_size == ELOG_ASYNC_OUTPUT_BUF_SIZE - read_index) { 182 | cpy_log_size += elog_cpyln(log + cpy_log_size, log_buf, size - cpy_log_size); 183 | read_index += cpy_log_size - ELOG_ASYNC_OUTPUT_BUF_SIZE; 184 | } else { 185 | read_index += cpy_log_size; 186 | } 187 | } 188 | 189 | if (used == cpy_log_size) { 190 | buf_is_empty = true; 191 | } 192 | 193 | if (cpy_log_size) { 194 | buf_is_full = false; 195 | } 196 | 197 | __exit: 198 | /* lock output */ 199 | elog_output_unlock(); 200 | return cpy_log_size; 201 | } 202 | #else 203 | /** 204 | * get log from asynchronous output ring buffer 205 | * 206 | * @param log get log buffer 207 | * @param size log size 208 | * 209 | * @return get log size, the log size is less than ring buffer used size 210 | */ 211 | size_t elog_async_get_log(char *log, size_t size) { 212 | size_t used = 0; 213 | /* lock output */ 214 | elog_output_lock(); 215 | used = elog_async_get_buf_used(); 216 | /* no log */ 217 | if (!used || !size) { 218 | size = 0; 219 | goto __exit; 220 | } 221 | /* less log */ 222 | if (used <= size) { 223 | size = used; 224 | buf_is_empty = true; 225 | } 226 | 227 | if (read_index + size < ELOG_ASYNC_OUTPUT_BUF_SIZE) { 228 | memcpy(log, log_buf + read_index, size); 229 | read_index += size; 230 | } else { 231 | memcpy(log, log_buf + read_index, ELOG_ASYNC_OUTPUT_BUF_SIZE - read_index); 232 | memcpy(log + ELOG_ASYNC_OUTPUT_BUF_SIZE - read_index, log_buf, 233 | size - (ELOG_ASYNC_OUTPUT_BUF_SIZE - read_index)); 234 | read_index += size - ELOG_ASYNC_OUTPUT_BUF_SIZE; 235 | } 236 | 237 | buf_is_full = false; 238 | 239 | __exit: 240 | /* lock output */ 241 | elog_output_unlock(); 242 | return size; 243 | } 244 | #endif /* ELOG_ASYNC_LINE_OUTPUT */ 245 | 246 | void elog_async_output(const char *log, size_t size) { 247 | /* this function must be implement by user when ELOG_ASYNC_OUTPUT_USING_PTHREAD is not defined */ 248 | extern void elog_async_output_notice(void); 249 | size_t put_size; 250 | 251 | if (is_enabled) { 252 | put_size = async_put_log(log, size); 253 | /* notify output log thread */ 254 | if (put_size > 0) { 255 | elog_async_output_notice(); 256 | } 257 | } else { 258 | elog_port_output(log, size); 259 | } 260 | } 261 | 262 | #ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD 263 | void elog_async_output_notice(void) { 264 | sem_post(&output_notice); 265 | } 266 | 267 | static void *async_output(void *arg) { 268 | size_t get_log_size = 0; 269 | static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE]; 270 | 271 | ELOG_ASSERT(init_ok); 272 | 273 | while(true) { 274 | /* waiting log */ 275 | sem_wait(&output_notice); 276 | /* polling gets and outputs the log */ 277 | while(true) { 278 | 279 | #ifdef ELOG_ASYNC_LINE_OUTPUT 280 | get_log_size = elog_async_get_line_log(poll_get_buf, ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE); 281 | #else 282 | get_log_size = elog_async_get_log(poll_get_buf, ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE); 283 | #endif 284 | 285 | if (get_log_size) { 286 | elog_port_output(poll_get_buf, get_log_size); 287 | } else { 288 | break; 289 | } 290 | } 291 | } 292 | return NULL; 293 | } 294 | #endif 295 | 296 | /** 297 | * enable or disable asynchronous output mode 298 | * the log will be output directly when mode is disabled 299 | * 300 | * @param enabled true: enabled, false: disabled 301 | */ 302 | void elog_async_enabled(bool enabled) { 303 | is_enabled = enabled; 304 | } 305 | 306 | /** 307 | * asynchronous output mode initialize 308 | * 309 | * @return result 310 | */ 311 | ElogErrCode elog_async_init(void) { 312 | ElogErrCode result = ELOG_NO_ERR; 313 | 314 | if (init_ok) { 315 | return result; 316 | } 317 | 318 | #ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD 319 | pthread_attr_t thread_attr; 320 | struct sched_param thread_sched_param; 321 | 322 | sem_init(&output_notice, 0, 0); 323 | 324 | pthread_attr_init(&thread_attr); 325 | pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); 326 | pthread_attr_setstacksize(&thread_attr, ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE); 327 | pthread_attr_setschedpolicy(&thread_attr, SCHED_RR); 328 | thread_sched_param.sched_priority = ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY; 329 | pthread_attr_setschedparam(&thread_attr, &thread_sched_param); 330 | pthread_create(&async_output_thread, &thread_attr, async_output, NULL); 331 | pthread_attr_destroy(&thread_attr); 332 | #endif 333 | 334 | init_ok = true; 335 | 336 | return result; 337 | } 338 | 339 | #endif /* ELOG_ASYNC_OUTPUT_ENABLE */ 340 | -------------------------------------------------------------------------------- /elog/src/elog_buf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyLogger Library. 3 | * 4 | * Copyright (c) 2016, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: Logs buffered output. 26 | * Created on: 2016-11-09 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #ifdef ELOG_BUF_OUTPUT_ENABLE 33 | #if !defined(ELOG_BUF_OUTPUT_BUF_SIZE) 34 | #error "Please configure buffer size for buffered output mode (in elog_cfg.h)" 35 | #endif 36 | 37 | /* buffered output mode's buffer */ 38 | static char log_buf[ELOG_BUF_OUTPUT_BUF_SIZE] = { 0 }; 39 | /* log buffer current write size */ 40 | static size_t buf_write_size = 0; 41 | /* buffered output mode enabled flag */ 42 | static bool is_enabled = false; 43 | 44 | extern void elog_port_output(const char *log, size_t size); 45 | extern void elog_output_lock(void); 46 | extern void elog_output_unlock(void); 47 | 48 | /** 49 | * output buffered logs when buffer is full 50 | * 51 | * @param log will be buffered line's log 52 | * @param size log size 53 | */ 54 | void elog_buf_output(const char *log, size_t size) { 55 | size_t write_size = 0, write_index = 0; 56 | 57 | if (!is_enabled) { 58 | elog_port_output(log, size); 59 | return; 60 | } 61 | 62 | while (true) { 63 | if (buf_write_size + size > ELOG_BUF_OUTPUT_BUF_SIZE) { 64 | write_size = ELOG_BUF_OUTPUT_BUF_SIZE - buf_write_size; 65 | memcpy(log_buf + buf_write_size, log + write_index, write_size); 66 | write_index += write_size; 67 | size -= write_size; 68 | buf_write_size += write_size; 69 | /* output log */ 70 | elog_port_output(log_buf, buf_write_size); 71 | /* reset write index */ 72 | buf_write_size = 0; 73 | } else { 74 | memcpy(log_buf + buf_write_size, log + write_index, size); 75 | buf_write_size += size; 76 | break; 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * flush all buffered logs to output device 83 | */ 84 | void elog_flush(void) { 85 | /* lock output */ 86 | elog_output_lock(); 87 | /* output log */ 88 | elog_port_output(log_buf, buf_write_size); 89 | /* reset write index */ 90 | buf_write_size = 0; 91 | /* unlock output */ 92 | elog_output_unlock(); 93 | } 94 | 95 | /** 96 | * enable or disable buffered output mode 97 | * the log will be output directly when mode is disabled 98 | * 99 | * @param enabled true: enabled, false: disabled 100 | */ 101 | void elog_buf_enabled(bool enabled) { 102 | is_enabled = enabled; 103 | } 104 | #endif /* ELOG_BUF_OUTPUT_ENABLE */ 105 | -------------------------------------------------------------------------------- /elog/src/elog_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyLogger Library. 3 | * 4 | * Copyright (c) 2015-2017, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: Some utils for this library. 26 | * Created on: 2015-04-28 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | /** 33 | * another copy string function 34 | * 35 | * @param cur_len current copied log length, max size is ELOG_LINE_BUF_SIZE 36 | * @param dst destination 37 | * @param src source 38 | * 39 | * @return copied length 40 | */ 41 | size_t elog_strcpy(size_t cur_len, char *dst, const char *src) { 42 | const char *src_old = src; 43 | 44 | assert(dst); 45 | assert(src); 46 | 47 | while (*src != 0) { 48 | /* make sure destination has enough space */ 49 | if (cur_len++ <= ELOG_LINE_BUF_SIZE) { 50 | *dst++ = *src++; 51 | } else { 52 | break; 53 | } 54 | } 55 | return src - src_old; 56 | } 57 | 58 | /** 59 | * Copy line log split by newline sign. It will copy all log when the newline sign isn't find. 60 | * 61 | * @param line line log buffer 62 | * @param log origin log buffer 63 | * @param len origin log buffer length 64 | * 65 | * @return copy size 66 | */ 67 | size_t elog_cpyln(char *line, const char *log, size_t len) { 68 | size_t newline_len = strlen(ELOG_NEWLINE_SIGN), copy_size = 0; 69 | 70 | assert(line); 71 | assert(log); 72 | 73 | while (len--) { 74 | *line++ = *log++; 75 | copy_size++; 76 | if (copy_size >= newline_len && !strncmp(log - newline_len, ELOG_NEWLINE_SIGN, newline_len)) { 77 | break; 78 | } 79 | } 80 | return copy_size; 81 | } 82 | 83 | /** 84 | * This function will copy memory content from source address to destination 85 | * address. 86 | * 87 | * @param dst the address of destination memory 88 | * @param src the address of source memory 89 | * @param count the copied length 90 | * 91 | * @return the address of destination memory 92 | */ 93 | void *elog_memcpy(void *dst, const void *src, size_t count) { 94 | char *tmp = (char *) dst, *s = (char *) src; 95 | 96 | assert(dst); 97 | assert(src); 98 | 99 | while (count--) 100 | *tmp++ = *s++; 101 | 102 | return dst; 103 | } 104 | -------------------------------------------------------------------------------- /refresher/rt-thread/refresher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: an auto refresher to refresh dynamic Cache data in this library 7 | * Created on: 2014-01-10 8 | */ 9 | 10 | #ifndef REFRESHER_H_ 11 | #define REFRESHER_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define REFRESHER_JOB_NAME_MAX RT_NAME_MAX /**< refresher job max name length */ 22 | #define REFRESHER_JOB_CONTINUES_RUN -1 /**< If priority is -1.The job will continuous running. */ 23 | 24 | /* refresher error code */ 25 | typedef enum{ 26 | REFRESHER_NO_ERR, /**< no error */ 27 | REFRESHER_NO_JOB, /**< refresher doesn't have job */ 28 | REFRESHER_JOB_NAME_ERROR, /**< job has name error */ 29 | REFRESHER_MEM_FULL_ERR, /**< memory full */ 30 | }RefresherErrCode; 31 | 32 | /* RefreshJob is an auto refresh job for a Cache data. */ 33 | typedef struct _RefreshJob{ 34 | char name[REFRESHER_JOB_NAME_MAX+1]; /**< the name of the refresher job, the end of name is include '\0'*/ 35 | int16_t times; /**< job running times.If it is -1,the job will continuous running. */ 36 | uint8_t priority; /**< refresh priority.The highest priority is 0. */ 37 | uint32_t period; /**< refresh time = period * refresher tick. @see Refresher.tickTime */ 38 | bool newThread; /**< time-consuming or block job set it true will be better. */ 39 | rt_thread_t threadID; /**< job running thread ID */ 40 | void (*refreshProcess)(void *arg); /**< it will call when the RefreshJob need wrok */ 41 | struct _RefreshJob* next; /**< point to next RefreshJob */ 42 | } RefreshJob , *pRefreshJob; 43 | 44 | /* Refresher ready job in ready queue */ 45 | typedef struct _ReadyJob{ 46 | pRefreshJob job; /**< RefreshJob pointer @see RefreshJob */ 47 | uint32_t curPeriod; /**< current left period @see RefreshJob.period */ 48 | struct _ReadyJob* next; /**< point to next ReadyJob */ 49 | } ReadyJob, *pReadyJob; 50 | 51 | /* Refresher supply functions set and RefreshJob list for app */ 52 | typedef struct _Refresher { 53 | /** 54 | * add a job to refresher 55 | * 56 | * @param refresher the refresher pointer 57 | * @param name job name 58 | * @param priority Job refresh priority.The highest priority is 0. 59 | * @param period Refresh time = period * refresher tick. @see Refresher.tickTime 60 | * @param times If it is REFRESHER_JOB_CONTINUES_RUN,the job will continuous running. 61 | * @param newThread If it is TRUE,refresher will new a thread to refresh this job. 62 | * @param satckSize The new thread job stack size.It is not NULL while newThread is TRUE. 63 | * @param refreshProcess the job refresh process 64 | * 65 | * @return error code 66 | */ 67 | RefresherErrCode (*add)(struct _Refresher* const refresher, const char* name, int8_t priority, uint32_t period, 68 | int16_t times, bool newThread, uint32_t satckSize, void (*refreshProcess)(void *arg)); 69 | /** 70 | * delete a job in refresher. 71 | * 72 | * @param refresher the refresher pointer 73 | * @param name job name 74 | * 75 | * @return error code 76 | * 77 | */ 78 | RefresherErrCode (*del)(struct _Refresher* const refresher, 79 | const char* name); 80 | /** 81 | * deleted all jobs in refresher. 82 | * 83 | * @param refresher the refresher pointer 84 | * 85 | * @return error code 86 | */ 87 | RefresherErrCode (*delAll)(struct _Refresher* const refresher); 88 | 89 | /** 90 | * set the job period and priority 91 | * 92 | * @param refresher the refresher pointer 93 | * @param name job name 94 | * @param period job period 95 | * @param priority job priority 96 | * 97 | * @return error code 98 | */ 99 | RefresherErrCode (*setPeriodAndPriority)(struct _Refresher* const refresher, const char* name, uint32_t period, 100 | int8_t priority); 101 | /** 102 | * set the job running times 103 | * 104 | * @param refresher the refresher pointer 105 | * @param name job name 106 | * @param times job running times 107 | * 108 | * @return error code 109 | */ 110 | RefresherErrCode (*setTimes)(struct _Refresher* const refresher, const char* name, int16_t times); 111 | /** 112 | * destroy refresher 113 | * 114 | * @param refresher 115 | * @return error code 116 | */ 117 | RefresherErrCode (*destroy)(struct _Refresher* const refresher); 118 | uint32_t tick; /**< the Refresher running tick time. unit:Millisecond */ 119 | rt_thread_t kernelID; /**< the Refresher kernel thread ID,running all nonblock job */ 120 | pRefreshJob queueHead; /**< the refresh job queue */ 121 | pReadyJob readyQueueHead; /**< the ready job queue */ 122 | rt_mutex_t queueLock; /**< The job queue mutex lock.Just write queue lock. */ 123 | } Refresher, *pRefresher; 124 | 125 | RefresherErrCode initRefresher(pRefresher const refresher, uint32_t stackSize, uint8_t priority, uint32_t tick); 126 | 127 | #endif /* REFRESHER_H_ */ 128 | -------------------------------------------------------------------------------- /thread_pool/pthread/pthread_pool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: a thread pool base as pthread 7 | * Created on: 2013-11-07 8 | */ 9 | 10 | #define LOG_TAG "edm.threadpool" 11 | 12 | #include "rtthread_pool.h" 13 | 14 | #ifdef EDM_USING_PTHREAD 15 | 16 | static ThreadPoolErrCode addTask(pThreadPool const pool, 17 | void *(*process)(void *arg), void *arg); 18 | static ThreadPoolErrCode destroy(pThreadPool pool); 19 | static void* threadJob(void* arg); 20 | static void syncLock(pThreadPool pool); 21 | static void syncUnlock(pThreadPool pool); 22 | static ThreadPoolErrCode delAll(pThreadPool const pool); 23 | 24 | /** 25 | * This function will initialize the thread pool. 26 | * 27 | * @param pool the ThreadPool pointer 28 | * @param name the ThreadPool name 29 | * @param maxThreadNum the max thread number in this ThreadPool 30 | * @param threadStackSize the thread stack size in this ThreadPool 31 | * 32 | * @return error code 33 | */ 34 | ThreadPoolErrCode initThreadPool(pThreadPool const pool, const char* name, uint8_t maxThreadNum, uint32_t threadStack) { 35 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 36 | uint8_t i = 0; 37 | 38 | if (maxThreadNum > THREAD_POOL_MAX_THREAD_NUM) { 39 | errorCode = THREAD_POOL_MAX_NUM_ERR; 40 | } 41 | if (errorCode == THREAD_POOL_NO_ERR) { 42 | pthread_mutex_init(&(pool->queueLock), NULL); 43 | pthread_mutex_init(&(pool->userLock), NULL); 44 | pthread_cond_init(&(pool->queueReady), NULL); 45 | pool->queueHead = NULL; 46 | pool->maxThreadNum = maxThreadNum; 47 | pool->curWaitThreadNum = 0; 48 | pool->isShutdown = false; 49 | pool->addTask = addTask; 50 | pool->delAll = delAll; 51 | pool->destroy = destroy; 52 | pool->lock = syncLock; 53 | pool->unlock = syncUnlock; 54 | pool->threadID = (pthread_t *) malloc(maxThreadNum * sizeof(pthread_t)); 55 | assert(pool->threadID != NULL); 56 | for (i = 0; i < maxThreadNum; i++) { 57 | pthread_create(&(pool->threadID[i]), NULL, threadJob, pool); 58 | log_d("create thread success.Current total thread number is %d", i + 1); 59 | } 60 | log_d("initialize thread pool success!"); 61 | } 62 | return errorCode; 63 | } 64 | 65 | /** 66 | * This function will add a task to thread pool. 67 | * 68 | * @param pool the ThreadPool pointer 69 | * @param process task function pointer 70 | * @param arg task function arguments 71 | * 72 | * @return error code 73 | */ 74 | static ThreadPoolErrCode addTask(pThreadPool const pool, void *(*process)(void *arg), 75 | void *arg) { 76 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 77 | pTask member = NULL; 78 | pTask newtask = (pTask) malloc(sizeof(Task)); 79 | assert(newtask != NULL); 80 | newtask->process = process; 81 | newtask->arg = arg; 82 | newtask->next = NULL; 83 | /* lock thread pool */ 84 | pthread_mutex_lock(&(pool->queueLock)); 85 | member = pool->queueHead; 86 | /* task queue is NULL */ 87 | if (member == NULL) { 88 | pool->queueHead = newtask; 89 | } else { 90 | /* look up for queue tail */ 91 | while (member->next != NULL) { 92 | member = member->next; 93 | } 94 | member->next = newtask; 95 | } 96 | /* add current waiting thread number */ 97 | pool->curWaitThreadNum++; 98 | pthread_mutex_unlock(&(pool->queueLock)); 99 | /* wake up a waiting thread to process task */ 100 | pthread_cond_signal(&(pool->queueReady)); 101 | log_d("add a task to task queue success."); 102 | return errorCode; 103 | } 104 | 105 | /** 106 | * This function will delete all wait task. 107 | * 108 | * @param pool the ThreadPool pointer 109 | * 110 | * @return error code 111 | */ 112 | static ThreadPoolErrCode delAll(pThreadPool const pool) { 113 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 114 | 115 | //fixme 116 | 117 | return errorCode; 118 | } 119 | 120 | /** 121 | * This function will destroy thread pool. 122 | * 123 | * @param pool the ThreadPool pointer 124 | * 125 | * @return error code 126 | */ 127 | static ThreadPoolErrCode destroy(pThreadPool pool) { 128 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 129 | pTask head = NULL; 130 | uint8_t i; 131 | if (pool->isShutdown) {/* thread already shutdown */ 132 | errorCode = THREAD_POOL_ALREADY_SHUTDOWN_ERR; 133 | } 134 | if (errorCode == THREAD_POOL_NO_ERR) { 135 | pool->isShutdown = true; 136 | /* wake up all thread from broadcast */ 137 | pthread_cond_broadcast(&(pool->queueReady)); 138 | /* wait all thread exit */ 139 | for (i = 0; i < pool->maxThreadNum; i++) { 140 | log_d("Thread pool will destroy,waiting the thread exit"); 141 | pthread_join(pool->threadID[i], NULL); 142 | } 143 | /* release memory */ 144 | free(pool->threadID); 145 | pool->threadID = NULL; 146 | /* destroy task queue */ 147 | while (pool->queueHead != NULL) { 148 | head = pool->queueHead; 149 | pool->queueHead = pool->queueHead->next; 150 | free(head); 151 | } 152 | /* destroy mutex and conditional variable */ 153 | pthread_mutex_destroy(&(pool->queueLock)); 154 | pthread_mutex_destroy(&(pool->userLock)); 155 | pthread_cond_destroy(&(pool->queueReady)); 156 | /* release memory */ 157 | free(pool); 158 | pool = NULL; 159 | log_d("Thread pool destroy success"); 160 | } 161 | return errorCode; 162 | } 163 | 164 | /** 165 | * This function is thread job. 166 | * 167 | * @param arg the thread job arguments 168 | * 169 | */ 170 | static void* threadJob(void* arg) { 171 | pThreadPool pool = NULL; 172 | while (1) { 173 | pool = (pThreadPool)arg; 174 | pTask task = NULL; 175 | /* lock thread pool */ 176 | pthread_mutex_lock(&(pool->queueLock)); 177 | /* If waiting thread number is 0 ,and thread is not shutdown. 178 | * The thread will block. 179 | * Before thread block the queueLock will unlock. 180 | * After thread wake up ,the queueLock will relock.*/ 181 | while (pool->curWaitThreadNum == 0 && !pool->isShutdown) { 182 | log_d("the thread waiting for task add to task queue"); 183 | pthread_cond_wait(&(pool->queueReady), &(pool->queueLock)); 184 | } 185 | if (pool->isShutdown) { /* thread pool will shutdown */ 186 | pthread_mutex_unlock(&(pool->queueLock)); 187 | pthread_exit(NULL); 188 | } 189 | assert(pool->curWaitThreadNum != 0); 190 | assert(pool->queueHead != NULL); 191 | /* load task to thread job */ 192 | pool->curWaitThreadNum--; 193 | task = pool->queueHead; 194 | pool->queueHead = task->next; 195 | pthread_mutex_unlock(&(pool->queueLock)); 196 | /* run task */ 197 | (*(task->process))(task->arg); 198 | /* release memory */ 199 | free(task); 200 | task = NULL; 201 | } 202 | /* never reach here */ 203 | pthread_exit(NULL); 204 | return NULL; 205 | } 206 | 207 | /** 208 | * This function will lock the synchronized lock. 209 | * 210 | * @param pool the ThreadPool pointer 211 | * 212 | */ 213 | static void syncLock(pThreadPool pool) { 214 | // log_d("is syncLock"); 215 | pthread_mutex_lock(&(pool->userLock)); 216 | } 217 | 218 | /** 219 | * This function will unlock the synchronized lock. 220 | * 221 | * @param pool the ThreadPool pointer 222 | * 223 | */ 224 | static void syncUnlock(pThreadPool pool) { 225 | // log_d("is syncUnlock"); 226 | pthread_mutex_unlock(&(pool->userLock)); 227 | } 228 | 229 | #endif 230 | -------------------------------------------------------------------------------- /thread_pool/pthread/pthread_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: a thread pool base as pthread 7 | * Created on: 2013-11-09 8 | */ 9 | 10 | #ifndef PTHREAD_POOL_H_ 11 | #define PTHREAD_POOL_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "edm_def.h" 18 | 19 | #ifdef EDM_USING_PTHREAD 20 | 21 | #define THREAD_POOL_MAX_THREAD_NUM 16 /**< thread pool max setting thread number */ 22 | 23 | /* thread pool error code */ 24 | typedef enum{ 25 | THREAD_POOL_NO_ERR, /**< no error */ 26 | THREAD_POOL_MAX_NUM_ERR, /**< max thread number out of range */ 27 | THREAD_POOL_ALREADY_SHUTDOWN_ERR, /**< thread pool already shutdown */ 28 | }ThreadPoolErrCode; 29 | 30 | /* a task queue which run in thread pool */ 31 | typedef struct _Task { 32 | void *(*process)(void *arg); /**< task callback function */ 33 | void *arg; /**< task callback function's arguments */ 34 | struct _Task *next; 35 | } Task, *pTask; 36 | 37 | /* thread pool struct */ 38 | typedef struct _ThreadPool{ 39 | pTask queueHead; /**< task queue which place all waiting task */ 40 | pthread_mutex_t userLock; /**< a synchronized lock provided to user */ 41 | pthread_mutex_t queueLock; /**< task queue mutex lock */ 42 | pthread_cond_t queueReady; /**< a conditional variable which for task queue ready */ 43 | uint8_t isShutdown; /**< shutdown state,if shutdown the value will equal TRUE */ 44 | pthread_t* threadID; /**< thread queue which in thread pool */ 45 | uint8_t maxThreadNum; /**< the thread max number in thread pool */ 46 | uint8_t curWaitThreadNum; /**< the current waiting thread number in thread pool */ 47 | /** 48 | * This function will add a task to thread pool. 49 | * 50 | * @param pool the ThreadPool pointer 51 | * @param process task function pointer 52 | * @param arg task function arguments 53 | * 54 | * @return error code 55 | */ 56 | ThreadPoolErrCode (*addTask)(struct _ThreadPool* const pool, 57 | void *(*process)(void *arg), void *arg); 58 | /** 59 | * This function will delete all task. 60 | * 61 | * @param pool 62 | * 63 | * @return error code 64 | */ 65 | ThreadPoolErrCode (*delAll)(struct _ThreadPool* const pool); 66 | /** 67 | * This function will destroy thread pool. 68 | * 69 | * @param pool the ThreadPool pointer 70 | * 71 | * @return error code 72 | */ 73 | ThreadPoolErrCode (*destroy)(struct _ThreadPool* pool); 74 | /** 75 | * This function will lock the synchronized lock. 76 | * 77 | * @param pool the ThreadPool pointer 78 | * 79 | */ 80 | void (*lock)(struct _ThreadPool* pool); 81 | /** 82 | * This function will unlock the synchronized lock. 83 | * 84 | * @param pool the ThreadPool pointer 85 | * 86 | */ 87 | void (*unlock)(struct _ThreadPool* pool); 88 | } ThreadPool,*pThreadPool; 89 | 90 | ThreadPoolErrCode initThreadPool(pThreadPool const pool, const char* name, uint8_t maxThreadNum, uint32_t threadStack); 91 | 92 | #endif 93 | 94 | #endif /* PTHREAD_POOL_H_ */ 95 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/drivers/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : board.c 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2009 RT-Thread Develop Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2009-01-05 Bernard first implementation 13 | */ 14 | 15 | #include 16 | #include 17 | #include "board.h" 18 | #include 19 | #include 20 | 21 | /** 22 | * @addtogroup simulator on win32 23 | */ 24 | rt_uint8_t *heap; 25 | 26 | rt_uint8_t *rt_hw_sram_init(void) 27 | { 28 | rt_uint8_t *heap; 29 | heap = malloc(RT_HEAP_SIZE); 30 | if (heap == RT_NULL) 31 | { 32 | rt_kprintf("there is no memory in pc."); 33 | _exit(1); 34 | } 35 | return heap; 36 | } 37 | 38 | /** 39 | * This function will initial win32 40 | */ 41 | void rt_hw_board_init() 42 | { 43 | /* init system memory */ 44 | heap = rt_hw_sram_init(); 45 | } 46 | 47 | /*@}*/ 48 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/drivers/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : board.h 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2009, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2009-09-22 Bernard add board.h to this bsp 13 | */ 14 | 15 | #ifndef __BOARD_H__ 16 | #define __BOARD_H__ 17 | void rt_hw_board_init(void); 18 | rt_uint8_t *rt_hw_sram_init(void); 19 | 20 | /* SD Card init function */ 21 | void rt_hw_sdcard_init(void); 22 | 23 | int rt_hw_mtd_nand_init(void); 24 | int sst25vfxx_mtd_init(const char *, unsigned int , unsigned int); 25 | void pcap_netif_hw_init(void); 26 | void rt_platform_init(void); 27 | void rt_hw_usart_init(void); 28 | void rt_hw_serial_init(void); 29 | void rt_hw_sdl_start(void); 30 | void rt_hw_win32_low_cpu(void); 31 | 32 | void rt_hw_exit(void); 33 | #endif 34 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/inc/rtdebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : rtdebug.h 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | */ 10 | 11 | #ifndef __RTDEBUG_H__ 12 | #define __RTDEBUG_H__ 13 | 14 | #include 15 | 16 | /* Using this macro to control all kernel debug features. */ 17 | #ifdef RT_DEBUG 18 | 19 | /* Turn on some of these (set to non-zero) to debug kernel */ 20 | #ifndef RT_DEBUG_MEM 21 | #define RT_DEBUG_MEM 0 22 | #endif 23 | 24 | #ifndef RT_DEBUG_MEMHEAP 25 | #define RT_DEBUG_MEMHEAP 0 26 | #endif 27 | 28 | #ifndef RT_DEBUG_MODULE 29 | #define RT_DEBUG_MODULE 0 30 | #endif 31 | 32 | #ifndef RT_DEBUG_SCHEDULER 33 | #define RT_DEBUG_SCHEDULER 0 34 | #endif 35 | 36 | #ifndef RT_DEBUG_SLAB 37 | #define RT_DEBUG_SLAB 0 38 | #endif 39 | 40 | #ifndef RT_DEBUG_THREAD 41 | #define RT_DEBUG_THREAD 0 42 | #endif 43 | 44 | #ifndef RT_DEBUG_TIMER 45 | #define RT_DEBUG_TIMER 0 46 | #endif 47 | 48 | #ifndef RT_DEBUG_IRQ 49 | #define RT_DEBUG_IRQ 0 50 | #endif 51 | 52 | #ifndef RT_DEBUG_IPC 53 | #define RT_DEBUG_IPC 0 54 | #endif 55 | 56 | /* Turn on this to enable context check */ 57 | #ifndef RT_DEBUG_CONTEXT_CHECK 58 | #define RT_DEBUG_CONTEXT_CHECK 1 59 | #endif 60 | 61 | #define RT_DEBUG_LOG(type, message) \ 62 | do \ 63 | { \ 64 | if (type) \ 65 | rt_kprintf message; \ 66 | } \ 67 | while (0) 68 | 69 | #define RT_ASSERT(EX) \ 70 | if (!(EX)) \ 71 | { \ 72 | volatile char dummy = 0; \ 73 | rt_kprintf("(%s) assert failed at %s:%d \n", #EX, __FUNCTION__, __LINE__);\ 74 | while (dummy == 0); \ 75 | } 76 | 77 | /* Macro to check current context */ 78 | #if RT_DEBUG_CONTEXT_CHECK 79 | #define RT_DEBUG_NOT_IN_INTERRUPT \ 80 | do \ 81 | { \ 82 | rt_base_t level; \ 83 | level = rt_hw_interrupt_disable(); \ 84 | if (rt_interrupt_get_nest() != 0) \ 85 | { \ 86 | rt_kprintf("Function[%s] shall not used in ISR\n", __FUNCTION__); \ 87 | RT_ASSERT(0) \ 88 | } \ 89 | rt_hw_interrupt_enable(level); \ 90 | } \ 91 | while (0) 92 | #else 93 | #define RT_DEBUG_NOT_IN_INTERRUPT 94 | #endif 95 | 96 | #else /* RT_DEBUG */ 97 | 98 | #define RT_ASSERT(EX) 99 | #define RT_DEBUG_LOG(type, message) 100 | #define RT_DEBUG_NOT_IN_INTERRUPT 101 | 102 | #endif /* RT_DEBUG */ 103 | 104 | #endif /* __RTDEBUG_H__ */ 105 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/inc/rthw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : rthw.h 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2006-03-18 Bernard the first version 13 | * 2006-04-25 Bernard add rt_hw_context_switch_interrupt declaration 14 | * 2006-09-24 Bernard add rt_hw_context_switch_to declaration 15 | * 2012-12-29 Bernard add rt_hw_exception_install declaration 16 | */ 17 | 18 | #ifndef __RT_HW_H__ 19 | #define __RT_HW_H__ 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | void rt_hw_cpu_icache_enable(void); 28 | void rt_hw_cpu_icache_disable(void); 29 | rt_base_t rt_hw_cpu_icache_status(void); 30 | void rt_hw_cpu_dcache_enable(void); 31 | void rt_hw_cpu_dcache_disable(void); 32 | rt_base_t rt_hw_cpu_dcache_status(void); 33 | void rt_hw_cpu_reset(void); 34 | void rt_hw_cpu_shutdown(void); 35 | 36 | rt_uint8_t *rt_hw_stack_init(void *entry, 37 | void *parameter, 38 | rt_uint8_t *stack_addr, 39 | void *exit); 40 | 41 | void rt_hw_interrupt_init(void); 42 | void rt_hw_interrupt_mask(int vector); 43 | void rt_hw_interrupt_umask(int vector); 44 | void rt_hw_interrupt_install(int vector, 45 | rt_isr_handler_t new_handler, 46 | rt_isr_handler_t *old_handler); 47 | void rt_hw_interrupt_handle(int vector); 48 | 49 | rt_base_t rt_hw_interrupt_disable(void); 50 | void rt_hw_interrupt_enable(rt_base_t level); 51 | void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to); 52 | void rt_hw_context_switch_to(rt_uint32_t to); 53 | void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to); 54 | 55 | void rt_hw_console_output(const char *str); 56 | 57 | void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry); 58 | void rt_hw_show_memory(rt_uint32_t addr, rt_uint32_t size); 59 | 60 | /* 61 | * exception interfaces 62 | */ 63 | void rt_hw_exception_install(rt_err_t (*exception_handle)(void* context)); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/inc/rtm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : rtm.h 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | */ 10 | 11 | #ifndef __RTM_H__ 12 | #define __RTM_H__ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef RT_USING_MODULE 18 | struct rt_module_symtab 19 | { 20 | void *addr; 21 | const char *name; 22 | }; 23 | 24 | #define RTM_EXPORT(symbol) \ 25 | const char __rtmsym_##symbol##_name[] = #symbol; \ 26 | const struct rt_module_symtab __rtmsym_##symbol SECTION("RTMSymTab")= \ 27 | { \ 28 | (void *)&symbol, \ 29 | __rtmsym_##symbol##_name \ 30 | }; 31 | #else 32 | #define RTM_EXPORT(symbol) 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/inc/rtservice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : rtservice.h 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2006-03-16 Bernard the first version 13 | * 2006-09-07 Bernard move the kservice APIs to rtthread.h 14 | * 2007-06-27 Bernard fix the rt_list_remove bug 15 | * 2012-03-22 Bernard rename kservice.h to rtservice.h 16 | */ 17 | 18 | #ifndef __RT_SERVICE_H__ 19 | #define __RT_SERVICE_H__ 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * @addtogroup KernelService 27 | */ 28 | 29 | /*@{*/ 30 | 31 | /** 32 | * @brief initialize a list object 33 | */ 34 | #define RT_LIST_OBJECT_INIT(object) { &(object), &(object) } 35 | 36 | /** 37 | * @brief initialize a list 38 | * 39 | * @param l list to be initialized 40 | */ 41 | rt_inline void rt_list_init(rt_list_t *l) 42 | { 43 | l->next = l->prev = l; 44 | } 45 | 46 | /** 47 | * @brief insert a node after a list 48 | * 49 | * @param l list to insert it 50 | * @param n new node to be inserted 51 | */ 52 | rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n) 53 | { 54 | l->next->prev = n; 55 | n->next = l->next; 56 | 57 | l->next = n; 58 | n->prev = l; 59 | } 60 | 61 | /** 62 | * @brief insert a node before a list 63 | * 64 | * @param n new node to be inserted 65 | * @param l list to insert it 66 | */ 67 | rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n) 68 | { 69 | l->prev->next = n; 70 | n->prev = l->prev; 71 | 72 | l->prev = n; 73 | n->next = l; 74 | } 75 | 76 | /** 77 | * @brief remove node from list. 78 | * @param n the node to remove from the list. 79 | */ 80 | rt_inline void rt_list_remove(rt_list_t *n) 81 | { 82 | n->next->prev = n->prev; 83 | n->prev->next = n->next; 84 | 85 | n->next = n->prev = n; 86 | } 87 | 88 | /** 89 | * @brief tests whether a list is empty 90 | * @param l the list to test. 91 | */ 92 | rt_inline int rt_list_isempty(const rt_list_t *l) 93 | { 94 | return l->next == l; 95 | } 96 | 97 | /** 98 | * @brief get the struct for this entry 99 | * @param node the entry point 100 | * @param type the type of structure 101 | * @param member the name of list in structure 102 | */ 103 | #define rt_list_entry(node, type, member) \ 104 | ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member))) 105 | 106 | /*@}*/ 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/libcpu/sim/win32/cpu_port.h: -------------------------------------------------------------------------------- 1 | /* 2 | ************************************************************************************************************************ 3 | * File : cpu_port.h 4 | * By : xyou 5 | * Version : V1.00.00 6 | ************************************************************************************************************************ 7 | */ 8 | 9 | 10 | 11 | #ifndef _CPU_PORT_H_ 12 | #define _CPU_PORT_H_ 13 | 14 | 15 | /* 16 | ********************************************************************************************************* 17 | * CPU INTERRUPT PRIORITY 18 | ********************************************************************************************************* 19 | */ 20 | #define CPU_INTERRUPT_YIELD 0x00 21 | #define CPU_INTERRUPT_TICK 0x01 22 | 23 | 24 | 25 | /* 26 | ********************************************************************************************************* 27 | * FUNCTION PROTOTYPES 28 | ********************************************************************************************************* 29 | */ 30 | void TriggerSimulateInterrupt(rt_uint32_t IntIndex); 31 | 32 | void WinThreadScheduler(void); 33 | #endif /* _CPU_PORT_H_ */ 34 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/rtconfig.h: -------------------------------------------------------------------------------- 1 | /* RT-Thread config file */ 2 | #ifndef __RTTHREAD_CFG_H__ 3 | #define __RTTHREAD_CFG_H__ 4 | 5 | /* SECTION: port for visual studio */ 6 | #ifdef _MSC_VER 7 | #undef RT_USING_NEWLIB 8 | #undef RT_USING_MINILIBC 9 | #define NORESOURCE //RT_VESRION in winuser.h 10 | #define _CRT_ERRNO_DEFINED //errno macro redefinition 11 | 12 | #define RT_HEAP_SIZE (1024*1024*2) 13 | 14 | /* disable some warning in MSC */ 15 | #pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */ 16 | #pragma warning(disable:4312) /* to ignore: warning C4312: 'type cast' : conversion from 'rt_uint32_t' to 'rt_uint32_t *' */ 17 | #pragma warning(disable:4311) /* to ignore: warning C4311: 'type cast' : pointer truncation from 'short *__w64 ' to 'long' */ 18 | #pragma warning(disable:4996) /* to ignore: warning C4996: The POSIX name for this item is deprecated. */ 19 | #pragma warning(disable:4267) /* to ignore: warning C4267: conversion from 'size_t' to 'rt_size_t', possible loss of data */ 20 | #pragma warning(disable:4244) /* to ignore: warning C4244: '=' : conversion from '__w64 int' to 'rt_size_t', possible loss of data */ 21 | #else 22 | /* SECTION: port for other ide */ 23 | #define RT_HEAP_SIZE (1024*1024*2) 24 | #endif 25 | 26 | 27 | /* SECTION: basic kernel options */ 28 | /* RT_NAME_MAX*/ 29 | #define RT_NAME_MAX 16 30 | 31 | /* RT_ALIGN_SIZE*/ 32 | #define RT_ALIGN_SIZE 4 33 | 34 | /* PRIORITY_MAX */ 35 | #define RT_THREAD_PRIORITY_MAX 32 36 | 37 | /* Tick per Second */ 38 | #define RT_TICK_PER_SECOND 1000 39 | 40 | /* SECTION: RT_DEBUG */ 41 | /* Thread Debug */ 42 | #define RT_DEBUG 43 | #define RT_THREAD_DEBUG 44 | 45 | #define RT_USING_OVERFLOW_CHECK 46 | 47 | /* Using Hook */ 48 | #define RT_USING_HOOK 49 | 50 | /* Using Software Timer */ 51 | /* #define RT_USING_TIMER_SOFT */ 52 | #define RT_TIMER_THREAD_PRIO 4 53 | #define RT_TIMER_THREAD_STACK_SIZE 512 54 | #define RT_TIMER_TICK_PER_SECOND 10 55 | 56 | /* SECTION: IPC */ 57 | /* Using Semaphore*/ 58 | #define RT_USING_SEMAPHORE 59 | 60 | /* Using Mutex */ 61 | #define RT_USING_MUTEX 62 | 63 | /* Using Event */ 64 | #define RT_USING_EVENT 65 | 66 | /* Using MailBox */ 67 | #define RT_USING_MAILBOX 68 | 69 | /* Using Message Queue */ 70 | #define RT_USING_MESSAGEQUEUE 71 | 72 | /* SECTION: Memory Management */ 73 | /* Using Memory Pool Management*/ 74 | /* #define RT_USING_MEMPOOL */ 75 | 76 | /* Using Dynamic Heap Management */ 77 | #define RT_USING_HEAP 78 | 79 | /* Using Small MM */ 80 | #define RT_USING_SMALL_MEM 81 | /* #define RT_TINY_SIZE */ 82 | 83 | #define RT_USING_CONSOLE 84 | 85 | /* SECTION: Device System */ 86 | /* Using Device System */ 87 | //#define RT_USING_DEVICE 88 | /* #define RT_USING_UART1 */ 89 | 90 | /* SECTION: Console options */ 91 | /* the buffer size of console*/ 92 | #define RT_CONSOLEBUF_SIZE 256 93 | 94 | /* SECTION: component options */ 95 | #define RT_USING_COMPONENTS_INIT 96 | 97 | ///* SECTION: finsh, a C-Express shell */ 98 | //#define RT_USING_FINSH 99 | ///* Using symbol table */ 100 | //#define FINSH_USING_SYMTAB 101 | //#define FINSH_USING_DESCRIPTION 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/rtthread_pool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: a thread pool base as RT-Thread 7 | * Created on: 2013-11-14 8 | */ 9 | #define LOG_TAG "edm.threadpool" 10 | 11 | #include "rtthread_pool.h" 12 | 13 | #ifdef EDM_USING_RTT 14 | 15 | 16 | static ThreadPoolErrCode addTask(pThreadPool const pool, void *(*process)(void *arg), void *arg); 17 | static ThreadPoolErrCode destroy(pThreadPool pool); 18 | static void threadJob(void* arg); 19 | static void syncLock(pThreadPool pool); 20 | static void syncUnlock(pThreadPool pool); 21 | static ThreadPoolErrCode delAll(pThreadPool const pool); 22 | /** 23 | * This function will initialize the thread pool. 24 | * 25 | * @param pool the ThreadPool pointer 26 | * @param name the ThreadPool name 27 | * @param maxThreadNum the max thread number in this ThreadPool 28 | * @param threadStackSize the thread stack size in this ThreadPool 29 | * 30 | * @return error code 31 | */ 32 | ThreadPoolErrCode initThreadPool(pThreadPool const pool, const char* name, uint8_t maxThreadNum, 33 | uint32_t threadStackSize) { 34 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 35 | char jobName[THREAD_POOL_NAME_MAX] = { 0 }; 36 | uint8_t i; 37 | 38 | assert(name); 39 | assert(strlen(name) <= THREAD_POOL_NAME_MAX); 40 | assert(maxThreadNum <= THREAD_POOL_MAX_THREAD_NUM); 41 | 42 | strcpy(pool->name, name); 43 | strcpy(jobName, name); 44 | strcpy(&jobName[strlen(jobName)], "_job"); 45 | 46 | pool->queueLock = rt_mutex_create("queueLock", RT_IPC_FLAG_FIFO); 47 | assert(pool->queueLock != NULL); 48 | pool->userLock = rt_mutex_create("userLock", RT_IPC_FLAG_FIFO); 49 | assert(pool->userLock != NULL); 50 | pool->queueReady = rt_sem_create("queueReady", 0, RT_IPC_FLAG_FIFO); 51 | assert(pool->queueReady != NULL); 52 | pool->queueHead = NULL; 53 | pool->maxThreadNum = maxThreadNum; 54 | pool->curWaitThreadNum = 0; 55 | pool->isShutdown = false; 56 | pool->addTask = addTask; 57 | pool->delAll = delAll; 58 | pool->destroy = destroy; 59 | pool->lock = syncLock; 60 | pool->unlock = syncUnlock; 61 | pool->threadID = (rt_thread_t*) rt_malloc(maxThreadNum * sizeof(rt_thread_t)); 62 | assert(pool->threadID != NULL); 63 | for (i = 0; i < maxThreadNum; i++) { 64 | jobName[strlen(jobName)] = '0' + i; 65 | pool->threadID[i] = rt_thread_create(jobName, threadJob, pool, threadStackSize, 66 | THREAD_POOL_JOB_DEFAULT_PRIORITY, THREAD_POOL_JOB_TICK * i); 67 | assert(pool->threadID[i] != NULL); 68 | rt_thread_startup(pool->threadID[i]); 69 | jobName[strlen(jobName) - 1] = '\0'; 70 | log_d("create thread success.Current total thread number is %d", i + 1); 71 | rt_thread_delay(THREAD_POOL_THREADS_INIT_TIME); 72 | } 73 | log_d("initialize thread pool success!"); 74 | 75 | return errorCode; 76 | } 77 | 78 | /** 79 | * This function will add a task to thread pool. 80 | * 81 | * @param pool the ThreadPool pointer 82 | * @param process task function pointer 83 | * @param arg task function arguments 84 | * 85 | * @return error code 86 | */ 87 | static ThreadPoolErrCode addTask(pThreadPool const pool, void *(*process)(void *arg), void *arg) { 88 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 89 | pTask member = NULL; 90 | pTask newtask = (pTask) rt_malloc(sizeof(Task)); 91 | if (!newtask) { 92 | log_w("Memory full!"); 93 | return THREAD_POOL_MEM_FULL_ERR; 94 | } 95 | newtask->process = process; 96 | newtask->arg = arg; 97 | newtask->next = NULL; 98 | /* lock thread pool */ 99 | rt_mutex_take(pool->queueLock, RT_WAITING_FOREVER); 100 | member = pool->queueHead; 101 | /* task queue is NULL */ 102 | if (member == NULL) { 103 | pool->queueHead = newtask; 104 | } else { 105 | /* look up for queue tail */ 106 | while (member->next != NULL) { 107 | member = member->next; 108 | } 109 | member->next = newtask; 110 | } 111 | /* add current waiting thread number */ 112 | pool->curWaitThreadNum++; 113 | rt_mutex_release(pool->queueLock); 114 | /* wake up a waiting thread to process task */ 115 | rt_sem_release(pool->queueReady); 116 | log_v("add a task to task queue success."); 117 | return errorCode; 118 | } 119 | 120 | /** 121 | * This function will delete all wait task. 122 | * 123 | * @param pool the ThreadPool pointer 124 | * 125 | * @return error code 126 | */ 127 | static ThreadPoolErrCode delAll(pThreadPool const pool) { 128 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 129 | 130 | rt_mutex_take(pool->queueLock, RT_WAITING_FOREVER); 131 | /* delete all task in queue */ 132 | for (;;) { 133 | if (pool->queueHead != NULL) { 134 | rt_free(pool->queueHead); 135 | pool->queueHead = pool->queueHead->next; 136 | pool->curWaitThreadNum--; 137 | } else { 138 | break; 139 | } 140 | } 141 | rt_sem_control(pool->queueReady, RT_IPC_CMD_RESET, NULL); 142 | log_d("delete all wait task success"); 143 | rt_mutex_release(pool->queueLock); 144 | return errorCode; 145 | } 146 | 147 | /** 148 | * This function will destroy thread pool. 149 | * 150 | * @param pool the ThreadPool pointer 151 | * 152 | * @return error code 153 | */ 154 | static ThreadPoolErrCode destroy(pThreadPool pool) { 155 | ThreadPoolErrCode errorCode = THREAD_POOL_NO_ERR; 156 | pTask head = NULL; 157 | uint8_t i; 158 | if (pool->isShutdown) {/* thread already shutdown */ 159 | errorCode = THREAD_POOL_ALREADY_SHUTDOWN_ERR; 160 | } 161 | if (errorCode == THREAD_POOL_NO_ERR) { 162 | pool->isShutdown = true; 163 | /* wait all thread exit */ 164 | for (i = 0; i < pool->maxThreadNum; i++) { 165 | rt_thread_delete(pool->threadID[i]); 166 | } 167 | /* wake up all thread from broadcast */ 168 | /* delete mutex and semaphore then all waiting thread will wake up */ 169 | rt_mutex_delete(pool->queueLock); 170 | rt_sem_delete(pool->queueReady); 171 | /* release memory */ 172 | rt_free(pool->threadID); 173 | pool->threadID = NULL; 174 | /* destroy task queue */ 175 | while (pool->queueHead != NULL) { 176 | head = pool->queueHead; 177 | pool->queueHead = pool->queueHead->next; 178 | rt_free(head); 179 | } 180 | /* destroy mutex */ 181 | rt_mutex_delete(pool->userLock); 182 | pool = NULL; 183 | log_d("Thread pool destroy success"); 184 | } 185 | return errorCode; 186 | } 187 | 188 | /** 189 | * This function is thread job. 190 | * 191 | * @param arg the thread job arguments 192 | * 193 | */ 194 | static void threadJob(void* arg) { 195 | pThreadPool pool = NULL; 196 | pTask task = NULL; 197 | while (1) { 198 | pool = (pThreadPool) arg; 199 | /* lock thread pool */ 200 | rt_mutex_take(pool->queueLock, RT_WAITING_FOREVER); 201 | /* If waiting thread number is 0 ,and thread is not shutdown. 202 | * The thread will block. 203 | * Before thread block the queueLock will unlock. 204 | * After thread wake up ,the queueLock will relock.*/ 205 | while (pool->curWaitThreadNum == 0 && !pool->isShutdown) { 206 | /* ququeReady is NULL,the thread will block */ 207 | if (pool->queueReady->value == 0) { 208 | rt_mutex_release(pool->queueLock); 209 | rt_sem_take(pool->queueReady, RT_WAITING_FOREVER); 210 | rt_mutex_take(pool->queueLock, RT_WAITING_FOREVER); 211 | } else {/* ququeReady is not NULL,the ququeReady semaphore will decrease */ 212 | rt_sem_take(pool->queueReady, RT_WAITING_FOREVER); 213 | } 214 | } 215 | if (pool->isShutdown) { /* thread pool will shutdown */ 216 | rt_mutex_release(pool->queueLock); 217 | return; 218 | } 219 | assert(pool->curWaitThreadNum != 0); 220 | assert(pool->queueHead != NULL); 221 | /* load task to thread job */ 222 | pool->curWaitThreadNum--; 223 | task = pool->queueHead; 224 | pool->queueHead = task->next; 225 | rt_mutex_release(pool->queueLock); 226 | /* run task */ 227 | (*(task->process))(task->arg); 228 | /* release memory */ 229 | rt_free(task); 230 | task = NULL; 231 | } 232 | } 233 | 234 | /** 235 | * This function will lock the synchronized lock. 236 | * 237 | * @param pool the ThreadPool pointer 238 | * 239 | */ 240 | static void syncLock(pThreadPool pool) { 241 | rt_mutex_take(pool->userLock, RT_WAITING_FOREVER); 242 | } 243 | 244 | /** 245 | * This function will unlock the synchronized lock. 246 | * 247 | * @param pool the ThreadPool pointer 248 | * 249 | */ 250 | static void syncUnlock(pThreadPool pool) { 251 | rt_mutex_release(pool->userLock); 252 | } 253 | 254 | #endif 255 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/rtthread_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the EasyDataManager Library. 3 | * 4 | * Copyright (C) 2013 by Armink 5 | * 6 | * Function: a thread pool base as RT-Thread 7 | * Created on: 2013-11-14 8 | */ 9 | 10 | #ifndef RTTHREAD_POOL_H_ 11 | #define RTTHREAD_POOL_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #ifdef EDM_USING_RTT 19 | 20 | #define THREAD_POOL_THREADS_INIT_TIME 30 /**< threads initialize average waiting time */ 21 | #define THREAD_POOL_MAX_THREAD_NUM 16 /**< thread pool max setting thread number */ 22 | #define THREAD_POOL_JOB_DEFAULT_PRIORITY 10 /**< thread poll job's priority in rt-thread */ 23 | #define THREAD_POOL_JOB_TICK 5 /**< thread poll job's time slice in rt-thread */ 24 | #define THREAD_POOL_NAME_MAX RT_NAME_MAX /**< thread poll max name length */ 25 | 26 | /* thread pool error code */ 27 | typedef enum { 28 | THREAD_POOL_NO_ERR, /**< no error */ 29 | THREAD_POOL_ALREADY_SHUTDOWN_ERR, /**< thread pool already shutdown */ 30 | THREAD_POOL_MEM_FULL_ERR, /**< memory full */ 31 | } ThreadPoolErrCode; 32 | 33 | /* a task queue which run in thread pool */ 34 | typedef struct _Task { 35 | void *(*process)(void *arg); /**< task callback function */ 36 | void *arg; /**< task callback function's arguments */ 37 | struct _Task *next; 38 | } Task, *pTask; 39 | 40 | /* thread pool struct */ 41 | typedef struct _ThreadPool{ 42 | char name[THREAD_POOL_NAME_MAX + 1];/**< the name of ThreadPool, the end of name is include '\0' */ 43 | pTask queueHead; /**< task queue which place all waiting task */ 44 | rt_mutex_t userLock; /**< a synchronized lock provided to user */ 45 | rt_mutex_t queueLock; /**< task queue mutex lock */ 46 | rt_sem_t queueReady; /**< a semaphore which for task queue ready */ 47 | uint8_t isShutdown; /**< shutdown state,if shutdown the value will equal TRUE */ 48 | rt_thread_t* threadID; /**< thread queue which in thread pool */ 49 | uint8_t maxThreadNum; /**< the thread max number in thread pool */ 50 | uint8_t curWaitThreadNum; /**< the current waiting thread number in thread pool */ 51 | /** 52 | * This function will add a task to thread pool. 53 | * 54 | * @param pool the ThreadPool pointer 55 | * @param process task function pointer 56 | * @param arg task function arguments 57 | * 58 | * @return error code 59 | */ 60 | ThreadPoolErrCode (*addTask)(struct _ThreadPool* const pool, 61 | void *(*process)(void *arg), void *arg); 62 | /** 63 | * This function will delete all task. 64 | * 65 | * @param pool 66 | * 67 | * @return error code 68 | */ 69 | ThreadPoolErrCode (*delAll)(struct _ThreadPool* const pool); 70 | /** 71 | * This function will destroy thread pool. 72 | * 73 | * @param pool the ThreadPool pointer 74 | * 75 | * @return error code 76 | */ 77 | ThreadPoolErrCode (*destroy)(struct _ThreadPool* pool); 78 | /** 79 | * This function will lock the synchronized lock. 80 | * 81 | * @param pool the ThreadPool pointer 82 | * 83 | */ 84 | void (*lock)(struct _ThreadPool* pool); 85 | /** 86 | * This function will unlock the synchronized lock. 87 | * 88 | * @param pool the ThreadPool pointer 89 | * 90 | */ 91 | void (*unlock)(struct _ThreadPool* pool); 92 | } ThreadPool,*pThreadPool; 93 | 94 | ThreadPoolErrCode initThreadPool(pThreadPool const pool, const char* name, uint8_t maxThreadNum, 95 | uint32_t threadStackSize); 96 | 97 | #endif 98 | 99 | #endif /* RTTHREAD_POOL_H_ */ 100 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/src/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : clock.c 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2006-03-12 Bernard first version 13 | * 2006-05-27 Bernard add support for same priority thread schedule 14 | * 2006-08-10 Bernard remove the last rt_schedule in rt_tick_increase 15 | * 2010-03-08 Bernard remove rt_passed_second 16 | * 2010-05-20 Bernard fix the tick exceeds the maximum limits 17 | * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca 18 | * 2011-06-26 Bernard add rt_tick_set function. 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | static rt_tick_t rt_tick = 0; 25 | 26 | extern void rt_timer_check(void); 27 | 28 | /** 29 | * This function will init system tick and set it to zero. 30 | * @ingroup SystemInit 31 | * 32 | * @deprecated since 1.1.0, this function does not need to be invoked 33 | * in the system initialization. 34 | */ 35 | void rt_system_tick_init(void) 36 | { 37 | } 38 | 39 | /** 40 | * @addtogroup Clock 41 | */ 42 | 43 | /*@{*/ 44 | 45 | /** 46 | * This function will return current tick from operating system startup 47 | * 48 | * @return current tick 49 | */ 50 | rt_tick_t rt_tick_get(void) 51 | { 52 | /* return the global tick */ 53 | return rt_tick; 54 | } 55 | RTM_EXPORT(rt_tick_get); 56 | 57 | /** 58 | * This function will set current tick 59 | */ 60 | void rt_tick_set(rt_tick_t tick) 61 | { 62 | rt_base_t level; 63 | 64 | level = rt_hw_interrupt_disable(); 65 | rt_tick = tick; 66 | rt_hw_interrupt_enable(level); 67 | } 68 | 69 | /** 70 | * This function will notify kernel there is one tick passed. Normally, 71 | * this function is invoked by clock ISR. 72 | */ 73 | void rt_tick_increase(void) 74 | { 75 | struct rt_thread *thread; 76 | 77 | /* increase the global tick */ 78 | ++ rt_tick; 79 | 80 | /* check time slice */ 81 | thread = rt_thread_self(); 82 | 83 | -- thread->remaining_tick; 84 | if (thread->remaining_tick == 0) 85 | { 86 | /* change to initialized tick */ 87 | thread->remaining_tick = thread->init_tick; 88 | 89 | /* yield */ 90 | rt_thread_yield(); 91 | } 92 | 93 | /* check timer */ 94 | rt_timer_check(); 95 | } 96 | 97 | /** 98 | * This function will calculate the tick from millisecond. 99 | * 100 | * @param ms the specified millisecond 101 | * 102 | * @return the calculated tick 103 | */ 104 | rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms) 105 | { 106 | /* return the calculated tick */ 107 | return (RT_TICK_PER_SECOND * ms + 999) / 1000; 108 | } 109 | RTM_EXPORT(rt_tick_from_millisecond); 110 | 111 | /*@}*/ 112 | 113 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/src/device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : device.c 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2007-01-21 Bernard the first version 13 | * 2010-05-04 Bernard add rt_device_init implementation 14 | * 2012-10-20 Bernard add device check in register function, 15 | * provided by Rob 16 | * 2012-12-25 Bernard return RT_EOK if the device interface not exist. 17 | */ 18 | 19 | #include 20 | 21 | #ifdef RT_USING_DEVICE 22 | 23 | /** 24 | * This function registers a device driver with specified name. 25 | * 26 | * @param dev the pointer of device driver structure 27 | * @param name the device driver's name 28 | * @param flags the flag of device 29 | * 30 | * @return the error code, RT_EOK on initialization successfully. 31 | */ 32 | rt_err_t rt_device_register(rt_device_t dev, 33 | const char *name, 34 | rt_uint16_t flags) 35 | { 36 | if (dev == RT_NULL) 37 | return -RT_ERROR; 38 | 39 | if (rt_device_find(name) != RT_NULL) 40 | return -RT_ERROR; 41 | 42 | rt_object_init(&(dev->parent), RT_Object_Class_Device, name); 43 | dev->flag = flags; 44 | 45 | return RT_EOK; 46 | } 47 | RTM_EXPORT(rt_device_register); 48 | 49 | /** 50 | * This function removes a previously registered device driver 51 | * 52 | * @param dev the pointer of device driver structure 53 | * 54 | * @return the error code, RT_EOK on successfully. 55 | */ 56 | rt_err_t rt_device_unregister(rt_device_t dev) 57 | { 58 | RT_ASSERT(dev != RT_NULL); 59 | 60 | rt_object_detach(&(dev->parent)); 61 | 62 | return RT_EOK; 63 | } 64 | RTM_EXPORT(rt_device_unregister); 65 | 66 | /** 67 | * This function initializes all registered device driver 68 | * 69 | * @return the error code, RT_EOK on successfully. 70 | */ 71 | rt_err_t rt_device_init_all(void) 72 | { 73 | struct rt_device *device; 74 | struct rt_list_node *node; 75 | struct rt_object_information *information; 76 | register rt_err_t result; 77 | 78 | extern struct rt_object_information rt_object_container[]; 79 | 80 | information = &rt_object_container[RT_Object_Class_Device]; 81 | 82 | /* for each device */ 83 | for (node = information->object_list.next; 84 | node != &(information->object_list); 85 | node = node->next) 86 | { 87 | rt_err_t (*init)(rt_device_t dev); 88 | device = (struct rt_device *)rt_list_entry(node, 89 | struct rt_object, 90 | list); 91 | 92 | /* get device init handler */ 93 | init = device->init; 94 | if (init != RT_NULL && !(device->flag & RT_DEVICE_FLAG_ACTIVATED)) 95 | { 96 | result = init(device); 97 | if (result != RT_EOK) 98 | { 99 | rt_kprintf("To initialize device:%s failed. The error code is %d\n", 100 | device->parent.name, result); 101 | } 102 | else 103 | { 104 | device->flag |= RT_DEVICE_FLAG_ACTIVATED; 105 | } 106 | } 107 | } 108 | 109 | return RT_EOK; 110 | } 111 | 112 | /** 113 | * This function finds a device driver by specified name. 114 | * 115 | * @param name the device driver's name 116 | * 117 | * @return the registered device driver on successful, or RT_NULL on failure. 118 | */ 119 | rt_device_t rt_device_find(const char *name) 120 | { 121 | struct rt_object *object; 122 | struct rt_list_node *node; 123 | struct rt_object_information *information; 124 | 125 | extern struct rt_object_information rt_object_container[]; 126 | 127 | /* enter critical */ 128 | if (rt_thread_self() != RT_NULL) 129 | rt_enter_critical(); 130 | 131 | /* try to find device object */ 132 | information = &rt_object_container[RT_Object_Class_Device]; 133 | for (node = information->object_list.next; 134 | node != &(information->object_list); 135 | node = node->next) 136 | { 137 | object = rt_list_entry(node, struct rt_object, list); 138 | if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) 139 | { 140 | /* leave critical */ 141 | if (rt_thread_self() != RT_NULL) 142 | rt_exit_critical(); 143 | 144 | return (rt_device_t)object; 145 | } 146 | } 147 | 148 | /* leave critical */ 149 | if (rt_thread_self() != RT_NULL) 150 | rt_exit_critical(); 151 | 152 | /* not found */ 153 | return RT_NULL; 154 | } 155 | RTM_EXPORT(rt_device_find); 156 | 157 | /** 158 | * This function will initialize the specified device 159 | * 160 | * @param dev the pointer of device driver structure 161 | * 162 | * @return the result 163 | */ 164 | rt_err_t rt_device_init(rt_device_t dev) 165 | { 166 | rt_err_t result = RT_EOK; 167 | 168 | RT_ASSERT(dev != RT_NULL); 169 | 170 | /* get device init handler */ 171 | if (dev->init != RT_NULL) 172 | { 173 | if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) 174 | { 175 | result = dev->init(dev); 176 | if (result != RT_EOK) 177 | { 178 | rt_kprintf("To initialize device:%s failed. The error code is %d\n", 179 | dev->parent.name, result); 180 | } 181 | else 182 | { 183 | dev->flag |= RT_DEVICE_FLAG_ACTIVATED; 184 | } 185 | } 186 | } 187 | 188 | return result; 189 | } 190 | 191 | /** 192 | * This function will open a device 193 | * 194 | * @param dev the pointer of device driver structure 195 | * @param oflag the flags for device open 196 | * 197 | * @return the result 198 | */ 199 | rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) 200 | { 201 | rt_err_t result = RT_EOK; 202 | 203 | RT_ASSERT(dev != RT_NULL); 204 | 205 | /* if device is not initialized, initialize it. */ 206 | if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) 207 | { 208 | if (dev->init != RT_NULL) 209 | { 210 | result = dev->init(dev); 211 | if (result != RT_EOK) 212 | { 213 | rt_kprintf("To initialize device:%s failed. The error code is %d\n", 214 | dev->parent.name, result); 215 | 216 | return result; 217 | } 218 | } 219 | 220 | dev->flag |= RT_DEVICE_FLAG_ACTIVATED; 221 | } 222 | 223 | /* device is a stand alone device and opened */ 224 | if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) && 225 | (dev->open_flag & RT_DEVICE_OFLAG_OPEN)) 226 | { 227 | return -RT_EBUSY; 228 | } 229 | 230 | /* call device open interface */ 231 | if (dev->open != RT_NULL) 232 | { 233 | result = dev->open(dev, oflag); 234 | } 235 | 236 | /* set open flag */ 237 | if (result == RT_EOK || result == -RT_ENOSYS) 238 | dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN; 239 | 240 | return result; 241 | } 242 | RTM_EXPORT(rt_device_open); 243 | 244 | /** 245 | * This function will close a device 246 | * 247 | * @param dev the pointer of device driver structure 248 | * 249 | * @return the result 250 | */ 251 | rt_err_t rt_device_close(rt_device_t dev) 252 | { 253 | rt_err_t result = RT_EOK; 254 | 255 | RT_ASSERT(dev != RT_NULL); 256 | 257 | /* call device close interface */ 258 | if (dev->close != RT_NULL) 259 | { 260 | result = dev->close(dev); 261 | } 262 | 263 | /* set open flag */ 264 | if (result == RT_EOK || result == -RT_ENOSYS) 265 | dev->open_flag = RT_DEVICE_OFLAG_CLOSE; 266 | 267 | return result; 268 | } 269 | RTM_EXPORT(rt_device_close); 270 | 271 | /** 272 | * This function will read some data from a device. 273 | * 274 | * @param dev the pointer of device driver structure 275 | * @param pos the position of reading 276 | * @param buffer the data buffer to save read data 277 | * @param size the size of buffer 278 | * 279 | * @return the actually read size on successful, otherwise negative returned. 280 | * 281 | * @note since 0.4.0, the unit of size/pos is a block for block device. 282 | */ 283 | rt_size_t rt_device_read(rt_device_t dev, 284 | rt_off_t pos, 285 | void *buffer, 286 | rt_size_t size) 287 | { 288 | RT_ASSERT(dev != RT_NULL); 289 | 290 | /* call device read interface */ 291 | if (dev->read != RT_NULL) 292 | { 293 | return dev->read(dev, pos, buffer, size); 294 | } 295 | 296 | /* set error code */ 297 | rt_set_errno(-RT_ENOSYS); 298 | 299 | return 0; 300 | } 301 | RTM_EXPORT(rt_device_read); 302 | 303 | /** 304 | * This function will write some data to a device. 305 | * 306 | * @param dev the pointer of device driver structure 307 | * @param pos the position of written 308 | * @param buffer the data buffer to be written to device 309 | * @param size the size of buffer 310 | * 311 | * @return the actually written size on successful, otherwise negative returned. 312 | * 313 | * @note since 0.4.0, the unit of size/pos is a block for block device. 314 | */ 315 | rt_size_t rt_device_write(rt_device_t dev, 316 | rt_off_t pos, 317 | const void *buffer, 318 | rt_size_t size) 319 | { 320 | RT_ASSERT(dev != RT_NULL); 321 | 322 | /* call device write interface */ 323 | if (dev->write != RT_NULL) 324 | { 325 | return dev->write(dev, pos, buffer, size); 326 | } 327 | 328 | /* set error code */ 329 | rt_set_errno(-RT_ENOSYS); 330 | 331 | return 0; 332 | } 333 | RTM_EXPORT(rt_device_write); 334 | 335 | /** 336 | * This function will perform a variety of control functions on devices. 337 | * 338 | * @param dev the pointer of device driver structure 339 | * @param cmd the command sent to device 340 | * @param arg the argument of command 341 | * 342 | * @return the result 343 | */ 344 | rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg) 345 | { 346 | RT_ASSERT(dev != RT_NULL); 347 | 348 | /* call device write interface */ 349 | if (dev->control != RT_NULL) 350 | { 351 | return dev->control(dev, cmd, arg); 352 | } 353 | 354 | return RT_EOK; 355 | } 356 | RTM_EXPORT(rt_device_control); 357 | 358 | /** 359 | * This function will set the indication callback function when device receives 360 | * data. 361 | * 362 | * @param dev the pointer of device driver structure 363 | * @param rx_ind the indication callback function 364 | * 365 | * @return RT_EOK 366 | */ 367 | rt_err_t 368 | rt_device_set_rx_indicate(rt_device_t dev, 369 | rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size)) 370 | { 371 | RT_ASSERT(dev != RT_NULL); 372 | 373 | dev->rx_indicate = rx_ind; 374 | 375 | return RT_EOK; 376 | } 377 | RTM_EXPORT(rt_device_set_rx_indicate); 378 | 379 | /** 380 | * This function will set the indication callback function when device has 381 | * written data to physical hardware. 382 | * 383 | * @param dev the pointer of device driver structure 384 | * @param tx_done the indication callback function 385 | * 386 | * @return RT_EOK 387 | */ 388 | rt_err_t 389 | rt_device_set_tx_complete(rt_device_t dev, 390 | rt_err_t (*tx_done)(rt_device_t dev, void *buffer)) 391 | { 392 | RT_ASSERT(dev != RT_NULL); 393 | 394 | dev->tx_complete = tx_done; 395 | 396 | return RT_EOK; 397 | } 398 | RTM_EXPORT(rt_device_set_tx_complete); 399 | 400 | #endif 401 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/src/idle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : idle.c 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2006-03-23 Bernard the first version 13 | * 2010-11-10 Bernard add cleanup callback function in thread exit. 14 | * 2012-12-29 Bernard fix compiling warning. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #ifndef IDLE_THREAD_STACK_SIZE 21 | #if defined (RT_USING_HOOK) || defined(RT_USING_HEAP) 22 | #define IDLE_THREAD_STACK_SIZE 256 23 | #else 24 | #define IDLE_THREAD_STACK_SIZE 128 25 | #endif 26 | #endif 27 | 28 | static struct rt_thread idle; 29 | ALIGN(RT_ALIGN_SIZE) 30 | static rt_uint8_t rt_thread_stack[IDLE_THREAD_STACK_SIZE]; 31 | 32 | extern rt_list_t rt_thread_defunct; 33 | 34 | #ifdef RT_USING_HOOK 35 | /** 36 | * @addtogroup Hook 37 | */ 38 | 39 | /*@{*/ 40 | 41 | static void (*rt_thread_idle_hook)(); 42 | 43 | /** 44 | * This function will set a hook function to idle thread loop. 45 | * 46 | * @param hook the specified hook function 47 | * 48 | * @note the hook function must be simple and never be blocked or suspend. 49 | */ 50 | void rt_thread_idle_sethook(void (*hook)(void)) 51 | { 52 | rt_thread_idle_hook = hook; 53 | } 54 | 55 | /*@}*/ 56 | #endif 57 | 58 | /** 59 | * @ingroup Thread 60 | * 61 | * This function will perform system background job when system idle. 62 | */ 63 | void rt_thread_idle_excute(void) 64 | { 65 | /* check the defunct thread list */ 66 | if (!rt_list_isempty(&rt_thread_defunct)) 67 | { 68 | rt_base_t lock; 69 | rt_thread_t thread; 70 | #ifdef RT_USING_MODULE 71 | rt_module_t module = RT_NULL; 72 | #endif 73 | RT_DEBUG_NOT_IN_INTERRUPT; 74 | 75 | /* disable interrupt */ 76 | lock = rt_hw_interrupt_disable(); 77 | 78 | /* re-check whether list is empty */ 79 | if (!rt_list_isempty(&rt_thread_defunct)) 80 | { 81 | /* get defunct thread */ 82 | thread = rt_list_entry(rt_thread_defunct.next, 83 | struct rt_thread, 84 | tlist); 85 | #ifdef RT_USING_MODULE 86 | /* get thread's parent module */ 87 | module = (rt_module_t)thread->module_id; 88 | 89 | /* if the thread is module's main thread */ 90 | if (module != RT_NULL && module->module_thread == thread) 91 | { 92 | /* detach module's main thread */ 93 | module->module_thread = RT_NULL; 94 | } 95 | #endif 96 | /* remove defunct thread */ 97 | rt_list_remove(&(thread->tlist)); 98 | /* invoke thread cleanup */ 99 | if (thread->cleanup != RT_NULL) 100 | thread->cleanup(thread); 101 | 102 | /* if it's a system object, not delete it */ 103 | if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) 104 | { 105 | /* enable interrupt */ 106 | rt_hw_interrupt_enable(lock); 107 | 108 | return; 109 | } 110 | } 111 | else 112 | { 113 | /* enable interrupt */ 114 | rt_hw_interrupt_enable(lock); 115 | 116 | /* may the defunct thread list is removed by others, just return */ 117 | return; 118 | } 119 | 120 | /* enable interrupt */ 121 | rt_hw_interrupt_enable(lock); 122 | 123 | #ifdef RT_USING_HEAP 124 | #if defined(RT_USING_MODULE) && defined(RT_USING_SLAB) 125 | /* the thread belongs to an application module */ 126 | if (thread->flags & RT_OBJECT_FLAG_MODULE) 127 | rt_module_free((rt_module_t)thread->module_id, thread->stack_addr); 128 | else 129 | #endif 130 | /* release thread's stack */ 131 | RT_KERNEL_FREE(thread->stack_addr); 132 | /* delete thread object */ 133 | rt_object_delete((rt_object_t)thread); 134 | #endif 135 | 136 | #ifdef RT_USING_MODULE 137 | if (module != RT_NULL) 138 | { 139 | extern rt_err_t rt_module_destroy(rt_module_t module); 140 | 141 | /* if sub thread list and main thread are all empty */ 142 | if ((module->module_thread == RT_NULL) && 143 | rt_list_isempty(&module->module_object[RT_Object_Class_Thread].object_list)) 144 | { 145 | module->nref --; 146 | } 147 | 148 | /* destroy module */ 149 | if (module->nref == 0) 150 | rt_module_destroy(module); 151 | } 152 | #endif 153 | } 154 | } 155 | 156 | static void rt_thread_idle_entry(void *parameter) 157 | { 158 | while (1) 159 | { 160 | #ifdef RT_USING_HOOK 161 | if (rt_thread_idle_hook != RT_NULL) 162 | rt_thread_idle_hook(); 163 | #endif 164 | 165 | rt_thread_idle_excute(); 166 | } 167 | } 168 | 169 | /** 170 | * @ingroup SymstemInit 171 | * 172 | * This function will initialize idle thread, then start it. 173 | * 174 | * @note this function must be invoked when system init. 175 | */ 176 | void rt_thread_idle_init(void) 177 | { 178 | /* initialize thread */ 179 | rt_thread_init(&idle, 180 | "tidle", 181 | rt_thread_idle_entry, 182 | RT_NULL, 183 | &rt_thread_stack[0], 184 | sizeof(rt_thread_stack), 185 | RT_THREAD_PRIORITY_MAX - 1, 186 | 32); 187 | 188 | /* startup */ 189 | rt_thread_startup(&idle); 190 | } 191 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/src/irq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : irq.c 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2006-02-24 Bernard first version 13 | * 2006-05-03 Bernard add IRQ_DEBUG 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | /* #define IRQ_DEBUG */ 20 | 21 | /** 22 | * @addtogroup Kernel 23 | */ 24 | 25 | /*@{*/ 26 | 27 | volatile rt_uint8_t rt_interrupt_nest; 28 | 29 | /** 30 | * This function will be invoked by BSP, when enter interrupt service routine 31 | * 32 | * @note please don't invoke this routine in application 33 | * 34 | * @see rt_interrupt_leave 35 | */ 36 | void rt_interrupt_enter(void) 37 | { 38 | rt_base_t level; 39 | 40 | RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq coming..., irq nest:%d\n", 41 | rt_interrupt_nest)); 42 | 43 | level = rt_hw_interrupt_disable(); 44 | rt_interrupt_nest ++; 45 | rt_hw_interrupt_enable(level); 46 | } 47 | RTM_EXPORT(rt_interrupt_enter); 48 | 49 | /** 50 | * This function will be invoked by BSP, when leave interrupt service routine 51 | * 52 | * @note please don't invoke this routine in application 53 | * 54 | * @see rt_interrupt_enter 55 | */ 56 | void rt_interrupt_leave(void) 57 | { 58 | rt_base_t level; 59 | 60 | RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq leave, irq nest:%d\n", 61 | rt_interrupt_nest)); 62 | 63 | level = rt_hw_interrupt_disable(); 64 | rt_interrupt_nest --; 65 | rt_hw_interrupt_enable(level); 66 | } 67 | RTM_EXPORT(rt_interrupt_leave); 68 | 69 | /** 70 | * This function will return the nest of interrupt. 71 | * 72 | * User application can invoke this function to get whether current 73 | * context is interrupt context. 74 | * 75 | * @return the number of nested interrupts. 76 | */ 77 | rt_uint8_t rt_interrupt_get_nest(void) 78 | { 79 | return rt_interrupt_nest; 80 | } 81 | RTM_EXPORT(rt_interrupt_get_nest); 82 | 83 | RTM_EXPORT(rt_hw_interrupt_disable); 84 | RTM_EXPORT(rt_hw_interrupt_enable); 85 | 86 | /*@}*/ 87 | 88 | -------------------------------------------------------------------------------- /thread_pool/rt-thread/src/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : module.h 3 | * This file is part of RT-Thread RTOS 4 | * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team 5 | * 6 | * The license and distribution terms for this file may be 7 | * found in the file LICENSE in this distribution or at 8 | * http://www.rt-thread.org/license/LICENSE 9 | * 10 | * Change Logs: 11 | * Date Author Notes 12 | * 2010-01-09 Bernard first version 13 | * 2010-04-09 yi.qiu implement based on first version 14 | */ 15 | 16 | #ifndef __MODULE_H__ 17 | #define __MODULE_H__ 18 | 19 | #include 20 | 21 | typedef rt_uint8_t Elf_Byte; 22 | 23 | typedef rt_uint32_t Elf32_Addr; /* Unsigned program address */ 24 | typedef rt_uint32_t Elf32_Off; /* Unsigned file offset */ 25 | typedef rt_int32_t Elf32_Sword; /* Signed large integer */ 26 | typedef rt_uint32_t Elf32_Word; /* Unsigned large integer */ 27 | typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */ 28 | 29 | /* e_ident[] magic number */ 30 | #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ 31 | #define ELFMAG1 'E' /* e_ident[EI_MAG1] */ 32 | #define ELFMAG2 'L' /* e_ident[EI_MAG2] */ 33 | #define ELFMAG3 'F' /* e_ident[EI_MAG3] */ 34 | #define RTMMAG "\177RTM" /* magic */ 35 | #define ELFMAG "\177ELF" /* magic */ 36 | #define SELFMAG 4 /* size of magic */ 37 | 38 | #define EI_CLASS 4 /* file class */ 39 | #define EI_NIDENT 16 /* Size of e_ident[] */ 40 | 41 | /* e_ident[] file class */ 42 | #define ELFCLASSNONE 0 /* invalid */ 43 | #define ELFCLASS32 1 /* 32-bit objs */ 44 | #define ELFCLASS64 2 /* 64-bit objs */ 45 | #define ELFCLASSNUM 3 /* number of classes */ 46 | 47 | /* e_ident[] data encoding */ 48 | #define ELFDATANONE 0 /* invalid */ 49 | #define ELFDATA2LSB 1 /* Little-Endian */ 50 | #define ELFDATA2MSB 2 /* Big-Endian */ 51 | #define ELFDATANUM 3 /* number of data encode defines */ 52 | 53 | /* e_ident */ 54 | #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 55 | (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 56 | (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 57 | (ehdr).e_ident[EI_MAG3] == ELFMAG3) 58 | 59 | #define ET_NONE 0 /* No file type */ 60 | #define ET_REL 1 /* Relocatable file */ 61 | #define ET_EXEC 2 /* Executable file */ 62 | #define ET_DYN 3 /* Shared object file */ 63 | #define ET_CORE 4 /* Core file */ 64 | 65 | /* ELF Header */ 66 | typedef struct elfhdr 67 | { 68 | unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ 69 | Elf32_Half e_type; /* object file type */ 70 | Elf32_Half e_machine; /* machine */ 71 | Elf32_Word e_version; /* object file version */ 72 | Elf32_Addr e_entry; /* virtual entry point */ 73 | Elf32_Off e_phoff; /* program header table offset */ 74 | Elf32_Off e_shoff; /* section header table offset */ 75 | Elf32_Word e_flags; /* processor-specific flags */ 76 | Elf32_Half e_ehsize; /* ELF header size */ 77 | Elf32_Half e_phentsize; /* program header entry size */ 78 | Elf32_Half e_phnum; /* number of program header entries */ 79 | Elf32_Half e_shentsize; /* section header entry size */ 80 | Elf32_Half e_shnum; /* number of section header entries */ 81 | Elf32_Half e_shstrndx; /* section header table's "section 82 | header string table" entry offset */ 83 | } Elf32_Ehdr; 84 | 85 | /* Section Header */ 86 | typedef struct 87 | { 88 | Elf32_Word sh_name; /* name - index into section header 89 | string table section */ 90 | Elf32_Word sh_type; /* type */ 91 | Elf32_Word sh_flags; /* flags */ 92 | Elf32_Addr sh_addr; /* address */ 93 | Elf32_Off sh_offset; /* file offset */ 94 | Elf32_Word sh_size; /* section size */ 95 | Elf32_Word sh_link; /* section header table index link */ 96 | Elf32_Word sh_info; /* extra information */ 97 | Elf32_Word sh_addralign; /* address alignment */ 98 | Elf32_Word sh_entsize; /* section entry size */ 99 | } Elf32_Shdr; 100 | 101 | /* Section names */ 102 | #define ELF_BSS ".bss" /* uninitialized data */ 103 | #define ELF_DATA ".data" /* initialized data */ 104 | #define ELF_DEBUG ".debug" /* debug */ 105 | #define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ 106 | #define ELF_DYNSTR ".dynstr" /* dynamic string table */ 107 | #define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ 108 | #define ELF_FINI ".fini" /* termination code */ 109 | #define ELF_GOT ".got" /* global offset table */ 110 | #define ELF_HASH ".hash" /* symbol hash table */ 111 | #define ELF_INIT ".init" /* initialization code */ 112 | #define ELF_REL_DATA ".rel.data" /* relocation data */ 113 | #define ELF_REL_FINI ".rel.fini" /* relocation termination code */ 114 | #define ELF_REL_INIT ".rel.init" /* relocation initialization code */ 115 | #define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ 116 | #define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ 117 | #define ELF_REL_TEXT ".rel.text" /* relocation code */ 118 | #define ELF_RODATA ".rodata" /* read-only data */ 119 | #define ELF_SHSTRTAB ".shstrtab" /* section header string table */ 120 | #define ELF_STRTAB ".strtab" /* string table */ 121 | #define ELF_SYMTAB ".symtab" /* symbol table */ 122 | #define ELF_TEXT ".text" /* code */ 123 | #define ELF_RTMSYMTAB "RTMSymTab" 124 | 125 | /* Symbol Table Entry */ 126 | typedef struct elf32_sym 127 | { 128 | Elf32_Word st_name; /* name - index into string table */ 129 | Elf32_Addr st_value; /* symbol value */ 130 | Elf32_Word st_size; /* symbol size */ 131 | unsigned char st_info; /* type and binding */ 132 | unsigned char st_other; /* 0 - no defined meaning */ 133 | Elf32_Half st_shndx; /* section header index */ 134 | } Elf32_Sym; 135 | 136 | #define STB_LOCAL 0 /* BIND */ 137 | #define STB_GLOBAL 1 138 | #define STB_WEAK 2 139 | #define STB_NUM 3 140 | 141 | #define STB_LOPROC 13 /* processor specific range */ 142 | #define STB_HIPROC 15 143 | 144 | #define STT_NOTYPE 0 /* symbol type is unspecified */ 145 | #define STT_OBJECT 1 /* data object */ 146 | #define STT_FUNC 2 /* code object */ 147 | #define STT_SECTION 3 /* symbol identifies an ELF section */ 148 | #define STT_FILE 4 /* symbol's name is file name */ 149 | #define STT_COMMON 5 /* common data object */ 150 | #define STT_TLS 6 /* thread-local data object */ 151 | #define STT_NUM 7 /* # defined types in generic range */ 152 | #define STT_LOOS 10 /* OS specific range */ 153 | #define STT_HIOS 12 154 | #define STT_LOPROC 13 /* processor specific range */ 155 | #define STT_HIPROC 15 156 | 157 | #define STN_UNDEF 0 /* undefined */ 158 | 159 | #define ELF_ST_BIND(info) ((info) >> 4) 160 | #define ELF_ST_TYPE(info) ((info) & 0xf) 161 | #define ELF_ST_INFO(bind, type) (((bind)<<4)+((type)&0xf)) 162 | 163 | /* Relocation entry with implicit addend */ 164 | typedef struct 165 | { 166 | Elf32_Addr r_offset; /* offset of relocation */ 167 | Elf32_Word r_info; /* symbol table index and type */ 168 | } Elf32_Rel; 169 | 170 | /* Relocation entry with explicit addend */ 171 | typedef struct 172 | { 173 | Elf32_Addr r_offset; /* offset of relocation */ 174 | Elf32_Word r_info; /* symbol table index and type */ 175 | Elf32_Sword r_addend; 176 | } Elf32_Rela; 177 | 178 | /* Extract relocation info - r_info */ 179 | #define ELF32_R_SYM(i) ((i) >> 8) 180 | #define ELF32_R_TYPE(i) ((unsigned char) (i)) 181 | #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) 182 | 183 | /* 184 | * Relocation type for arm 185 | */ 186 | #define R_ARM_NONE 0 187 | #define R_ARM_PC24 1 188 | #define R_ARM_ABS32 2 189 | #define R_ARM_REL32 3 190 | #define R_ARM_THM_CALL 10 191 | #define R_ARM_GLOB_DAT 21 192 | #define R_ARM_JUMP_SLOT 22 193 | #define R_ARM_RELATIVE 23 194 | #define R_ARM_GOT_BREL 26 195 | #define R_ARM_PLT32 27 196 | #define R_ARM_CALL 28 197 | #define R_ARM_JUMP24 29 198 | #define R_ARM_THM_JUMP24 30 199 | #define R_ARM_V4BX 40 200 | 201 | /* Program Header */ 202 | typedef struct 203 | { 204 | Elf32_Word p_type; /* segment type */ 205 | Elf32_Off p_offset; /* segment offset */ 206 | Elf32_Addr p_vaddr; /* virtual address of segment */ 207 | Elf32_Addr p_paddr; /* physical address - ignored? */ 208 | Elf32_Word p_filesz; /* number of bytes in file for seg. */ 209 | Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ 210 | Elf32_Word p_flags; /* flags */ 211 | Elf32_Word p_align; /* memory alignment */ 212 | } Elf32_Phdr; 213 | 214 | /* p_type */ 215 | #define PT_LOAD 1 216 | 217 | /* p_flags */ 218 | #define PF_X 1 219 | #define PF_W 2 220 | #define PF_R 4 221 | 222 | /* sh_type */ 223 | #define SHT_NULL 0 /* inactive */ 224 | #define SHT_PROGBITS 1 /* program defined information */ 225 | #define SHT_SYMTAB 2 /* symbol table section */ 226 | #define SHT_STRTAB 3 /* string table section */ 227 | #define SHT_RELA 4 /* relocation section with addends*/ 228 | #define SHT_HASH 5 /* symbol hash table section */ 229 | #define SHT_DYNAMIC 6 /* dynamic section */ 230 | #define SHT_NOTE 7 /* note section */ 231 | #define SHT_NOBITS 8 /* no space section */ 232 | #define SHT_REL 9 /* relation section without addends */ 233 | #define SHT_SHLIB 10 /* reserved - purpose unknown */ 234 | #define SHT_DYNSYM 11 /* dynamic symbol table section */ 235 | #define SHT_NUM 12 /* number of section types */ 236 | #define SHT_LOPROC 0x70000000 /* reserved range for processor */ 237 | #define SHT_HIPROC 0x7fffffff /* specific section header types */ 238 | #define SHT_LOUSER 0x80000000 /* reserved range for application */ 239 | #define SHT_HIUSER 0xffffffff /* specific indexes */ 240 | 241 | /* Section Attribute Flags - sh_flags */ 242 | #define SHF_WRITE 0x1 /* Writable */ 243 | #define SHF_ALLOC 0x2 /* occupies memory */ 244 | #define SHF_EXECINSTR 0x4 /* executable */ 245 | #define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ 246 | /* specific section attributes */ 247 | 248 | #endif 249 | -------------------------------------------------------------------------------- /thread_pool/ucos2/arch/app_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucos2/arch/app_cfg.h -------------------------------------------------------------------------------- /thread_pool/ucos2/arch/os_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/OS-II 4 | * The Real-Time Kernel 5 | * 6 | * (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL 7 | * All Rights Reserved 8 | * 9 | * uC/OS-II Configuration File for V2.51 10 | * 11 | * File : OS_CFG.H 12 | * By : Jean J. Labrosse 13 | ********************************************************************************************************* 14 | */ 15 | 16 | /* 17 | ********************************************************************************************************* 18 | * uC/OS-II CONFIGURATION 19 | ********************************************************************************************************* 20 | */ 21 | 22 | #include "os_cpu.h" 23 | 24 | #define OS_MAX_EVENTS 10 /* Max. number of event control blocks in your application ... */ 25 | /* ... MUST be > 0 */ 26 | #define OS_MAX_FLAGS 10 /* Max. number of Event Flag Groups in your application ... */ 27 | /* ... MUST be > 0 */ 28 | #define OS_MAX_MEM_PART 5 /* Max. number of memory partitions ... */ 29 | /* ... MUST be > 0 */ 30 | #define OS_MAX_QS 2 /* Max. number of queue control blocks in your application ... */ 31 | /* ... MUST be > 0 */ 32 | #define OS_MAX_TASKS 11 /* Max. number of tasks in your application ... */ 33 | /* ... MUST be >= 2 */ 34 | 35 | #define OS_LOWEST_PRIO 12 /* Defines the lowest priority that can be assigned ... */ 36 | /* ... MUST NEVER be higher than 63! */ 37 | 38 | #define OS_TASK_IDLE_STK_SIZE 512 /* Idle task stack size (# of OS_STK wide entries) */ 39 | 40 | #define OS_TASK_STAT_EN 1 /* Enable (1) or Disable(0) the statistics task */ 41 | #define OS_TASK_STAT_STK_SIZE 512 /* Statistics task stack size (# of OS_STK wide entries) */ 42 | 43 | #define OS_ARG_CHK_EN 1 /* Enable (1) or Disable (0) argument checking */ 44 | #define OS_CPU_HOOKS_EN 1 /* uC/OS-II hooks are found in the processor port files */ 45 | 46 | 47 | /* ----------------------- EVENT FLAGS ------------------------ */ 48 | #define OS_FLAG_EN 1 /* Enable (1) or Disable (0) code generation for EVENT FLAGS */ 49 | #define OS_FLAG_WAIT_CLR_EN 1 /* Include code for Wait on Clear EVENT FLAGS */ 50 | #define OS_FLAG_ACCEPT_EN 1 /* Include code for OSFlagAccept() */ 51 | #define OS_FLAG_DEL_EN 1 /* Include code for OSFlagDel() */ 52 | #define OS_FLAG_QUERY_EN 1 /* Include code for OSFlagQuery() */ 53 | 54 | 55 | /* -------------------- MESSAGE MAILBOXES --------------------- */ 56 | #define OS_MBOX_EN 1 /* Enable (1) or Disable (0) code generation for MAILBOXES */ 57 | #define OS_MBOX_ACCEPT_EN 1 /* Include code for OSMboxAccept() */ 58 | #define OS_MBOX_DEL_EN 1 /* Include code for OSMboxDel() */ 59 | #define OS_MBOX_POST_EN 1 /* Include code for OSMboxPost() */ 60 | #define OS_MBOX_POST_OPT_EN 1 /* Include code for OSMboxPostOpt() */ 61 | #define OS_MBOX_QUERY_EN 1 /* Include code for OSMboxQuery() */ 62 | 63 | 64 | /* --------------------- MEMORY MANAGEMENT -------------------- */ 65 | #define OS_MEM_EN 1 /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */ 66 | #define OS_MEM_QUERY_EN 1 /* Include code for OSMemQuery() */ 67 | 68 | 69 | /* ---------------- MUTUAL EXCLUSION SEMAPHORES --------------- */ 70 | #define OS_MUTEX_EN 1 /* Enable (1) or Disable (0) code generation for MUTEX */ 71 | #define OS_MUTEX_ACCEPT_EN 1 /* Include code for OSMutexAccept() */ 72 | #define OS_MUTEX_DEL_EN 1 /* Include code for OSMutexDel() */ 73 | #define OS_MUTEX_QUERY_EN 1 /* Include code for OSMutexQuery() */ 74 | 75 | 76 | /* ---------------------- MESSAGE QUEUES ---------------------- */ 77 | #define OS_Q_EN 1 /* Enable (1) or Disable (0) code generation for QUEUES */ 78 | #define OS_Q_ACCEPT_EN 1 /* Include code for OSQAccept() */ 79 | #define OS_Q_DEL_EN 1 /* Include code for OSQDel() */ 80 | #define OS_Q_FLUSH_EN 1 /* Include code for OSQFlush() */ 81 | #define OS_Q_POST_EN 1 /* Include code for OSQPost() */ 82 | #define OS_Q_POST_FRONT_EN 1 /* Include code for OSQPostFront() */ 83 | #define OS_Q_POST_OPT_EN 1 /* Include code for OSQPostOpt() */ 84 | #define OS_Q_QUERY_EN 1 /* Include code for OSQQuery() */ 85 | 86 | 87 | /* ------------------------ SEMAPHORES ------------------------ */ 88 | #define OS_SEM_EN 1 /* Enable (1) or Disable (0) code generation for SEMAPHORES */ 89 | #define OS_SEM_ACCEPT_EN 1 /* Include code for OSSemAccept() */ 90 | #define OS_SEM_DEL_EN 1 /* Include code for OSSemDel() */ 91 | #define OS_SEM_QUERY_EN 1 /* Include code for OSSemQuery() */ 92 | 93 | 94 | /* --------------------- TASK MANAGEMENT ---------------------- */ 95 | #define OS_TASK_CHANGE_PRIO_EN 1 /* Include code for OSTaskChangePrio() */ 96 | #define OS_TASK_CREATE_EN 1 /* Include code for OSTaskCreate() */ 97 | #define OS_TASK_CREATE_EXT_EN 1 /* Include code for OSTaskCreateExt() */ 98 | #define OS_TASK_DEL_EN 1 /* Include code for OSTaskDel() */ 99 | #define OS_TASK_SUSPEND_EN 1 /* Include code for OSTaskSuspend() and OSTaskResume() */ 100 | #define OS_TASK_QUERY_EN 1 /* Include code for OSTaskQuery() */ 101 | 102 | 103 | /* --------------------- TIME MANAGEMENT ---------------------- */ 104 | #define OS_TIME_DLY_HMSM_EN 1 /* Include code for OSTimeDlyHMSM() */ 105 | #define OS_TIME_DLY_RESUME_EN 1 /* Include code for OSTimeDlyResume() */ 106 | #define OS_TIME_GET_SET_EN 1 /* Include code for OSTimeGet() and OSTimeSet() */ 107 | 108 | 109 | /* ---------------------- MISCELLANEOUS ----------------------- */ 110 | #define OS_SCHED_LOCK_EN 1 /* Include code for OSSchedLock() and OSSchedUnlock() */ 111 | 112 | 113 | #define OS_TICKS_PER_SEC 1000 /* Set the number of ticks in one second */ 114 | 115 | 116 | typedef INT16U OS_FLAGS; /* Date type for event flag bits (8, 16 or 32 bits) */ 117 | -------------------------------------------------------------------------------- /thread_pool/ucos2/arch/os_cpu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucos2/arch/os_cpu.h -------------------------------------------------------------------------------- /thread_pool/ucos2/arch/os_cpu_c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucos2/arch/os_cpu_c.c -------------------------------------------------------------------------------- /thread_pool/ucos2/source/os_globle.c: -------------------------------------------------------------------------------- 1 | #include 2 | /*$PAGE*/ 3 | /* 4 | ********************************************************************************************************* 5 | * GLOBAL VARIABLES 6 | ********************************************************************************************************* 7 | */ 8 | 9 | INT32U OSCtxSwCtr; /* Counter of number of context switches */ 10 | 11 | #if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 0) 12 | OS_EVENT *OSEventFreeList; /* Pointer to list of free EVENT control blocks */ 13 | OS_EVENT OSEventTbl[OS_MAX_EVENTS];/* Table of EVENT control blocks */ 14 | #endif 15 | 16 | #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0) 17 | OS_FLAG_GRP OSFlagTbl[OS_MAX_FLAGS]; /* Table containing event flag groups */ 18 | OS_FLAG_GRP *OSFlagFreeList; /* Pointer to free list of event flag groups */ 19 | #endif 20 | 21 | #if OS_TASK_STAT_EN > 0 22 | INT8S OSCPUUsage; /* Percentage of CPU used */ 23 | INT32U OSIdleCtrMax; /* Max. value that idle ctr can take in 1 sec. */ 24 | INT32U OSIdleCtrRun; /* Val. reached by idle ctr at run time in 1 sec. */ 25 | BOOLEAN OSStatRdy; /* Flag indicating that the statistic task is rdy */ 26 | OS_STK OSTaskStatStk[OS_TASK_STAT_STK_SIZE]; /* Statistics task stack */ 27 | #endif 28 | 29 | INT8U OSIntNesting; /* Interrupt nesting level */ 30 | INT8U OSIntExitY; 31 | 32 | INT8U OSLockNesting; /* Multitasking lock nesting level */ 33 | 34 | INT8U OSPrioCur; /* Priority of current task */ 35 | INT8U OSPrioHighRdy; /* Priority of highest priority task */ 36 | 37 | INT8U OSRdyGrp; /* Ready list group */ 38 | INT8U OSRdyTbl[OS_RDY_TBL_SIZE]; /* Table of tasks which are ready to run */ 39 | 40 | BOOLEAN OSRunning; /* Flag indicating that kernel is running */ 41 | 42 | INT8U OSTaskCtr; /* Number of tasks created */ 43 | 44 | INT32U OSIdleCtr; /* Idle counter */ 45 | 46 | OS_STK OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE]; /* Idle task stack */ 47 | 48 | 49 | OS_TCB *OSTCBCur; /* Pointer to currently running TCB */ 50 | OS_TCB *OSTCBFreeList; /* Pointer to list of free TCBs */ 51 | OS_TCB *OSTCBHighRdy; /* Pointer to highest priority TCB R-to-R */ 52 | OS_TCB *OSTCBList; /* Pointer to doubly linked list of TCBs */ 53 | OS_TCB *OSTCBPrioTbl[OS_LOWEST_PRIO + 1];/* Table of pointers to created TCBs */ 54 | OS_TCB OSTCBTbl[OS_MAX_TASKS + OS_N_SYS_TASKS]; /* Table of TCBs */ 55 | 56 | #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0) 57 | OS_MEM *OSMemFreeList; /* Pointer to free list of memory partitions */ 58 | OS_MEM OSMemTbl[OS_MAX_MEM_PART];/* Storage for memory partition manager */ 59 | #endif 60 | 61 | #if (OS_Q_EN > 0) && (OS_MAX_QS > 0) 62 | OS_Q *OSQFreeList; /* Pointer to list of free QUEUE control blocks */ 63 | OS_Q OSQTbl[OS_MAX_QS]; /* Table of QUEUE control blocks */ 64 | #endif 65 | 66 | #if OS_TIME_GET_SET_EN > 0 67 | volatile INT32U OSTime; /* Current value of system time (in ticks) */ 68 | #endif 69 | -------------------------------------------------------------------------------- /thread_pool/ucos2/source/os_time.c: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/OS-II 4 | * The Real-Time Kernel 5 | * TIME MANAGEMENT 6 | * 7 | * (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL 8 | * All Rights Reserved 9 | * 10 | * File : OS_TIME.C 11 | * By : Jean J. Labrosse 12 | ********************************************************************************************************* 13 | */ 14 | 15 | #ifndef OS_MASTER_FILE 16 | #include 17 | #endif 18 | 19 | /* 20 | ********************************************************************************************************* 21 | * DELAY TASK 'n' TICKS (n from 0 to 65535) 22 | * 23 | * Description: This function is called to delay execution of the currently running task until the 24 | * specified number of system ticks expires. This, of course, directly equates to delaying 25 | * the current task for some time to expire. No delay will result If the specified delay is 26 | * 0. If the specified delay is greater than 0 then, a context switch will result. 27 | * 28 | * Arguments : ticks is the time delay that the task will be suspended in number of clock 'ticks'. 29 | * Note that by specifying 0, the task will not be delayed. 30 | * 31 | * Returns : none 32 | ********************************************************************************************************* 33 | */ 34 | 35 | void OSTimeDly (INT16U ticks) 36 | { 37 | #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ 38 | OS_CPU_SR cpu_sr; 39 | #endif 40 | 41 | 42 | if (ticks > 0) { /* 0 means no delay! */ 43 | OS_ENTER_CRITICAL(); 44 | if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) { /* Delay current task */ 45 | OSRdyGrp &= ~OSTCBCur->OSTCBBitY; 46 | } 47 | OSTCBCur->OSTCBDly = ticks; /* Load ticks in TCB */ 48 | OS_EXIT_CRITICAL(); 49 | OS_Sched(); /* Find next task to run! */ 50 | } 51 | } 52 | /*$PAGE*/ 53 | /* 54 | ********************************************************************************************************* 55 | * DELAY TASK FOR SPECIFIED TIME 56 | * 57 | * Description: This function is called to delay execution of the currently running task until some time 58 | * expires. This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and 59 | * MILLISECONDS instead of ticks. 60 | * 61 | * Arguments : hours specifies the number of hours that the task will be delayed (max. is 255) 62 | * minutes specifies the number of minutes (max. 59) 63 | * seconds specifies the number of seconds (max. 59) 64 | * milli specifies the number of milliseconds (max. 999) 65 | * 66 | * Returns : OS_NO_ERR 67 | * OS_TIME_INVALID_MINUTES 68 | * OS_TIME_INVALID_SECONDS 69 | * OS_TIME_INVALID_MS 70 | * OS_TIME_ZERO_DLY 71 | * 72 | * Note(s) : The resolution on the milliseconds depends on the tick rate. For example, you can't do 73 | * a 10 mS delay if the ticker interrupts every 100 mS. In this case, the delay would be 74 | * set to 0. The actual delay is rounded to the nearest tick. 75 | ********************************************************************************************************* 76 | */ 77 | 78 | #if OS_TIME_DLY_HMSM_EN > 0 79 | INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U milli) 80 | { 81 | INT32U ticks; 82 | INT16U loops; 83 | 84 | 85 | if (hours > 0 || minutes > 0 || seconds > 0 || milli > 0) { 86 | if (minutes > 59) { 87 | return (OS_TIME_INVALID_MINUTES); /* Validate arguments to be within range */ 88 | } 89 | if (seconds > 59) { 90 | return (OS_TIME_INVALID_SECONDS); 91 | } 92 | if (milli > 999) { 93 | return (OS_TIME_INVALID_MILLI); 94 | } 95 | /* Compute the total number of clock ticks required.. */ 96 | /* .. (rounded to the nearest tick) */ 97 | ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC 98 | + OS_TICKS_PER_SEC * ((INT32U)milli + 500L / OS_TICKS_PER_SEC) / 1000L; 99 | loops = (INT16U)(ticks / 65536L); /* Compute the integral number of 65536 tick delays */ 100 | ticks = ticks % 65536L; /* Obtain the fractional number of ticks */ 101 | OSTimeDly((INT16U)ticks); 102 | while (loops > 0) { 103 | OSTimeDly(32768); 104 | OSTimeDly(32768); 105 | loops--; 106 | } 107 | return (OS_NO_ERR); 108 | } 109 | return (OS_TIME_ZERO_DLY); 110 | } 111 | #endif 112 | /*$PAGE*/ 113 | /* 114 | ********************************************************************************************************* 115 | * RESUME A DELAYED TASK 116 | * 117 | * Description: This function is used resume a task that has been delayed through a call to either 118 | * OSTimeDly() or OSTimeDlyHMSM(). Note that you MUST NOT call this function to resume a 119 | * task that is waiting for an event with timeout. This situation would make the task look 120 | * like a timeout occurred (unless you desire this effect). Also, you cannot resume a task 121 | * that has called OSTimeDlyHMSM() with a combined time that exceeds 65535 clock ticks. In 122 | * other words, if the clock tick runs at 100 Hz then, you will not be able to resume a 123 | * delayed task that called OSTimeDlyHMSM(0, 10, 55, 350) or higher. 124 | * 125 | * (10 Minutes * 60 + 55 Seconds + 0.35) * 100 ticks/second. 126 | * 127 | * Arguments : prio specifies the priority of the task to resume 128 | * 129 | * Returns : OS_NO_ERR Task has been resumed 130 | * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed 131 | * (i.e. >= OS_LOWEST_PRIO) 132 | * OS_TIME_NOT_DLY Task is not waiting for time to expire 133 | * OS_TASK_NOT_EXIST The desired task has not been created 134 | ********************************************************************************************************* 135 | */ 136 | 137 | #if OS_TIME_DLY_RESUME_EN > 0 138 | INT8U OSTimeDlyResume (INT8U prio) 139 | { 140 | #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ 141 | OS_CPU_SR cpu_sr; 142 | #endif 143 | OS_TCB *ptcb; 144 | 145 | 146 | if (prio >= OS_LOWEST_PRIO) { 147 | return (OS_PRIO_INVALID); 148 | } 149 | OS_ENTER_CRITICAL(); 150 | ptcb = (OS_TCB *)OSTCBPrioTbl[prio]; /* Make sure that task exist */ 151 | if (ptcb != (OS_TCB *)0) { 152 | if (ptcb->OSTCBDly != 0) { /* See if task is delayed */ 153 | ptcb->OSTCBDly = 0; /* Clear the time delay */ 154 | if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == 0x00) { /* See if task is ready to run */ 155 | OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */ 156 | OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX; 157 | OS_EXIT_CRITICAL(); 158 | OS_Sched(); /* See if this is new highest priority */ 159 | } else { 160 | OS_EXIT_CRITICAL(); /* Task may be suspended */ 161 | } 162 | return (OS_NO_ERR); 163 | } else { 164 | OS_EXIT_CRITICAL(); 165 | return (OS_TIME_NOT_DLY); /* Indicate that task was not delayed */ 166 | } 167 | } 168 | OS_EXIT_CRITICAL(); 169 | return (OS_TASK_NOT_EXIST); /* The task does not exist */ 170 | } 171 | #endif 172 | /*$PAGE*/ 173 | /* 174 | ********************************************************************************************************* 175 | * GET CURRENT SYSTEM TIME 176 | * 177 | * Description: This function is used by your application to obtain the current value of the 32-bit 178 | * counter which keeps track of the number of clock ticks. 179 | * 180 | * Arguments : none 181 | * 182 | * Returns : The current value of OSTime 183 | ********************************************************************************************************* 184 | */ 185 | 186 | #if OS_TIME_GET_SET_EN > 0 187 | INT32U OSTimeGet (void) 188 | { 189 | #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ 190 | OS_CPU_SR cpu_sr; 191 | #endif 192 | INT32U ticks; 193 | 194 | 195 | OS_ENTER_CRITICAL(); 196 | ticks = OSTime; 197 | OS_EXIT_CRITICAL(); 198 | return (ticks); 199 | } 200 | #endif 201 | 202 | /* 203 | ********************************************************************************************************* 204 | * SET SYSTEM CLOCK 205 | * 206 | * Description: This function sets the 32-bit counter which keeps track of the number of clock ticks. 207 | * 208 | * Arguments : ticks specifies the new value that OSTime needs to take. 209 | * 210 | * Returns : none 211 | ********************************************************************************************************* 212 | */ 213 | 214 | #if OS_TIME_GET_SET_EN > 0 215 | void OSTimeSet (INT32U ticks) 216 | { 217 | #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ 218 | OS_CPU_SR cpu_sr; 219 | #endif 220 | 221 | 222 | OS_ENTER_CRITICAL(); 223 | OSTime = ticks; 224 | OS_EXIT_CRITICAL(); 225 | } 226 | #endif 227 | -------------------------------------------------------------------------------- /thread_pool/ucosii/Ports/app_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Ports/app_cfg.h -------------------------------------------------------------------------------- /thread_pool/ucosii/Ports/cpu_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/CPU 4 | * CPU CONFIGURATION & PORT LAYER 5 | * 6 | * (c) Copyright 2004-2007; Micrium, Inc.; Weston, FL 7 | * 8 | * All rights reserved. Protected by international copyright laws. 9 | * 10 | * uC/CPU is provided in source form for FREE evaluation, for educational 11 | * use or peaceful research. If you plan on using uC/CPU in a commercial 12 | * product you need to contact Micrium to properly license its use in your 13 | * product. We provide ALL the source code for your convenience and to 14 | * help you experience uC/CPU. The fact that the source code is provided 15 | * does NOT mean that you can use it without paying a licensing fee. 16 | * 17 | * Knowledge of the source code may NOT be used to develop a similar product. 18 | * 19 | * Please help us continue to provide the Embedded community with the finest 20 | * software available. Your honesty is greatly appreciated. 21 | ********************************************************************************************************* 22 | */ 23 | 24 | /* 25 | ********************************************************************************************************* 26 | * 27 | * CORE CPU MODULE 28 | * 29 | * Filename : cpu_core.h 30 | * Version : V1.18 31 | * Programmer(s) : SR 32 | * ITJ 33 | ********************************************************************************************************* 34 | */ 35 | 36 | 37 | /* 38 | ********************************************************************************************************* 39 | * MODULE 40 | ********************************************************************************************************* 41 | */ 42 | 43 | #ifndef CPU_CORE_MODULE_PRESENT 44 | #define CPU_CORE_MODULE_PRESENT 45 | 46 | 47 | /*$PAGE*/ 48 | /* 49 | ********************************************************************************************************* 50 | * CORE CPU MODULE VERSION NUMBER 51 | * 52 | * Note(s) : (1) (a) The core CPU module software version is denoted as follows : 53 | * 54 | * Vx.yy 55 | * 56 | * where 57 | * V denotes 'Version' label 58 | * x denotes major software version revision number 59 | * yy denotes minor software version revision number 60 | * 61 | * (b) The software version label #define is formatted as follows : 62 | * 63 | * ver = x.yy * 100 64 | * 65 | * where 66 | * ver denotes software version number scaled as an integer value 67 | * x.yy denotes software version number 68 | ********************************************************************************************************* 69 | */ 70 | 71 | #define CPU_CORE_VERSION 117u /* See Note #1. */ 72 | 73 | 74 | /* 75 | ********************************************************************************************************* 76 | * EXTERNS 77 | ********************************************************************************************************* 78 | */ 79 | 80 | #ifdef CPU_CORE_MODULE 81 | #define CPU_CORE_EXT 82 | #else 83 | #define CPU_CORE_EXT extern 84 | #endif 85 | 86 | 87 | /* 88 | ********************************************************************************************************* 89 | * INCLUDE FILES 90 | ********************************************************************************************************* 91 | */ 92 | 93 | #include 94 | #include 95 | #include 96 | 97 | #include 98 | #include 99 | 100 | 101 | /*$PAGE*/ 102 | /* 103 | ********************************************************************************************************* 104 | * DEFINES 105 | ********************************************************************************************************* 106 | */ 107 | 108 | /* 109 | ********************************************************************************************************* 110 | * CPU ERROR CODES 111 | ********************************************************************************************************* 112 | */ 113 | 114 | #define CPU_ERR_NONE 0 115 | #define CPU_ERR_NULL_PTR 10 116 | 117 | #define CPU_ERR_NAME_SIZE 100 118 | 119 | 120 | /*$PAGE*/ 121 | /* 122 | ********************************************************************************************************* 123 | * DATA TYPES 124 | ********************************************************************************************************* 125 | */ 126 | 127 | /* 128 | ********************************************************************************************************* 129 | * CPU ERROR CODES DATA TYPE 130 | ********************************************************************************************************* 131 | */ 132 | 133 | typedef CPU_INT16U CPU_ERR; 134 | 135 | 136 | /* 137 | ********************************************************************************************************* 138 | * GLOBAL VARIABLES 139 | ********************************************************************************************************* 140 | */ 141 | 142 | #if (CPU_CFG_NAME_EN == DEF_ENABLED) 143 | CPU_CORE_EXT CPU_CHAR CPU_Name[CPU_CFG_NAME_SIZE]; 144 | #endif 145 | 146 | 147 | /*$PAGE*/ 148 | /* 149 | ********************************************************************************************************* 150 | * FUNCTION PROTOTYPES 151 | ********************************************************************************************************* 152 | */ 153 | 154 | void CPU_Init (void); 155 | 156 | 157 | #if (CPU_CFG_NAME_EN == DEF_ENABLED) /* ------------------ CPU NAME FNCTS ------------------ */ 158 | void CPU_NameClr(void); 159 | 160 | void CPU_NameGet(CPU_CHAR *pname, 161 | CPU_ERR *perr); 162 | 163 | void CPU_NameSet(CPU_CHAR *pname, 164 | CPU_ERR *perr); 165 | #endif 166 | 167 | 168 | /* 169 | ********************************************************************************************************* 170 | * CONFIGURATION ERRORS 171 | ********************************************************************************************************* 172 | */ 173 | 174 | #ifndef CPU_CFG_NAME_EN 175 | #error "CPU_CFG_NAME_EN not #define'd in 'cpu_cfg.h'" 176 | #error " [MUST be DEF_ENABLED ] " 177 | #error " [ || DEF_DISABLED] " 178 | 179 | #elif ((CPU_CFG_NAME_EN != DEF_ENABLED ) && \ 180 | (CPU_CFG_NAME_EN != DEF_DISABLED)) 181 | #error "CPU_CFG_NAME_EN illegally #define'd in 'cpu_cfg.h'" 182 | #error " [MUST be DEF_ENABLED ] " 183 | #error " [ || DEF_DISABLED] " 184 | 185 | #else 186 | 187 | #ifndef CPU_CFG_NAME_SIZE 188 | #error "CPU_CFG_NAME_SIZE not #define'd in 'cpu_cfg.h' " 189 | #error " [CPU_CFG_NAME_SIZE MUST be >= 1]" 190 | #error " [ && <= 255]" 191 | 192 | #elif ((CPU_CFG_NAME_SIZE < 1) || \ 193 | (CPU_CFG_NAME_SIZE > DEF_INT_08U_MAX_VAL)) 194 | #error "CPU_CFG_NAME_SIZE illegally #define'd in 'cpu_cfg.h' " 195 | #error " [CPU_CFG_NAME_SIZE MUST be >= 1]" 196 | #error " [ && <= 255]" 197 | #endif 198 | 199 | #endif 200 | 201 | 202 | /*$PAGE*/ 203 | /* 204 | ********************************************************************************************************* 205 | * MODULE END 206 | ********************************************************************************************************* 207 | */ 208 | 209 | #endif /* End of CPU core module include. */ 210 | 211 | -------------------------------------------------------------------------------- /thread_pool/ucosii/Ports/os_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Ports/os_cfg.h -------------------------------------------------------------------------------- /thread_pool/ucosii/Ports/os_cpu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Ports/os_cpu.h -------------------------------------------------------------------------------- /thread_pool/ucosii/Ports/os_cpu_c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Ports/os_cpu_c.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_core.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_core.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_flag.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_flag.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_mbox.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_mbox.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_mem.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_mem.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_mutex.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_mutex.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_q.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_q.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_sem.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_sem.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_task.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_task.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_time.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_time.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/os_tmr.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/os_tmr.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/ucos_ii.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/ucos_ii.c -------------------------------------------------------------------------------- /thread_pool/ucosii/Source/ucos_ii.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosii/Source/ucos_ii.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/App/Exec.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/App/Exec.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/App/Radian.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/App/Radian.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/App/Random.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/App/Random.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/App/Stack.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/App/Stack.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/App/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/App/main.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/bsp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/bsp.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/cpu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/cpu.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/cpu_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/cpu_cfg.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/cpu_core.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/cpu_core.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/cpu_def.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/cpu_def.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/includes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/includes.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/os_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/os_cfg.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/os_cfg_app.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/os_cfg_app.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/os_cpu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/os_cpu.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/os_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | ************************************************************************************************************************ 3 | * uC/OS-III 4 | * The Real-Time Kernel 5 | * 6 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 7 | * All rights reserved. Protected by international copyright laws. 8 | * 9 | * File : OS_TYPE.H 10 | * By : JJL 11 | * Version : V3.03.00 12 | * 13 | * LICENSING TERMS: 14 | * --------------- 15 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 16 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 17 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 18 | * application/product. We provide ALL the source code for your convenience and to help you 19 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 20 | * it commercially without paying a licensing fee. 21 | * 22 | * Knowledge of the source code may NOT be used to develop a similar product. 23 | * 24 | * Please help us continue to provide the embedded community with the finest software available. 25 | * Your honesty is greatly appreciated. 26 | * 27 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 28 | ************************************************************************************************************************ 29 | */ 30 | 31 | #ifndef OS_TYPE_H 32 | #define OS_TYPE_H 33 | 34 | #ifdef VSC_INCLUDE_H_FILE_NAMES 35 | const CPU_CHAR *os_type__h = "$Id: $"; 36 | #endif 37 | 38 | /* 39 | ************************************************************************************************************************ 40 | * INCLUDE HEADER FILES 41 | ************************************************************************************************************************ 42 | */ 43 | 44 | /* Description # Bits */ 45 | /* */ 46 | /* ----------------------------------------------------------- */ 47 | 48 | typedef CPU_INT16U OS_CPU_USAGE; /* CPU Usage 0..10000 <16>/32 */ 49 | 50 | typedef CPU_INT32U OS_CTR; /* Counter, 32 */ 51 | 52 | typedef CPU_INT32U OS_CTX_SW_CTR; /* Counter of context switches, 32 */ 53 | 54 | typedef CPU_INT32U OS_CYCLES; /* CPU clock cycles, <32>/64 */ 55 | 56 | typedef CPU_INT32U OS_FLAGS; /* Event flags, 8/16/<32> */ 57 | 58 | typedef CPU_INT32U OS_IDLE_CTR; /* Holds the number of times the idle task runs, <32>/64 */ 59 | 60 | typedef CPU_INT16U OS_MEM_QTY; /* Number of memory blocks, <16>/32 */ 61 | typedef CPU_INT16U OS_MEM_SIZE; /* Size in bytes of a memory block, <16>/32 */ 62 | 63 | typedef CPU_INT16U OS_MSG_QTY; /* Number of OS_MSGs in the msg pool, <16>/32 */ 64 | typedef CPU_INT16U OS_MSG_SIZE; /* Size of messages in number of bytes, <16>/32 */ 65 | 66 | typedef CPU_INT08U OS_NESTING_CTR; /* Interrupt and scheduler nesting, <8>/16/32 */ 67 | 68 | typedef CPU_INT16U OS_OBJ_QTY; /* Number of kernel objects counter, <16>/32 */ 69 | typedef CPU_INT32U OS_OBJ_TYPE; /* Special flag to determine object type, 32 */ 70 | 71 | typedef CPU_INT16U OS_OPT; /* Holds function options <16>/32 */ 72 | 73 | typedef CPU_INT08U OS_PRIO; /* Priority of a task, <8>/16/32 */ 74 | 75 | typedef CPU_INT16U OS_QTY; /* Quantity <16>/32 */ 76 | 77 | typedef CPU_INT32U OS_RATE_HZ; /* Rate in Hertz 32 */ 78 | 79 | typedef CPU_INT32U OS_REG; /* Task register 8/16/<32> */ 80 | typedef CPU_INT08U OS_REG_ID; /* Index to task register <8>/16/32 */ 81 | 82 | typedef CPU_INT32U OS_SEM_CTR; /* Semaphore value 16/<32> */ 83 | 84 | typedef CPU_INT08U OS_STATE; /* State variable <8>/16/32 */ 85 | 86 | typedef CPU_INT08U OS_STATUS; /* Status <8>/16/32 */ 87 | 88 | typedef CPU_INT32U OS_TICK; /* Clock tick counter <32>/64 */ 89 | typedef CPU_INT16U OS_TICK_SPOKE_IX; /* Tick wheel spoke position 8/<16>/32 */ 90 | 91 | typedef CPU_INT16U OS_TMR_SPOKE_IX; /* Timer wheel spoke position 8/<16>/32 */ 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/pc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/pc.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Include/system.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Include/system.h -------------------------------------------------------------------------------- /thread_pool/ucosiii/Ports/bsp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Ports/bsp.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/Ports/cpu_core.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Ports/cpu_core.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/Ports/os_cpu_c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Ports/os_cpu_c.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/Ports/pc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/EasyDataManager/a0b7adebb7fd5490bab6f2e197ddde381aa8aedb/thread_pool/ucosiii/Ports/pc.c -------------------------------------------------------------------------------- /thread_pool/ucosiii/uCOS-III/os_prio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ************************************************************************************************************************ 3 | * uC/OS-III 4 | * The Real-Time Kernel 5 | * 6 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 7 | * All rights reserved. Protected by international copyright laws. 8 | * 9 | * PRIORITY MANAGEMENT 10 | * 11 | * File : OS_PRIO.C 12 | * By : JJL 13 | * Version : V3.03.00 14 | * 15 | * LICENSING TERMS: 16 | * --------------- 17 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 18 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 19 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 20 | * application/product. We provide ALL the source code for your convenience and to help you 21 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 22 | * it commercially without paying a licensing fee. 23 | * 24 | * Knowledge of the source code may NOT be used to develop a similar product. 25 | * 26 | * Please help us continue to provide the embedded community with the finest software available. 27 | * Your honesty is greatly appreciated. 28 | * 29 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 30 | ************************************************************************************************************************ 31 | */ 32 | 33 | #define MICRIUM_SOURCE 34 | #include 35 | 36 | #ifdef VSC_INCLUDE_SOURCE_FILE_NAMES 37 | const CPU_CHAR *os_prio__c = "$Id: $"; 38 | #endif 39 | 40 | 41 | CPU_DATA OSPrioTbl[OS_PRIO_TBL_SIZE]; /* Declare the array local to this file to allow for ... */ 42 | /* ... optimization. In other words, this allows the ... */ 43 | /* ... table to be located in fast memory */ 44 | 45 | /* 46 | ************************************************************************************************************************ 47 | * INITIALIZE THE PRIORITY LIST 48 | * 49 | * Description: This function is called by uC/OS-III to initialize the list of ready priorities. 50 | * 51 | * Arguments : none 52 | * 53 | * Returns : none 54 | * 55 | * Note : This function is INTERNAL to uC/OS-III and your application should not call it. 56 | ************************************************************************************************************************ 57 | */ 58 | 59 | void OS_PrioInit (void) 60 | { 61 | CPU_DATA i; 62 | 63 | 64 | /* Clear the bitmap table ... no task is ready */ 65 | for (i = 0u; i < OS_PRIO_TBL_SIZE; i++) { 66 | OSPrioTbl[i] = (CPU_DATA)0; 67 | } 68 | } 69 | 70 | /* 71 | ************************************************************************************************************************ 72 | * GET HIGHEST PRIORITY TASK WAITING 73 | * 74 | * Description: This function is called by other uC/OS-III services to determine the highest priority task 75 | * waiting on the event. 76 | * 77 | * Arguments : none 78 | * 79 | * Returns : The priority of the Highest Priority Task (HPT) waiting for the event 80 | * 81 | * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it. 82 | ************************************************************************************************************************ 83 | */ 84 | 85 | OS_PRIO OS_PrioGetHighest (void) 86 | { 87 | CPU_DATA *p_tbl; 88 | OS_PRIO prio; 89 | 90 | 91 | prio = (OS_PRIO)0; 92 | p_tbl = &OSPrioTbl[0]; 93 | while (*p_tbl == (CPU_DATA)0) { /* Search the bitmap table for the highest priority */ 94 | prio += DEF_INT_CPU_NBR_BITS; /* Compute the step of each CPU_DATA entry */ 95 | p_tbl++; 96 | } 97 | prio += (OS_PRIO)CPU_CntLeadZeros(*p_tbl); /* Find the position of the first bit set at the entry */ 98 | return (prio); 99 | } 100 | 101 | /* 102 | ************************************************************************************************************************ 103 | * INSERT PRIORITY 104 | * 105 | * Description: This function is called to insert a priority in the priority table. 106 | * 107 | * Arguments : prio is the priority to insert 108 | * 109 | * Returns : none 110 | * 111 | * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it. 112 | ************************************************************************************************************************ 113 | */ 114 | 115 | void OS_PrioInsert (OS_PRIO prio) 116 | { 117 | CPU_DATA bit; 118 | CPU_DATA bit_nbr; 119 | OS_PRIO ix; 120 | 121 | 122 | ix = prio / DEF_INT_CPU_NBR_BITS; 123 | bit_nbr = (CPU_DATA)prio & (DEF_INT_CPU_NBR_BITS - 1u); 124 | bit = 1u; 125 | bit <<= (DEF_INT_CPU_NBR_BITS - 1u) - bit_nbr; 126 | OSPrioTbl[ix] |= bit; 127 | } 128 | 129 | /* 130 | ************************************************************************************************************************ 131 | * REMOVE PRIORITY 132 | * 133 | * Description: This function is called to remove a priority in the priority table. 134 | * 135 | * Arguments : prio is the priority to remove 136 | * 137 | * Returns : none 138 | * 139 | * Note(s) : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it. 140 | ************************************************************************************************************************ 141 | */ 142 | 143 | void OS_PrioRemove (OS_PRIO prio) 144 | { 145 | CPU_DATA bit; 146 | CPU_DATA bit_nbr; 147 | OS_PRIO ix; 148 | 149 | 150 | ix = prio / DEF_INT_CPU_NBR_BITS; 151 | bit_nbr = (CPU_DATA)prio & (DEF_INT_CPU_NBR_BITS - 1u); 152 | bit = 1u; 153 | bit <<= (DEF_INT_CPU_NBR_BITS - 1u) - bit_nbr; 154 | OSPrioTbl[ix] &= ~bit; 155 | } 156 | -------------------------------------------------------------------------------- /thread_pool/ucosiii/uCOS-III/os_var.c: -------------------------------------------------------------------------------- 1 | /* 2 | ************************************************************************************************************************ 3 | * uC/OS-III 4 | * The Real-Time Kernel 5 | * 6 | * (c) Copyright 2009-2012; Micrium, Inc.; Weston, FL 7 | * All rights reserved. Protected by international copyright laws. 8 | * 9 | * VARIABLES 10 | * 11 | * File : OS_VAR.C 12 | * By : JJL 13 | * Version : V3.03.00 14 | * 15 | * LICENSING TERMS: 16 | * --------------- 17 | * uC/OS-III is provided in source form for FREE short-term evaluation, for educational use or 18 | * for peaceful research. If you plan or intend to use uC/OS-III in a commercial application/ 19 | * product then, you need to contact Micrium to properly license uC/OS-III for its use in your 20 | * application/product. We provide ALL the source code for your convenience and to help you 21 | * experience uC/OS-III. The fact that the source is provided does NOT mean that you can use 22 | * it commercially without paying a licensing fee. 23 | * 24 | * Knowledge of the source code may NOT be used to develop a similar product. 25 | * 26 | * Please help us continue to provide the embedded community with the finest software available. 27 | * Your honesty is greatly appreciated. 28 | * 29 | * You can contact us at www.micrium.com, or by phone at +1 (954) 217-2036. 30 | ************************************************************************************************************************ 31 | */ 32 | 33 | #define OS_GLOBALS 34 | 35 | #define MICRIUM_SOURCE 36 | #include 37 | 38 | #ifdef VSC_INCLUDE_SOURCE_FILE_NAMES 39 | const CPU_CHAR *os_var__c = "$Id: $"; 40 | #endif 41 | --------------------------------------------------------------------------------