Skip to content

Commit

Permalink
Made work in progress firmware intrim. usable
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Mar 2, 2016
1 parent 39beec4 commit 59ce9df
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 34 deletions.
Binary file modified avr/bootloader/standard/.vs/StandardVscpBoot/v14/.atsuo
Binary file not shown.
2 changes: 2 additions & 0 deletions avr/bootloader/standard/StandardVscpBoot.atsln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "StandardVscpBoot", "StandardVscpBoot\StandardVscpBoot.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B0716DC3-F54A-4F93-BDF6-44A32E9C2BDF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AVR = Debug|AVR
Expand Down
40 changes: 23 additions & 17 deletions avr/bootloader/standard/StandardVscpBoot/StandardVscpBoot.cproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\..\common\crc.c">
<SubType>compile</SubType>
<Link>crc.c</Link>
</Compile>
<Compile Include="..\..\..\..\common\crc.h">
<SubType>compile</SubType>
<Link>crc.h</Link>
</Compile>
<Compile Include="..\..\..\..\common\vscp_bootloader.c">
<SubType>compile</SubType>
<Link>vscp_bootloader.c</Link>
Expand All @@ -138,31 +146,35 @@
<SubType>compile</SubType>
<Link>vscp_bootloader.h</Link>
</Compile>
<Compile Include="..\..\..\..\common\vscp_firmware.h">
<Compile Include="..\..\..\..\common\vscp_class.h">
<SubType>compile</SubType>
<Link>vscp_firmware.h</Link>
<Link>vscp_class.h</Link>
</Compile>
<Compile Include="..\..\..\common\uart.c">
<Compile Include="..\..\..\..\common\vscp_firmware.h">
<SubType>compile</SubType>
<Link>uart.c</Link>
<Link>vscp_firmware.h</Link>
</Compile>
<Compile Include="..\..\..\common\uart.h">
<Compile Include="..\..\..\..\common\vscp_type.h">
<SubType>compile</SubType>
<Link>uart.h</Link>
<Link>vscp_type.h</Link>
</Compile>
<Compile Include="bootloader.h">
<Compile Include="..\..\..\common\can_at90can128.c">
<SubType>compile</SubType>
<Link>can_at90can128.c</Link>
</Compile>
<Compile Include="can_at90can128.c">
<Compile Include="..\..\..\common\can_at90can128.h">
<SubType>compile</SubType>
<Link>can_at90can128.h</Link>
</Compile>
<Compile Include="can_at90can128.h">
<Compile Include="..\..\..\common\uart.c">
<SubType>compile</SubType>
<Link>uart.c</Link>
</Compile>
<Compile Include="crc.c">
<Compile Include="..\..\..\common\uart.h">
<SubType>compile</SubType>
<Link>uart.h</Link>
</Compile>
<Compile Include="crc.h">
<Compile Include="bootloader.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="hardware.c">
Expand All @@ -177,18 +189,12 @@
<Compile Include="version.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="vscp_class.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="vscp_compiler.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="vscp_projdefs.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="vscp_type.h">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
75 changes: 66 additions & 9 deletions common/vscp_bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void vscpboot_loader( void )

uint32_t blockno; // Current block to program
uint8_t blockdata[ VSCPBOOT_BLOCKSIZE ]; // Block data buffer
uint16_t offset; // offset into blockdata

while ( 1 ) { // not only diamonds are forever...

Expand Down Expand Up @@ -122,7 +123,7 @@ void vscpboot_loader( void )

if ( ( e.vscp_class == VSCP_CLASS1_PROTOCOL ) &&
( e.vscp_type == VSCP_TYPE_PROTOCOL_ENTER_BOOT_LOADER ) &&
( 8 == ( e.flags & 7 ) ) && // Eight data bytes
( 8 == ( e.flags & 0x0F ) ) && // Eight data bytes
( vscpboot_nickname == e.data[ 0 ] ) && // Our nickname
( VSCP_BOOTLOADER_VSCP == e.data[ 1 ] ) && // VSCP boot algorithm
( vscpboot_getGUID( 0 ) == e.data[ 2 ] ) && // GUID 0
Expand Down Expand Up @@ -171,7 +172,8 @@ void vscpboot_loader( void )

if ( ( e.vscp_class == VSCP_CLASS1_PROTOCOL ) &&
( e.vscp_type == VSCP_TYPE_PROTOCOL_START_BLOCK ) &&
(( e.flags & 7 ) >= 4 ) ) {
( ( e.flags & 0x0F ) >= 4 ) ) {

blockno = construct_unsigned32( e.data[0],
e.data[1],
e.data[2],
Expand All @@ -182,7 +184,7 @@ void vscpboot_loader( void )
e.priority = VSCP_PRIORITY_NORMAL;
e.flags = 0;
e.vscp_class = VSCP_CLASS1_PROTOCOL;
e.vscp_type = VSCP_TYPE_PROTOCOL_BLOCK_DATA_NACK;
e.vscp_type = VSCP_TYPE_PROTOCOL_START_BLOCK_NACK;
vscpboot_sendEvent( &e ); // NACK start block request
}
else {
Expand All @@ -191,24 +193,79 @@ void vscpboot_loader( void )
e.priority = VSCP_PRIORITY_NORMAL;
e.flags = 0;
e.vscp_class = VSCP_CLASS1_PROTOCOL;
e.vscp_type = VSCP_TYPE_PROTOCOL_BLOCK_DATA_ACK;
e.vscp_type = VSCP_TYPE_PROTOCOL_START_BLOCK_ACK;

if ( vscpboot_sendEvent( &e ) ) { // ACK program block request
memset( blockdata, 0xFF, sizeof( blockdata ) );
state = STATE_BLOCKDATA;
offset = 0;
}

}
}
else {
// Is this an abort?
if ( ( e.vscp_class == VSCP_CLASS1_PROTOCOL ) &&
( e.vscp_type == VSCP_TYPE_PROTOCOL_ENTER_BOOT_LOADER ) ) {
state = STATE_BOOTWAIT;
goto ENTER_BOOT_MODE;
}
}
}

break;

// ----------------------------------------------------------------
case STATE_BLOCKDATA:
if ( vscpboot_getEvent( &e ) ) {

if ( ( e.vscp_class == VSCP_CLASS1_PROTOCOL ) &&
( e.vscp_type == VSCP_TYPE_PROTOCOL_ENTER_BOOT_LOADER ) &&
( 8 == ( e.flags & 0x0F ) ) ) {

// copy in data
memcpy( blockdata + offset, e.data, 8 );
offset += 8;

// ACK the block data
e.priority = VSCP_PRIORITY_NORMAL;
e.flags = 0;
e.vscp_class = VSCP_CLASS1_PROTOCOL;
e.vscp_type = VSCP_TYPE_PROTOCOL_BLOCK_DATA_ACK;
vscpboot_sendEvent( &e );

// Check if the block is full
if ( offset == sizeof( blockdata ) ) {

// ACK the block



e.priority = VSCP_PRIORITY_NORMAL;
e.flags = 0;
e.vscp_class = VSCP_CLASS1_PROTOCOL;
e.vscp_type = VSCP_TYPE_PROTOCOL_BLOCK_DATA_NACK;
vscpboot_sendEvent( &e ); // NACK start block request
}
}
break;
e.vscp_type = VSCP_TYPE_PROTOCOL_START_BLOCK_ACK;

if ( vscpboot_sendEvent( &e ) ) { // ACK program block request
memset( blockdata, 0xFF, sizeof( blockdata ) );
state = STATE_BLOCKDATA;
offset = 0;
}

}

}

}
else {
// Is this an abort?
if ( ( e.vscp_class == VSCP_CLASS1_PROTOCOL ) &&
( e.vscp_type == VSCP_TYPE_PROTOCOL_ENTER_BOOT_LOADER ) ) {
state = STATE_BOOTWAIT;
goto ENTER_BOOT_MODE;
}
}
break;

// ----------------------------------------------------------------
default:
Expand Down
4 changes: 2 additions & 2 deletions common/vscp_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ uint8_t vscp_node_substate; // State machine sub state
uint8_t vscp_probe_cnt; // Number of time-out probes

// Incoming event
struct _imsg vscp_imsg;
vscpevent_t vscp_imsg;

// Outgoing event
struct _omsg vscp_omsg;
vscpevent_t vscp_omsg;

uint8_t vscp_probe_address; // Address used during initialization
uint8_t vscp_initledfunc; // Init. LED functionality
Expand Down
12 changes: 6 additions & 6 deletions common/vscp_firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ low end hardware device.
#define VSCP_LED_BLINK1 0x02


typedef struct vscpevent_t {
typedef struct {
/*!
Input message flags\n
==================\n
Expand All @@ -234,13 +234,13 @@ typedef struct vscpevent_t {
uint8_t vscp_type; // VSCP type
uint8_t oaddr; // Packet originating address
uint8_t data[8]; // data bytes
} vscpevent;
} vscpevent_t;


//////////////////////////////////////////////////////////
// Deprecated
// imsg and omsg has been deprecated and is replaced by
// vscpmsg from version 1.6.0
// vscpevent from version 1.6.0
//////////////////////////////////////////////////////////


Expand Down Expand Up @@ -312,9 +312,9 @@ extern uint8_t vscp_alarmstatus; // VSCP alarm status register
extern uint8_t vscp_node_state; // VSCP state machine main state
extern uint8_t vscp_node_substate; // VSCP state machine sub state
extern uint8_t vscp_initledfunc; //
// The following are defined in vscp.c
extern struct _imsg vscp_imsg; // Current input event
extern struct _omsg vscp_omsg; // Current outgoing event
// The following are defined in vscp_firmware.c
extern vscpevent_t vscp_imsg; // Current input event
extern vscpevent_t vscp_omsg; // Current outgoing event
extern volatile uint16_t vscp_timer; // 1 ms timer counter
extern uint8_t vscp_probe_address; // Probe address for nickname discovery
extern volatile uint8_t vscp_initbtncnt; // init. button counter
Expand Down

0 comments on commit 59ce9df

Please sign in to comment.