ECE 4760: Laboratory 3
Infrared key and lock
Introduction.
You will build a IR remote key and base-lock. Your project will have to act as both the base-lock and the remote key (but not at the same time, except for testing). The key will lock/unlock someone else's base-lock, if authorized. Their key will lock/unlock your base-lock, if authorized. You will be required to use a multitasking kernel and write your program as tasks within the kernel API.
Procedures.
Concurrency:
For this assignment you must write your code for a multitasking
kernel called Tiny Real Time (TRT).
Look through the examples on the TRT
page to see how to use the API and to download the kernel.
The author's page may also be useful http://www.control.lth.se/~anton/tinyrealtime/
You must edit the trtSettings.h file!
If the kernel continually resets then:
- check MAXNBRTASKS and MAXNBRSEMAPHORES in the settings file.
- Also make sure
you have big enough stack allocations for each task.
- Make sure that every task function is written so that it never exits!
- When running TRT,
main
becomes the default
task. Don't put any initialization or other code in main
except for the uart init.
One possibility is the following task layout, but you can use anything that works for you:
- TRT Task 1 handles lock/unlock commands from the IR link to act as the base-lock controller. It will need to receive the key request, generate and send the security challange and receive the security response.
- TRT Task 2 acts as the remote key. It will need to request lock/unlock, receive the base station challange, and send the security response.
- TRT Task 3 sends lock/unlock attempts to the PC using an USART. The
(deadline)
- (release
time)
should be greater than the USART send time so that the kernel
can meet all the deadlines. If you give a slow task a release time equal
to it's deadline, then it has to execute in zero time to meet deadline,
and nothing else can run until the slow task completes.
- The IR link is coded using USART0 and so is the TRT console output. You will have either:
-- Hook the USART1 ouput to the communication header (replacing D.1) and
use this function for PC communication trtUart_usart_1.c (replaces trtUart.c in the project).
-- Recode the IR
communication to use USART1.
IR control link
Use this IR packet system
which will require that you include the timer0 ISR for full-duplex IR handling.
You will port the transmit and receive routines to TRT. At the very least you will need to:
- You will need to remove all instances of a millisecond timer
and replace them with
trtCurrentTime()
.
DO NOT use the millisecond timer hard coded in the IR interrupt.
- As noted above You will have to either:
- Hook the USART1 ouput to the communication header (replacing D.1) and
use this function for PC communication
trtUart_usart_1.c (replaces trtUart.c in the project).
- Recode the IR
communication to use USART1.
Assignment
Write two to four tasks using the TRT kernel API and construct a circuit which will:
- Have three SPDT switches:
- Switch 1: Select test or normal
- Switch 2: If in normal mode, select base-lock or key (In test mode your device is both base-lock and key).
- Switch 3: In either test or normal-key mode, select identity of key '>' or key '<' (authorized and unauthorized)
- Have two push buttons to send lock and unlock requests from the key in either test or normal-key mode.
- The base-lock lights an led to signal the unlock state. Transition between lock and unlock is controlled by security procedure below.
- The base-lock will log all lock/unlock attempts to the PC console, including system time, lock/unlock command and sucess/fail.
- The base-lock always transmits on IR tx_identifier 'L'.
- The key always transmits on IR tx_identifier 'K'.
- Security validation will require:
- Key requests lock/unlock.
Payload format is sprintf(ir_tx_data, "r");
- Base-lock sends challange to key as current time.
Payload format is
sprintf(ir_tx_data, "%ld", trtCurrentTime());
- Key receives challange, forms a new message consisting of the concanenation of the key ID ('>' or '<'), command lock encoded as '0' or unlock encoded as '1', and the challange time string received from the base-lock..
Payload format is
sprintf(ir_tx_data, "%c>%s", lock_command, challange_time_string);
for authorized
Payload format is
sprintf(ir_tx_data, "%c<%s", lock_command, challange_time_string);
for unauthorized
- Key sends response to base-lock, which receives the command, checks the key ID, and checks the time. The difference between the current time and the challange time (set back from the key) should be less than TICKSPERSECOND for the lock to operate. To control the lock the key ID should be '>'.
- the entire 4-step validation should take less than 1 second.
To test, you can use the loopback function of test mode.
To demo you must operate with the TAs reference IR transceiver lock/key.
Your project should be able to act as both lock and key separately.
You will demo all the features above to your TA.
Your program should not need to be
reset or reprogrammed during the demo.
Your written lab report should include the sections mentioned in the policy page, and :
- A schematic of the circuit you built.
- A heavily commented listing of your code.
Copyright Cornell University
September 30, 2013