class: center, middle # Benjamin Fair Introduction Presentation --- # About Me - Third year undergrad at The Ohio State University - Electrical and Computer Engineering Major with Computer Engineering Specialization - Interested in embedded systems, hardware/software engineering - Proficient in C, C++, Go - Some experience in Java, MSP430/x86 assembly - Previously interned at Google in summer of 2015 --- # Projects 1. U-Root 2. BugsWorld 3. MSP430 Class 4. Personal Library --- # U-Root - Embed Go toolchain, kernel, and Coreboot in BIOS chip - Compile Coreboot for development board - Configure tiny (~300k) Linux kernel - Create initramfs from U-Root source - Chain all three and flash a BIOS chip - Gained experience working with and debugging firmware and embedded code - GitHub page: https://github.com/rminnich/u-root --- # BugsWorld - Based on a school project - Bugs controlled by simple bytecode programs - World simulation, program interpretation, display - Future enhancements - Assembler/Compiler - Evolutionary algorithm --- # BugsWorld - Structure ``` ├── Makefile.am ├── configure.ac ├── examples │ ├── infect.bo │ └── rover.bo └── src ├── Makefile.am ├── board.c ├── board.h ├── display.c ├── display.h ├── interpreter.c ├── interpreter.h ├── moves.c ├── moves.h ├── species.c ├── species.h ├── types.h ├── util.c ├── util.h ├── world.c └── world.h ``` --- # BugsWorld - board.c ```c /** * Performs one step of the simulation on the board */ void stepBoard(Board *board) { Move *moves = (Move *) malloc(sizeof(Move) * board->width * board->height); getMoves(board, moves); int *order = (int *) malloc(sizeof(int) * board->width * board->height); randIntFill(order, board->width * board->height); processMoves(board, moves, order); free(moves); free(order); } ``` --- # BugsWorld - interpreter.c ```c /** * Executes a bug's code until it produces a move or an error */ Move step(Bug *bug, CellState state) { Move move; if((bug->pc >= 0) && (bug->pc < bug->species->progLen)) { switch(bug->species->program[bug->pc]) { case 0: // MOVE bug->pc++; move = MOVE; break; ... case 3: // INFECT bug->pc++; move = INFECT; break; ... case 6: // JUMP jump(bug, 1); move = step(bug, state); break; case 7: // JUMP_IF_NOT_NEXT_IS_EMPTY jump(bug, state != EMPTY); move = step(bug, state); break; ... ``` --- # BugsWorld - moves.c ```c /* * Resolves the desired moves in the specified order */ void processMoves(Board *board, Move *moves, int *order) { for(int i = 0; i < board->width * board->height; i++) { int x = cur % board->width; int y = cur / board->width; Bug *bug = getBoardElement(board, x, y); switch(moves[order[i]]) { case MOVE: { int nextX = x, nextY = y; getNextCell(bug->dir, &nextX, &nextY); if(getBoardElement(board, nextX, nextY) == NULL) { // cell is empty setBoardElement(board, nextX, nextY, bug); // move the bug setBoardElement(board, x, y, NULL); // and clear its current spot moves[nextY * board->width + nextX] = SKIP; // only move once } } break; ... case INFECT: { int nextX = x, nextY = y; getNextCell(bug->dir, &nextX, &nextY); Bug *target = getBoardElement(board, nextX, nextY); if(target != NULL && target->species != bug->species) { // enemy bug target->species = bug->species; // infect it start(target); // and restart it with new code } } break; ... ``` --- #BugsWorld - Demo .center[
] --- # MSP430 Class - MSP430 Assembly - Projects using various integrated components - Timer, interrupts, PWM, ADC, GPIO - Measuring frequency of a square wave --- # MSP430 - Frequency Measure - Main Code ```armasm bic.b #RSEL0+RSEL1+RSEL2+RSEL3, &BCSCTL1 ; Configure oscillator bis.b #DCO2+DCO1+DCO0, &DCOCTL bis.b #DIVS_2, &BCSCTL2 bis.w #ID_3+TASSEL_2+MC_2, &TA0CTL ; Configure Timer A bis.b #BIT4, &P1DIR bis.b #BIT1+BIT4, &P1SEL ; Configure sampling pin bis.w #CM_1+CCIS_0+CAP+CCIE, &TA0CCTL0 ; Configure CCR0 clr.w R13 bis.w #BIT0, R14 bis.w #GIE, SR ; Enable interrupts loop: jmp loop ``` --- # MSP430 - Frequency Measure - Interrupt Handler ```armasm Handler: bic.w #CCIFG, &TA0CCTL0 ; Clear interrupt flag xor.w #BIT0, R14 bit.w #BIT0, R14 jnz else mov.w &TACCR0, R13 ; First measurement reti else: mov.w &TACCR0, R12 ; Second measurement sub.w R13, R12 mov.w R12, &period ; Store the difference reti ... .sect ".int09" .short Handler ``` --- # Personal Library - Collection of useful code from other projects - Still collecting, optimizing, and testing it - Built with Autotools - Unit tested with Check framework --- # Personal Library - Unit Tests ```c #test empty ll *l = ll_make(); ll_push_back_int(l, 1); ll_pop_front_int(l); ck_assert(ll_is_empty(l)); ll_free(l); #test retrieve_5 ll *l = ll_make(); int i; for(i = 0; i < 5; i++) { ll_push_back_int(l, i); } for(i = 0; i < 5; i++) { int data = ll_pop_front_int(l); ck_assert_int_eq(data, i); } ll_free(l); #test store_1_retrieve_1_x5 ll *l = ll_make(); int i; for(i = 0; i < 5; i++) { ll_push_back_int(l, i); int data = ll_pop_front_int(l); ck_assert_int_eq(data, i); } ll_free(l); ``` --- class: center, middle # Thank You Questions?