Small walk-through the inner workings of the task scheduler and other library features.
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
void ledTask(void);
void printVoltage(void);
void printRaw(void);
void ramTest(void);
void bluetoothTest(void);
char PROGMEM voltageString[] = "Battery Voltage";
char PROGMEM sensorString[] = "Raw Sensor Data";
char PROGMEM ramString[] = "Test external RAM";
char PROGMEM bluetoothString[] = "Test Bluetooth Module";
int main(void) {
printf("Initializing Hardware Test...\n");
printf("Hardware Test Initialized!\n");
for(;;) {
}
return 0;
}
void ledTask(void) {
}
}
void printVoltage(void) {
}
void printRaw(void) {
printf(
"Ax: %f Ay: %f Az: %f\n", v.
x, v.
y, v.
z);
printf(
"Gx: %f Gy: %f Gz: %f\n", v.
x, v.
y, v.
z);
printf(
"Mx: %f My: %f Mz: %f\n", v.
x, v.
y, v.
z);
}
#define CHECKSIZE 53248 // 52KB
void ramTest(void) {
printf("Allocating Test Memory...\n");
for (uint8_t i = 0; i <
MEMBANKS; i++) {
blocks[i] = (uint8_t *)malloc(CHECKSIZE);
if (blocks[i] == NULL) {
printf(" Error: Couldn't allocate %liKB in Bank %i!\n", (CHECKSIZE / 1024), i);
} else {
printf(" Bank %i ready!\n", i);
}
}
printf("Filling with data...\n");
for (uint8_t i = 0; i <
MEMBANKS; i++) {
for (uint16_t j = 0; j < CHECKSIZE; j++) {
blocks[i][j] = (j & 0xFF);
}
printf(" Filled Bank %i!\n", i);
}
printf("Checking data...\n");
for (uint8_t i = 0; i <
MEMBANKS; i++) {
uint8_t error = 0;
for (uint16_t j = 0; ((j < CHECKSIZE) && (!error)); j++) {
if (blocks[i][j] != (j & 0xFF)) {
printf(" Error at %i in %i!\n", j, i);
error = 1;
}
}
if (!error) {
printf(" Bank %i okay!\n", i);
}
}
printf("Freeing memory...\n");
for (uint8_t i = 0; i <
MEMBANKS; i++) {
free(blocks[i]);
}
printf("Finished!\n");
}
void bluetoothTest(void) {
printf("Please disconnect, wait 10s, then reconnect!\n");
printf("All data will be logged, then printed after 15s.\n");
}
printf("\n\nDone!\n");
}