CS185C: Embedded Programming in C
Course Syllabus Fall 2008
San Jose State University


Description:: Practical experience creating self standing firmware for microcontroller based embedded system. Use of C language to access and control processor elements and integrated peripheral devices. Small embedded environment without separate operating system. Architectural features of typical small microcontroller from programmer's point of view. Use of (free open source) GNU Compiler and tools. C code at low level as related to processor features, assembly language, execution timing and program debug. C data representation at low level. High level C language features: structures, pointers and arrays. Elements of C++ appropriate in the small embedded environment and how to emulate them in C. Interrupt programming, volatile keyword and concurrency. Details of the stack in C. Memory allocation. Saving and restoring context and multithreading. Integrated peripherals: Pin I/O, UART, other serial protocols, timers and flash memory self programming. Develop code for peripherals and for common useful functionality: character I/O, real time event processing, sound and speech generation and task management.
Instructor: Max Marshall
Contact Info: EMAIL: CS185C@sublogical.org, PHONE: TBD, OFFICE: DH 282
Class Sched: 1330 – 1445 MW MH225
Office Hours: MW 1445-1600
Textbooks: Required:

C Programming Language (2nd Edition), Brian W. Kernighan & Dennis M. Ritchie, Prentice-Hall Inc., 1988. ISBN 0131103628

Highly recommended for everyone. Terse but very clear presentation of C language by creators of C and UNIX. Reference and tutorial.

Those unable to afford this book may download one of several free tutorials. Also, the first edition can be bought used at very low cost but lacks some important modern features of the language.

Optional:

Programming Embedded Systems, Second Edition, Michael Barr, Anthony Massa, Addison-Wesley, 1999. ISBN 0-596-00983-6

Covers the course material in less detail, but goes farther in presenting a more powerful microprocessor and a large operating system. An supplement for those wanting more than course notes and lectures.

Required Reading: All reference materials for the specific microcontroller and the C Compiler tool chain are free, downloadable and provided on disk.
Required Hardware: Students must bring to class meetings laptop PC running Windows. Students must purchase Microcontroller P.C. Board.
Software: All required software is free, downloadable and provided on disk. Software runs in Windows environment.
Prerequisites: CS 49C and CS 47 with grade of C- or better, or knowledge of the 'C' Programming Language with instructor's consent. Note: The instructor and/or the CS Department are authorized to drop students at any time should it be determined that all prerequisites have not been met.
Grading:

Weekly homework will involve a combination of written problems and extension of in class programming topics.

Grading will account for likely difficulty of all students to absorb all the material presented, by generous grading of homework and final grade based on class curve. Collaboration on class work and on homework is encouraged, but forbidden for exams.

Completion of homework will be reflected in exam scores rather than counting directly towards grade. Two thirds of the exam questions will recapitulate homework items. Credit for those exam questions will be reduced by up to 50% depending on the percentage score on the corresponding previous homework item. Awarded credit = ( 50%*homework_problem_score + 50% ) * exam_question_score. Not all homework problems will have corresponding exam questions, therefore some homework problems will not be counted in the final grade. Some exam questions will not correspond to homework - these will count directly to the total score.

There will be in class two midterm exams counting 30% each and a final counting 40%.
Late assignments will not be accepted. The final exam must be taken at the university specified date and time. All students must uphold academic honesty per http://www2.sjsu.edu/senate/f88-10.htm

30% Midterm Week 6 (tentative)
30% Midterm Week 12 (tentative)
40% Final Exam TBD

 

Student Learning Outcomes:

Upon successful completion of this course, students will understand:

• How to design, implement and debug the complete firmware in an embedded system.
• Details of small microcontroller architectural elements and how to control them from the program.
• The operation, use and programming of integrated peripherals in small microcontrollers.
• Elements of microcontroller related to program execution at assembly language (processor instruction) level.
• How C code is reflected as assembly language instructions, the environmental constructs that support them and the implications for program operation.
• How to use C language to control low level elements of microcontroller and integrated peripherals.
• How to use structures and pointers to create clear and compact high level C code.
• The GNU tool chain, C language extensions peculiar to it and details of its use.

Schedule (Tentative):

The 21 lessons listed will be taught over 29 class meetings excluding exams. Depending on actual rate of progress, some lessons may be dropped or more material added.

Course reading will be available by first class meeting.

Lesson Chapter Topic
1 TBD Introduction, Motivation, and Overview of an Embedded System and Microcontroller. Microcontroller elements. Elements of embedded system used in class. Students install development software, upload and run a simple program.
2 TBD Microcontroller elements in detail. Comparison to similar and more powerful processors. Memory spaces. Overview of assembly language. Bootloader program.
3 TBD Data representation. Unsigned and signed arithmetic. Data representation in C and casting. Install C compiler. Simple program in C. Examine assembly code using Simulator.
4 TBD Memory mapping of device control registers. <io.h> C Control flow syntax review. Introduction to interrupts. Port pin I/O. Contact bounce.
5 TBD C tool chain in detail: Preprocessor, Compiler, Linker and Libraries.
6 TBD Interrupts: concurrency issues, non atomic operations, volatile keyword. Pin change interrupt. Concurrency demo. C and assembly language interrupt handlers.
7 TBD Serial communication: RS-232, RS-422 and RS-485. Bit banging. UART peripheral.
8 TBD Advanced C: pointers, structures, pointer to pointer, pointer to structure, pointer to function. Declaration and Cast syntax. Correspondence to C++ classes and polymorphism. Replacing complex code with data. Permutation demo.
9 TBD The stack: usage by hardware, usage by C code. Register usage in C code. Frame pointer. Parameters, register storage and local variables. Global variables. Recursion - avoid almost always. Examining memory. Stack overflow demo.
10 TBD The stack continued. Array bounds overflow vulnerability demo.
11 TBD Interrupt UART driver. Circular buffer algorithm. Forcing location of global variables. Character I/O routines. printf() function.
12 TBD Counter/timer peripherals: count, interrupt, PWM, event capture. PWM to generate sound. PWM to control LED brightness.
13 TBD Event capture. Capacitance sensing demo. System time. Calculating intervals.
14 TBD Real time event manager. Memory management algorithm. LED and Polyphonic sound demo.
15 TBD SPI peripheral. External DAC. Fractional multiplication. Interpolation. Analog sound generation.
16 TBD External serial flash memory. Erasing and writing flash. Driver software.
17 TBD Nyquist theorem. Digital filtering. Outputting speech.
18 TBD Saving and restoring C context. longjmp() function. Alternating multiple contexts, multithreading. Shared vs. separate task memory.
19 TBD Cooperative multithreading. Scheduling: implementing sleep, events and mutex.
20 TBD Multithreading demo.
21 TBD Top half and bottom half interrupt handlers. Preemptive multitasking.



General University Policies

DISABILITIES:

Academic integrity is essential to the mission of San José State University. As such, students are expected to perform their own work (except when collaboration is expressly permitted by the course instructor) without the use of any outside resources. Students are not permitted to use old tests, quizzes when preparing for exams, nor may they consult with students who have already taken the exam. When practiced, academic integrity ensures that all students are fairly graded. Violations to the Academic Integrity Policy undermine the educational process and will not be tolerated. It also demonstrates a lack of respect for oneself, fellow students and the course instructor and can ruin the university’s reputation and the value of the degrees it offers.

We all share the obligation to maintain an environment which practices academic integrity. Violators of the Academic Integrity Policy will be subject to failing this course and being reported to the Office of Judicial Affairs for disciplinary action which could result in suspension or expulsion from San José State University.

ACADEMIC INTEGRITY:

Academic integrity is essential to the mission of San José State University. As such, students are expected to perform their own work (except when collaboration is expressly permitted by the course instructor) without the use of any outside resources. Students are not permitted to use old tests, quizzes when preparing for exams, nor may they consult with students who have already taken the exam. When practiced, academic integrity ensures that all students are fairly graded. Violations to the Academic Integrity Policy undermine the educational process and will not be tolerated. It also demonstrates a lack of respect for oneself, fellow students and the course instructor and can ruin the university’s reputation and the value of the degrees it offers.

We all share the obligation to maintain an environment which practices academic integrity. Violators of the Academic Integrity Policy will be subject to failing this course and being reported to the Office of Judicial Affairs for disciplinary action which could result in suspension or expulsion from San José State University.

CHEATING:

At SJSU, cheating is the act of obtaining or attempting to obtain credit for academic work through the use of any dishonest, deceptive, or fraudulent means. Cheating at SJSU includes but is not limited to:

Copying in part or in whole, from another’s test or other evaluation instrument; Submitting work previously graded in another course unless this has been approved by the course instructor or by departmental policy. Submitting work simultaneously presented in two courses, unless this has been approved by both course instructors or by departmental policy. Altering or interfering with grading or grading instructions; Sitting for an examination by a surrogate, or as a surrogate; any other act committed by a student in the course of his or her academic work which defrauds or misrepresents, including aiding or abetting in any of the actions defined above.

PLAGIARISM:

At SJSU, plagiarism is the act of representing the work of another as one’s own (without giving appropriate credit) regardless of how that work was obtained, and submitting it to fulfill academic requirements. Plagiarism at SJSU includes but is not limited to:

The act of incorporating the ideas, words, sentences, paragraphs, or parts thereof, or the specific substances of another’s work, without giving appropriate credit, and representing the product as one’s own work; and representing another’s artistic/scholarly works such as musical compositions, computer programs, photographs, painting, drawing, sculptures, or similar works as one’s own.

For Additional Information:

http://www.sjsu.edu/senate/F06-2.htm

http://www.cs.sjsu.edu/greensheetinfo/index.html