kmilo17pet / QuarkTS

An open-source OS for embedded applications that supports prioritized cooperative scheduling, time control, inter-task communications primitives, hierarchical state machines and CoRoutines.
MIT License
218 stars 35 forks source link

MPLAB X IDE v6.05, XC8 2.40 Compiler, PIC16F1xxx #51

Closed NickNifontov closed 1 year ago

NickNifontov commented 1 year ago

IDE: MPLAB X 6.05 COMPILER: XC8 2.40 MCU: PIC16F1779

Create empty project

include "mcc_generated_files/mcc.h"

include "quarkts/QuarkTS.h"

void main(void) { while (1) { } }

Include (SET and etc) all path and directory of QuarkTS

include "quarkts/QuarkTS.h"

try to compile

MAIN ISSUE

quarkts/qatcli.c:554:21: error: initializer element is not a compile-time constant
                    const qINT32_t errorCode = qATCLI_ERRORCODE( (qINT32_t)retval );
                    ^
1 error generated.
(908) exit status = 1
"/Applications/microchip/xc8/v2.40/bin/xc8-cc"  -mcpu=16F1779 -c   -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8"  -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default  -msummary=-psect,-class,+mem,-hex,-file  -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits   -std=c99 -gdwarf-3 -mstack=compiled:auto:auto     -o build/default/production/quarkts/qedgecheck.p1 quarkts/qedgecheck.c 
make[2]: *** [nbproject/Makefile-default.mk:288: build/default/production/quarkts/qatcli.p1] Error 1
make[2]: *** Waiting for unfinished jobs....
quarkts/qcritical.c:24:9: error: initializer element is not a compile-time constant
        const qInt_Disabler_t xDisabler = critical.disable;
        ^
quarkts/qcritical.c:33:9: error: initializer element is not a compile-time constant
        const qInt_Restorer_t xRestorer = critical.restore;

FULL LOG

CLEAN SUCCESSFUL (total time: 56ms) make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]: Entering directory '/Users/RadaR_1/MPLABXProjects/demo.X' make -f nbproject/Makefile-default.mk dist/default/production/demo.X.production.hex make[2]: Entering directory '/Users/RadaR_1/MPLABXProjects/demo.X' "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/quarkts/qclock.p1 quarkts/qclock.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/main.p1 main.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/quarkts/qatcli.p1 quarkts/qatcli.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/quarkts/qbsbuffers.p1 quarkts/qbsbuffers.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/mcc.p1 mcc_generated_files/mcc.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/quarkts/qcoroutine.p1 quarkts/qcoroutine.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/pin_manager.p1 mcc_generated_files/pin_manager.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/device_config.p1 mcc_generated_files/device_config.c "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/quarkts/qcritical.p1 quarkts/qcritical.c quarkts/qatcli.c:554:21: error: initializer element is not a compile-time constant const qINT32_t errorCode = qATCLI_ERRORCODE( (qINT32_t)retval ); ^ 1 error generated. (908) exit status = 1 "/Applications/microchip/xc8/v2.40/bin/xc8-cc" -mcpu=16F1779 -c -mdfp="/Applications/microchip/mplabx/v6.05/packs/Microchip/PIC12-16F1xxx_DFP/1.3.90/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/quarkts/qedgecheck.p1 quarkts/qedgecheck.c make[2]: [nbproject/Makefile-default.mk:288: build/default/production/quarkts/qatcli.p1] Error 1 make[2]: Waiting for unfinished jobs.... quarkts/qcritical.c:24:9: error: initializer element is not a compile-time constant const qInt_Disabler_t xDisabler = critical.disable; ^ quarkts/qcritical.c:33:9: error: initializer element is not a compile-time constant const qInt_Restorer_t xRestorer = critical.restore; ^ 2 errors generated. (908) exit status = 1 default: Empty make[2]: [nbproject/Makefile-default.mk:320: build/default/production/quarkts/qcritical.p1] Error 1 default: Empty make[2]: [nbproject/Makefile-default.mk:328: build/default/production/quarkts/qedgecheck.p1] Error 1 default: Empty quarkts/qedgecheck.c:66:9: error: initializer element is not a compile-time constant const qCoreRegSize_t pinReader = ec->qPrivate.reader; ^ quarkts/qedgecheck.c:91:5: error: initializer element is not a compile-time constant const qCoreRegSize_t pinReader = ec->qPrivate.reader; ^ 2 errors generated. (908) exit status = 1 make[2]: Leaving directory '/Users/RadaR_1/MPLABXProjects/demo.X' make[1]: Leaving directory '/Users/RadaR_1/MPLABXProjects/demo.X' make[1]: [nbproject/Makefile-default.mk:85: .build-conf] Error 2 make: [nbproject/Makefile-impl.mk:39: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)

kmilo17pet commented 1 year ago

hi @NickNifontov, as described in documentation here: https://kmilo17pet.github.io/QuarkTS/q_background.html#q_codstandard, "all the QuarkTS implementation follows the ANSI C99 standard strictly". Please make sure to enable the C99 flag on the compiler settings

NickNifontov commented 1 year ago

С99 is set Снимок экрана 2022-12-25 в 20 21 59 Снимок экрана 2022-12-25 в 20 23 05

NickNifontov commented 1 year ago

any ideas?

kmilo17pet commented 1 year ago

well, XC8 is not fully standardized for C99 from one side. Still, I'm going to make the pertinent changes, but honestly from the other side, I don't have much faith in that compiler due to previous tests, for 8 bit PIC cores, the stack is compiled and requires a fixed call tree. This is since the chip has no parameter stack pointer and the limited HW call stack. QuarkTS makes advanced use of indirection including function pointers and due to the restrictions of these cores and compiler optimizations, we sometimes ran into messages like "Can't generate code for this expression".

some quote from Microchip... "The 8 bit PIC architecture has no stack and no registers so parameters passed to functions must be stored in memory as must local variables for functions. The compiler jumps through hoops tracking call trees to understand how memory allocated to locals and parameters can be overloaded. The compiler supports function pointers but needs to know what function they point to so it can place parameters at the locations expected by that function and possibly track overlaying of memory for locals used by that function. All terribly complicated and inefficient (and possibly buggy) but at least it tries to let you use most C features on a very C unfriendly"

kmilo17pet commented 1 year ago

fix const qualifiers on some variables on last commit to prevent error messages on non-fully C99 compliant compilers

NickNifontov commented 1 year ago

Compile error

QuarkTS-7.3.2/qkernel.c:887:: error: (1466) registers unavailable for code generation of this expression

qkermel.c

            case byQueueReceiver:
                /*the EventData will point to the queue front-data*/
                eventInfo->EventData = qQueue_Peek( Task->qPrivate.aQueue );

Simple code in Main.C

#include "QuarkTS.h"

#define TIMER_TICK ( 0.001f ) /* 1ms */

void main(void)
{
    SYSTEM_Initialize();
    qOS_Setup( NULL , TIMER_TICK , NULL );
    qClock_SysTick();
    qOS_Run();
    while (1)  {}
}

### qconfig.h

    #define Q_PRIORITY_LEVELS           ( 3 )       /**< The number of priorities available to the application tasks*/
    #define Q_SETUP_TIME_CANONICAL      ( 0 )       /**< If enabled, kernel assumes the timing Base to 1mS(1KHz). All time specifications for tasks and STimers must be set in mS*/
    #define Q_SETUP_TICK_IN_HERTZ       ( 0 )       /**< If enabled, the timing base will be taken as frequency(Hz) instead of period(S)*/
    #define Q_PRIO_QUEUE_SIZE           ( 10 )      /**< The size of the priority queue (use a 0(zero) value to disable it)*/
    #define Q_PRESERVE_TASK_ENTRY_ORDER ( 0 )       /**< If enabled, kernel will preserve the tasks entry order every OS scheduling cycle*/
    #define Q_MEMORY_MANAGER            ( 1 )       /**< Used to enable or disable the Memory Manager*/
    #define Q_BYTE_ALIGNMENT            ( 8 )       /**< Byte alignment used by the memory manager*/
    #define Q_DEFAULT_HEAP_SIZE         ( 512 )     /**< The default heap size for the memory manager*/
    #define Q_NOTIFICATION_SPREADER     ( 1 )       /**< Used to enable or disable the spread notification functionality*/
    #define Q_FSM                       ( 1 )       /**< Used to enable or disable the Finite State Machine (FSM) module */
    #define Q_FSM_MAX_NEST_DEPTH        ( 5 )       /**< The max depth of nesting for the Finite State Machines (FSM) module*/
    #define Q_FSM_MAX_TIMEOUTS          ( 3 )       /**< Max number of timeouts inside a timeout specification for the Finite State machine (FSM) module*/
    #define Q_FSM_PS_SIGNALS_MAX        ( 8 )       /**< Max number of signals to subscribe for a Finite State Machine (FSM)*/
    #define Q_FSM_PS_SUB_PER_SIGNAL_MAX ( 4 )       /**< Max number of FSM subscribers per signal*/
    #define Q_QUEUES                    ( 1 )       /**< Used to enable or disable the qQueues*/
    #define Q_TRACE_VARIABLES           ( 1 )       /**< Used to enable or disable variable tracing and debugging*/
    #define Q_DEBUGTRACE_BUFSIZE        ( 36 )      /**< Size for the debug/trace buffer: 36 bytes should be enough*/
    #define Q_DEBUGTRACE_FULL           ( 1 )       /**< Used to enable or disable a full trace output*/
    #define Q_ATCLI                     ( 1 )       /**< Used to enable or disable the AT Command Line Interface(CLI)*/
    #define Q_TASK_COUNT_CYCLES         ( 1 )       /**< Used to enable or disable the task cycles counter*/
    #define Q_TASK_EVENT_FLAGS          ( 1 )       /**< Used to enable or disable the task event flags*/
    #define Q_MAX_FTOA_PRECISION        ( 10u )     /**< default qFtoA precision*/
    #define Q_ATOF_FULL                 ( 0 )       /**< Used to enable or disable the extended "e" notation parsing in qAtoF*/
    #define Q_ALLOW_SCHEDULER_RELEASE   ( 1 )       /**< Used to enable or disable the release of the scheduling */
    #define Q_RESPONSE_HANDLER          ( 1 )       /**< Used to enable or disable the response handler*/
    #define Q_EDGE_CHECK_IOGROUPS       ( 1 )       /**< Used to enable or disable the edge check for I/O groups*/
    #define Q_BYTE_SIZED_BUFFERS        ( 1 )       /**< Used to enable or disable the Byte-sized buffers*/
    #define Q_USE_STDINT_H              ( 1 )       /**< Use the stdint.h header to define kernel data-types */
    #define Q_ALLOW_TASK_NAMING         ( 1 )       /**< Tag and locate tasks by using a name string*/
    #define Q_ALLOW_YIELD_TO_TASK       ( 1 )       /**< Allows you to transfer the current CPU usage to another task without having to wait for another cycle of the scheduler*/
    #define Q_TRACE_KERNEL_AND_MODULES  ( 0 )       /**< Experimental*/
NickNifontov commented 1 year ago

If i set in qconfig.h

#define Q_FSM                       ( 0 )
#define Q_QUEUES                    ( 0 )

Then compiles - Ok

kmilo17pet commented 1 year ago

Hi @NickNifontov, as I said previously here : https://github.com/kmilo17pet/QuarkTS/issues/51#issuecomment-1365889140 Its a issue related with the hardware and the compiler itself. This is why you can't find well-known RTOSes for these cores The 8-bit AVR cores have a better stack design compared to the PIC16 and you shouldn't have any kind of problem in the compilation. It should also compile correctly with the PIC24/dsPIC33 and PIC32 cores.