-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major update including work on the usb driver, the console, the loggi…
…ng subsystem, button input handling code and updates for the new board layout.
- Loading branch information
Dimitris Papavasiliou
committed
Feb 25, 2015
1 parent
9811e6e
commit cd4a20c
Showing
21 changed files
with
841 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "mk20dx128.h" | ||
#include "usbserial.h" | ||
#include "button.h" | ||
|
||
static uint8_t down; | ||
static button_callback callback; | ||
|
||
__attribute__((interrupt ("IRQ"))) void lptmr_isr(void) | ||
{ | ||
if (!down) { | ||
down = 1; | ||
|
||
/* Set the lop power timer for active-low to catch the button | ||
* release. */ | ||
|
||
LPTMR0_CSR &= ~LPTMR_CSR_TEN; | ||
LPTMR0_CSR |= LPTMR_CSR_TPP; | ||
LPTMR0_CSR |= LPTMR_CSR_TEN; | ||
} else { | ||
down = 0; | ||
|
||
if (callback) { | ||
callback(); | ||
} | ||
|
||
/* Set the lop power timer for active-low to catch the next | ||
* button press. */ | ||
|
||
LPTMR0_CSR &= ~LPTMR_CSR_TEN; | ||
LPTMR0_CSR &= ~LPTMR_CSR_TPP; | ||
LPTMR0_CSR |= LPTMR_CSR_TEN; | ||
} | ||
|
||
LPTMR0_CSR |= LPTMR_CSR_TCF; | ||
} | ||
|
||
void button_set_callback(button_callback new_callback) | ||
{ | ||
callback = new_callback; | ||
} | ||
|
||
void button_initialize() | ||
{ | ||
/* Enable the low power timer and port C modules. */ | ||
|
||
SIM_SCGC5 |= SIM_SCGC5_PORTC | SIM_SCGC5_LPTIMER; | ||
PORTC_PCR5 = PORT_PCR_MUX(3) | PORT_PCR_PFE | PORT_PCR_PE; | ||
|
||
/* Reset the low power timer module. */ | ||
|
||
LPTMR0_CSR = 0; | ||
|
||
/* Configure for single pulse counting, clocked by the 1kHz LPO | ||
* clock and set the glitch filter for 16 rising clock edges. */ | ||
|
||
LPTMR0_CSR = LPTMR_CSR_TPS(2) | LPTMR_CSR_TMS | LPTMR_CSR_TIE; | ||
LPTMR0_CMR = 0; | ||
LPTMR0_PSR = LPTMR_PSR_PCS(1) | LPTMR_PSR_PRESCALE(4); | ||
|
||
/* Enable the timer and the corresponding interrupt. */ | ||
|
||
LPTMR0_CSR |= LPTMR_CSR_TEN; | ||
|
||
/* Enable the button interrupt and set its priority as low as it | ||
* gets. */ | ||
|
||
enable_interrupt(39); | ||
prioritize_interrupt(39, 15) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef __BUTTON__ | ||
#define __BUTTON__ | ||
|
||
typedef void (*button_callback)(); | ||
|
||
void button_initialize(); | ||
void button_set_callback(button_callback new_callback); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
|
||
history -r .console_history | ||
quit=false | ||
|
||
# Suppress error messages to get rid of kill notifications. | ||
|
||
#exec 2>/dev/null | ||
|
||
while ! $quit; do | ||
device=$(ls -1 /dev | grep ttyACM | head -n 1) | ||
|
||
# Wait for the file to become available, if necessary. | ||
|
||
if [ ! $device ]; then | ||
echo "Waiting for device to come on-line..." | ||
|
||
while file=$(inotifywait /dev/ -qe create --format %f); do | ||
if [[ $file = ttyACM* ]]; then | ||
device=$file | ||
break; | ||
fi | ||
done | ||
|
||
while [ ! -w /dev/$device -o ! -w /dev/$device ]; do | ||
sleep 1 | ||
done | ||
fi | ||
|
||
echo "Using device $device." | ||
|
||
# Set up a redirect from stdin to fd 3. | ||
|
||
exec 3<&0 | ||
|
||
# Start the console in a subprocess and let it source its input from | ||
# fd 3. | ||
|
||
stty 4000000 -icrnl -onlcr -isig -icanon -opost -echo < /dev/$device | ||
|
||
cat /dev/$device & | ||
catpid=$! | ||
disown $catpid | ||
|
||
( | ||
while read -e line; do | ||
history -s "$line" | ||
echo "$line" > /dev/$device | ||
done | ||
) 0<&3 & | ||
|
||
readpid=$! | ||
|
||
trap "kill $readpid" SIGINT | ||
|
||
# Wait for the device to disappear. | ||
|
||
( | ||
while file=$(inotifywait /dev/ -qe delete --format %f); do | ||
if [ "$file" = "$device" ]; then | ||
kill $readpid 2>/dev/null | ||
break | ||
fi | ||
done | ||
) & | ||
|
||
waitpid=$! | ||
disown $waitpid | ||
|
||
if wait $readpid 2>/dev/null; then | ||
quit=true | ||
else | ||
echo "Device went off-line." | ||
fi | ||
|
||
trap - SIGINT | ||
pkill -P $readpid,$catpid,$waitpid 2>/dev/null | ||
kill $readpid $catpid $waitpid 2>/dev/null | ||
|
||
# Restore stdin and close fd 3. | ||
|
||
exec 0<&3 3<&- | ||
done | ||
|
||
history -w .console_history |
Oops, something went wrong.