-
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.
- Loading branch information
Showing
13 changed files
with
511 additions
and
6 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
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
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
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,71 @@ | ||
# Makefile | ||
TARGET = CurrSour | ||
LIBDIR = ../lib | ||
OBJECTS = main.o \ | ||
cs.o \ | ||
status.o \ | ||
../Uart/id.o \ | ||
$(LIBDIR)/timers.o \ | ||
$(LIBDIR)/uart.o \ | ||
$(LIBDIR)/twi.o \ | ||
$(LIBDIR)/rpu_mgr.o \ | ||
$(LIBDIR)/parse.o | ||
|
||
## Chip and project-specific global definitions | ||
MCU = atmega328p | ||
F_CPU = 16000000UL | ||
BAUD = 38400UL | ||
CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. | ||
|
||
## Cross-compilation | ||
CC = avr-gcc | ||
OBJCOPY = avr-objcopy | ||
SIZE = avr-size | ||
|
||
# FTDI's USB to serial bridge shows as /dev/ttyUSB0, | ||
# Uno's serial bridge (an ATmega16U2) shows as /dev/ttyACM0 (a modem,?) | ||
# Pi Zero on chip hardware serial shows as /dev/ttyAMA0 (hardware UART on a Linux system) | ||
detect_PORT := $(shell sh -c 'ls /dev/ttyAMA0 2>/dev/null || echo not') | ||
ifeq ($(detect_PORT),/dev/ttyAMA0) | ||
BOOTLOAD_PORT = /dev/ttyAMA0 | ||
endif | ||
detect_PORT := $(shell sh -c 'ls /dev/ttyUSB0 2>/dev/null || echo not') | ||
ifeq ($(detect_PORT),/dev/ttyUSB0) | ||
BOOTLOAD_PORT = /dev/ttyUSB0 | ||
endif | ||
|
||
## Compiler/linker options | ||
CFLAGS = -Os -g -std=gnu99 -Wall | ||
# CFLAGS = -funsigned-char -funsigned-bitfields | ||
# CFLAGS = -fpack-struct -fshort-enums | ||
CFLAGS = -ffunction-sections -fdata-sections | ||
|
||
TARGET_ARCH = -mmcu=$(MCU) | ||
|
||
LDFLAGS = -Wl,-Map,$(TARGET).map | ||
LDFLAGS = -Wl,--gc-sections | ||
|
||
## printf() is one of the vfprintf() family of functions which does not implement floating point conversion by default | ||
## warning this takes about 2k of program space | ||
LDFLAGS = -Wl,-u,vfprintf -lprintf_flt -lm | ||
|
||
all: $(TARGET).hex | ||
|
||
$(TARGET): $(TARGET).hex | ||
|
||
$(TARGET).hex: $(TARGET).elf | ||
$(OBJCOPY) -j .text -j .data -O ihex $< $@ | ||
rm -f $(TARGET).elf | ||
|
||
## works with optiboot which erases flash without being told (e.g. -e ) | ||
bootload: $(TARGET).hex | ||
avrdude -v -p $(MCU) -c arduino -P $(BOOTLOAD_PORT) -b 115200 -U flash:w:$(TARGET).hex | ||
|
||
$(TARGET).elf: $(OBJECTS) | ||
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@ | ||
$(SIZE) -C --mcu=$(MCU) $@ | ||
rm -f $(TARGET).o $(OBJECTS) | ||
|
||
clean: | ||
rm -f $(TARGET).hex $(TARGET).map | ||
|
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,71 @@ | ||
# Current Source | ||
|
||
## Overview | ||
|
||
There are two 22mA current sources CS0..CS1 controlled with ATmega328p pins PB4, PB5. | ||
|
||
|
||
# Firmware Upload | ||
|
||
With a serial port connection (set the BOOT_PORT in Makefile) and optiboot installed on the RPUno run 'make bootload' and it should compile and then flash the MCU. | ||
|
||
``` | ||
git clone https://github.com/epccs/RPUlux/ | ||
cd /RPUlux/CurrSour | ||
make bootload | ||
... | ||
avrdude done. Thank you. | ||
``` | ||
|
||
Now connect with picocom (or ilk). | ||
|
||
|
||
``` | ||
#exit is C-a, C-x | ||
picocom -b 38400 /dev/ttyUSB0 | ||
``` | ||
|
||
|
||
# Commands | ||
|
||
Commands are interactive over the serial interface at 38400 baud rate. The echo will start after the second character of a new line. | ||
|
||
|
||
## /\[rpu_address\]/\[command \[arg\]\] | ||
|
||
rpu_address is taken from the I2C address 0x29 (e.g. get_Rpu_address() which is included form ../lib/rpu_mgr.h). The value of rpu_address is used as a character in a string, which means don't use a null value (C strings are null terminated) as an adddress. The ASCII value for '1' (0x31) is easy and looks nice, though I fear it will cause some confusion when it is discovered that the actual address value is 49. | ||
|
||
Commands and their arguments follow. | ||
|
||
|
||
## /0/id? \[name|desc|avr-gcc\] | ||
|
||
identify | ||
|
||
``` | ||
/1/id? | ||
{"id":{"name":"CurrSour","desc":"RPUlux (17323^2) Board /w atmega328p","avr-gcc":"5.4.0"}} | ||
``` | ||
|
||
## /0/cs 0..1,ON|OFF | ||
|
||
Turn on (or off) 22mA current sources CS0..CS3 | ||
|
||
``` | ||
/1/cs 1,ON | ||
{"PB5":"ON"} | ||
/1/cs 1,OFF | ||
{"PB5":"OFF"} | ||
``` | ||
|
||
|
||
## /0/showstat ON|OFF | ||
|
||
A current source can be used to show status, but it is not ON by default. | ||
|
||
``` | ||
/1/showstat ON | ||
{"SHOW":"ON"} | ||
/1/showstat OFF | ||
{"SHOW":"OFF"} | ||
``` |
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,112 @@ | ||
/* | ||
cs is part of CurrSour, a serial command interface to control current sources. | ||
Copyright (C) 2018 Ronald Sutherland | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
For a copy of the GNU General Public License use | ||
http://www.gnu.org/licenses/gpl-2.0.html | ||
*/ | ||
#include <avr/pgmspace.h> | ||
#include <util/atomic.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <ctype.h> | ||
#include <stdbool.h> | ||
#include "../lib/parse.h" | ||
#include "../lib/timers.h" | ||
#include "../lib/pin_num.h" | ||
#include "../lib/pins_board.h" | ||
#include "cs.h" | ||
|
||
#define SERIAL_PRINT_DELAY_MILSEC 10000 | ||
static unsigned long serial_print_started_at; | ||
|
||
// show the current source pin number used | ||
void echo_cs_pin_in_json_rply(uint8_t cs) | ||
{ | ||
switch(cs) | ||
{ | ||
case 0 : | ||
printf_P(PSTR("PD5")); // CS0 | ||
break; | ||
case 1 : | ||
printf_P(PSTR("PD6")); // CS1 | ||
break; | ||
case 2 : | ||
printf_P(PSTR("PD3")); // CS2 | ||
break; | ||
case 3 : | ||
printf_P(PSTR("PD4")); // CS3 | ||
break; | ||
} | ||
} | ||
|
||
// pinMode( arg[0], arg[1] ) | ||
void CurrSour(void) | ||
{ | ||
if ( (command_done == 10) ) | ||
{ | ||
// check that arg[0] is a digit | ||
if ( ( !( isdigit(arg[0][0]) ) ) ) | ||
{ | ||
printf_P(PSTR("{\"err\":\"CSarg0NaN\"}\r\n")); | ||
initCommandBuffer(); | ||
return; | ||
} | ||
// and arg[0] value is 0..3 | ||
uint8_t cs = atoi(arg[0]); | ||
if ( ( cs < 0) || (cs > 3) ) | ||
{ | ||
printf_P(PSTR("{\"err\":\"CSarg0OutOfRng\"}\r\n")); | ||
initCommandBuffer(); | ||
return; | ||
} | ||
// also arg[1] is not ('INPUT' or 'OUTPUT') | ||
if ( !( (strcmp_P( arg[1], PSTR("ON")) == 0) || (strcmp_P( arg[1], PSTR("OFF")) == 0) ) ) | ||
{ | ||
printf_P(PSTR("{\"err\":\"CSarg1NaMode\"}\r\n")); | ||
initCommandBuffer(); | ||
return; | ||
} | ||
serial_print_started_at = millis(); | ||
printf_P(PSTR("{\"")); | ||
if (strcmp_P( arg[1], PSTR("ON")) == 0 ) | ||
{ | ||
pinMode(cs_pin_map[cs].pin, OUTPUT); | ||
digitalWrite(cs_pin_map[cs].pin, HIGH); | ||
} | ||
else | ||
{ | ||
pinMode(cs_pin_map[cs].pin, OUTPUT); | ||
digitalWrite(cs_pin_map[cs].pin, LOW); | ||
} | ||
command_done = 11; | ||
} | ||
else if ( (command_done == 11) ) | ||
{ | ||
uint8_t cs = atoi(arg[0]); | ||
echo_cs_pin_in_json_rply( cs ); | ||
printf_P(PSTR("\":\"")); | ||
command_done = 12; | ||
} | ||
else if ( (command_done == 12) ) | ||
{ | ||
printf( arg[1] ); | ||
printf_P(PSTR("\"}\r\n")); | ||
initCommandBuffer(); | ||
} | ||
else | ||
{ | ||
printf_P(PSTR("{\"err\":\"CSCmdDnWTF\"}\r\n")); | ||
initCommandBuffer(); | ||
} | ||
} |
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,17 @@ | ||
#ifndef CS_H | ||
#define CS_H | ||
|
||
#define NUM_CS_PINS 2 | ||
|
||
typedef struct { | ||
uint8_t pin; | ||
} CS_Map; | ||
|
||
static const CS_Map cs_pin_map[NUM_CS_PINS] = { | ||
[0] = { .pin=12 }, // number is defined in ../lib/pin_num.h | ||
[1] = { .pin=13 } | ||
}; | ||
|
||
extern void CurrSour(void); | ||
|
||
#endif // CS_H |
Oops, something went wrong.