/* * mur.sat * * Somewhen in the year 20xx, mur.at will have a nano satellite launched * into a low earth orbit (310 km above the surface of our planet). The * satellite itself is a TubeSat personal satellite kit, developed and * launched by interorbital systems. mur.sat is a joint venture of mur.at, * ESC im Labor and realraum. * * Please visit the project hompage at sat.mur.at for further information. * * * Copyright (C) 2012 Christian Pointner * Markus Grüneis * * This file is part of mur.sat. * * mur.sat is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * mur.sat is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mur.sat. If not, see . */ #include #include #include #include #include #define BUFFER_START 0x2000u //#define BUFFER_SIZE 960u #define BUFFER_SIZE 10u #define BUFFER_END (BUFFER_START + BUFFER_SIZE) #define RAM_SIZE (BUFFER_END + 1) #define BOOL int #define FALSE 0 #define TRUE 1 char picRam[RAM_SIZE] = { 0 }; char* bufferStart = &(picRam[BUFFER_START]); char* bufferEnd = &(picRam[BUFFER_END - 1]); char spiData = -1; char *writePtr, *readPtr; BOOL overrun, underrun, cmd_read; /* ##### Code under Test ##### */ void buf_init() { writePtr = bufferStart; readPtr = bufferStart; overrun = FALSE; underrun = TRUE; cmd_read = FALSE; } void wbuf_next() { if (!overrun) { writePtr++; writePtr = writePtr > bufferEnd ? bufferStart : writePtr; underrun = FALSE; if(writePtr == readPtr) { overrun = TRUE; } } } void rbuf_next() { if(!underrun) { readPtr++; readPtr = readPtr > bufferEnd ? bufferStart : readPtr; overrun = FALSE; if(readPtr == writePtr) { underrun = TRUE; } } } void adcInterrupt() { static char value = 0; if (!overrun) { *writePtr = ++value; wbuf_next(); } } void sspInterrupt() { if (cmd_read && spiData == 0) { *readPtr = 0; rbuf_next(); spiData = underrun ? -1 : *readPtr; } else if (spiData == 'r') { cmd_read = TRUE; spiData = underrun ? -1 : *readPtr; } else { cmd_read = FALSE; printf("%s\n", "I don't like you!"); } } /* ##### test environment ##### */ void debugPrint(char cmd) { printf("cmd('%c'): wPtr=%d, rPtr=%d, ovr=%d, udr=%d, sspbuf=%02hhx\n", cmd, (int) (writePtr - bufferStart), (int) (readPtr - bufferStart), (int) overrun, (int) underrun, (int) spiData); int i; printf(" "); for(i = 0; i < BUFFER_SIZE; ++i) { printf("%02hhx ", (unsigned int)bufferStart[i]); } printf("\n"); } int main() { struct termios t; tcgetattr(STDIN_FILENO, &t); t.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &t); buf_init(); int key; debugPrint(' '); for(;;) { key = getchar(); switch(key) { case EOF: case 4: case 'q': return 0; case '\r': case '\n': break; case '+': adcInterrupt(); debugPrint(key); break; case '0': spiData = 0; sspInterrupt(); debugPrint(key); break; default: spiData = key; sspInterrupt(); debugPrint(key); break; } } return 0; }