Pão de Queijo Development Board. This repo has all libraries from pqdb shield.

Dependents:   pqdb_demo

Pão de Queijo development board is a shield for add-on on any arduino compatible board.

/media/uploads/rmaalmeida/compatibilidade_branco.png

This project presents the libraries to control the board peripherals using mbed framework. The libraries works as interfaces to keep the main code compatible with the examples from the book "Programação de sistemas embarcados". The peripherals on the board are presented on the folowing picture

/media/uploads/rmaalmeida/pqdb_perifericos.png

The main objective of the project is to develop a low cost, easy to assemble board with a group of peripheral that allows one to start learning embedded systems. The board was routed on one side copper PCB to make easier to buid it yourself.

/media/uploads/rmaalmeida/pqdb_fenolite_-_cortada.png

The source code for Arduino boards (wiring) can be found on: https://github.com/projetopqdb/PQDB-Arduino

The source code for freedom frdm KL05 board (using direct register access) can be found on: https://github.com/projetopqdb/PQDB-KL05Z

The source code from the board schematics and layout can be found on: https://github.com/projetopqdb/PQDB-Hardware

Committer:
rmaalmeida
Date:
Tue Oct 03 00:17:53 2017 +0000
Revision:
4:357a34c10ef2
cooperative soft real time kernel added. using tick as timer interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rmaalmeida 4:357a34c10ef2 1 #include "kernel.h"
rmaalmeida 4:357a34c10ef2 2 #include "mbed.h"
rmaalmeida 4:357a34c10ef2 3 #include "lcd.h"
rmaalmeida 4:357a34c10ef2 4
rmaalmeida 4:357a34c10ef2 5
rmaalmeida 4:357a34c10ef2 6 #define MIN_INT -30000
rmaalmeida 4:357a34c10ef2 7 Ticker tick;
rmaalmeida 4:357a34c10ef2 8
rmaalmeida 4:357a34c10ef2 9 static process* pool[POOL_SIZE];
rmaalmeida 4:357a34c10ef2 10 //primeiro elemento do buffer
rmaalmeida 4:357a34c10ef2 11 int start;
rmaalmeida 4:357a34c10ef2 12 //�ltimo elemento do buffer
rmaalmeida 4:357a34c10ef2 13 int end;
rmaalmeida 4:357a34c10ef2 14
rmaalmeida 4:357a34c10ef2 15 //adiciona os processos no pool
rmaalmeida 4:357a34c10ef2 16 char kernelAddProc(process* func){
rmaalmeida 4:357a34c10ef2 17 // adiciona processo somente se houver espa�o livre
rmaalmeida 4:357a34c10ef2 18 //o fim nunca pode coincidir com o inicio
rmaalmeida 4:357a34c10ef2 19 if ( ((end+1)%POOL_SIZE) != start){
rmaalmeida 4:357a34c10ef2 20 //adiciona o novo processo e agenda para executar imediatamente
rmaalmeida 4:357a34c10ef2 21 func->deadline += func->period;
rmaalmeida 4:357a34c10ef2 22 pool[end] = func;
rmaalmeida 4:357a34c10ef2 23 end = (end+1)%POOL_SIZE;
rmaalmeida 4:357a34c10ef2 24 return SUCCESS; //sucesso
rmaalmeida 4:357a34c10ef2 25 }
rmaalmeida 4:357a34c10ef2 26 return FAIL; //falha
rmaalmeida 4:357a34c10ef2 27 }
rmaalmeida 4:357a34c10ef2 28 //inicializa o kernel em conjunto com a controladora de drivers
rmaalmeida 4:357a34c10ef2 29 void kernelInit(void){
rmaalmeida 4:357a34c10ef2 30 start = 0;
rmaalmeida 4:357a34c10ef2 31 end = 0;
rmaalmeida 4:357a34c10ef2 32 tick.attach(&kernelTick, 0.01); // setup ticker to call flip every 0.7 seconds
rmaalmeida 4:357a34c10ef2 33 }
rmaalmeida 4:357a34c10ef2 34 //executa os processos do 'pool' de acordo com seus tempos de execu��o
rmaalmeida 4:357a34c10ef2 35 void kernelLoop(void){
rmaalmeida 4:357a34c10ef2 36 unsigned int count;
rmaalmeida 4:357a34c10ef2 37 unsigned int next;
rmaalmeida 4:357a34c10ef2 38 process* tempProc;
rmaalmeida 4:357a34c10ef2 39 for(;;){
rmaalmeida 4:357a34c10ef2 40 if (start != end){
rmaalmeida 4:357a34c10ef2 41 //Procura a pr�xima fun��o a ser executada com base no tempo
rmaalmeida 4:357a34c10ef2 42 count = (start+1)%POOL_SIZE;
rmaalmeida 4:357a34c10ef2 43 next = start;
rmaalmeida 4:357a34c10ef2 44 while(count!=end){
rmaalmeida 4:357a34c10ef2 45 if ((pool[count]->deadline) < (pool[next]->deadline)){
rmaalmeida 4:357a34c10ef2 46 next = count;
rmaalmeida 4:357a34c10ef2 47 }
rmaalmeida 4:357a34c10ef2 48 //para poder incrementar e ciclar o contador
rmaalmeida 4:357a34c10ef2 49 count = (count+1)%POOL_SIZE;
rmaalmeida 4:357a34c10ef2 50 }
rmaalmeida 4:357a34c10ef2 51 //troca e coloca o processo com menor tempo como o pr�ximo
rmaalmeida 4:357a34c10ef2 52 tempProc = pool[next];
rmaalmeida 4:357a34c10ef2 53 pool[next] = pool[start];
rmaalmeida 4:357a34c10ef2 54 pool[start] = tempProc;
rmaalmeida 4:357a34c10ef2 55 while((pool[start]->deadline) > 0){
rmaalmeida 4:357a34c10ef2 56 //lcdCommand(0xC0);
rmaalmeida 4:357a34c10ef2 57 //lcdNumber(pool[start]->deadline);
rmaalmeida 4:357a34c10ef2 58 //coloca a cpu em modo de economia de energia
rmaalmeida 4:357a34c10ef2 59 }
rmaalmeida 4:357a34c10ef2 60 //retorna se precisa repetir novamente ou n�o
rmaalmeida 4:357a34c10ef2 61 switch (pool[start]->function()) {
rmaalmeida 4:357a34c10ef2 62 case REPEAT:
rmaalmeida 4:357a34c10ef2 63 kernelAddProc(pool[start]);
rmaalmeida 4:357a34c10ef2 64 break;
rmaalmeida 4:357a34c10ef2 65 case FAIL:
rmaalmeida 4:357a34c10ef2 66 break;
rmaalmeida 4:357a34c10ef2 67 default: ;
rmaalmeida 4:357a34c10ef2 68 }
rmaalmeida 4:357a34c10ef2 69 //pr�xima fun��o
rmaalmeida 4:357a34c10ef2 70 start = (start + 1) % POOL_SIZE;
rmaalmeida 4:357a34c10ef2 71 }
rmaalmeida 4:357a34c10ef2 72 }
rmaalmeida 4:357a34c10ef2 73 }
rmaalmeida 4:357a34c10ef2 74 //atualiza os tempos de execu��o dos processos
rmaalmeida 4:357a34c10ef2 75 void kernelTick(void){
rmaalmeida 4:357a34c10ef2 76 int proc;
rmaalmeida 4:357a34c10ef2 77 proc = start;
rmaalmeida 4:357a34c10ef2 78 while(proc!=end){
rmaalmeida 4:357a34c10ef2 79 if((pool[proc]->deadline)>(MIN_INT)){
rmaalmeida 4:357a34c10ef2 80 pool[proc]->deadline--;
rmaalmeida 4:357a34c10ef2 81 }
rmaalmeida 4:357a34c10ef2 82
rmaalmeida 4:357a34c10ef2 83 proc = (proc+1)%POOL_SIZE;
rmaalmeida 4:357a34c10ef2 84 }
rmaalmeida 4:357a34c10ef2 85
rmaalmeida 4:357a34c10ef2 86 }