Beispiel #1
0
int main(void)
{
  try
  {
    // Configure the clock
    clock_configure();

    // Initialise the Serial
    serial_init(&Serial, true);
    serial_input_handler(&input_manager_process);
    serial_println("Console initialised");

		// Initialise the AD9833 and Pulse geneator. These can be controlled via the serial port
    ad9833_init(&Timer);
    serial_println("AD9833 initialised");

    pulse_generator_init(&Pulse);
    serial_println("Pulse Generator initialised");

    // Some tests
    // flash_light_test();
    // pulse_test();
  }
  catch(RuntimeException)
  {
    serial_println(E4C_EXCEPTION.message);
  }

  while (1);
}
Beispiel #2
0
void getdate()
{
	char *encodedweekday = getweekday();
    serial_print(toweekday(encodedweekday));
    serial_print(" ");

    char *encodedmonth = getmonth();
    serial_print(tomonth(encodedmonth));
    serial_print(" ");

    serial_print(getmonthday());
    serial_print(" ");

    char *encodedyear = getyear();
    char *year = sys_alloc_mem(5);
    year[0] = '2';
    year[1] = '0';
    year[2] = encodedyear[0];
    year[3] = encodedyear[1];
    year[4] = '\0';
    serial_println(year);
    serial_println("");
    sys_free_mem(encodedyear);
    sys_free_mem(encodedweekday);
    sys_free_mem(encodedmonth);
    sys_free_mem(year);
}
void setup() {
  serial_init(9600);
  serial_println("Loading...");
  
  spi_init(SPI_CLOCK_DIV128, SPI_MODE0);
  
  DDR_LED |= (1<<PIN_LED);  // LED pin output
  PORT_LED |= (1<<PIN_LED); // LED pin high
  
  DDR_nRF24L01_IRQ &= ~(1<<PIN_nRF24L01_IRQ);  // nRF24L01_IRQ pin input
  PORT_nRF24L01_IRQ &= ~(1<<PIN_nRF24L01_IRQ); // nRF24L01_IRQ pin low

  DDR_nRF24L01_CS |= (1<<PIN_nRF24L01_CS);  // nRF24L01_CS pin output
  PORT_nRF24L01_CS |= (1<<PIN_nRF24L01_CS); // nRF24L01_CS pin high

  DDR_nRF24L01_CE |= (1<<PIN_nRF24L01_CE);  // nRF24L01_CE pin output
  PORT_nRF24L01_CE &= ~(1<<PIN_nRF24L01_CE); // nRF24L01_CE pin low
  
  _delay_ms(5);

  nRF24L01_SetRxAddress(rxAddress);
  nRF24L01_WriteRegister(nRF24L01_REG_RF_CH, CHANNEL);
  nRF24L01_WriteRegister(nRF24L01_REG_RX_PW_P0, PAYLOAD_SIZE);
  nRF24L01_WriteRegister(nRF24L01_REG_RX_PW_P1, PAYLOAD_SIZE);
  nRF24L01_PrintRegisters();
  nRF24L01_PowerUpRx();
  nRF24L01_FlushRx();
  nRF24L01_PrintRegisters();

  serial_println("Begin TX");
}
Beispiel #4
0
void gettime()
{
    serial_print(gethour());
    serial_print(":");

    serial_print(getminute());
    serial_print(":");

    serial_println(getsecond());
    serial_println("");
}
Beispiel #5
0
void proc1()
{
  int i;

  // repeat forever if termination fails
  while(1){
    for(i=0; i<RC_1; i++){
      serial_println("proc1 dispatched");
      sys_req(IDLE);
    }
    sys_req(EXIT);
    serial_println("proc1 ran after it was terminated");
  }
}
Beispiel #6
0
void comhandle()
{
	serial_println("");
	serial_println("Welcome to the MPX OS.");
	serial_println("Feel free to begin entering commands.");
	serial_println("");
	while(1) {
		char *command = polling();
		if (!strcmpigncase(command, "shutdown")) {
			if (shutdownConfirmed()) {
				serial_println("System shutting down...");
				clearAllQueues();
				break;
			} else {
				serial_println("Shutdown canceled.");
			}
		} else if (!strcmpigncase(command, "version")) {
			version();
		} else if (!strcmpigncase(command, "help")) {
			help();
		} else if (!strcmpigncase(command, "setdate")) {
			setdate();
		} else if (!strcmpigncase(command, "getdate")) {
			getdate();
		} else if (!strcmpigncase(command, "settime")) {
			settime();
		} else if (!strcmpigncase(command, "gettime")) {
			gettime();
		} else if (!strcmpigncase(command, "suspend")) {
			suspendPCB();
		} else if (!strcmpigncase(command, "resume")) {
			resumePCB();
		} else if (!strcmpigncase(command, "setpriority")) {
			setPriority();
		} else if (!strcmpigncase(command, "showPCB")) {
		        showPCB();
		} else if (!strcmpigncase(command, "showReady")) {
		        showReady();
		} else if (!strcmpigncase(command, "showBlocked")) {
		        showBlocked();
		} else if (!strcmpigncase(command, "showAll")) {
		        showAll();
		} else if (!strcmpigncase(command, "yield")) {
		        asm volatile ("int $60");
		        serial_println("");
		} else if (!strcmpigncase(command, "loadr3")) {
		        loadR3();
		} else if (strcmp(command, '\0')) {
			serial_println("Command not recognized. Type help to view commands.");
			serial_println("");
		}
		sys_free_mem(command);
	}
Beispiel #7
0
int shutdownConfirmed()
{
	while(1) {
		serial_println("Are you sure you would like to shutdown? (Y/N)");
		char *response = polling();
		if (!strcmpigncase(response, "y") || !strcmpigncase(response, "yes")) {
			sys_free_mem(response);
			return 1;
		} else if (!strcmpigncase(response, "n") || !strcmpigncase(response, "no")) {
			sys_free_mem(response);
			return 0;
		} else {
			sys_free_mem(response);
			serial_println("Entered value not recognized.");
		}
	}
}
Beispiel #8
0
void loadR3()
{
	void (*func1)() = &proc1;
	loadBasicFunctionToPCB("proc1", 0, 9, 0, 1, 512, func1);
	sys_free_mem(func1);
	void (*func2)() = &proc2;
	loadBasicFunctionToPCB("proc2", 0, 9, 0, 1, 512, func2);
	sys_free_mem(func2);
	void (*func3)() = &proc3;
	loadBasicFunctionToPCB("proc3", 0, 9, 0, 1, 512, func3);
	sys_free_mem(func3);
	void (*func4)() = &proc4;
	loadBasicFunctionToPCB("proc4", 0, 9, 0, 1, 512, func4);
	sys_free_mem(func4);
	void (*func5)() = &proc5;
	loadBasicFunctionToPCB("proc5", 0, 9, 0, 1, 512, func5);
	sys_free_mem(func5);
    serial_println("Processes successfully created.");
    serial_println("");
}
Beispiel #9
0
void setPriority()
{
	serial_print("Please enter the name of the process to alter: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		serial_print("What is the new priority? ");
		char* newPriority = polling();
		int priority = atoi(newPriority);
		if(-1 < priority && 10 > priority)
		{
			target->priority = priority;
			int readyIndex = indexByNameReady(name);
			int blockedIndex = indexByNameBlocked(name);
			if (readyIndex >= 0) {
				removePCBAtIndexReady(readyIndex);
			} else {
				removePCBAtIndexBlocked(blockedIndex);
			}
			insertPCB(target);
			serial_print("The process \"");
			serial_print(name);
			serial_println("\" has successfully updated its priority");
		}
		else
		{
			serial_println("Cannot set priority: invalid range");
		}
		sys_free_mem(newPriority);
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Beispiel #10
0
void settime()
{
	serial_println("What is the current hour?");
    char *response = polling();
    unsigned char portnum = 0x04; //hours port
    writetoRTC(portnum, response);

    serial_println("What is the current minute?");
    response = polling();
    portnum = 0x02; //minutes port
    writetoRTC(portnum, response);

    serial_println("What is the current second?");
    response = polling();
    portnum = 0x00; //seconds port
    writetoRTC(portnum, response);

    serial_print("Time successfully changed to -> ");
    gettime();
    sys_free_mem(response);
}
Beispiel #11
0
int main(void)
{
    fuse_init();
    pin_init();
    serial_init();

    while (1) {
        serial_println("Hello");
        __delay_ms(10);
    }
    return 0;
}
Beispiel #12
0
void comhandle()
{
	serial_println("");
	serial_println("Welcome to the MPX OS.");
	serial_println("Feel free to begin entering commands.");
	serial_println("");
	while(1) {
		char *command = polling();
		if (!strcmpigncase(command, "Shutdown")) {
			if (shutdownConfirmed()) {
				serial_println("System shutting down...");
				break;
			} else {
				serial_println("Shutdown canceled.");
			}
		} else if (!strcmpigncase(command, "Version")) {
			version();
		} else if (!strcmpigncase(command, "Help")) {
			help();
		} else if (!strcmpigncase(command, "Setdate")) {
			setdate();
		} else if (!strcmpigncase(command, "Getdate")) {
			getdate();
		} else if (!strcmpigncase(command, "Settime")) {
			settime();
		} else if (!strcmpigncase(command, "Gettime")) {
			gettime();
		}
	}
}
Beispiel #13
0
void resumePCB()
{
	serial_print("Please enter the name of the process to resume: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		target->suspendedState = 0;
		serial_print("The process \"");
		serial_print(name);
		serial_println("\" has resumed successfully");
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Beispiel #14
0
void getdate()
{
	outb(0x70, 0x06);
	unsigned char beforeconv = inb(0x71);
	char *afterconv = sys_alloc_mem(5);
	fromBCD(beforeconv, afterconv);
	char *weekday = toweekday(afterconv);
    serial_print(weekday);
    serial_print(" ");

    outb(0x70, 0x08);
    beforeconv = inb(0x71);
    fromBCD(beforeconv, afterconv);
    char *month = tomonth(afterconv);
    serial_print(month);
    serial_print(" ");

    outb(0x70, 0x07);
    beforeconv = inb(0x71);
    fromBCD(beforeconv, afterconv);
    serial_print(afterconv);
    serial_print(" ");

    outb(0x70, 0x09);
    beforeconv = inb(0x71);
    fromBCD(beforeconv, afterconv);
    char *year = sys_alloc_mem(5);
    year[0] = '2';
    year[1] = '0';
    year[2] = afterconv[0];
    year[3] = afterconv[1];
    year[4] = '\0';
    serial_println(year);
    serial_println("");
    sys_free_mem(afterconv);
    sys_free_mem(weekday);
    sys_free_mem(month);
    sys_free_mem(year);
}
Beispiel #15
0
void gettime()
{
	outb(0x70, 0x04);
	unsigned char bcdtime = inb(0x71);
	char *convtime = sys_alloc_mem(5);
	fromBCD(bcdtime, convtime);
    serial_print(convtime);
    serial_print(":");

    outb(0x70, 0x02);
    bcdtime = inb(0x71);
    fromBCD(bcdtime, convtime);
    serial_print(convtime);
    serial_print(":");

    outb(0x70, 0x00);
    bcdtime = inb(0x71);
    fromBCD(bcdtime, convtime);
    serial_println(convtime);
    serial_println("");
    sys_free_mem(convtime);
}
Beispiel #16
0
void setdate()
{
	serial_println("What day of the week is it?");
    char *response = polling();
  	char *bcdweekday = fromweekday(response);
    unsigned char portnum = 0x06; //weekday port
    writetoRTC(portnum, bcdweekday);

    serial_println("What month is it?");
    response = polling();
  	char *bcdmonth = frommonth(response);
    portnum = 0x08; //month port
  	writetoRTC(portnum, bcdmonth);

    serial_println("What day of the month is it?");
    response = polling();
    portnum = 0x07; //month day port
  	writetoRTC(portnum, response);

    serial_println("What year is it?");
    response = polling();
  	char *bcdyear = sys_alloc_mem(2);
  	if (strlen(response) != 4 || atoi(response) < 2000) {
  		bcdyear[0] = '\0';
  	} else {
  		bcdyear[0] = response[2];
  		bcdyear[1] = response[3];
  	}
    portnum = 0x09;
    writetoRTC(portnum, bcdyear);

    serial_print("Time successfully changed to -> ");
    getdate();
    sys_free_mem(response);
    sys_free_mem(bcdweekday);
    sys_free_mem(bcdmonth);
    sys_free_mem(bcdyear);
}
Beispiel #17
0
void showPCB() {
    serial_print("Please enter the name of the desired PCB to view: ");
    char* pcbName = polling();
    PCB* process = findPCB(pcbName);
    
    if (process == NULL) {
      serial_print(pcbName);
      serial_println(" is not a valid PCB");
      return;
    } 
    PrintPCB(process);
    sys_free_mem(pcbName);
    sys_free_mem(process);
}
Beispiel #18
0
void deletePCB()
{
	serial_print("Please enter the name of the process to delete: ");
	char* name = polling();
	PCB* target = findPCB(name);
	if(target == NULL)
	{
		if(strlen(name) == 0) {
			serial_print("Process not found: \"");
			serial_print(name);
			serial_println("\" does not appear to exist");
		}
	}
	else
	{
		int readyIndex = indexByNameReady(name);
		int blockedIndex = indexByNameBlocked(name);
		PCB* removedPCB = NULL;
		if (readyIndex >- 0) {
			removedPCB = removePCBAtIndexReady(readyIndex);
		} else {
			removedPCB = removePCBAtIndexBlocked(blockedIndex);
		}
		FreePCB(removedPCB);
		// if (!FreePCB(removedPCB)) {
			serial_print("The process \"");
			serial_print(name);
			serial_print("\" has been deleted successfully");
		// } else {
		//	serial_print("An error occurred while attempting to remove the process \"");
		//	serial_print(name);
		//	serial_println("\"");
		//}
	}
	serial_println("");
}
Beispiel #19
0
void lcd_line(char* msg, int line, uint8_t usepgm) {
  int len;
  strncpy_P(g_char_buffer, S_MAX_BLANK_LINE, MAX_LCD_LINE_LEN);
  
  lcd_setCursor(0, line);
  if (usepgm) {
    len = strlen_P(msg);
    memcpy_P(g_char_buffer, msg, len > MAX_LCD_LINE_LEN ? MAX_LCD_LINE_LEN : len);
  } else {
    len = strlen(msg);
    memcpy(g_char_buffer, msg, len > MAX_LCD_LINE_LEN ? MAX_LCD_LINE_LEN : len);
  }
  lcd_print(g_char_buffer);
  serial_println(g_char_buffer);
}
Beispiel #20
0
void interrupt ISR()
{
    // UART Receiver
    if (PIR1bits.RCIF) {
        static uint8_t rx[1];
        /* while (!PIR1bits.RCIF); */

        if (RC1STAbits.OERR) {
            // Overflow occured
            RC1STAbits.CREN = 0;
            RC1STAbits.CREN = 1;
        }
        rx[0] = RC1REG;
        serial_println(rx);

        PIR1bits.RCIF = 0;
    }
}
Beispiel #21
0
DSTATUS disk_initialize (void)
{
	BYTE n, cmd, ty, ocr[4];
	UINT tmr;

#if _USE_WRITE
	if(CardType && SPI_IS_SEL()) disk_writep(0, 0);		/* Finalize write process if it is in progress */
#endif
//	init_spi();		/* Initialize ports to control MMC */
	SPI_DESELECT();
	for (n = 10; n; n--) SPI_Recv();	/* 80 dummy clocks with CS=H */

	ty = 0;
	serial_println("init");
	if (send_cmd(CMD0, 0) == 1) {			/* Enter Idle state */
		if (send_cmd(CMD8, 0x1AA) == 1) {	/* SDv2 */
			for (n = 0; n < 4; n++) ocr[n] = SPI_Recv();		/* Get trailing return value of R7 resp */
			if (ocr[2] == 0x01 && ocr[3] == 0xAA) {				/* The card can work at vdd range of 2.7-3.6V */
				for (tmr = 10000; tmr && send_cmd(ACMD41, 1UL << 30); tmr--) dly_100us();	/* Wait for leaving idle state (ACMD41 with HCS bit) */
				if (tmr && send_cmd(CMD58, 0) == 0) {		/* Check CCS bit in the OCR */
					for (n = 0; n < 4; n++) ocr[n] = SPI_Recv();
					ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2;	/* SDv2 (HC or SC) */
				}
			}
		} else {							/* SDv1 or MMCv3 */
			if (send_cmd(ACMD41, 0) <= 1) 	{
				ty = CT_SD1; cmd = ACMD41;	/* SDv1 */
			} else {
				ty = CT_MMC; cmd = CMD1;	/* MMCv3 */
			}
			for (tmr = 10000; tmr && send_cmd(cmd, 0); tmr--) dly_100us();	/* Wait for leaving idle state */
			if (!tmr || send_cmd(CMD16, 512) != 0)			/* Set R/W block length to 512 */
				ty = 0;
		}
	}
	CardType = ty;
	SPI_DESELECT();
	SPI_Recv();

	return ty ? 0 : STA_NOINIT;
}
Beispiel #22
0
void menu_process_keypad(int key)
{
	serial_print("menu process keyboard ");
	serial_println(key);

	switch (key) {
		case 0: /* cancel */
			setmode_cb(MENU_CANCEL);
			break;
		case KEYPAD_POUND: /* enter */
			setmode_cb(modes[mode_idx].mode_val);
			break;
		case 3:
			rotate_mode_up();
			break;
		case 9:
			rotate_mode_down();
			break;
		default:
			break;
	}
}
Beispiel #23
0
void help()
{
	while(1) {
		serial_println("Which command would you like to know more about?");
		serial_println("Enter \"commands\" for a list of commands.");
		serial_println("Enter \"quit\" to exit.");
		char *command = polling();
		if (!strcmpigncase(command, "commands")) {
			serial_println("Here's a list of available commands:");
			serial_println("Version");
			serial_println("Help");
			serial_println("Setdate");
			serial_println("Getdate");
			serial_println("Settime");
			serial_println("Gettime");
			serial_println("Shutdown");
			serial_println("Suspend");
			serial_println("Resume");
			serial_println("SetPriority");
			serial_println("ShowPCB");
			serial_println("ShowAll");
			serial_println("ShowReady");
			serial_println("ShowBlocked");
			serial_println("Loadr3");
			serial_println("Allocate");
			serial_println("printFree");
			serial_println("printAlloc");
			serial_println("freeMemory");
			serial_println("");
		}
		else if (!strcmpigncase(command, "quit")) {
			break;
		}
		else if (!strcmpigncase(command, "allocate")) {
			serial_println("Allocates the specified amount of memory from the heap.");
			break;
		}
		else if (!strcmpigncase(command, "printfree")) {
			serial_println("Displays a list of all free memory blocks, along with basic information.");
			break;
		}
		else if (!strcmpigncase(command, "printalloc")) {
			serial_println("Displays a list of all allocated memory blocks, along with basic information.");
			break;
		}
		else if (!strcmpigncase(command, "freememory")) {
			serial_println("Frees an allocated memory block with a specified address.");
			break;
		}
		else if (!strcmpigncase(command, "version")) {
			serial_println("Version shows the current version of the operating system, and it's release date.");
			break;
		}
		else if (!strcmpigncase(command, "help")) {
			serial_println("Help gets further help for a prompted command.");
			break;
		}
		else if (!strcmpigncase(command, "setdate")) {
			serial_println("Setdate allows the user to set the date of the operating system through a series of prompts.");
			serial_println("The prompt follows a format of yy mm dd.");
			break;
		}
		else if (!strcmpigncase(command, "getdate")) {
			serial_println("Getdate returns the current date of the operating system.");
			break;
		}
		else if (!strcmpigncase(command, "settime")) {
			serial_println("Settime allows the user to set the time of the operating system through a series of prompts.");
			serial_println("The prompt follows a format of HH MM SS.");
			break;
		}
		else if (!strcmpigncase(command, "gettime")) {
			serial_println("Gettime returns the current date of the operating system.");
			break;
		}
		else if (!strcmpigncase(command, "shutdown")) {
			serial_println("Shutdown presents the user with the option to terminate the system.");
			break;
		}
		else if (!strcmpigncase(command, "suspend"))  {
		  serial_println("Places a PCB in a suspended state and reinserts it into the appropriate queue.");
		  break;
		}

		else if (!strcmpigncase(command, "resume"))  {
		  serial_println("Places a PCB in in the not suspended state and reinserts it into the appropriate queue.");
		  break;
		}

		else if (!strcmpigncase(command, "setpriority"))  {
		  serial_println("Sets a PCB's priority and reinserts the process into the correct place in the correct queue");
		  break;
		}

		else if (!strcmpigncase(command, "showPCB"))  {
		  serial_println("Displays the following information for a PCB:");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "showall"))  {
		  serial_println("Displays the folling information for each PCB in the ready and blocked queues.");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "showready"))  {
		  serial_println("Displays the folling information for each PCB in the ready queue.");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "showblocked"))  {
		  serial_println("Displays the following information for each PCB in the blocked queue.");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "loadr3")) {
		  serial_println("Loads all r3 processes into memory in a ready blocked state. Used for testing of multiprogramming functionality.");
		  break;
		}

		else {
			serial_print("Unrecognized command: ");
			serial_println(command);
		}
		sys_free_mem(command);
	}
	serial_println("");
}
Beispiel #24
0
void version()
{
	serial_println("Version 6.9 Module R5");
	serial_println("Completion Date: Friday, April 10, 2015");
	serial_println("");
}
Beispiel #25
0
void help()
{
  while(1) {
    serial_println("Which command would you like to know more about?");
    serial_println("Enter CommandList for a list of commands.");
    serial_println("Enter QuitHelp to exit.");
    char *command = polling();
    if (!strcmpigncase(command, "CommandList")) {
	serial_println("Here's a list of available commands:");
	serial_println("Version");
	serial_println("Help");
	serial_println("Setdate");
	serial_println("Getdate");
	serial_println("Settime");
	serial_println("Gettime");
	serial_println("Shutdown");
	serial_println("");
    }
    else if (!strcmpigncase(command, "QuitHelp")) {
      return;
    }
    else if (!strcmpigncase(command, "Version")) {
      serial_println("Version shows the current version of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Help")) {
      serial_println("Help gets further help for a prompted command");
      return;
    }
    else if (!strcmpigncase(command, "Setdate")) {
      serial_println("Setdate allows the user to set the date of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Getdate")) {
      serial_println("Getdate returns the current date of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Settime")) {
      serial_println("Settime allows the user to set the time of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Gettime")) {
      serial_println("Gettime returns the current date of the operating system.");
      return;
    }
    else if (!strcmpigncase(command, "Shutdown")) {
      serial_println("Shutdown turns off the operating system.");
      return;
    }
    else {
      serial_print("Unrecognized command: ");
      serial_println(command);
    }
  }    
}
Beispiel #26
0
void version()
{
	serial_println("Version R1");
	serial_println("Completion Date: Thursday, February 5, 2015");
	serial_println("");
}