Go Down

Topic: Unos 0.0.1 - A Simple OS for the Arduino (Read 22258 times) previous topic - next topic

goodinventor

You mean that code should be changed to this?

Code: [Select]

void Hardware::Restart()
{
  Hardware Hardware;
  noInterrupts();
  if (Hardware.Time(3000) == 1)
  {
    interrupts();
  }
}

AWOL

What happened when you tested it?(hint)

Robin2

#107
Jan 20, 2015, 10:31 pm Last Edit: Jan 20, 2015, 10:35 pm by Robin2
You mean that code should be changed to this?
This is snake oil.

Have you read the Atmel Atmega 328 datasheet?
I have never seen anything in it that would lead me to think that your code has ANYTHING to do with resetting the processor. If you think I am wrong please refer me to the relevant paragraph in the datasheet.

You are fully entitled to have a different opinion from me about the value of an Uno operating system but you are not entitled to advocate the use of code that is technically incorrect.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

goodinventor

OK. I'll read the datasheet and get back to you later.

goodinventor

All right. I fixed Hardware::Restart() and Hardware::Shutdown(). Here's the code.

goodinventor


goodinventor

And the source code.

Robin2

#112
Jan 21, 2015, 11:44 am Last Edit: Jan 21, 2015, 12:40 pm by Robin2
Why don't you put all the attachments in a single post?

I don't understand what this code is supposed to do. From a little bit of research I don't think it causes the processor to restart.
Code: [Select]
void Hardware::Restart()
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  cli();
  sei();
  sleep_enable();
  sleep_cpu();
  sleep_disable();
}



...R
Two or three hours spent thinking and reading documentation solves most programming problems.

ShapeShifter

don't understand what this code is supposed to do.
Well, let's see:
  • set lowest power consumption mode as the pending sleep mode
  • disable interrupts
  • enable interrupts
  • allow the processor to enter sleep mode
  • put the processor in sleep mode
  • wait for an external interrupt (implied, since it will do nothing else while sleeping)
  • don't allow the processor to enter sleep mode
  • continue where it left off


Quote
From a little bit of research I don't think it causes the processor to restart.
Nope, no restarting happening there.

It's been said before, but I take exception to calling this an "operating system." It simply isn't one. It doesn't load and manage applications in memory and provide an abstract API for the applications to access process control and management functions. It doesn't manage hardware and provide an abstract API to access them, and arbitrate access to the hardware from the various processes. It's pretty much a sketch that implements a fairly useless and inefficient command interpreter.

I've not studied the code in depth, but a few things jump out at me (in no particular order.)

The command prompt is printed all over the place, using this code:
Code: [Select]
       Serial.print(F("root@unos:"));
The issue is that the same string is used over and over again. Whether the compiler is smart enough to combine all of these strings into one allocation is only half the issue. What happens if you want to change the prompt string? You have to go through and make the same change in may different places. It would be better to have a single showPrompt() function that displays the prompt, and call it from various places. It would ensure that the prompt string is only defined once, it would centralize the place to change the string, and it would allow the prompt to show additional dynamic data (such as the current SD card folder or other status info.)

There is a function ListUSB() that simply prints "A device has been connected." but only if there are unread characters waiting on the serial input? What use does such a message have, and why would pending serial data have anything to do with it? Furthermore, the lsusb command handler, which one would assume should call this function, simply hard-codes exactly the same serial test and print statement.

There is an SDHelp() function, which might give some useful information, but it is never called. Instead, the sdHelp command handler calls InitSD().

There is an open command handler. It displays the contents of the input buffer (which is presumable the word open followed by a file name) but then all it does is call data.read() and display the results. data is global instance of a File object, created by a call to SD.open(input) at the top of the file. The issue is that this is outside of any of the sketch functions, so it is executed (and the file is opened) before any other code is run. There is nothing but garbage in the input buffer at this point (certainly it has not yet seen any kind of command input) so I'm sure no valid file has been opened (especially since the SD card has not yet been initialized.) Even if the call to SD.open(input) was placed in the command handler, it would still have an issue that the string it would try to process includes the initial open command word, which will surely confuse it.

The print command just takes the input string, converts it to a number and prints it? Why?

We've already talked about the restart command, which could be useful if it worked, but what's up with the shutdown command? It disables interrupts and then enters sleep mode. Yep, that will stop the processor, and prevent it from ever waking up because interrupts are disabled. Why would you want to do this? The point of an embedded system is that it starts running when powered up, and keeps running until it loses power. Why have a shutdown command? For a real operating system, a shutdown command is useful to make sure file systems are closed and data is saved before losing power, but none of this is done here.

I'm sure I would find may other questions if I kept looking at the code, but my eyes are starting to bleed and my brain hurts.

I guess I'm seriously missing the point...

I guess I'm just grumpy and crotchety... but he did ask for reviews and feedback...

(My apologies for any grammatical and spelling errors. I normally go back and re-read my posts a few times before submitting them, but I've spent way to much time on this already.)

AWOL

. . .and with that, I think we'll close this thread now.

Go Up