Re: [EE] New projects on Github

Isaac Marino Bavaresco <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.pic
Message-ID <[email protected]>
Hi Justin!


Em 13/02/2025 10:28, Justin Richards escreveu:
> Hi Isaac,
>
> Thanks for sharing.
>
> Always on the lookout for other people's code to learn from  Yours
> certainly is a level up for me. So naturally I have many questions but will
> keep it short.
>
> Snip from Co-Routines/Source/CoRoutines.h
> #else /* defined ARDUINO */
> #include <xc.h>
> #define DISABLEINTERRUPT() do{INTCONbits.GIE=0;}while(0)
> #define ENABLEINTERRUPT() do{INTCONbits.GIE=1;}while(0)
> #define CLEARWATCHDOG() CLRWDT()
> tickcount_t GetTickCount( void );
> #endif /* defined ARDUINO */*

> 1.I am guessing The first line should read /*defined PIC */


I put in the #else's and #endif's comment the same condition as in the 
#if so it is easy to identify to which #if they belong, not what 
condition it would represent.

I do it that way because often some blocks of code take several pages 
and can have a lot of nested #ifs and it is more important to know to 
what #if the #else is subordinated than the condition it represents.

Each #elif obviously needs its own condition.

If the #else or #elif follows another #elif, then I put in the comment 
the condition of the previous #elif. The #endif always takes the comment 
of the initial #if.


> 2. 3rd and 4th lines - are the do ()while(0) a way to make the macros look
> function like so it is consistent across platforms.

It is a necessity created by C's syntax. The semicolon signals the end 
of an statement, but a bracketed block ends with the close-brace. For 
instance:

#define SomeMacro()    some_statement;another_statement
...
if( some_condition )  SomeMacro();

Is *WRONG* because it will produce: "if( some_condition ) 
some_statement;another_statement;" and "another_statement" is not inside 
the 'if'.


#define SomeMacro()    {some_statement;another_statement;}
...
if( some_condition )  SomeMacro();

Works OK, produces: "if( some_condition ) 
{some_statement;another_statement;};"

*BUT*:

if( some_condition )
     SomeMacro();
else
     one_more_statement;

Will produce:

if( some_condition )
     {some_statement;another_statement;};  // <<<=== *ERROR*
else        // <<<=== dangling 'else'
     one_more_statement;

The bracketed block ends at the '}', but there is an extra semicolon 
that ends the entire 'if' statement making the 'else' becoming orphaned.

*BUT*:

#define SomeMacro()    do{some_statement;another_statement;}while(0)
Works OK in every situation, because it produces:

if( some_condition )
     do{some_statement;another_statement;}while(0);    // <<<=== now the 
semicolon ends the 'do/while' statement, not the 'if'
else
     one_more_statement;


Cheers,

Isaac


>
> Or perhaps you did what you did because the following would not work. If
> so, I  just cant work out why.
> #if         defined ARDUINO
> ...
>      #define DISABLEINTERRUPT noInterrupts()
> ...
> #elif       defined AVR
> ...
>      #define DISABLEINTERRUPT asm("cli")
> ...
> #else   /*  defined PIC */
> ...
>      #define DISABLEINTERRUPT INTCONbits.GIE=0...
> ...
> There are many other lines of your code that are intriguing but I will try
> to puzzle them out.
>
> Thanks again.
> justin
>
> On Thu, Feb 13, 2025 at 8:07 PM Isaac M. Bavaresco <[email protected]>
> wrote:
>
>>   Dear All,
>>
>>
>> I published some more projects on Github, perhaps some may be of interest
>> to the members of the list.
>>
>> <https://github.com/Ibavaresco> <https://github.com/Ibavaresco>
>>
>> A few of them I simply copied from my Piclist page, others are being
>> published now for the first time.
>>
>> Cheers,
>>
>> Isaac
>>
>>
>> Their descriptions are as follow:
>>
>> PCADSch2KiCAD
>> Program to convert ASCII P-CAD 2006 Schematics to KiCAD v8.0 format. It can
>> also output P-CAD format with all the fields sorted.
>>
>> BCDFloat
>> Routines to implement calculations with very long floating-point numbers in
>> BCD format. Not particularly efficient but good for didactical purposes.
>>
>> Co-Routines
>> A simple co-routines framework
>>
>> SimpleRTOS
>> RTOS for microcrontrollers
>>
>> LCD-HD44780
>> Routines to interface microcrontrollers to LCD modules based on the HD44780
>> and HD44780U controller
>>
>> HX711
>> Routines to interface microcrontrollers to the HX711 24-bit differential
>> ADC
>>
>> OneWire
>> Routines to interface microcrontrollers to 1-Wire (iButton) devices
>>
>> wxSimCM0
>> Simulator for a generic ARM Cortex-M0 processor with a few onboard
>> peripherals - Work in progress
>>
>> wxCesar
>> Simulator for the abstract computer 'Cesar'
>> <https://www.inf.ufrgs.br/arq/wiki/doku.php?id=cesar>
>> <https://www.inf.ufrgs.br/arq/wiki/doku.php?id=cesar>
>>
>> NewFATFS
>> POSIX and NewLib compatible FAT filesystem based on Chan's FatFs
>>
>> FileSystem
>> Simple FLASH file system for embedded systems. This implementation is for
>> PIC18F87J60 and AT45DB642D.
>>
>> <
>> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
>> Não
>> contém vírus.www.avast.com <http://xn--vrus-vpa.www.avast.com>
>> <
>> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
>> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>> --
>> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
>> View/change your membership options at
>> https://mailman.mit.edu/mailman/listinfo/piclist
>>

-- 
O software antivírus Avast realizou uma checagem de vírus neste e-mail.
www.avast.com
-- 
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
https://mailman.mit.edu/mailman/listinfo/piclist
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.