Code Monkey home page Code Monkey logo

chnil's People

Contributors

greiman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chnil's Issues

Read string from Serial port is not working

I just implemented the ChNil for my project and everything works great without any issue. However, I found that Serial string read is not working and I can only fetch first char of string.

Below code is for your reference and ran on Uno. Please note that I have even tried with native Serial class but same result.

Could you please help me what is wrong.

#include "ChNil.h"

ChNilSerialClass ChNilSerial;
#define Serial ChNilSerial

String recvString = "";

void setup() {
  Serial.begin(9600);

  chFillStacks();
  chBegin();
}

void loop() {
}

THD_WORKING_AREA(waThread1, 64);
THD_FUNCTION(Thread1, arg) {
  (void)arg;
  
  while (TRUE) {
    while (Serial.available()) {
      char c = Serial.read();
      recvString += c;
    }
  
    recvString.trim();

    Serial.print("Received String: ");
    Serial.println(recvString);

    recvString = "";

    chThdSleep(1000);
  }
}

THD_TABLE_BEGIN
  THD_TABLE_ENTRY(waThread1, NULL, Thread1, NULL)
THD_TABLE_END

ChiNil not behaving like NilRTOS

Hello:

I just made one of my more ambitious little projects work with NilRTOS on Arduino.
It works great. I then converted it over the ChNil to try to help with testing chnil
and perhaps migrate to the later base. I used some #ifdefs and simple macro substitutions
as follows to make very few text changes. Seemed to me the semantics of the two systems
is pretty identical. I did a similar thing successfully with a different program for Nil vs ChibiOS
comparison.

#ifdef NIL
#include <NilRTOS.h>
#else
// Stub out chi stuff in terms of existing nil items
//#include <ChibiOS_AVR.h>
#include "ChNil.h"
#define NIL_WORKING_AREA THD_WORKING_AREA
#define NIL_THREAD THD_FUNCTION
#define NIL_MSG_OK MSG_OK
#define NIL_MSG_TMO MSG_TIMEOUT
#define nilThdSleepMilliseconds chThdSleepMilliseconds
#define nilSemSignal chSemSignal
#define nilSemWaitTimeout chSemWaitTimeout
#define nilSysBegin chBegin
#endif

It all looks right for chnil, but doesn't run right on ChNil.
Each of two tasks appear to be going into their very first chSemWaitTimeout and not coming back.
And the serial connection goes down on my Arduino Micro.
I have some Serial prints before and after one of the task's use of the semWaitTimeout
which is in a routine called AnimDelay,

void AnimDelay(unsigned int nMillis) {
msg_t semmsg;
Serial.print("in n= ");
Serial.println(nMillis);
semmsg = nilSemWaitTimeout(&semPinWheel, nMillis);
Serial.println("Out");
if (semmsg == NIL_MSG_OK) // Got semi, time to do spinner
{
PinWheel();
}
}

that gives the runtime results:
in n= 10
Out
in n= 83

I never get another Out. It could be it crashed elsewhere preventing this from coming back.
But it looks, based on what happens with my LEDs and display, that perhaps
both tasks running are running until they go into a chSemiWaitTimeout.

When run in with nilRTOS, where it works, I get
in n= 10
Out
in n= 89
Out
in n= 51
Out
in n= 25
Out
in n= 25
Out
.
.
.

I am looking into why one ch reports 83 and nilRTOS reports 89 on the second n= line.
It is a mystery that doesn't seem to me like it should be. But that might not
be an RTOS issue.

Also, be advised the program uses TimerOne_ library and SPI, which perhaps ch isn't compatible with.
I may have violated some constraints of ch vs nil vs Arduino. If there is a guidance on what one
can and can't do, what the RTOS uses that might preclude other libraries, etc, it has escaped me.

I thought you might be able to detect a flaw with the sketch as it is especially in light of
the nil mode that works (uncomment #define NIL at the top) , but if its too complex,
I can try to pair it down to something that might be more easily tested without my hardware.

I can't drop .ino files onto here, so here is the code in a txt file.
SwitchAndMatrixToyRTOS.txt

Thanks in advance, I hope it helps discover something in chnil and is not an app problem
on my part.

Control Task Switching to avoid I2C data corruption

I have two I2C devices which are handled in two different threads. After sometime (randomly), my I2C LCD display show all junk chars followed that system hung. Then, have to forcefully reset the Arduino Uno R3.

Please note that this wasn't happened when only one I2C device was added (RTC) in my project. Later, have added I2C LCD as second one.

Could you please help how corruption can be avoided and control task switching

Trouble compiling using ChNilSerial in my code and also failure compiling ChNilBlinkPrint.ino

ChNilBlink.ino is fine.
ChiNilBlinkPrint.ino gets errors:


C:\Users\DC\AppData\Local\Temp\cc61h7SR.ltrans0.ltrans.o: In function `Thread2':

C:\Users\DC\Documents\Arduino\libraries\ChNil\examples\ChNilBlinkPrint/ChNilBlinkPrint.ino:58: undefined reference to `ChNilSerialClass::begin(unsigned long)'

C:\Users\DC\AppData\Local\Temp\cc61h7SR.ltrans0.ltrans.o: In function `ChNilSerialClass::ChNilSerialClass()':

C:\Users\DC\Documents\Arduino\libraries\ChNil\src/ChNilSerial.h:35: undefined reference to `vtable for ChNilSerialClass'

C:\Users\DC\Documents\Arduino\libraries\ChNil\src/ChNilSerial.h:35: undefined reference to `vtable for ChNilSerialClass'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Micro.

I discovered this while trying to add stack info printing similar to ChNilBlinkPrint.ino.
I had difficulty with what was integrated into my code, then discovered my
reference file ChNilBlinkPrint.ino had some trouble of its own as I already showed.
Below is the trouble I had putting some pieces into my file:
I added to near the top of my sketch:

#include "ChNil.h"
#include "ChNilSerial.h"
#define Serial ChNilSerial

which causes problems:

C:\Users\DC\Documents\Arduino\SwitchRBGPinWheelYingEyeRTOS7\SwitchRBGPinWheelYingEyeRTOS7.ino: In function 'void setup()':

SwitchRBGPinWheelYingEyeRTOS7:67: error: 'ChNilSerial' was not declared in this scope

#define Serial ChNilSerial

              ^

C:\Users\DC\Documents\Arduino\SwitchRBGPinWheelYingEyeRTOS7\SwitchRBGPinWheelYingEyeRTOS7.ino:1427:3: note: in expansion of macro 'Serial'

Serial.begin(9600);

^

Multiple libraries were found for "TimerOne.h"
Used: C:\Users\DC\Documents\Arduino\libraries\TimerOne
Not used: C:\Users\DC\Documents\Arduino\libraries\TimerOne-v9
exit status 1
'ChNilSerial' was not declared in this scope

To try to diagnose, I saw in ChNilSerial.cpp

/** ChNilSerial object.
*
/
//ChNilSerialClass ChNilSerial; <<<<------------ that looks suspicious.
#endif // defined(UDR0) || defined(DOXYGEN)
/
* @} */

.................... and in the header file.................

#ifdef UDR0 <<<<<<--------------- what's that mean?
extern ChNilSerialClass ChNilSerial;
#endif // UDR0

Back in my source, I tested to see if UDR0 is defined.
This throws the error, its not defined.
#ifndef UDR0
#error UDR0 not defined
#endif

I think between the commented out line and the UDR0 ifdef, there
is no ChNilSerial anywhere in the ChNil sources.

Arduino Library Manager Inclusion

I've noticed that this repository hasn't been updated in over a year.
I also noticed it is not in the library manager list for install and updates yet the repository has the 1.5 folder layout.

Can we get this library updated to work with the new Arduino library manager? Possibly along with ChiRTOS? Or is there something in the library that doesn't follow the new standards?

Typo error in ChNilWaitSignal.cpp

Minor one but needs to be addressed nonetheless.
line #20 of the said file may be modified in the repository from
#include "chNil.h"
to
#include "ChNil.h"

On a side note, I am just starting to dive in the realm of Nil/Chibi and in the same day i end up stumbling on both your libraries NilRTOS and ChNil. Could you please tell what could be the possible advantages of using ChNil over NilRTOS. I understand that the former is new, but does it improve speeds efficiency, memory signature etc? Just a newbie here

Library is using too much ram!

Good day All!

AM very new to the platform. i wish to use it as part of a library i working on for the AVR platform mostly Arduino Mega baord.

I have tested the library code blink(niblink and chblink) example using Arduino 1.8.2 IDE with arduino mega(atmega 2560)

The example did work. although i wanted to check the amount of memory being use
sso i made a call to the function below inside the thread function.

[code]int freeMemory() {
int free_memory;
if ((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__heap_start);
} else {
free_memory = ((int)&free_memory) - ((int)__brkval);
free_memory += freeListSize();
}
return free_memory;
}[/code]

i Have tested the function with other code and it does return acceptable result
Although in this case i can see that the difereece between Stack pointer and Heap pointer is -2265(niBlink) and -461(chBlinks in this case i still can see the led flash). however, this show an overflow of memory. i wish to use chibios as part of a larger project so this behavior is unexpected as i come to chibios understanding that it was lightweight and stack only.

can one suggest some help here! Also i havnet touch any config file as yet.

Regards!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.