Skip to content

Commit

Permalink
setup procedure done
Browse files Browse the repository at this point in the history
  • Loading branch information
technocake committed Mar 24, 2013
1 parent 1367510 commit 1dac883
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 40 deletions.
2 changes: 2 additions & 0 deletions pizzanetmap_firmware/Makefile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
open -a "Arduino" *.ino
95 changes: 55 additions & 40 deletions pizzanetmap_firmware/pizzanetmap_firmware.ino
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,20 +24,40 @@ int MR_Pin = 7; // Master Reset
#define RE_PULSE 8 // Repulse - timeslots between retransmitting pulse. #define RE_PULSE 8 // Repulse - timeslots between retransmitting pulse.
#define MAX_NODE_COUNT 512 // if no BKTRK is connected. #define MAX_NODE_COUNT 512 // if no BKTRK is connected.
#define number_of_cores 2 // Core switches in use #define number_of_cores 2 // Core switches in use
#define n_74hc595_per_distro 2 // Shift registers per distro
#define n_shiftregister_pins 8 // Number of output pins on shiftreg.

/*____________________________________________________________ /*____________________________________________________________
* END OF CONFIGURATION * END OF CONFIGURATION
*/ */


typedef struct
{
int n_distros;
int n_pins;
boolean active;
} _core;


_core * core_stat;






/* helper arrays */ /* helper arrays */
int CLK[number_of_cores] = {CLK1_Pin, CLK2_Pin}; int CLK[number_of_cores] = {CLK1_Pin, CLK2_Pin};
int RX[number_of_cores] = {RX1_Pin, RX2_Pin}; int RX[number_of_cores] = {RX1_Pin, RX2_Pin};
int TX[number_of_cores] = {TX1_Pin, TX2_Pin}; int TX[number_of_cores] = {TX1_Pin, TX2_Pin};


uint cores, bits_shifted, tot_nodes = 0; int active_cores, bits_shifted, tot_nodes = 0;
int nodes = 0; int nodes = 0;



/*###################################################################################
*
* SETUP
*
*##################################################################################*/


void setup(){ void setup(){
//Core #1 //Core #1
Expand All @@ -48,38 +68,53 @@ void setup(){
pinMode(TX2_Pin, OUTPUT); pinMode(TX2_Pin, OUTPUT);
pinMode(CLK2_Pin, OUTPUT); pinMode(CLK2_Pin, OUTPUT);
pinMode(RX2_Pin, INPUT); pinMode(RX2_Pin, INPUT);

//Reset
pinMode(MR_Pin, OUTPUT); pinMode(MR_Pin, OUTPUT);


// For the API to work :).
Serial.begin(9600); Serial.begin(9600);


// Keeping track of core-statistics. i.e numbers.
core_stat = (_core *) malloc(number_of_cores * sizeof(_core));

//Determine how many nodes connected to each core: //Determine how many nodes connected to each core:
tot_nodes = 0; tot_nodes = 0;
for (uint core = number_of_cores-1; core-- >0;;) { active_cores = 0;

// 1, 2,3,4,5,6,7,8,9,10,11,12
for (int c=0; c < number_of_cores; c++) {
nodes=0; nodes=0;
countNodes( core, &nodes); countNodes( c, &nodes);


if (nodes > 0) if (nodes > 0) {
tot_nodes += nodes; core_stat[c].n_distros = nodes / (n_shiftregister_pins * n_74hc595_per_distro);
core_stat[c].n_pins = nodes;
core_stat[c].active = true;
tot_nodes += nodes;
active_cores += 1;
}
else { // Error occured
core_stat[c].n_distros = 0;
core_stat[c].n_pins = 0;
core_stat[c].active = false;
}
} }


Serial.print(tot_nodes) Serial.print(core_stat[0].n_distros);
Serial.print(active_cores);


} }






void reset(int dt) { void reset(int dt) {
digitalWrite(MR_Pin, LOW); digitalWrite(MR_Pin, LOW);
delay(dt); delay(dt);
digitalWrite(MR_Pin, HIGH); digitalWrite(MR_Pin, HIGH);
} }


// Dynamically count the number of nodes on one line.


void countNodes (uint line, int * nodes) { // Dynamically count the number of nodes on a core (one ser-line).
void countNodes (int line, int * nodes) {
*nodes = 0; *nodes = 0;
int bkval = 0; int bkval = 0;
//reset //reset
Expand All @@ -93,38 +128,18 @@ void countNodes (uint line, int * nodes) {
digitalWrite(CLK[line], HIGH); digitalWrite(CLK[line], HIGH);
//Counting //Counting


} while ( int(bkval = digitalRead(RX[line])) == 0 && ((*nodes)++) < MAX_NODE_COUNT ); } while ( ((*nodes)++) < MAX_NODE_COUNT && int(bkval = digitalRead(RX[line])) == 0 );



if (*nodes >= MAX_NODE_COUNT) { if (*nodes >= MAX_NODE_COUNT) {
*nodes = -1; *nodes = -1;
} }

} }//end countNodes






void loop(){ void loop(){




while (1) {
if (Serial.available() > 0) {

}
}


//CORE 1
countNodes(0, &nodes);
if (Serial.available() > 0) {

Serial.write("Core 1::\t %i nodes counted\n", nodes);
}

delay(1000);
// CORE 2
countNodes(1, &nodes);
if (Serial.available() > 0) {

printf("Core 2::\t %i nodes counted\n", nodes);
}
} }

0 comments on commit 1dac883

Please sign in to comment.