![]() |
||||
|
DOWNLOAD
|
CHANGES
|
SCREENSHOTS
|
DOCUMENTATION
| |
This is a complete demo session showing WhatOS working with an embedded system. Starting from zero we build an embedded system application that receives "hello" packets and transmits "reply" packets over the serial port. For example, if it receives "Bob" it replies "hello Bob". The communication protocol used is SLIP (Serial Line IP). The application is compiled using avr-gcc and programmed using uisp onto a target board consisting of an Atmel AVR ATMEGA8 microcontroller.
We do not explain the details at all; only the main idea should get across. Other sections in the Documentation cover this information.
The complete application is contained in two source code files, hello_whatos.py and main.c:
hello_whatos.py
from whatos.avr import * class hello_whatos(ctask): packet = packet(size = 16) hello = input('hello', type = 'packet') reply = output('reply', type = 'packet') process = """ int i; packet * p = (packet *) inputval; for (i = 0; i < p->len; i++) { p->data[i+6] = p->data[i]; } sprintf(p->data, "hello"); p->data[5] = ' '; p->len = p->len + 6; emit(reply, p); accept(); """ class csystem(avr_system): header = """ #include <avr/io.h> #include <avr/interrupt.h> #define hook_sub_tx_byte(src, val) {UDR = (wuint8) (unsigned int)(val);} #define wos_periodic() { \ if (UCSRA & (1<<TXC)) { \ UCSRA |= (1<<TXC); \ wos_emit(wos_sig_sub_tx_rdy, 0, WOS_ENVIRONMENT); \ } \ \ if (UCSRA & (1<<RXC)) { \ wos_emit(wos_sig_sub_rx_byte, \ (void *) (unsigned int) UDR, WOS_ENVIRONMENT); \ } \ } """ sources = 'main.c' clean = 0 hello_whatos = hello_whatos() csliprx = csliprx(rx_packet = csliprx.rx_packet('hello')) csliptx = csliptx(tx_packet = csliptx.tx_packet('reply')) csystem.wos_Signal.allocate = 10 csystem.packet.allocate = 2 class receive_reply(pytask): packet = packet() reply = input('reply', type = 'packet') def process(self, input, inputval): print self.packet.to_string(inputval) class pysystem(system): simulation_viewer = simulation_null_viewer uartslip = uartslip( enabled = 1, serial = Serial('/dev/ttyUSB0', baudrate = 38400), tx_packet = uartslip.tx_packet('hello'), rx_packet = uartslip.rx_packet('reply')) receive_reply = receive_reply() pysystem.wos_Signal.allocate = 10 pysystem.packet.allocate = 1 pysystem.threadstart()
main.c
#include "wossystem.h" #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> int main(void) { /* uart: 38400 at 8MHz CPU clock */ UBRRL = 12; UCSRA = (0 << U2X); UCSRB = (1<<RXEN)|(1<<TXEN); wos_init(); wos_process(1); }
In the following interactive Python session we build the flash image, program it on the microcontroller and test that the target is behaving as expected:
$ wospython --interactive hello_whatos.py
Starting WhatOS Interactive Tkinter Shell...
>>> csystem.avrbuild()
writing wossystem.c
writing wossystem.h
Aap: avr-gcc -mmcu=atmega8 -g -Os -o wosrom.out wossystem.c main.c
Aap: avr-objcopy -O ihex wosrom.out wosrom.hex
>>> csystem.avrprog()
Aap: uisp -dprog=stk500 -dserial=/dev/ttyUSB1 -dpart=ATmega8 -v=3 --erase --upload if=wosrom.hex
Vendor Code: 0x1e
Part Family: 0x93
Part Number: 0x07
Atmel AVR ATmega8 is found.
Page Write Enabled, size=64
FLASH Write Delay (t_wd_flash): 12500 us
EEPROM Write Delay (t_wd_eeprom): 25000 us
Uploading: flash
####################################################################################################
(total 3188 bytes transferred in 1.47 s (2172 bytes/s)
Firmware Version: 1.10
Firmware Version: 1.10
>>> pysystem.hello.emit('whatos')
>>> hello whatos
>>> pysystem.hello.emit('world')
>>> hello world
In the process of building the flash image two extra files are generated by WhatOS: wossystem.c, wossystem.h. If you click on the links you can see these files. wossystem.c contains all the user-defined tasks plus a full state-machine operating system including memory manager, signal routing, and priority scheduler. In summary:
This is a very minimal starter application that a beginner might try to implement on his microcontroller. Other small applications which are very useful to begin with when starting a new project are found in $WOSROOT/tests/simple/:
©
Mircea Hossu ( ) |
WhatOS
2.0.3 (2006 Feb 26) |