Changeset - ed10eff104e9
[Not reviewed]
DataFlowDiagrams.pptx
Show inline comments
 
binary diff not shown
master/master/config.h
Show inline comments
 
@@ -11,6 +11,6 @@
 
 
#define F_CPU 11059200
 
#define USART_BAUDRATE 19200
 
 
#define MODULE_ID '1'
 
 
#endif /* CONFIG_H_ */
 
\ No newline at end of file
master/master/lib/serial.c
Show inline comments
 
@@ -13,7 +13,7 @@ void serial_SendChar( char byte )
 
	UDR0 = byte;
 
}
 
 
void serial_SendCommand( char moduleID, char measureType, uint8_t dataLength, char* data )
 
void serial_SendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data )
 
{
 
	char checkSum = 0x00; //initialize checksum
 
	
 
@@ -21,8 +21,8 @@ void serial_SendCommand( char moduleID, 
 
	serial_SendChar(moduleID);
 
	checkSum+=moduleID;
 
	
 
	serial_SendChar(measureType);
 
	checkSum+=measureType;
 
	serial_SendChar(sensorID);
 
	checkSum+=sensorID;
 
	
 
	//send each character of data individually
 
	for (int i=0; i<dataLength; i++)
master/master/lib/serial.h
Show inline comments
 
@@ -12,7 +12,7 @@
 
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) -1 )
 
 
void serial_SendChar( char byte );
 
void serial_SendCommand( char moduleID, char measureType, uint8_t dataLength, char* data );
 
void serial_SendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data );
 
void serial_SendResponseData();
 
void serial_setup();
 
master/master/lib/serparser.c
Show inline comments
 
@@ -5,81 +5,123 @@
 
 *  Author: ethanzonca
 
 */ 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
 
// ************* Macros ***************
 
#define SERIAL_RX_HASBYTES UCSR0A & _BV(RXC0)
 
#define MAX_CMD_LEN 8
 
#define BROADCAST_ADDR 0
 
#define SERIAL_RX_HASBYTES UCSR0A & _BV(RXC)
 
#define MAX_CMD_LEN 16
 
#define BROADCAST_ADDR 0 //public address
 
#include <avr/io.h>
 
#include "../config.h"
 
 
//#define DEBUG
 
 
// ************* Command Definitions ***************
 
 
// Serial Commands
 
enum luma_cmd {  // CMD ID#
 
enum cmd // CMD ID#
 
{
 
	BOARDTEMP = 0, // 0
 
	PRESSURE,      // 1
 
};
 
 
// Data length of each command, in bytes
 
uint8_t cmd_len[] = {
 
	2, // BOARDTEMP_LEN
 
	0, // PRESSURE_LEN
 
};
 
 
// Incoming command buffer
 
uint8_t buffer[MAX_CMD_LEN+2];
 
 
// Current buffer location
 
uint8_t buffercount = 0;
 
uint8_t bufferPosition = 0;
 
 
//current length of the data transmission (and checksum)
 
int dataLength;
 
 
//data (and checksum) of most recent transmission
 
char data[16];
 
 
//ID of the sensor of most recent transmission
 
char sensorID;
 
 
/* Get char from UART */
 
//checksum to be calculated and then compared to the received checksum
 
char checksumCalc;
 
 
/* return char from UART (h/w buffer) */
 
uint8_t uart_getchar(void)
 
{
 
	// Wait for chars
 
	while (!(UCSR0A & (1<<RXC0))){
 
		//idle
 
	/*	while (!(UCSRA & (1<<RXC)))
 
	{
 
		idle();
 
	}
 
	return UDR0;
 
	return UDR;
 
	*/
 
	return 0;
 
}
 
 
 
 
/* Process incoming serial data */
 
int uart_machine(void) {
 
int uart_Parser(void)
 
{
 
 
	char byte;
 
 
	// Only process data if buffer has a byte
 
	if(SERIAL_RX_HASBYTES) {
 
		#ifdef DEBUG
 
		redflash();
 
		#endif
 
	if(SERIAL_RX_HASBYTES) // Only process data if buffer has a byte
 
	{
 
		
 
		// Pull byte off of the buffer
 
		byte = uart_getchar();
 
		buffer[buffercount] = byte;
 
 
		buffer[bufferPosition] = byte;
 
		
 
		// Start byte
 
		if(buffercount == 0) {
 
			if(byte == '[') {
 
				// If this is a start byte, we're OK. Keep reading.
 
				buffercount++;
 
		// byte checking/validation
 
		if(bufferPosition == 0)
 
		{
 
			if(byte == '[') // If this is a start byte, we're OK. Keep reading.
 
			{
 
				bufferPosition++;
 
			}
 
			else // Not a start byte that we're expecting. Reset to initial state.
 
			{
 
				bufferPosition = 0;
 
			}
 
			}
 
			else {
 
				// Not a start byte that we're expecting. Reset to initial state.
 
				buffercount = 0;
 
		else if(bufferPosition == 1)
 
		{
 
			if(byte == MODULE_ID) //this transmission is intended for the master; continue parsing
 
			{
 
				bufferPosition++;
 
				checksumCalc += byte;
 
				dataLength = 0; //reset dataLength here to protect from bad inputs
 
			}
 
			else //this transmission is intended for another module; stop parsing and reset
 
			{
 
				bufferPosition = 0;
 
			}
 
		}
 
		
 
		else if(bufferPosition == 2)
 
		{
 
			sensorID = byte; //store the type of data receiving
 
			bufferPosition++;
 
			checksumCalc += byte;
 
		}
 
		else if (bufferPosition == MAX_CMD_LEN) //command is too long and bad data has been recieved; reset
 
		{
 
			bufferPosition = 0;
 
		}
 
		else
 
		{
 
			if (byte == ']') //this is the end of the transmission
 
			{
 
				bufferPosition = 0;
 
			}
 
			else //still receiving data
 
			{
 
				data[dataLength] = byte;
 
				dataLength++;
 
				bufferPosition++;
 
				checksumCalc += byte;
 
			}
 
		
 
	}
 
	else {
 
		
 
	}
 
	else
 
	{
 
		return 0; // serial data not available
 
	}
 
}
 
\ No newline at end of file
slave2/slave/slave.atsln
Show inline comments
 
new file 100644
 

 
Microsoft Visual Studio Solution File, Format Version 11.00
 
# Atmel Studio Solution File, Format Version 11.00
 
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "slave", "slave\slave.cproj", "{40D97B6E-7FF4-48E7-9A9E-5E50BA18526B}"
 
EndProject
 
Global
 
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 
		Debug|AVR = Debug|AVR
 
		Release|AVR = Release|AVR
 
	EndGlobalSection
 
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 
		{40D97B6E-7FF4-48E7-9A9E-5E50BA18526B}.Debug|AVR.ActiveCfg = Debug|AVR
 
		{40D97B6E-7FF4-48E7-9A9E-5E50BA18526B}.Debug|AVR.Build.0 = Debug|AVR
 
		{40D97B6E-7FF4-48E7-9A9E-5E50BA18526B}.Release|AVR.ActiveCfg = Release|AVR
 
		{40D97B6E-7FF4-48E7-9A9E-5E50BA18526B}.Release|AVR.Build.0 = Release|AVR
 
	EndGlobalSection
 
	GlobalSection(SolutionProperties) = preSolution
 
		HideSolutionNode = FALSE
 
	EndGlobalSection
 
EndGlobal
slave2/slave/slave/config.h
Show inline comments
 
new file 100644
 
/*
 
 * IncFile1.h
 
 *
 
 * Created: 10/25/2012 10:00:09 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #ifndef CONFIG_H_
 
 #define CONFIG_H_
 
 
 #define F_CPU 11059200
 
 #define USART_BAUDRATE 19200
 
 #define MODULE_ID '2'
 
 
 #endif /* CONFIG_H_ */
 
\ No newline at end of file
slave2/slave/slave/lib/led.c
Show inline comments
 
new file 100644
 
/*
 
 * CFile1.c
 
 *
 
 * Created: 10/25/2012 10:03:22 PM
 
 *  Author: mkanning
 
 */
 
 
 #include <avr/io.h>
 
 
 void led_Configure() {
 
	 // Configure ports/pins for LEDs
 
 }
 
 
 void led_On(uint8_t led) {
 
	 // Turn the specified LED on
 
 }
 
 
 void led_Off(uint8_t led) {
 
	 // Turn the specified LED off
 
 }
 
 
 void led_Toggle(uint8_t led) {
 
	 // Toggle the specified LED
 
 }
 
\ No newline at end of file
slave2/slave/slave/lib/led.h
Show inline comments
 
new file 100644
 
/*
 
 * IncFile1.h
 
 *
 
 * Created: 10/25/2012 10:01:29 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #ifndef LED_H_
 
 #define LED_H_
 
 
 #define POWER 1
 
 #define ERROR 2
 
 #define STAT 2
 
 #define OK 2
 
 
 void led_Configure();
 
 void led_On(uint8_t led);
 
 void led_Off(uint8_t led);
 
 void led_Toggle(uint8_t led);
 
 
 
 #endif /* LED_H_ */
slave2/slave/slave/lib/serial.c
Show inline comments
 
new file 100644
 
/*
 
 * CFile1.c
 
 *
 
 * Created: 10/25/2012 10:02:38 PM
 
 *  Author: mkanning
 
 */
 
 
 #include <avr/io.h>
 
 
 void serial_SendChar( char byte )
 
 {
 
	 while (!(UCSR0A & (1<<UDRE0)));
 
	 UDR0 = byte;
 
 }
 
 
 void serial_SendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data )
 
 {
 
	 char checkSum = 0x00; //initialize checksum
 
	 
 
	 serial_SendChar('['); //bracket indicates start of command
 
	 serial_SendChar(moduleID);
 
	 checkSum+=moduleID;
 
	 
 
	 serial_SendChar(sensorID);
 
	 checkSum+=sensorID;
 
	 
 
	 //send each character of data individually
 
	 for (int i=0; i<dataLength; i++)
 
	 {
 
		 serial_SendChar(data[i]);
 
		 checkSum += data[i];
 
	 }
 
	 
 
	 serial_SendChar(checkSum);
 
	 serial_SendChar(']'); //bracket indicates end of command
 
 }
 
 
 void serial_SendResponseData(){
 
	 
 
 }
 
 
 void serial_Configure() {
 
	 // Set registers!
 
	 
 
	 // from mnl
 
	 // uart
 
	 //UBRRH = (BAUD_PRESCALE >> 8); // 0
 
	 //UBRRL = BAUD_PRESCALE; // 8
 
	 //UCSRA = 0;
 
	 //UCSRB = 0x18;
 
	 //UCSRC = 0x06;
 
	 //OCR0B = 0xff;
 
	 //OCR0A = 0xff;
 
	 //OCR1AL = 0xff;
 
	 //OCR1BL = 0xff;
 
 }
slave2/slave/slave/lib/serial.h
Show inline comments
 
new file 100644
 
/*
 
 * IncFile1.h
 
 *
 
 * Created: 10/25/2012 10:01:43 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #ifndef SERIAL_H_
 
 #define SERIAL_H_
 
 
 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) -1 )
 
 
 void serial_SendChar( char byte );
 
 void serial_SendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data );
 
 void serial_SendResponseData();
 
 void serial_Configure();
 
 
 #endif /* SERIAL_H_ */
 
\ No newline at end of file
slave2/slave/slave/lib/serparser.c
Show inline comments
 
new file 100644
 
/*
 
 * serparser.c
 
 *
 
 * Created: 10/25/2012 10:04:09 PM
 
 *  Author: mkanning
 
*/
 
 
 
// ************* Macros ***************
 
#define SERIAL_RX_HASBYTES UCSR0A & _BV(RXC)
 
#define MAX_CMD_LEN 16
 
#define BROADCAST_ADDR 0 //public address
 
#include <avr/io.h>
 
#include "../config.h"
 
 
//#define DEBUG
 
 
// ************* Command Definitions ***************
 
 
// Serial Commands
 
enum cmd // CMD ID#
 
{
 
	BOARDTEMP = 0, // 0
 
	PRESSURE,      // 1
 
};
 
 
// Incoming command buffer
 
uint8_t buffer[MAX_CMD_LEN+2];
 
 
// Current buffer location
 
uint8_t bufferPosition = 0;
 
 
//ID of the sensor of most recent transmission
 
char sensorID;
 
 
//checksum to be calculated and then compared to the received checksum
 
char checksumCalc;
 
 
/* return char from UART (h/w buffer) */
 
uint8_t uart_getchar(void)
 
{
 
	// Wait for chars
 
	/*	while (!(UCSRA & (1<<RXC)))
 
	{
 
		idle();
 
	}
 
	return UDR;
 
	*/
 
	return 0;
 
}
 
 
/* Process incoming serial data */
 
int uart_Parser(void)
 
{
 
	char byte;
 
	
 
	if(SERIAL_RX_HASBYTES) // Only process data if buffer has a byte
 
	{
 
		
 
		// Pull byte off of the buffer
 
		byte = uart_getchar();
 
		buffer[bufferPosition] = byte;
 
		
 
		// byte checking/validation
 
		if(bufferPosition == 0)
 
		{
 
			if(byte == '[') // If this is a start byte, we're OK. Keep reading.
 
			{
 
				bufferPosition++;
 
			}
 
			else // Not a start byte that we're expecting. Reset to initial state.
 
			{
 
				bufferPosition = 0;
 
			}
 
		}
 
		else if(bufferPosition == 1)
 
		{
 
			if(byte == MODULE_ID) //this transmission is intended for this module; continue parsing
 
			{
 
				bufferPosition++;
 
				checksumCalc += byte;
 
			}
 
			else //this transmission is intended for another module; stop parsing and reset
 
			{
 
				bufferPosition = 0;
 
			}
 
		}
 
		else if(bufferPosition == 2)
 
		{
 
			sensorID = byte; //store the type of data receiving
 
			bufferPosition++;
 
			checksumCalc += byte;
 
		}
 
		else if(bufferPosition == 3)
 
		{
 
			if (byte == checksumCalc) //the computed and recieved checksums match; data is valid
 
			{
 
				bufferPosition++;
 
				checksumCalc += byte;
 
			} 
 
			else //the computed and recieved checksums do not match; data is invalid
 
			{
 
				bufferPosition = 0;
 
			}
 
		}
 
		//this else if and the final else have the same results - combine ??
 
		else if (bufferPosition == 4) //this should be end of transmission
 
		{
 
			if (byte == ']') //this is the end of the transmission
 
			{
 
				bufferPosition = 0;
 
			}
 
			else // unexpected character; reset
 
			{
 
				bufferPosition = 0;
 
			}
 
		
 
		}
 
		else //command is too long and bad data has been recieved; reset
 
		{
 
			bufferPosition = 0;
 
		}
 
	
 
	
 
	}
 
	else
 
	{
 
		return 0; // serial data not available
 
	}
 
}
 
\ No newline at end of file
slave2/slave/slave/lib/serparser.h
Show inline comments
 
new file 100644
 
/*
 
 * serparser.h
 
 *
 
 * Created: 10/25/2012 10:04:23 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #ifndef SERPARSER_H_
 
 #define SERPARSER_H_
 
 
 
 // Prototypes
 
 uint8_t convertchar(uint8_t);
 
 uint8_t uart_getchar(void);
 
 void got_char(uint8_t);
 
 int uart_machine(void);
 
 void uart_putchar(uint8_t);
 
 void exec_cmd(void);
 
 void idle(void);
 
 void uart_init(void);
 
 
 
 
 #endif /* SERPARSER_H_ */
 
\ No newline at end of file
slave2/slave/slave/slave.c
Show inline comments
 
new file 100644
 
/*
 
 * slave.c
 
 *
 
 * Created: 10/25/2012 9:59:40 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #include "config.h"
 
 
 #include <avr/io.h>
 
 #include <util/delay.h>
 
 
 #include "lib/serial.h"
 
 
 
 void micro_Configure() {
 
	 // Generic microcontroller config options
 
 }
 
 
 int main(void)
 
 {
 
	 // Initialize
 
	 micro_Configure();
 
	 led_Configure();
 
	 serial_Configure(); // Config serial ports
 
	 
 
	 while(1)
 
	 {
 
		 serial_SendCommand('0','A',0,0);
 
	 }
 
 }
 
\ No newline at end of file
slave2/slave/slave/slave.cproj
Show inline comments
 
new file 100644
 
<?xml version="1.0" encoding="utf-8"?>
 
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  <PropertyGroup>
 
    <SchemaVersion>2.0</SchemaVersion>
 
    <ProjectVersion>6.0</ProjectVersion>
 
    <ToolchainName>com.Atmel.AVRGCC8</ToolchainName>
 
    <ProjectGuid>{40d97b6e-7ff4-48e7-9a9e-5e50ba18526b}</ProjectGuid>
 
    <avrdevice>ATmega644P</avrdevice>
 
    <avrdeviceseries>none</avrdeviceseries>
 
    <OutputType>Executable</OutputType>
 
    <Language>C</Language>
 
    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
 
    <OutputFileExtension>.elf</OutputFileExtension>
 
    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
 
    <AssemblyName>slave</AssemblyName>
 
    <Name>slave</Name>
 
    <RootNamespace>slave</RootNamespace>
 
    <ToolchainFlavour>Native</ToolchainFlavour>
 
    <KeepTimersRunning>true</KeepTimersRunning>
 
    <OverrideVtor>false</OverrideVtor>
 
    <OverrideVtorValue />
 
    <eraseonlaunchrule>0</eraseonlaunchrule>
 
    <AsfVersion>3.1.3</AsfVersion>
 
  </PropertyGroup>
 
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 
    <ToolchainSettings>
 
      <AvrGcc>
 
  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
 
  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
 
  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
 
  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
 
  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
 
  <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
 
  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
 
  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
 
  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
 
  <avrgcc.linker.libraries.Libraries>
 
    <ListValues>
 
      <Value>m</Value>
 
    </ListValues>
 
  </avrgcc.linker.libraries.Libraries>
 
</AvrGcc>
 
    </ToolchainSettings>
 
  </PropertyGroup>
 
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
 
    <ToolchainSettings>
 
      <AvrGcc>
 
  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
 
  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
 
  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
 
  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
 
  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
 
  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
 
  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
 
  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
 
  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
 
  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
 
  <avrgcc.linker.libraries.Libraries>
 
    <ListValues>
 
      <Value>m</Value>
 
    </ListValues>
 
  </avrgcc.linker.libraries.Libraries>
 
  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
 
</AvrGcc>
 
    </ToolchainSettings>
 
  </PropertyGroup>
 
  <ItemGroup>
 
    <Compile Include="config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serial.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serial.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serparser.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serparser.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="slave.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
  </ItemGroup>
 
  <ItemGroup>
 
    <Folder Include="lib" />
 
  </ItemGroup>
 
  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
 
</Project>
 
\ No newline at end of file
0 comments (0 inline, 0 general)