master
commit
61e63ebeb7
@ -0,0 +1,19 @@
|
||||
3xThermo1xHT/bootloaderFiles/.vs
|
||||
3xThermo1xHT/bootloaderFiles/Release
|
||||
3xThermo1xHT/bootloaderFiles/Debug
|
||||
3xThermo1xHT/bootloaderFiles/Cutter_Debug
|
||||
3xThermo1xHT/bootloaderFiles/idiBUS_bootloader/\[Build\] Release_2560
|
||||
3xThermo1xHT/bootloaderFiles/idiBUS_bootloader/\[Build\] Release_328pb
|
||||
3xThermo1xHT/bootloaderFiles/idiBUS_bootloader/\[Build\] Debug_2560
|
||||
3xThermo1xHT/bootloaderFiles/idiBUS_bootloader/\[Build\] Debug_328pb
|
||||
3xThermo1xHT/bootloaderFiles/idiBUS_bootloader/\[Build\] Cutter_2560
|
||||
3xThermo1xHT/bootloaderFiles/idiBUS_bootloader/\[Build\] Cutter_328pb
|
||||
3xThermo1xHT/idiBusCoreFiles/bin
|
||||
3xThermo1xHT/idiBusCoreFiles/.vs
|
||||
3xThermo1xHT/idiBusCoreFiles/\[Build\] Debug_328pb
|
||||
3xThermo1xHT/idiBusCoreFiles/\[Build\] Debug_2560
|
||||
3xThermo1xHT/idiBusCoreFiles/\[Build\] Release_328pb
|
||||
3xThermo1xHT/idiBusCoreFiles/\[Build\] Release_2560
|
||||
3xThermo1xHT/\[Build\] Release
|
||||
3xThermo1xHT/\[Build\] Debug
|
||||
3xThermo1xHT/.vs
|
Binary file not shown.
@ -0,0 +1,98 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v3.1",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v3.1": {
|
||||
"idiBusFmwPrepTool/1.0.0": {
|
||||
"dependencies": {
|
||||
"Crc32.NET": "1.2.0",
|
||||
"System.Text.RegularExpressions": "4.3.1"
|
||||
},
|
||||
"runtime": {
|
||||
"idiBusFmwPrepTool.dll": {}
|
||||
}
|
||||
},
|
||||
"Crc32.NET/1.2.0": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "2.0.0"
|
||||
},
|
||||
"runtime": {
|
||||
"lib/netstandard2.0/Crc32.NET.dll": {
|
||||
"assemblyVersion": "1.0.0.0",
|
||||
"fileVersion": "1.2.0.5"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Microsoft.NETCore.Platforms/1.1.1": {},
|
||||
"Microsoft.NETCore.Targets/1.1.3": {},
|
||||
"NETStandard.Library/2.0.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Platforms": "1.1.1"
|
||||
}
|
||||
},
|
||||
"System.Runtime/4.3.1": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Platforms": "1.1.1",
|
||||
"Microsoft.NETCore.Targets": "1.1.3"
|
||||
}
|
||||
},
|
||||
"System.Text.RegularExpressions/4.3.1": {
|
||||
"dependencies": {
|
||||
"System.Runtime": "4.3.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"idiBusFmwPrepTool/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
},
|
||||
"Crc32.NET/1.2.0": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-wNW/huzolu8MNKUnwCVKxjfAlCFpeI8AZVfF46iAWJ1+P6bTU1AZct7VAkDDEjgeeTJCVTkGZaD6jSd/fOiUkA==",
|
||||
"path": "crc32.net/1.2.0",
|
||||
"hashPath": "crc32.net.1.2.0.nupkg.sha512"
|
||||
},
|
||||
"Microsoft.NETCore.Platforms/1.1.1": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-TMBuzAHpTenGbGgk0SMTwyEkyijY/Eae4ZGsFNYJvAr/LDn1ku3Etp3FPxChmDp5HHF3kzJuoaa08N0xjqAJfQ==",
|
||||
"path": "microsoft.netcore.platforms/1.1.1",
|
||||
"hashPath": "microsoft.netcore.platforms.1.1.1.nupkg.sha512"
|
||||
},
|
||||
"Microsoft.NETCore.Targets/1.1.3": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-3Wrmi0kJDzClwAC+iBdUBpEKmEle8FQNsCs77fkiOIw/9oYA07bL1EZNX0kQ2OMN3xpwvl0vAtOCYY3ndDNlhQ==",
|
||||
"path": "microsoft.netcore.targets/1.1.3",
|
||||
"hashPath": "microsoft.netcore.targets.1.1.3.nupkg.sha512"
|
||||
},
|
||||
"NETStandard.Library/2.0.0": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-7jnbRU+L08FXKMxqUflxEXtVymWvNOrS8yHgu9s6EM8Anr6T/wIX4nZ08j/u3Asz+tCufp3YVwFSEvFTPYmBPA==",
|
||||
"path": "netstandard.library/2.0.0",
|
||||
"hashPath": "netstandard.library.2.0.0.nupkg.sha512"
|
||||
},
|
||||
"System.Runtime/4.3.1": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-abhfv1dTK6NXOmu4bgHIONxHyEqFjW8HwXPmpY9gmll+ix9UNo4XDcmzJn6oLooftxNssVHdJC1pGT9jkSynQg==",
|
||||
"path": "system.runtime/4.3.1",
|
||||
"hashPath": "system.runtime.4.3.1.nupkg.sha512"
|
||||
},
|
||||
"System.Text.RegularExpressions/4.3.1": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-N0kNRrWe4+nXOWlpLT4LAY5brb8caNFlUuIRpraCVMDLYutKkol1aV079rQjLuSxKMJT2SpBQsYX9xbcTMmzwg==",
|
||||
"path": "system.text.regularexpressions/4.3.1",
|
||||
"hashPath": "system.text.regularexpressions.4.3.1.nupkg.sha512"
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"additionalProbingPaths": [
|
||||
"C:\\Users\\Stanislav\\.dotnet\\store\\|arch|\\|tfm|",
|
||||
"C:\\Users\\Stanislav\\.nuget\\packages"
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "netcoreapp3.1",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "3.1.0"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
This is template repo.
|
||||
|
||||
Auto generated description:
|
||||
|
||||
idiBus_3xThermo1xHT
|
||||
|
||||
idiBus_3xThermo1xHT
|
@ -0,0 +1,13 @@
|
||||
FmwInfo
|
||||
|
||||
[Block 1]
|
||||
FmwHash: 4
|
||||
FmwSizeInPages: 2
|
||||
ModuleType: 3
|
||||
HWRevision: 2
|
||||
Dummy: 5
|
||||
|
||||
[Block 2]
|
||||
SWVersion: 2
|
||||
Dummy: 10
|
||||
InfoHash: 4
|
@ -0,0 +1 @@
|
||||
Do not use this repository separetly from idiBusSlaveTemplate!!!
|
@ -0,0 +1,7 @@
|
||||
#ifndef BOOTVERSION_H_
|
||||
#define BOOTVERSION_H_
|
||||
|
||||
#define BOOT_VERSION_MAJOR 0
|
||||
#define BOOT_VERSION_MINOR 2
|
||||
|
||||
#endif /* BOOTVERSION_H_ */
|
@ -0,0 +1,17 @@
|
||||
// USARTCUSTOM (FOR 2560)
|
||||
#define USART1_TX_DDR DDRD
|
||||
#define USART1_TX_PORT PORTD
|
||||
#define USART1_TX_BIT 3
|
||||
#define USART1_RX_DDR DDRD
|
||||
#define USART1_RX_PORT PORTD
|
||||
#define USART1_RX_BIT 2
|
||||
#define USART1_DRE_DDR DDRD
|
||||
#define USART1_DRE_PORT PORTD
|
||||
#define USART1_DRE_BIT 4
|
||||
// USARTCUSTOM (FOR 2560)
|
||||
#define USART0_TX_DDR DDRE
|
||||
#define USART0_TX_PORT PORTE
|
||||
#define USART0_TX_BIT 1
|
||||
#define USART0_RX_DDR DDRE
|
||||
#define USART0_RX_PORT PORTE
|
||||
#define USART0_RX_BIT 0
|
@ -0,0 +1,19 @@
|
||||
//USART CUSTOM (FOR 328pb)
|
||||
#define USART0_TX_DDR DDRD
|
||||
#define USART0_TX_PORT PORTD
|
||||
#define USART0_TX_BIT 1
|
||||
#define USART0_RX_DDR DDRD
|
||||
#define USART0_RX_PORT PORTD
|
||||
#define USART0_RX_BIT 0
|
||||
|
||||
//USART CUSTOM (FOR 328pb)
|
||||
#define USART1_TX_DDR DDRB
|
||||
#define USART1_TX_PORT PORTB
|
||||
#define USART1_TX_BIT 3
|
||||
#define USART1_RX_DDR DDRB
|
||||
#define USART1_RX_PORT PORTB
|
||||
#define USART1_RX_BIT 4
|
||||
#define USART1_DRE_DDR DDRB
|
||||
#define USART1_DRE_PORT PORTB
|
||||
#define USART1_DRE_BIT 5
|
||||
|
@ -0,0 +1,249 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "AES.h"
|
||||
//=============================================================================================================================================================================================================
|
||||
const uint8_t AES_INV_SBOX[256] PROGMEM= {
|
||||
0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB ,
|
||||
0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB ,
|
||||
0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E ,
|
||||
0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25 ,
|
||||
0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92 ,
|
||||
0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84 ,
|
||||
0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06 ,
|
||||
0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B ,
|
||||
0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73 ,
|
||||
0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E ,
|
||||
0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B ,
|
||||
0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4 ,
|
||||
0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F ,
|
||||
0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF ,
|
||||
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61 ,
|
||||
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
|
||||
};
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
//Static functions
|
||||
|
||||
inline uint8_t AES_RotWord(uint8_t *Word);
|
||||
uint8_t AES_SubWord (uint8_t Word);
|
||||
inline void AES_KeyExpansion(uint8_t *AES_KEY, uint8_t *w);
|
||||
|
||||
//uint8_t AES_xTime(uint8_t Value);
|
||||
void AES_AddRoundKey (uint8_t *State, uint8_t *Key);
|
||||
|
||||
void AES_InvSubBytes(uint8_t *state);
|
||||
void AES_InvShiftRows(uint8_t *state);
|
||||
inline void AES_InvMixColumns(uint8_t *state);
|
||||
|
||||
//void AES_ApplyIV(uint8_t *state, uint8_t *IV);
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
inline uint8_t AES_RotWord(uint8_t *Word){
|
||||
Word[0+4] = Word[1];
|
||||
Word[1+4] = Word[2];
|
||||
Word[2+4] = Word[3];
|
||||
Word[3+4] = Word[0];
|
||||
return Word[1];
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t AES_SubWord (uint8_t Word)
|
||||
{
|
||||
//for (uint8_t i = 0; i < 256; i++){ //FIND BETTER SOLUTION (with out using precomputed values)
|
||||
// if (flash_read_byte((AES_INV_SBOX),i) == Word)
|
||||
// return i;
|
||||
//}
|
||||
//return 0;
|
||||
uint8_t j,i = 0;
|
||||
do {
|
||||
if (flash_read_byte((AES_INV_SBOX),i) == Word)
|
||||
j = i;
|
||||
i++;
|
||||
} while (i != 0);
|
||||
return j;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const uint8_t Rcon[7] PROGMEM= { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40};//, 0x80};//, 0x1B, 0x36 };
|
||||
|
||||
inline void AES_KeyExpansion(uint8_t *AES_KEY, uint8_t *w)
|
||||
{
|
||||
uint8_t KeyTmp;
|
||||
uint8_t I;
|
||||
|
||||
//for (I = 0; I < AES_NK_256BIT*4; I++)
|
||||
//{
|
||||
// w[I] = pgm_read_byte(&(AES_KEY[I]));
|
||||
//}
|
||||
_memcopy(AES_KEY,w,AES_NK_256BIT*4);
|
||||
|
||||
for (I = AES_NK_256BIT*4; I < (uint8_t)(AES_NB*(uint8_t)(AES_NR_256BIT+1U)*4); I++)
|
||||
{
|
||||
KeyTmp = w[I-4];
|
||||
|
||||
if ((I & 0b11100) == 0 ) {
|
||||
if ((I & 0b11) == 0 ) {
|
||||
KeyTmp = AES_RotWord(&w[I-4]);
|
||||
KeyTmp = AES_SubWord(KeyTmp);
|
||||
//KeyTmp = KeyTmp ^ (1<<(I>>5));
|
||||
KeyTmp = KeyTmp ^ flash_read_byte((Rcon),(I>>5)-1);
|
||||
} else
|
||||
KeyTmp = AES_SubWord(w[I]);
|
||||
}
|
||||
else if ( (I & 0b11100) == 16 )
|
||||
KeyTmp = AES_SubWord(w[I-4]);
|
||||
|
||||
w[I] = w[I-(AES_NK_256BIT*4)] ^ KeyTmp;
|
||||
}
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
//uint8_t AES_xTime(uint8_t Value) { return ( (Value & 0x80) ? ((uint8_t)(Value<<1)^0x1B) : (uint8_t)(Value<<1) ); }
|
||||
//
|
||||
//#define AES_MULTIPLY_02(X) AES_xTime((X))
|
||||
//#define AES_MULTIPLY_03(X) ( (X) ^ AES_xTime((X)) )
|
||||
//#define AES_MULTIPLY_09(X) ( (X) ^ AES_xTime(AES_xTime(AES_xTime((X)))) )
|
||||
//#define AES_MULTIPLY_0B(X) ( (X) ^ AES_xTime((X)) ^ AES_xTime(AES_xTime(AES_xTime((X)))) )
|
||||
//#define AES_MULTIPLY_0E(X) ( AES_xTime((X)) ^ AES_xTime(AES_xTime((X))) ^ AES_xTime(AES_xTime(AES_xTime((X)))) )
|
||||
//#define AES_MULTIPLY_0D(X) ( (X) ^ AES_xTime(AES_xTime((X))) ^ AES_xTime(AES_xTime(AES_xTime((X)))) )
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//static uint8_t rstate[4*AES_NB];
|
||||
|
||||
#define GF28_MUL2(a) { asm ("lsl %0 \n brcc .+2 \n eor %0, %1 \n" : "=r" (a) : "r" (c0x1b), "0" (a)); }
|
||||
//#define GF28_MUL2(a) { if (a&0x80) { a = (a<<1) ^ 0x1b; } else { a <<= 1; } }
|
||||
//#define GF28_MUL2(a) {a=AES_xTime(a);}
|
||||
|
||||
inline void AES_InvMixColumns(uint8_t *state)
|
||||
{
|
||||
//for (uint8_t i = 0; i<16; i++)
|
||||
// rstate[i]=state[i];
|
||||
//_memcopy(state,rstate,16);
|
||||
|
||||
const uint8_t c0x1b = 0x1b;
|
||||
uint8_t i, a0, a1, a2, a3, sum, b, c, d, e;
|
||||
uint8_t* ptr = state;
|
||||
for(i = 0; i < 16; i+=4) //https://github.com/kildom/AVR-AES/blob/master/aes.c I don't fully understand this, but it works really fast
|
||||
{
|
||||
a0 = ptr[0];
|
||||
a1 = ptr[1];
|
||||
a2 = ptr[2];
|
||||
a3 = ptr[3];
|
||||
sum = a0 ^ a1 ^ a2 ^ a3;
|
||||
c = sum; GF28_MUL2(c);
|
||||
d = c ^ a0 ^ a2; GF28_MUL2(d); GF28_MUL2(d);
|
||||
d ^= sum;
|
||||
e = c ^ a1 ^ a3; GF28_MUL2(e); GF28_MUL2(e);
|
||||
e ^= sum;
|
||||
b = a0^a1; GF28_MUL2(b);
|
||||
*ptr++ = d ^ a0 ^ b;
|
||||
b = a1^a2; GF28_MUL2(b);
|
||||
*ptr++ = e ^ a1 ^ b;
|
||||
b = a2^a3; GF28_MUL2(b);
|
||||
*ptr++ = d ^ a2 ^ b;
|
||||
b = a3^a0; GF28_MUL2(b);
|
||||
*ptr++ = e ^ a3 ^ b;
|
||||
}
|
||||
|
||||
//for (uint8_t i = 0; i < 16; i++){
|
||||
// state[i] = AES_MULTIPLY_0E(rstate[(i&0xFC)+((i+0)&0b11)])
|
||||
// ^ AES_MULTIPLY_0B(rstate[(i&0xFC)+((i+1)&0b11)])
|
||||
// ^ AES_MULTIPLY_0D(rstate[(i&0xFC)+((i+2)&0b11)])
|
||||
// ^ AES_MULTIPLY_09(rstate[(i&0xFC)+((i+3)&0b11)]);
|
||||
//}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void AES_AddRoundKey (uint8_t *State, uint8_t *_key)
|
||||
{
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
State[i] ^= (_key[i]);
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void AES_InvShiftRows(uint8_t *state)
|
||||
{
|
||||
uint8_t ByteTmp1;
|
||||
uint8_t ByteTmp2;
|
||||
|
||||
//Do not loop!!! Otherwise bad performance
|
||||
ByteTmp1 = state[13];
|
||||
state[13] = state[9];
|
||||
state[9] = state[5];
|
||||
state[5] = state[1];
|
||||
state[1] = ByteTmp1;
|
||||
|
||||
ByteTmp1 = state[14];
|
||||
ByteTmp2 = state[10];
|
||||
state[14] = state[6];
|
||||
state[10] = state[2];
|
||||
state[6] = ByteTmp1;
|
||||
state[2] = ByteTmp2;
|
||||
|
||||
ByteTmp1 = state[3];
|
||||
state[3] = state[7];
|
||||
state[7] = state[11];
|
||||
state[11] = state[15];
|
||||
state[15] = ByteTmp1;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void AES_InvSubBytes(uint8_t *state)
|
||||
{
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
state[i] = flash_read_byte((AES_INV_SBOX),state[i]);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static uint8_t NextIV[16];
|
||||
|
||||
void AES_InvCipher(uint8_t *IN, uint8_t *w, uint8_t *IV)
|
||||
{
|
||||
uint8_t *state = IN;
|
||||
|
||||
_memcopy(IN,NextIV,16);
|
||||
|
||||
AES_AddRoundKey(state, &w[AES_NR_256BIT*AES_NB*4]);
|
||||
for (uint8_t I = (uint8_t)(AES_NR_256BIT-1); I > 0; I--)
|
||||
{
|
||||
AES_InvShiftRows(state);
|
||||
AES_InvSubBytes(state);
|
||||
AES_AddRoundKey(state, &w[I<<4]);
|
||||
AES_InvMixColumns(state);
|
||||
}
|
||||
AES_InvShiftRows(state);
|
||||
AES_InvSubBytes(state);
|
||||
AES_AddRoundKey(state, &w[0]);
|
||||
|
||||
AES_AddRoundKey(state, IV); //XOR output with IV
|
||||
|
||||
_memcopy(NextIV,IV,16);
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
uint8_t w[(uint8_t)(AES_NB * (uint8_t)(AES_NR_256BIT+1U))*4];
|
||||
|
||||
uint8_t IVstored[16];
|
||||
|
||||
void AES_Decrypt(uint8_t *InpData, uint16_t InpDataLength)
|
||||
{
|
||||
//if (KeyLength != AES_256) return; //Only AES CBC 256 is supported
|
||||
if ( (InpDataLength & 0b1111) != 0 ) { return; }
|
||||
|
||||
uint16_t DataPos = 0;
|
||||
while ( InpDataLength > 0 )
|
||||
{
|
||||
AES_InvCipher(&InpData[DataPos], w, IVstored);
|
||||
DataPos = (uint16_t)(DataPos + AES_BLOCK_SIZE);
|
||||
InpDataLength = (uint16_t)(InpDataLength - AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void AES_PrepareKeys(uint8_t *Key, uint8_t *IV){
|
||||
AES_KeyExpansion(Key, w);
|
||||
//AES_Copy(IV,IVstored);
|
||||
//for (uint8_t i = 0; i < 16; i++){
|
||||
// IVstored[i] = pgm_read_byte(&(IV[i]));
|
||||
//}
|
||||
_memcopy(IV,IVstored,16);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,36 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_AES_H_
|
||||
#define _INC_AES_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
//#include <string.h>
|
||||
//#include <avr/pgmspace.h>
|
||||
#include "SYSTEM.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define AES_NB 4U
|
||||
|
||||
#define AES_NK_256BIT 8U
|
||||
|
||||
#define AES_NR_256BIT 14U
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define AES_KEY_AES256_SIZE 32U
|
||||
|
||||
#define AES_BLOCK_SIZE 16U
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
enum AES_CIPHER_KEY_LENGTH {
|
||||
AES_128 = 0x00,
|
||||
AES_192, //UNSUPPORTED
|
||||
AES_256
|
||||
};
|
||||
*/
|
||||
//ONLY AES256 SUPPORTED!!!
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void AES_InvCipher(uint8_t *IN, uint8_t *w, uint8_t *IV);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void AES_Decrypt(uint8_t *InpData, uint16_t InpDataLength);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void AES_PrepareKeys(uint8_t *Key, uint8_t *IV);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif //_INC_AES_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,109 @@
|
||||
#include "CRCs.h"
|
||||
|
||||
uint16_t CRC16(uint8_t *data, uint16_t length)
|
||||
{
|
||||
uint16_t crc=0xFFFF;
|
||||
|
||||
for (uint16_t Mp=0; Mp<length; Mp++)
|
||||
{
|
||||
crc^=(uint16_t)data[Mp]; // XOR byte into least sig. byte of crc
|
||||
for (uint8_t Mi=8; Mi!=0; Mi--) // Loop over each bit
|
||||
{
|
||||
uint8_t tmp = (crc&0x0001);
|
||||
crc>>=1;
|
||||
if (tmp != 0) crc^=0xA001;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
#ifdef _FAT_CRC_
|
||||
|
||||
const uint32_t crc32Lookup[256] PROGMEM =
|
||||
{ 0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,
|
||||
0x0EDB8832,0x79DCB8A4,0xE0D5E91E,0x97D2D988,0x09B64C2B,0x7EB17CBD,0xE7B82D07,0x90BF1D91,
|
||||
0x1DB71064,0x6AB020F2,0xF3B97148,0x84BE41DE,0x1ADAD47D,0x6DDDE4EB,0xF4D4B551,0x83D385C7,
|
||||
0x136C9856,0x646BA8C0,0xFD62F97A,0x8A65C9EC,0x14015C4F,0x63066CD9,0xFA0F3D63,0x8D080DF5,
|
||||
0x3B6E20C8,0x4C69105E,0xD56041E4,0xA2677172,0x3C03E4D1,0x4B04D447,0xD20D85FD,0xA50AB56B,
|
||||
0x35B5A8FA,0x42B2986C,0xDBBBC9D6,0xACBCF940,0x32D86CE3,0x45DF5C75,0xDCD60DCF,0xABD13D59,
|
||||
0x26D930AC,0x51DE003A,0xC8D75180,0xBFD06116,0x21B4F4B5,0x56B3C423,0xCFBA9599,0xB8BDA50F,
|
||||
0x2802B89E,0x5F058808,0xC60CD9B2,0xB10BE924,0x2F6F7C87,0x58684C11,0xC1611DAB,0xB6662D3D,
|
||||
0x76DC4190,0x01DB7106,0x98D220BC,0xEFD5102A,0x71B18589,0x06B6B51F,0x9FBFE4A5,0xE8B8D433,
|
||||
0x7807C9A2,0x0F00F934,0x9609A88E,0xE10E9818,0x7F6A0DBB,0x086D3D2D,0x91646C97,0xE6635C01,
|
||||
0x6B6B51F4,0x1C6C6162,0x856530D8,0xF262004E,0x6C0695ED,0x1B01A57B,0x8208F4C1,0xF50FC457,
|
||||
0x65B0D9C6,0x12B7E950,0x8BBEB8EA,0xFCB9887C,0x62DD1DDF,0x15DA2D49,0x8CD37CF3,0xFBD44C65,
|
||||
0x4DB26158,0x3AB551CE,0xA3BC0074,0xD4BB30E2,0x4ADFA541,0x3DD895D7,0xA4D1C46D,0xD3D6F4FB,
|
||||
0x4369E96A,0x346ED9FC,0xAD678846,0xDA60B8D0,0x44042D73,0x33031DE5,0xAA0A4C5F,0xDD0D7CC9,
|
||||
0x5005713C,0x270241AA,0xBE0B1010,0xC90C2086,0x5768B525,0x206F85B3,0xB966D409,0xCE61E49F,
|
||||
0x5EDEF90E,0x29D9C998,0xB0D09822,0xC7D7A8B4,0x59B33D17,0x2EB40D81,0xB7BD5C3B,0xC0BA6CAD,
|
||||
0xEDB88320,0x9ABFB3B6,0x03B6E20C,0x74B1D29A,0xEAD54739,0x9DD277AF,0x04DB2615,0x73DC1683,
|
||||
0xE3630B12,0x94643B84,0x0D6D6A3E,0x7A6A5AA8,0xE40ECF0B,0x9309FF9D,0x0A00AE27,0x7D079EB1,
|
||||
0xF00F9344,0x8708A3D2,0x1E01F268,0x6906C2FE,0xF762575D,0x806567CB,0x196C3671,0x6E6B06E7,
|
||||
0xFED41B76,0x89D32BE0,0x10DA7A5A,0x67DD4ACC,0xF9B9DF6F,0x8EBEEFF9,0x17B7BE43,0x60B08ED5,
|
||||
0xD6D6A3E8,0xA1D1937E,0x38D8C2C4,0x4FDFF252,0xD1BB67F1,0xA6BC5767,0x3FB506DD,0x48B2364B,
|
||||
0xD80D2BDA,0xAF0A1B4C,0x36034AF6,0x41047A60,0xDF60EFC3,0xA867DF55,0x316E8EEF,0x4669BE79,
|
||||
0xCB61B38C,0xBC66831A,0x256FD2A0,0x5268E236,0xCC0C7795,0xBB0B4703,0x220216B9,0x5505262F,
|
||||
0xC5BA3BBE,0xB2BD0B28,0x2BB45A92,0x5CB36A04,0xC2D7FFA7,0xB5D0CF31,0x2CD99E8B,0x5BDEAE1D,
|
||||
0x9B64C2B0,0xEC63F226,0x756AA39C,0x026D930A,0x9C0906A9,0xEB0E363F,0x72076785,0x05005713,
|
||||
0x95BF4A82,0xE2B87A14,0x7BB12BAE,0x0CB61B38,0x92D28E9B,0xE5D5BE0D,0x7CDCEFB7,0x0BDBDF21,
|
||||
0x86D3D2D4,0xF1D4E242,0x68DDB3F8,0x1FDA836E,0x81BE16CD,0xF6B9265B,0x6FB077E1,0x18B74777,
|
||||
0x88085AE6,0xFF0F6A70,0x66063BCA,0x11010B5C,0x8F659EFF,0xF862AE69,0x616BFFD3,0x166CCF45,
|
||||
0xA00AE278,0xD70DD2EE,0x4E048354,0x3903B3C2,0xA7672661,0xD06016F7,0x4969474D,0x3E6E77DB,
|
||||
0xAED16A4A,0xD9D65ADC,0x40DF0B66,0x37D83BF0,0xA9BCAE53,0xDEBB9EC5,0x47B2CF7F,0x30B5FFE9,
|
||||
0xBDBDF21C,0xCABAC28A,0x53B39330,0x24B4A3A6,0xBAD03605,0xCDD70693,0x54DE5729,0x23D967BF,
|
||||
0xB3667A2E,0xC4614AB8,0x5D681B02,0x2A6F2B94,0xB40BBE37,0xC30C8EA1,0x5A05DF1B,0x2D02EF8D
|
||||
};
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
uint32_t CRC32(uint8_t* data, uint32_t length)
|
||||
#else
|
||||
//uint32_t CRC32(uint8_t* data, uint16_t length)
|
||||
#endif
|
||||
{
|
||||
uint32_t crc = (~(0));
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
uint32_t flashAddr = 0;
|
||||
#else
|
||||
//uint16_t flashAddr = 0;
|
||||
#endif
|
||||
|
||||
uint8_t offset;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
if (data != NULL) offset = ((uint8_t)crc) ^ *data++;
|
||||
else offset = ((uint8_t)crc) ^ pgm_read_byte_far(flashAddr++);
|
||||
|
||||
crc = (crc >> 8) ^ pgm_read_dword_far(pgm_get_far_address(crc32Lookup) + ((uint16_t)offset<<2));
|
||||
}
|
||||
|
||||
return ~crc; // same as crc ^ 0xFFFFFFFF
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
uint32_t CRC32(uint8_t* data, uint16_t length)
|
||||
{
|
||||
#define Polynomial 0xEDB88320
|
||||
uint32_t crc = 0xFFFFFFFF; // same as previousCrc32 ^ 0xFFFFFFFF
|
||||
uint16_t flashAddr = 0;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
if (data != NULL) crc ^= *data++; //Check data pointer
|
||||
else crc ^= pgm_read_byte(flashAddr++); //Check flash memory
|
||||
|
||||
for (uint8_t j = 0; j < 8; j++)
|
||||
{
|
||||
uint8_t lowestBit = crc & 1;
|
||||
crc >>= 1;
|
||||
if (lowestBit) crc ^= Polynomial;
|
||||
}
|
||||
}
|
||||
|
||||
return ~crc; // same as crc ^ 0xFFFFFFFF
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,19 @@
|
||||
#ifndef CRCS_H_
|
||||
#define CRCS_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
uint16_t CRC16(uint8_t *data, uint16_t length);
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
uint32_t CRC32(uint8_t* data, uint32_t length);
|
||||
#else
|
||||
uint32_t CRC32(uint8_t* data, uint16_t length);
|
||||
#endif
|
||||
|
||||
#endif /* CRCS_H_ */
|
@ -0,0 +1,13 @@
|
||||
#include "System.h"
|
||||
|
||||
void _memcopy(volatile uint8_t *src,volatile uint8_t *dest, uint16_t size) {
|
||||
for (uint16_t pos = 0; pos < size; pos++){
|
||||
dest[pos] = src[pos];
|
||||
}
|
||||
}
|
||||
|
||||
void System_SWReboot(){
|
||||
cli();
|
||||
wdt_enable(WDTO_15MS);
|
||||
while(1); //Dumb reset
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef SYSTEM_H_
|
||||
#define SYSTEM_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "config.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
#define flash_read_byte(x,y) pgm_read_byte_far(pgm_get_far_address(x)+y)
|
||||
#define flash_read_word(x,y) pgm_read_word_far(pgm_get_far_address(x)+y)
|
||||
#define flash_read_dword(x,y) pgm_read_dword_far(pgm_get_far_address(x)+y)
|
||||
#else
|
||||
#define flash_read_byte(x,y) pgm_read_byte((uint16_t)(&x)+y)
|
||||
#define flash_read_word(x,y) pgm_read_word((uint16_t)(&x)+y)
|
||||
#define flash_read_dword(x,y) pgm_read_dword((uint16_t)(&x)+y)
|
||||
#endif
|
||||
|
||||
//#define NULL 0
|
||||
|
||||
void _memcopy(volatile uint8_t *src,volatile uint8_t *dest, uint16_t size);
|
||||
void System_SWReboot();
|
||||
|
||||
|
||||
#endif /* SYSTEM_H_ */
|
@ -0,0 +1,29 @@
|
||||
#ifndef BOOT_H_
|
||||
#define BOOT_H_
|
||||
|
||||
typedef struct {
|
||||
uint8_t Status;
|
||||
uint8_t Reason;
|
||||
int16_t BlockNumber;
|
||||
} BOOTLOADER_INFO;
|
||||
|
||||
#define FMW_INFO_SIZE 32
|
||||
|
||||
typedef struct {
|
||||
//[BLOCK 1]
|
||||
uint16_t FmwHash[2]; //CRC32
|
||||
uint16_t FmwSizeInPages;
|
||||
uint8_t ModuleType[3];
|
||||
uint8_t HwRevision[2];
|
||||
uint8_t Reserved1[5];
|
||||
//[BLOCK 2]
|
||||
uint16_t SwVersion; //uint8_t[2]
|
||||
uint8_t Reserved2[10];
|
||||
uint32_t InfoHash;
|
||||
} FMW_INFO;
|
||||
|
||||
volatile uint8_t AES_DISABLED; //Bootloader AES Decription disabled flag (if non-zero AES is disabled)
|
||||
BOOTLOADER_INFO BootloaderInfo;// = {.Status = 0, .Reason = 0, .BlockNumber = -1};
|
||||
FMW_INFO FmwInfo;
|
||||
|
||||
#endif /* BOOT_H_ */
|
@ -0,0 +1,242 @@
|
||||
#include "bootFunctions.h"
|
||||
|
||||
#include "Common/MEMORY.h"
|
||||
#include "EEMEM.h"
|
||||
#include "keys.h"
|
||||
|
||||
uint8_t CheckFirmware(){
|
||||
boot_rww_enable_safe();
|
||||
uint32_t crcRead = flash_read_dword(STATIC_DATA_APP.AppCRC,0);
|
||||
uint32_t crcCalc = CRC32(NULL,locationInApp<<1);
|
||||
if (crcRead != crcCalc) return IDIFMW_REASON_NoFmwDetected;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t CheckEEPROMFlag(){
|
||||
eeprom_busy_wait();
|
||||
uint8_t flag = eeprom_read_byte(&(EEBLOCK.BOOTFLAG));
|
||||
if (flag != 0xFF) return IDIFMW_REASON_EnterFromApplication;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline uint8_t CheckADDR(){
|
||||
if (RS_Address == IDIBUS_DEVELOPER_ADDR_3) return IDIFMW_REASON_EnterForced;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void DisableAES(){
|
||||
AES_DISABLED = 1;
|
||||
}
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
uint32_t baseAddr;
|
||||
#else
|
||||
uint16_t baseAddr;
|
||||
#endif
|
||||
|
||||
void BootloaderDataHandler(){
|
||||
wdt_reset();
|
||||
boot_spm_busy_wait();
|
||||
if (BootloaderInfo.BlockNumber == -1) {
|
||||
|
||||
if (AES_DISABLED == 0) {
|
||||
AES_PrepareKeys(key,IV);
|
||||
AES_Decrypt(BootloaderData,FMW_INFO_SIZE);
|
||||
}
|
||||
|
||||
_memcopy(BootloaderData,&FmwInfo,FMW_INFO_SIZE);
|
||||
uint32_t calculatedCRC = CRC32(&FmwInfo,FMW_INFO_SIZE-CRC32_SIZE);
|
||||
|
||||
uint8_t Check = 1;
|
||||
|
||||
if (calculatedCRC != FmwInfo.InfoHash) {
|
||||
Check = 0;
|
||||
}
|
||||
|
||||
if (FmwInfo.FmwSizeInPages >= PAGE_COUNT) {
|
||||
Check = 0;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < IDISN_FIXP_MODULE_TYPE_Length; i++)
|
||||
{
|
||||
if (flash_read_byte(STATIC_DATA_BL.ModuleType,i) != FmwInfo.ModuleType[i]) Check = 0;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < IDISN_FIXP_HW_REV_Length; i++)
|
||||
{
|
||||
if (flash_read_byte(STATIC_DATA_BL.HW_revision,i) != FmwInfo.HwRevision[i]) Check = 0;
|
||||
}
|
||||
|
||||
if (Check == 0) {
|
||||
BootloaderInfo.Status = IDIFMW_STATUS_IncompatibleFmw;
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint16_t page = 0; page < PAGE_COUNT; page++){
|
||||
boot_spm_busy_wait();
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
boot_page_erase(((uint32_t)page)<<PAGE_SIZE_BIT);
|
||||
#else
|
||||
boot_page_erase(page<<PAGE_SIZE_BIT);
|
||||
#endif
|
||||
wdt_reset();
|
||||
}
|
||||
} else {
|
||||
|
||||
if (AES_DISABLED == 0)
|
||||
AES_Decrypt(BootloaderData,PAGE_SIZE);
|
||||
|
||||
//Fill page
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
baseAddr = ((uint32_t)BootloaderInfo.BlockNumber)<<PAGE_SIZE_BIT;
|
||||
#else
|
||||
baseAddr = (BootloaderInfo.BlockNumber)<<PAGE_SIZE_BIT;
|
||||
#endif
|
||||
|
||||
//boot_rww_enable_safe();
|
||||
|
||||
//BE CAREFUL
|
||||
wdt_reset();
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
for (uint16_t counter = 0; counter < PAGE_SIZE; counter+=2, baseAddr+=2)
|
||||
#else
|
||||
for (uint8_t counter = 0; counter < PAGE_SIZE; counter+=2, baseAddr+=2)
|
||||
#endif
|
||||
{
|
||||
uint16_t word = *((uint16_t *)&BootloaderData[counter]);
|
||||
boot_page_fill(baseAddr,word);
|
||||
}
|
||||
|
||||
baseAddr-=PAGE_SIZE;
|
||||
|
||||
//Write page
|
||||
boot_spm_busy_wait();
|
||||
boot_page_write(baseAddr);
|
||||
}
|
||||
|
||||
BootloaderInfo.BlockNumber++;
|
||||
|
||||
if (BootloaderInfo.BlockNumber == FmwInfo.FmwSizeInPages){
|
||||
/*Write personal info*/
|
||||
|
||||
wdt_reset();
|
||||
|
||||
boot_spm_busy_wait();
|
||||
//boot_rww_enable();
|
||||
|
||||
baseAddr = locationInApp<<1;
|
||||
|
||||
boot_rww_enable();
|
||||
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
for (uint16_t counter = 0; counter < PAGE_SIZE; counter+=2, baseAddr+=2)
|
||||
#else
|
||||
for (uint8_t counter = 0; counter < PAGE_SIZE; counter+=2, baseAddr+=2)
|
||||
#endif
|
||||
{
|
||||
uint16_t word;
|
||||
if (counter < IDISN_FIXP_SW_REV_Pos)
|
||||
word = flash_read_word(STATIC_DATA_BL,counter);
|
||||
else if (counter < IDISN_FIXP_SW_REV_Pos+IDISN_FIXP_SW_REV_Length)
|
||||
word = FmwInfo.SwVersion;
|
||||
else if (counter < IDISN_FIXP_SW_REV_Pos+CRC32_SIZE)
|
||||
word = FmwInfo.FmwHash[0];
|
||||
else if (counter < IDISN_FIXP_SW_REV_Pos+IDISN_FIXP_SW_REV_Length+CRC32_SIZE)
|
||||
word = FmwInfo.FmwHash[1];
|
||||
else
|
||||
word = 0xFFFF;
|
||||
|
||||
boot_page_fill(baseAddr,word);
|
||||
}
|
||||
|
||||
baseAddr-=PAGE_SIZE;
|
||||
|
||||
boot_spm_busy_wait();
|
||||
boot_page_write(baseAddr);
|
||||
boot_spm_busy_wait();
|
||||
|
||||
wdt_reset();
|
||||
|
||||
if (CheckFirmware() == 0){
|
||||
BootloaderInfo.Reason &= ~(IDIFMW_REASON_NoFmwDetected);
|
||||
BootloaderInfo.Status = IDIFMW_STATUS_FmwUploadComplete;
|
||||
} else {
|
||||
BootloaderInfo.Status = IDIFMW_STATUS_FmwUploadCRCError;
|
||||
}
|
||||
}
|
||||
else
|
||||
BootloaderInfo.Status = IDIFMW_STATUS_ReadyToGetBlock;
|
||||
}
|
||||
|
||||
void LaunchApplication() {
|
||||
//After flash remove boot flag from eeprom
|
||||
if (CheckEEPROMFlag() != 0) eeprom_write_byte(&EEBLOCK.BOOTFLAG, 0xff);
|
||||
|
||||
eeprom_busy_wait();
|
||||
|
||||
MCUCR=(1<<IVCE);
|
||||
MCUCR=(0<<IVSEL);
|
||||
|
||||
boot_rww_enable_safe(); // enable application section
|
||||
|
||||
asm volatile(
|
||||
//Clear SRAM
|
||||
//Should work needs testing
|
||||
"clr r28 \n\t"
|
||||
"LDI r30, %0 \n\t"
|
||||
"LDI r31, %1 \n\t"
|
||||
"CLEAR_%=: \n\t"
|
||||
"adiw r30, 1 \n\t"
|
||||
"st Z, r28 \n\t"
|
||||
"cpi r30, %2 \n\t"
|
||||
"ldi r29, %3 \n\t"
|
||||
"cpc r31, r29 \n\t"
|
||||
"BRNE CLEAR_%= \n\t"
|
||||
//Jmp to app
|
||||
"clr r30 \n\t"
|
||||
"clr r31 \n\t"
|
||||
"ijmp \n\t"
|
||||
://No output
|
||||
:"M" (RAMSTART&0xFF), "M" (RAMSTART>>8), "M" (RAMEND&0xFF), "M" (RAMEND>>8));
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
void FindBootloaderEnterReason(){
|
||||
BootloaderInfo.Reason = 0;
|
||||
BootloaderInfo.Reason |= CheckFirmware();
|
||||
BootloaderInfo.Reason |= CheckEEPROMFlag();
|
||||
BootloaderInfo.Reason |= CheckADDR();
|
||||
}
|
||||
|
||||
void GetBootloaderInfo(volatile uint8_t *dst){
|
||||
for (uint8_t i = IDISN_FIXP_MODULE_TYPE_Pos; i < IDISN_FIXP_MAC_Pos; i++){
|
||||
*dst++ = flash_read_byte(STATIC_DATA_BL,i);
|
||||
}
|
||||
*dst++ = flash_read_byte(STATIC_DATA_BL,IDISN_FIXP_SW_REV_Pos);
|
||||
*dst++ = flash_read_byte(STATIC_DATA_BL,IDISN_FIXP_SW_REV_Pos+1);
|
||||
|
||||
*dst++ = BootloaderInfo.Reason;
|
||||
*dst = AES_DISABLED;
|
||||
}
|
||||
|
||||
uint16_t GetNextBlockSize(){
|
||||
if (BootloaderInfo.Status < IDIFMW_STATUS_Busy){
|
||||
if (BootloaderInfo.BlockNumber != -1) {
|
||||
return PAGE_SIZE;
|
||||
} else {
|
||||
return FMW_INFO_SIZE;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GetBootloaderStatus(volatile uint8_t *dst){
|
||||
*dst++ = BootloaderInfo.Status;
|
||||
uint16_t BlockSize = GetNextBlockSize();
|
||||
*dst++ = (uint8_t)(BlockSize>>8);
|
||||
*dst++ = (uint8_t)BlockSize;
|
||||
*dst++ = (uint8_t)(BootloaderInfo.BlockNumber>>8);
|
||||
*dst = (uint8_t)BootloaderInfo.BlockNumber;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef BOOTFUNCTIONS_H_
|
||||
#define BOOTFUNCTIONS_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "boot.h"
|
||||
#include "IDIBUS_BOOTLOADER_DEFS.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <avr/boot.h>
|
||||
#include <avr/wdt.h>
|
||||
#include "System.h"
|
||||
#include "RSLink.h"
|
||||
#include "AES.h"
|
||||
|
||||
void FindBootloaderEnterReason();
|
||||
|
||||
uint8_t BootloaderData[PAGE_SIZE];
|
||||
|
||||
void BootloaderDataHandler();
|
||||
|
||||
void LaunchApplication();
|
||||
|
||||
void GetBootloaderInfo(volatile uint8_t *dst);
|
||||
void GetBootloaderStatus(volatile uint8_t *dst);
|
||||
uint16_t GetNextBlockSize();
|
||||
void DisableAES();
|
||||
|
||||
#endif /* BOOTFUNCTIONS_H_ */
|
@ -0,0 +1,373 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
|
||||
<avrdevice>ATmega2560</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>idiBUS_bootloader</AssemblyName>
|
||||
<Name>idiBUS_bootloader_2560</Name>
|
||||
<RootNamespace>idiBUS_bootloader</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
||||
<avrtoolserialnumber>J41800094359</avrtoolserialnumber>
|
||||
<avrdeviceexpectedsignature>0x1E9801</avrdeviceexpectedsignature>
|
||||
<com_atmel_avrdbg_tool_atmelice>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<JtagDbgClock>200000</JtagDbgClock>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
||||
<ToolNumber>J41800094359</ToolNumber>
|
||||
<ToolName>Atmel-ICE</ToolName>
|
||||
</com_atmel_avrdbg_tool_atmelice>
|
||||
<avrtoolinterface>ISP</avrtoolinterface>
|
||||
<avrtoolinterfaceclock>200000</avrtoolinterfaceclock>
|
||||
<com_atmel_avrdbg_tool_simulator>
|
||||
<ToolOptions xmlns="">
|
||||
<InterfaceProperties>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
|
||||
<ToolNumber xmlns="">
|
||||
</ToolNumber>
|
||||
<ToolName xmlns="">Simulator</ToolName>
|
||||
</com_atmel_avrdbg_tool_simulator>
|
||||
<com_atmel_avrdbg_tool_stk500>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.stk500</ToolType>
|
||||
<ToolNumber>
|
||||
</ToolNumber>
|
||||
<ToolName>STK500</ToolName>
|
||||
</com_atmel_avrdbg_tool_stk500>
|
||||
<custom>
|
||||
<ToolOptions xmlns="">
|
||||
<InterfaceProperties>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType xmlns="">custom</ToolType>
|
||||
<ToolNumber xmlns="">
|
||||
</ToolNumber>
|
||||
<ToolName xmlns="">Custom Programming Tool</ToolName>
|
||||
</custom>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release 2560' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega2560 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega2560"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA2560_</Value>
|
||||
<Value>_BOOTLOADER_</Value>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../SysCommon</Value>
|
||||
<Value>../idiBus</Value>
|
||||
<Value>../CustomHWDefines</Value>
|
||||
<Value>../bootloader</Value>
|
||||
<Value>..</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../../personalizationFiles</Value>
|
||||
<Value>../../../moduleFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.Verbose>False</avrgcc.compiler.miscellaneous.Verbose>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>False</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>False</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x1F000</Value>
|
||||
<Value>.locationInBoot=0x1FF80</Value>
|
||||
<Value>.locationInApp=0x1EF80</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug 2560' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega2560 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega2560"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA2560_</Value>
|
||||
<Value>_BOOTLOADER_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
<Value>_CPU_ATMEGA328PB_D</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../SysCommon</Value>
|
||||
<Value>../idiBus</Value>
|
||||
<Value>../CustomHWDefines</Value>
|
||||
<Value>../bootloader</Value>
|
||||
<Value>..</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../../personalizationFiles</Value>
|
||||
<Value>../../../moduleFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.Verbose>True</avrgcc.compiler.miscellaneous.Verbose>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x1F000</Value>
|
||||
<Value>.locationInBoot=0x1FF80</Value>
|
||||
<Value>.locationInApp=0x1EF80</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Cutter_2560' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega2560 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega2560"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA2560_</Value>
|
||||
<Value>_BOOTLOADER_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
<Value>_CPU_ATMEGA328PB_D</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../SysCommon</Value>
|
||||
<Value>../idiBus</Value>
|
||||
<Value>../CustomHWDefines</Value>
|
||||
<Value>../bootloader</Value>
|
||||
<Value>..</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../../personalizationFiles</Value>
|
||||
<Value>../../../moduleFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.Verbose>True</avrgcc.compiler.miscellaneous.Verbose>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x1F000</Value>
|
||||
<Value>.locationInBoot=0x1FF80</Value>
|
||||
<Value>.locationInApp=0x1EF80</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputPath>bin\Cutter_Debug\</OutputPath>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>start "ahk" "$(CUTTER)\cutterStart.ahk"
|
||||
start "cutter_cmd" /B "$(CUTTER)\cutter.exe" "$(OutputDirectory)\$(OutputFileName).elf"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\moduleFiles\EEMEM.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>SysCommon\EEMEM.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\idiBusFiles\RSLinkCustom.c">
|
||||
<SubType>compile</SubType>
|
||||
<Link>CustomHWDefines\RSLinkCustom.c</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\idiBusFiles\RSLinkCustom.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>CustomHWDefines\RSLinkCustom.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\personalizationFiles\config.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>config.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\personalizationFiles\keys.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>keys.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="bootloader\boot.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="bootloader\bootFunctions.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="bootloader\bootFunctions.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BootVersion.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CustomHWDefines\m2560_defs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\Common\IDIBUS_DEFS.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>idiBus\IDIBUS_DEFS.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\Common\MEMORY.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>idiBus\MEMORY.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\IDIBUS_BOOTLOADER_DEFS.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\IDIBUS_IMPL.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\IDIBUS_IMPL.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\RSLink.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\RSLink.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\USART1.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\USART1.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\USART_COM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="main.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\AES.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\AES.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\CRCs.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\CRCs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\System.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\System.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="CustomHWDefines\" />
|
||||
<Folder Include="SysCommon" />
|
||||
<Folder Include="idiBus" />
|
||||
<Folder Include="bootloader" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\personalizationFiles\device.cfg">
|
||||
<SubType>compile</SubType>
|
||||
<Link>device.cfg</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
@ -0,0 +1,385 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad899</ProjectGuid>
|
||||
<avrdevice>ATmega328PB</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>idiBUS_bootloader</AssemblyName>
|
||||
<Name>idiBUS_bootloader_2560</Name>
|
||||
<RootNamespace>idiBUS_bootloader</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
||||
<avrtoolserialnumber>J41800094359</avrtoolserialnumber>
|
||||
<avrdeviceexpectedsignature>0x1E9516</avrdeviceexpectedsignature>
|
||||
<com_atmel_avrdbg_tool_atmelice>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<JtagDbgClock>1609087</JtagDbgClock>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
||||
<ToolNumber>J41800094359</ToolNumber>
|
||||
<ToolName>Atmel-ICE</ToolName>
|
||||
</com_atmel_avrdbg_tool_atmelice>
|
||||
<avrtoolinterface>ISP</avrtoolinterface>
|
||||
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
||||
<com_atmel_avrdbg_tool_simulator>
|
||||
<ToolOptions xmlns="">
|
||||
<InterfaceProperties>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
|
||||
<ToolNumber xmlns="">
|
||||
</ToolNumber>
|
||||
<ToolName xmlns="">Simulator</ToolName>
|
||||
</com_atmel_avrdbg_tool_simulator>
|
||||
<com_atmel_avrdbg_tool_stk500>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>0</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.stk500</ToolType>
|
||||
<ToolNumber>
|
||||
</ToolNumber>
|
||||
<ToolName>STK500</ToolName>
|
||||
</com_atmel_avrdbg_tool_stk500>
|
||||
<custom>
|
||||
<ToolOptions xmlns="">
|
||||
<InterfaceProperties>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType xmlns="">custom</ToolType>
|
||||
<ToolNumber xmlns="">
|
||||
</ToolNumber>
|
||||
<ToolName xmlns="">Custom Programming Tool</ToolName>
|
||||
</custom>
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.47.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Release_328pb' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>_BOOTLOADER_</Value>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../SysCommon</Value>
|
||||
<Value>../idiBus</Value>
|
||||
<Value>../CustomHWDefines</Value>
|
||||
<Value>../bootloader</Value>
|
||||
<Value>..</Value>
|
||||
<Value>../../../personalizationFiles</Value>
|
||||
<Value>../../../moduleFiles</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.Verbose>False</avrgcc.compiler.miscellaneous.Verbose>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>False</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>False</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
<Value>.locationInBoot=0x3FE8</Value>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Debug_328pb' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>_BOOTLOADER_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
<Value>_CPU_ATMEGA328PB_D</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../SysCommon</Value>
|
||||
<Value>../idiBus</Value>
|
||||
<Value>../CustomHWDefines</Value>
|
||||
<Value>../bootloader</Value>
|
||||
<Value>..</Value>
|
||||
<Value>../../../personalizationFiles</Value>
|
||||
<Value>../../../moduleFiles</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.Verbose>True</avrgcc.compiler.miscellaneous.Verbose>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
<Value>.locationInBoot=0x3FE8</Value>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Cutter_328pb' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>_BOOTLOADER_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
<Value>_CPU_ATMEGA328PB_D</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../SysCommon</Value>
|
||||
<Value>../idiBus</Value>
|
||||
<Value>../CustomHWDefines</Value>
|
||||
<Value>../bootloader</Value>
|
||||
<Value>..</Value>
|
||||
<Value>../../../personalizationFiles</Value>
|
||||
<Value>../../../moduleFiles</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.Verbose>True</avrgcc.compiler.miscellaneous.Verbose>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
<Value>.locationInBoot=0x3FE8</Value>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputPath>bin\Cutter_Debug\</OutputPath>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>start "ahk" "$(CUTTER)\cutterStart.ahk"
|
||||
start "cutter_cmd" /B "$(CUTTER)\cutter.exe" "$(OutputDirectory)\$(OutputFileName).elf"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\moduleFiles\EEMEM.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>SysCommon\EEMEM.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\idiBusFiles\RSLinkCustom.c">
|
||||
<SubType>compile</SubType>
|
||||
<Link>CustomHWDefines\RSLinkCustom.c</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\idiBusFiles\RSLinkCustom.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>CustomHWDefines\RSLinkCustom.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\personalizationFiles\config.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>config.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\personalizationFiles\keys.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>keys.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="bootloader\boot.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="bootloader\bootFunctions.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="bootloader\bootFunctions.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BootVersion.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CustomHWDefines\m2560_defs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\Common\IDIBUS_DEFS.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>idiBus\IDIBUS_DEFS.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\Common\MEMORY.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>idiBus\MEMORY.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\IDIBUS_BOOTLOADER_DEFS.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\IDIBUS_IMPL.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\IDIBUS_IMPL.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\RSLink.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\RSLink.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\USART1.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\USART1.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBus\USART_COM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="main.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\AES.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\AES.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\CRCs.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\CRCs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\System.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysCommon\System.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="CustomHWDefines\" />
|
||||
<Folder Include="SysCommon" />
|
||||
<Folder Include="idiBus" />
|
||||
<Folder Include="bootloader" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\personalizationFiles\device.cfg">
|
||||
<SubType>compile</SubType>
|
||||
<Link>device.cfg</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
@ -0,0 +1,456 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_IDIBUS_DEFS_H_
|
||||
#define _INC_IDIBUS_DEFS_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define F_CPU 16000000UL
|
||||
#define MODBUS_CRC16_SIZE 2
|
||||
#define CRC32_SIZE 4
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_19200B 0x00
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_500K 0x01
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_2400B 0x02
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_9600B 0x03
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_115200B 0x04
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_250K 0x05
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_1M 0x06
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_10M 0x07
|
||||
|
||||
// Full timeout will be (InterframeTimeout + ResponseTimeout) for request(Write + Read) or InterframeTimeout for write(Write only)
|
||||
#define IDIBUS_2400B_INTERFRAME_TIMEOUT_US 16042ULL //11 * 3.5 / Baudrate
|
||||
#define IDIBUS_9600B_INTERFRAME_TIMEOUT_US 4011ULL
|
||||
#define IDIBUS_19200B_INTERFRAME_TIMEOUT_US 2006ULL
|
||||
#define IDIBUS_115200B_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_250K_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_500K_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_1M_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_10M_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
|
||||
#define IDIBUS_2400B_ALARM_TIMEOUT_US 34375ULL //11 * 3.5 / Baudrate
|
||||
#define IDIBUS_9600B_ALARM_TIMEOUT_US 8594ULL
|
||||
#define IDIBUS_19200B_ALARM_TIMEOUT_US 4297ULL
|
||||
#define IDIBUS_115200B_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_250K_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_500K_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_1M_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_10M_ALARM_TIMEOUT_US 1750ULL
|
||||
|
||||
#define IDIBUS_2400B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_2400B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_9600B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_9600B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_19200B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_19200B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_115200B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_115200B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_250K_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_250K_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_500K_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_500K_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_1M_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_1M_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_10M_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_10M_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
|
||||
#define IDIBUS_2400B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_2400B_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_9600B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_9600B_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_19200B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_19200B_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_115200B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_115200B_INTERFRAME_TIMEOUT_US)
|
||||
#define IDIBUS_250K_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_250K_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_500K_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_500K_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_1M_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_1M_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_10M_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_10M_INTERFRAME_TIMEOUT_US )
|
||||
|
||||
|
||||
enum IDIBUS_SERIAL_BAUDRATE {
|
||||
IDIBUS_BAUDRATE_2400 = IDIBUS_BAUDRATE_DSW_CODE_2400B,
|
||||
IDIBUS_BAUDRATE_9600 = IDIBUS_BAUDRATE_DSW_CODE_9600B,
|
||||
IDIBUS_BAUDRATE_19200 = IDIBUS_BAUDRATE_DSW_CODE_19200B,
|
||||
IDIBUS_BAUDRATE_115200 = IDIBUS_BAUDRATE_DSW_CODE_115200B,
|
||||
IDIBUS_BAUDRATE_250K = IDIBUS_BAUDRATE_DSW_CODE_250K,
|
||||
IDIBUS_BAUDRATE_500K = IDIBUS_BAUDRATE_DSW_CODE_500K,
|
||||
IDIBUS_BAUDRATE_1M = IDIBUS_BAUDRATE_DSW_CODE_1M,
|
||||
IDIBUS_BAUDRATE_10M = IDIBUS_BAUDRATE_DSW_CODE_10M
|
||||
};
|
||||
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_SEC 60U
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_MS ( IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_SEC * 1000U )
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_SEC 15U
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_MS ( IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_SEC * 1000U )
|
||||
|
||||
enum IDIBUS_RXTIMER_TIMEOUT_MODE {
|
||||
IDIBUS_TIMER_MODE_RX_TIMEOUT = 0x00,
|
||||
IDIBUS_TIMER_MODE_ALARM_TIMEOUT,
|
||||
IDIBUS_TIMER_MODE_RESPONSE_TIMEOUT
|
||||
};
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDISN_FIXP_Pos 1U //Internal padding
|
||||
#define IDISN_FIXP_GS1_COUNTRY_Pos ( IDISN_FIXP_Pos + 0U)
|
||||
#define IDISN_FIXP_GS1_COUNTRY_Length 3
|
||||
#define IDISN_FIXP_GS1_COMPANY_Pos ( IDISN_FIXP_GS1_COUNTRY_Pos + IDISN_FIXP_GS1_COUNTRY_Length )
|
||||
#define IDISN_FIXP_GS1_COMPANY_Length 6
|
||||
#define IDISN_FIXP_MODULE_TYPE_Pos ( IDISN_FIXP_GS1_COMPANY_Pos + IDISN_FIXP_GS1_COMPANY_Length )
|
||||
#define IDISN_FIXP_MODULE_TYPE_Length 3
|
||||
#define IDISN_FIXP_HW_REV_Pos ( IDISN_FIXP_MODULE_TYPE_Pos + IDISN_FIXP_MODULE_TYPE_Length )
|
||||
#define IDISN_FIXP_HW_REV_Length 2
|
||||
#define IDISN_FIXP_SERIAL_Pos ( IDISN_FIXP_HW_REV_Pos + IDISN_FIXP_HW_REV_Length )
|
||||
#define IDISN_FIXP_SERIAL_Length 7
|
||||
#define IDISN_FIXP_MAC_Pos ( IDISN_FIXP_SERIAL_Pos + IDISN_FIXP_SERIAL_Length )
|
||||
#define IDISN_FIXP_MAC_Length 6
|
||||
#define IDISN_FIXP_SW_REV_Pos ( IDISN_FIXP_MAC_Pos + IDISN_FIXP_MAC_Length )
|
||||
#define IDISN_FIXP_SW_REV_Length 2
|
||||
#define IDISN_FIXP_LENGTH ( IDISN_FIXP_GS1_COUNTRY_Length + IDISN_FIXP_GS1_COMPANY_Length + IDISN_FIXP_MODULE_TYPE_Length + \
|
||||
IDISN_FIXP_HW_REV_Length + IDISN_FIXP_SERIAL_Length + IDISN_FIXP_MAC_Length + IDISN_FIXP_SW_REV_Length )
|
||||
|
||||
#define IDISN_VARP_Pos 0 //IDISN_FIXP_LENGTH
|
||||
#define IDISN_VARP_VERIF_DATE_Pos ( IDISN_VARP_Pos )
|
||||
#define IDISN_VARP_VERIF_DATE_Length 4U
|
||||
#define IDISN_VARP_EXPIR_DATE_Pos ( IDISN_VARP_VERIF_DATE_Pos + IDISN_VARP_VERIF_DATE_Length )
|
||||
#define IDISN_VARP_EXPIR_DATE_Length 4U
|
||||
#define IDISN_VARP_IPv4_Pos ( IDISN_VARP_EXPIR_DATE_Pos + IDISN_VARP_EXPIR_DATE_Length )
|
||||
#define IDISN_VARP_IPv4_Length 4U
|
||||
#define IDISN_VARP_IPv6_Pos ( IDISN_VARP_IPv4_Pos + IDISN_VARP_IPv4_Length )
|
||||
#define IDISN_VARP_IPv6_Length 16U
|
||||
#define IDISN_VARP_AES256_Pos ( IDISN_VARP_IPv6_Pos + IDISN_VARP_IPv6_Length )
|
||||
#define IDISN_VARP_AES256_Length 32U
|
||||
#define IDISN_VARP_LENGTH ( IDISN_VARP_VERIF_DATE_Length + IDISN_VARP_EXPIR_DATE_Length + \
|
||||
IDISN_VARP_IPv4_Length + IDISN_VARP_IPv6_Length + IDISN_VARP_AES256_Length )
|
||||
|
||||
#define IDISN_FULL_LENGTH ( IDISN_FIXP_LENGTH + IDISN_VARP_LENGTH )
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define ISIBUS_MASTER_MAIN_ADDR 255U
|
||||
#define ISIBUS_MASTER_SPARE_ADDR 254U
|
||||
#define IDIBUS_SLAVE_ADDR_MIN 1U
|
||||
#define IDIBUS_SLAVE_ADDR_MAX 229U
|
||||
#define IDIBUS_DEVELOPER_ADDR_0 250U
|
||||
#define IDIBUS_DEVELOPER_ADDR_1 251U
|
||||
#define IDIBUS_DEVELOPER_ADDR_2 252U
|
||||
#define IDIBUS_DEVELOPER_ADDR_3 253U
|
||||
#define IDIBUS_GROUP_0_ADDR 230U
|
||||
#define IDIBUS_GROUP_1_ADDR 231U
|
||||
#define IDIBUS_GROUP_2_ADDR 232U
|
||||
#define IDIBUS_GROUP_3_ADDR 233U
|
||||
#define IDIBUS_GROUP_4_ADDR 234U
|
||||
#define IDIBUS_GROUP_5_ADDR 235U
|
||||
#define IDIBUS_GROUP_6_ADDR 236U
|
||||
#define IDIBUS_GROUP_7_ADDR 237U
|
||||
#define IDIBUS_GROUP_8_ADDR 238U
|
||||
#define IDIBUS_GROUP_9_ADDR 239U
|
||||
#define IDIBUS_GROUP_10_ADDR 240U
|
||||
#define IDIBUS_GROUP_11_ADDR 241U
|
||||
#define IDIBUS_GROUP_12_ADDR 242U
|
||||
#define IDIBUS_GROUP_13_ADDR 243U
|
||||
#define IDIBUS_GROUP_14_ADDR 244U
|
||||
#define IDIBUS_GROUP_15_ADDR 245U
|
||||
|
||||
#define IDIBUS_GROUPS_NUMBER 16U
|
||||
#define IDIBUS_GROUP_FIRST_NUMBER 0U
|
||||
#define IDIBUS_GROUP_LAST_NUMBER 15U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIMMES_ADDR_Pos 00U
|
||||
#define IDIMMES_MMPS_Pos 01U
|
||||
#define IDIMMES_MMPS_LONG_MES_Pos 0U
|
||||
#define IDIMMES_MMPS_LONG_MES_Msk 0x01U
|
||||
#define IDIMMES_MMPS_MES_TYPE_Pos 1U
|
||||
#define IDIMMES_MMPS_MES_TYPE_Msk 0x02U
|
||||
#define IDIMMES_MMPS_MES_TYPE_MMES 0x00U
|
||||
#define IDIMMES_MMPS_MES_TYPE_MMESG 0x01U
|
||||
#define IDIMMES_MMPS_FAST_FUNC_Pos 2U
|
||||
#define IDIMMES_MMPS_FAST_FUNC_Msk 0x3CU
|
||||
#define IDIMMES_MMPS_ALARM_FRAME_Pos 6U
|
||||
#define IDIMMES_MMPS_ALARM_FRAME_Msk 0x40U
|
||||
#define IDIMMES_MMPS_ENCRYPTED_AES_Pos 7U
|
||||
#define IDIMMES_MMPS_ENCRYPTED_AES_Msk 0x80U
|
||||
#define IDIMMES_DEV_Pos 02U
|
||||
#define IDIMMES_DEV_NUM_Pos 0U
|
||||
#define IDIMMES_DEV_NUM_Msk 0x1FU
|
||||
#define IDIMMES_DEV_ALLCH_Pos 5U
|
||||
#define IDIMMES_DEV_ALLCH_Msk 0x20U
|
||||
#define IDIMMES_CHNL_Pos 03U
|
||||
#define IDIMMES_CHNL_NUM_Pos 0U
|
||||
#define IDIMMES_CHNL_NUM_Msk 0x7FU
|
||||
#define IDIMMES_CHNL_ALLSAME_Pos 7U
|
||||
#define IDIMMES_CHNL_ALLSAME_Msk 0x80U
|
||||
#define IDIMMES_DATA_FUNC_COM_DATA_Pos 04U
|
||||
#define IDIMMES_MAX_HEADER_LENGTH (IDIMMES_DATA_FUNC_COM_DATA_Pos + 1)
|
||||
#define IDIMMES_MAX_DATA_SIZE 256U
|
||||
#define IDIMMES_MAX_MES_SIZE (IDIMMES_MAX_DATA_SIZE + IDIMMES_MAX_HEADER_LENGTH + MODBUS_CRC16_SIZE)
|
||||
#define IDIMMES_MIN_MES_SIZE (IDIMMES_DATA_FUNC_COM_DATA_Pos + MODBUS_CRC16_SIZE)
|
||||
|
||||
#define IDIMMESG_DATA_COM_FUNC_Pos 02U
|
||||
#define IDIMMESG_MAX_HEADER_LENGTH (IDIMMESG_DATA_COM_FUNC_Pos + 1)
|
||||
#define IDIMMESG_MAX_DATA_SIZE IDIMMES_MAX_DATA_SIZE
|
||||
#define IDIMMESG_MAX_MES_SIZE (IDIMMESG_MAX_DATA_SIZE + IDIMMESG_MAX_HEADER_LENGTH + MODBUS_CRC16_SIZE)
|
||||
#define IDIMMESG_MODULE_MIN_MES_SIZE (IDIMMESG_DATA_COM_FUNC_Pos + 1 + MODBUS_CRC16_SIZE)
|
||||
#define IDIMMESG_GROUP_MIN_MES_SIZE (IDIMMESG_DATA_COM_FUNC_Pos + MODBUS_CRC16_SIZE)
|
||||
|
||||
#define IDIMMES_LMES_MSIZE_Pos 0U
|
||||
#define IDIMMES_LMES_BSIZE_Pos (IDIMMES_LMES_MSIZE_Pos + 4U)
|
||||
#define IDIMMES_LMES_IDENTIFIER_LENGTH (IDIMMES_LMES_BSIZE_Pos + 1U)
|
||||
#define IDIMMES_LMES_BSIZE_256B 0U
|
||||
#define IDIMMES_LMES_BSIZE_1K 1U
|
||||
#define IDIMMES_LMES_BSIZE_4K 2U
|
||||
#define IDIMMES_LMES_BSIZE_8K 3U
|
||||
#define IDIMMES_LMES_BSIZE_16K 4U
|
||||
#define IDIMMES_LMES_BSIZE_32K 5U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDISMES_ADDR_Pos 00U
|
||||
#define IDISMES_SMPS_Pos 01U
|
||||
#define IDISMES_SMPS_ERROR_BIT_Pos 0U
|
||||
#define IDISMES_SMPS_LONG_MES_Pos 1U
|
||||
#define IDISMES_SMPS_LONG_OP_Pos 2U
|
||||
#define IDISMES_ERROR_Pos 02U
|
||||
#define IDISMES_DATA_Pos 03U
|
||||
#define IDISMES_MAX_DATA_SIZE 256U
|
||||
#define IDISMES_MIN_MES_SIZE (IDISMES_DATA_Pos + MODBUS_CRC16_SIZE)
|
||||
#define IDISMES_MAX_MES_SIZE (IDISMES_DATA_Pos + IDISMES_MAX_DATA_SIZE + MODBUS_CRC16_SIZE)
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDILONGOP_STATE_COMPLETE_NO_ERR 0x00U
|
||||
#define IDILONGOP_STATE_IN_PROC 0x01U
|
||||
#define IDILONGOP_STATE_COMPLETE_WITH_ERR 0x02U
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define IDILONGOP_MES_DATA_LENGTH 5U
|
||||
#define IDILONGOP_STATE_Pos 0U
|
||||
#define IDILONGOP_REMAIN_TIME_Pos 1U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDISTATUS_B0S_Pos 00U
|
||||
#define IDISTATUS_B0S_ST_ERROR_Pos 0U
|
||||
#define IDISTATUS_B0S_ST_STATE_Pos 1U
|
||||
#define IDISTATUS_B0S_ST_STATE_Msk 0x07U
|
||||
#define IDISTATUS_B0S_ST_STATE_StNoInit 0x00U
|
||||
#define IDISTATUS_B0S_ST_STATE_StOperate 0x01U
|
||||
#define IDISTATUS_B0S_ST_STATE_StFreeze 0x02U
|
||||
#define IDISTATUS_B0S_ST_STATE_StVirtual 0x03U
|
||||
#define IDISTATUS_B0S_ST_STATE_StFirmwareUpd 0x04U
|
||||
#define IDISTATUS_B0S_ST_STATE_StReservedMaster 0x05U
|
||||
#define IDISTATUS_B0S_ST_STATE_StBroken 0x06U
|
||||
#define IDISTATUS_B0S_ST_STATE_StReserved0 0x07U
|
||||
#define IDISTATUS_B0S_AES_SUPPORTED_Pos 4U
|
||||
#define IDISTATUS_B0S_AES_INSTALLED_Pos 5U
|
||||
#define IDISTATUS_B0S_SEND_ALARM_L0_Pos 6U
|
||||
#define IDISTATUS_B0S_SEND_ALARM_L1_Pos 7U
|
||||
|
||||
#define IDISTATUS_B1S_Pos 01U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Pos 0U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Msk 0x03U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Master 0x00U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_SpareMaster 0x01U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Slave 0x02U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Bridge 0x03U
|
||||
#define IDISTATUS_B1S_BRIDGE_CONNECTED_Pos 2U
|
||||
#define IDISTATUS_B1S_SELF_INIT_Pos 3U
|
||||
#define IDISTATUS_B1S_TIMEOUT_LED_Pos 4U
|
||||
#define IDISTATUS_B1S_NO_MMES_TIMEOUT_Pos 5U
|
||||
#define IDISTATUS_B1S_CATCH_ALARM_L0_Pos 6U
|
||||
#define IDISTATUS_B1S_CATCH_ALARM_L1_Pos 7U
|
||||
|
||||
#define IDISTATUS_SN_Pos 02U
|
||||
#define IDISTATUS_LENGTH ( IDISTATUS_SN_Pos + IDISN_FULL_LENGTH )
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIMMES_NOT_FAST_FUNC 0U
|
||||
#define IDIMMES_MAX_FAST_FUNC_NUM 15U
|
||||
#define IDIMMES_COM_START_NUM 220U
|
||||
#define IDIMMES_COM_C_Init 220U
|
||||
#define IDIMMES_COM_C_ShtDown 221U
|
||||
#define IDIMMES_COM_C_Freeze 222U
|
||||
#define IDIMMES_COM_C_Resume 223U
|
||||
#define IDIMMES_COM_C_Dummy 224U
|
||||
#define IDIMMES_COM_C_AssignGroup 225U
|
||||
#define IDIMMES_COM_C_SetAlarmL12 226U
|
||||
#define IDIMMES_COM_C_SetAlarmL 227U
|
||||
#define IDIMMES_COM_C_Virtual 228U
|
||||
#define IDIMMES_COM_C_SyncReadChnl 229U
|
||||
#define IDIMMES_COM_C_SyncRead 230U
|
||||
#define IDIMMES_COM_C_SyncDoChnl 231U
|
||||
#define IDIMMES_COM_C_SyncDo 232U
|
||||
#define IDIMMES_COM_C_SyncClear 233U
|
||||
#define IDIMMES_COM_C_BurstReadCnt 234U
|
||||
#define IDIMMES_COM_C_BurstReadTime 235U
|
||||
#define IDIMMES_COM_C_SendTimeDate 236U
|
||||
#define IDIMMES_COM_C_MkTimedMaster 237U
|
||||
#define IDIMMES_COM_C_EnterBootloader 238U //OUT OF SPEC !!!
|
||||
//#define IDIMMES_COM_C_EndFmwUpd 239U
|
||||
//#define IDIMMES_COM_C_FmwWrite 240U
|
||||
#define IDIMMES_COM_C_ReadDevFullSN_MS 241U
|
||||
#define IDIMMES_COM_C_WriteSnIPv4IPv6 242U
|
||||
#define IDIMMES_COM_C_WriteSnVerifyDates 243U
|
||||
#define IDIMMES_COM_C_WriteSnAES256 244U
|
||||
#define IDIMMES_COM_C_SendLongMessage 245U
|
||||
#define IDIMMES_COM_C_GetLondMessage 246U
|
||||
#define IDIMMES_COM_C_DummyModule 247U
|
||||
#define IDIMMES_COM_C_CheckModuleLongOp 248U
|
||||
#define IDIMMES_COM_C_CheckChannelLongOp 249U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIER_MODBUS_NUM_START 1U
|
||||
#define IDIER_MODBUS_NUM_END 9U
|
||||
#define IDIER_MODULE_MASTER_NUM_START 10U
|
||||
#define IDIER_MODULE_MASTER_NUM_END 32U
|
||||
#define IDIER_MODULE_SLAVE_NUM_START 33U
|
||||
#define IDIER_MODULE_SLAVE_NUM_END 71U
|
||||
#define IDIER_MODULE_NUM_START IDIER_MODULE_MASTER_NUM_START
|
||||
#define IDIER_MODULE_NUM_END IDIER_MODULE_SLAVE_NUM_END
|
||||
#define IDIER_DEVICE_NUM_START 72U
|
||||
#define IDIER_DEVICE_NUM_END 89U
|
||||
|
||||
#define IDIER_NOPE 0U
|
||||
#define MODBUSER_WRONGFUNC 1U
|
||||
#define MODBUSER_WRONGADDR 2U
|
||||
#define MODBUSER_WRONGDATA 3U
|
||||
#define MODBUSER_BROKE 4U
|
||||
#define MODBUSER_LONGCOMMAND 5U
|
||||
#define MODBUSER_BUSY 6U
|
||||
#define MODBUSER_CANTDOFUNC 7U
|
||||
#define MODBUSER_EXTMEMORYERROR 8U
|
||||
#define MODBUSER_RESERVED 9U
|
||||
#define IDIERMST_INVALID_ADDR_NUM 10U
|
||||
#define IDIERMST_INVALID_DEV_NUM 11U
|
||||
#define IDIERMST_INVALID_CHN_NUM 12U
|
||||
#define IDIERMST_INVALID_FUNC_NUM 13U
|
||||
#define IDIERMST_INVALID_TX_REQUEST_FORMAT 14U
|
||||
#define IDIERMST_INVALID_TX_PARAM 15U
|
||||
#define IDIERMST_TX_MES 16U
|
||||
#define IDIERMST_RCV_TIMEOUT 17U
|
||||
#define IDIERMST_MES_RX_INTEGRITY 18U
|
||||
#define IDIERMST_CRC 19U
|
||||
#define IDIERMST_MULTIPLE_CRC 20U
|
||||
#define IDIERMST_INVALID_RX_REQUEST_FORMAT 21U
|
||||
#define IDIERMST_INVALID_RX_PARAM 22U
|
||||
#define IDIERMST_RESEVED_23 23U
|
||||
#define IDIERMST_RESEVED_24 24U
|
||||
#define IDIERMST_RESEVED_25 25U
|
||||
#define IDIERMST_RESEVED_26 26U
|
||||
#define IDIERMST_RESEVED_27 27U
|
||||
#define IDIERMST_EXTRA_28 28U
|
||||
#define IDIERMST_EXTRA_29 29U
|
||||
#define IDIERMST_EXTRA_30 30U
|
||||
#define IDIERMST_EXTRA_31 31U
|
||||
#define IDIERMST_EXTRA_32 32U
|
||||
#define IDIERSLV_RESEVED_33 33U
|
||||
#define IDIERSLV_ENCRYPTION_NOT_SUPPORTED 34U
|
||||
#define IDIERSLV_ENCRYPTION_NOT_INSTALLED 35U
|
||||
#define IDIERSLV_JUMBO_NOT_SUPPORTED 36U
|
||||
#define IDIERSLV_UNSUPPORTED_FUNC_NUM 37U
|
||||
#define IDIERSLV_INVALID_RX_REQUEST_FORMAT 38U
|
||||
#define IDIERSLV_INVALID_RX_PARAM 39U
|
||||
#define IDIERSLV_IN_FREEZE 40U
|
||||
#define IDIERSLV_RESERVED_41 41U
|
||||
#define IDIERSLV_RESERVED_42 42U
|
||||
#define IDIERSLV_RESERVED_43 43U
|
||||
#define IDIERSLV_RESERVED_44 44U
|
||||
#define IDIERSLV_RESERVED_45 45U
|
||||
#define IDIERSLV_EXTRA_46 46U
|
||||
#define IDIERSLV_EXTRA_47 47U
|
||||
#define IDIERSLV_EXTRA_48 48U
|
||||
#define IDIERSLV_EXTRA_49 49U
|
||||
#define IDIERSLV_EXTRA_50 50U
|
||||
#define IDIERSLV_BROKE 51U
|
||||
#define IDIERSLV_NO_FIRMWARE 52U
|
||||
#define IDIERSLV_NO_INIT 53U
|
||||
#define IDIERSLV_OVERHEAT 54U
|
||||
#define IDIERSLV_INP_VOLTAGE 55U
|
||||
#define IDIERSLV_BRIDGE_OVERFLOW 56U
|
||||
#define IDIERSLV_BRIDGE_NOT_CONF 57U
|
||||
#define IDIERSLV_VERIF_DATE 58U
|
||||
#define IDIERSLV_RTC 59U
|
||||
#define IDIERSLV_LONG_OP_IN_PROC 60U
|
||||
#define IDIERSLV_RESERVED_61 61U
|
||||
#define IDIERSLV_RESERVED_62 62U
|
||||
#define IDIERSLV_RESERVED_63 63U
|
||||
#define IDIERSLV_RESERVED_64 64U
|
||||
#define IDIERSLV_RESERVED_65 65U
|
||||
#define IDIERSLV_RESERVED_66 66U
|
||||
#define IDIERSLV_EXTRA_67 67U
|
||||
#define IDIERSLV_EXTRA_68 68U
|
||||
#define IDIERSLV_EXTRA_69 69U
|
||||
#define IDIERSLV_EXTRA_70 70U
|
||||
#define IDIERSLV_EXTRA_71 71U
|
||||
#define IDIERDEV_INVALID_DEV_NUM 72U
|
||||
#define IDIERDEV_INVALID_CHN_NUM 73U
|
||||
#define IDIERDEV_INVALID_FUNC_NUM 74U
|
||||
#define IDIERDEV_LONG_OP_IN_PROC 75U
|
||||
#define IDIERDEV_RESERVED_76 76U
|
||||
#define IDIERDEV_PARAM_LOW_ST_TIMEOUT 77U
|
||||
#define IDIERDEV_PARAM_HIGH_ST_TIMEOUT 78U
|
||||
#define IDIERDEV_PARAM_NOT_CHANGE_TIMEOUT 79U
|
||||
#define IDIERDEV_RESERVED_80 80U
|
||||
#define IDIERDEV_RESERVED_81 81U
|
||||
#define IDIERDEV_RESERVED_82 82U
|
||||
#define IDIERDEV_RESERVED_83 83U
|
||||
#define IDIERDEV_RESERVED_84 84U
|
||||
#define IDIERDEV_RESERVED_85 85U
|
||||
#define IDIERDEV_RESERVED_86 86U
|
||||
#define IDIERDEV_RESERVED_87 87U
|
||||
#define IDIERDEV_RESERVED_88 88U
|
||||
#define IDIERDEV_RESERVED_89 89U
|
||||
|
||||
#define IDIER_MULTIPLE_CRC_AVRBUF_SIZE 16U
|
||||
#define IDIER_MULTIPLE_CRC_AVRBUF_THR 5U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIDATE_FORMAT_DAY_Pos 0U
|
||||
#define IDIDATE_FORMAT_MONTH_Pos 1U
|
||||
#define IDIDATE_FORMAT_CENTURY_Pos 2U
|
||||
#define IDIDATE_FORMAT_YEAR99_Pos 3U
|
||||
#define IDIDATE_FORMAT_LENGTH 4U
|
||||
|
||||
#define IDITIME_FORMAT_SECONDS_Pos 0U
|
||||
#define IDITIME_FORMAT_MINUTES_Pos 1U
|
||||
#define IDITIME_FORMAT_HOURS_Pos 2U
|
||||
#define IDITIME_FORMAT_TIMEZONE_Pos 3U
|
||||
#define IDITIME_FORMAT_LENGTH 4U
|
||||
|
||||
#define IDITIME_FORMAT_TIMEZONE_MIN (-12)
|
||||
#define IDITIME_FORMAT_TIMEZONE_MAX 14
|
||||
|
||||
#define IDIMMES_C_DATETIME_TIME_Pos 0
|
||||
#define IDIMMES_C_DATETIME_DATE_Pos (IDIMMES_C_DATETIME_TIME_Pos + IDIDATE_FORMAT_LENGTH)
|
||||
#define IDIMMES_C_DATETIME_LENGTH (IDIDATE_FORMAT_LENGTH + IDITIME_FORMAT_LENGTH)
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
typedef struct {
|
||||
struct {
|
||||
uint8_t StError : 1;
|
||||
uint8_t StState : 3;
|
||||
uint8_t AesSupported : 1;
|
||||
uint8_t AesInstalled : 1;
|
||||
uint8_t SendAlarmL0 : 1;
|
||||
uint8_t SendAlarmL1 : 1;
|
||||
} B0S;
|
||||
struct {
|
||||
uint8_t ModuleType : 2;
|
||||
uint8_t BridgeConnected : 1;
|
||||
uint8_t SelfInit : 1;
|
||||
uint8_t TimeoutLed : 1;
|
||||
uint8_t NoMMESTimeout : 1;
|
||||
uint8_t CatchAlarmL0 : 1;
|
||||
uint8_t CatchAlarmL1 : 1;
|
||||
} B1S;
|
||||
} IDISTATUS_STATE_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
IDISTATUS_STATE_TYPE STATE;
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
volatile uint_farptr_t SNfix;
|
||||
#else
|
||||
volatile uint8_t *SNfix;
|
||||
#endif
|
||||
volatile uint8_t *SNvar;
|
||||
//uint8_t SN[IDISN_FULL_LENGTH];
|
||||
} IDISTATUS_SLAVE_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif //_INC_IDIBUS_DEFS_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,33 @@
|
||||
#ifndef MEMORY_H_
|
||||
#define MEMORY_H_
|
||||
volatile typedef struct{
|
||||
volatile uint8_t Padding;
|
||||
volatile uint8_t GS1_country[IDISN_FIXP_GS1_COUNTRY_Length];
|
||||
volatile uint8_t GS1_company[IDISN_FIXP_GS1_COMPANY_Length];
|
||||
volatile uint8_t ModuleType[IDISN_FIXP_MODULE_TYPE_Length];
|
||||
volatile uint8_t HW_revision[IDISN_FIXP_HW_REV_Length];
|
||||
volatile uint8_t SN[IDISN_FIXP_SERIAL_Length];
|
||||
volatile uint8_t MAC[IDISN_FIXP_MAC_Length];
|
||||
volatile uint8_t SW[IDISN_FIXP_SW_REV_Length]; //SW Version (Bootloader/App)
|
||||
volatile uint32_t AppCRC; //Only in APP
|
||||
} FLASH_DATABLOCK;
|
||||
//Universal data block
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _BOOTLOADER_
|
||||
#include "BootVersion.h"
|
||||
const volatile FLASH_DATABLOCK STATIC_DATA_BL __attribute__((section (".locationInBoot"))) = {
|
||||
//STATIC PART
|
||||
#include "device.cfg"
|
||||
.SW = {BOOT_VERSION_MAJOR, BOOT_VERSION_MINOR} //Botloader version
|
||||
};
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define APP_VERSION
|
||||
const volatile FLASH_DATABLOCK STATIC_DATA_APP __attribute__((section (".locationInApp"))) = {
|
||||
//.AppCRC = 0x8d173a8c //CRC32 for empty flash
|
||||
#include "device.cfg"
|
||||
};
|
||||
#undef APP_VERSION
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* MEMORY_H_ */
|
@ -0,0 +1,34 @@
|
||||
#ifndef IDIBUS_BOOTLOADER_DEFS_H_
|
||||
#define IDIBUS_BOOTLOADER_DEFS_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "Common/IDIBUS_DEFS.h"
|
||||
//#include "config.h"
|
||||
|
||||
#define IDIMMES_COM_C_FmwBootloaderInfo 255U
|
||||
//[Module Type][Module HW Revision][Module SN][Module BL Revision][Reason for bootloader enter][Custom FMW loading enabled]
|
||||
#define IDIMMES_COM_C_FmwBootloaderInfo_Length (IDISN_FIXP_MODULE_TYPE_Length+IDISN_FIXP_HW_REV_Length+\
|
||||
IDISN_FIXP_SERIAL_Length+IDISN_FIXP_SW_REV_Length+1+1)
|
||||
#define IDIMMES_COM_C_FmwBootloaderStatus 254U
|
||||
//[Module Status][Block Size Hi][Block Size Lo]
|
||||
#define IDIMMES_COM_C_FmwBootloaderWrite 253U
|
||||
//[FMW DATA (in expected size)]
|
||||
|
||||
//FLAG FIELD
|
||||
#define IDIFMW_REASON_NoReason 0
|
||||
#define IDIFMW_REASON_EnterFromApplication 1 //EEPROM FLAG
|
||||
#define IDIFMW_REASON_EnterForced 2 //Address detection
|
||||
#define IDIFMW_REASON_NoFmwDetected 4
|
||||
|
||||
//Maybe move to common idi error list???
|
||||
#define IDIFMW_STATUS_ReadyToGetBlock 0
|
||||
#define IDIFMW_STATUS_ErrorPacketCRC 1
|
||||
//NO BLOCK ACCEPT
|
||||
#define IDIFMW_STATUS_Busy 2
|
||||
#define IDIFMW_STATUS_IncompatibleFmw 3
|
||||
#define IDIFMW_STATUS_FmwUploadCRCError 4 //Final Check
|
||||
#define IDIFMW_STATUS_FmwUploadComplete 5
|
||||
#define IDIFMW_STATUS_Reboot 10
|
||||
|
||||
#endif /* IDIBUS_BOOTLOADER_DEFS_H_ */
|
@ -0,0 +1,120 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "IDIBUS_IMPL.h"
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ModuleBackgroundHandler(void)
|
||||
{
|
||||
if (BootloaderInfo.Status == IDIFMW_STATUS_Busy){
|
||||
BootloaderDataHandler();
|
||||
} else if (BootloaderInfo.Status >= IDIFMW_STATUS_Reboot) {
|
||||
uint8_t TimeOut = 200; //ms
|
||||
while(USART1STR.TxComplete == 0 && TimeOut != 0) {_delay_ms(1);TimeOut--;}
|
||||
if ((BootloaderInfo.Reason & IDIFMW_REASON_NoFmwDetected) == 0){
|
||||
LaunchApplication();
|
||||
} else {
|
||||
System_SWReboot();
|
||||
}
|
||||
}
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ModuleCommandHandler()
|
||||
{
|
||||
if (FARG.ComFunc == IDIMMES_COM_C_Init) {
|
||||
BootloaderInfo.Status += IDIFMW_STATUS_Reboot;
|
||||
IDIBUS_ResponseProtectedWrite(NULL,0,IDIER_NOPE);
|
||||
} else if (FARG.ComFunc == IDIMMES_COM_C_FmwBootloaderWrite) {
|
||||
uint16_t BlockSize = GetNextBlockSize();
|
||||
if (FARG.InpDataLength != BlockSize || FARG.InpDataLength == 0) {IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);}
|
||||
else {
|
||||
if (BootloaderInfo.Status < IDIFMW_STATUS_Busy){
|
||||
BootloaderInfo.Status = IDIFMW_STATUS_Busy;
|
||||
_memcopy(&RxMesageBuf[3],BootloaderData,BlockSize);
|
||||
}
|
||||
//volatile uint8_t Response[3];
|
||||
//GetBootloaderStatus(Response);
|
||||
IDIBUS_ResponseProtectedWrite(NULL,0,IDIER_NOPE);
|
||||
}
|
||||
} else if (FARG.ComFunc == IDIMMES_COM_C_FmwBootloaderStatus) {
|
||||
if (FARG.InpDataLength != 0) {IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);}
|
||||
else{
|
||||
uint8_t Response[5];
|
||||
GetBootloaderStatus(Response);
|
||||
IDIBUS_ResponseProtectedWrite(Response,5,IDIER_NOPE);
|
||||
}
|
||||
} else if (FARG.ComFunc == IDIMMES_COM_C_FmwBootloaderInfo) {
|
||||
if (FARG.InpDataLength != 0 && FARG.InpDataLength != 1) {IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);}
|
||||
else{
|
||||
uint8_t Response[IDIMMES_COM_C_FmwBootloaderInfo_Length];
|
||||
if (FARG.InpDataLength == 1) DisableAES(); //Disable AES if we get something
|
||||
GetBootloaderInfo(Response);
|
||||
IDIBUS_ResponseProtectedWrite(Response,IDIMMES_COM_C_FmwBootloaderInfo_Length,IDIER_NOPE);
|
||||
}
|
||||
} else { IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_NO_FIRMWARE); } //TODO!!!
|
||||
/*
|
||||
switch ( FARG.ComFunc )
|
||||
{
|
||||
case (IDIMMES_COM_C_Init) : {
|
||||
BootloaderInfo.Status += IDIFMW_STATUS_Reboot;
|
||||
IDIBUS_ResponseProtectedWrite(NULL,0,IDIER_NOPE);
|
||||
break;
|
||||
}
|
||||
case (IDIMMES_COM_C_FmwBootloaderWrite) : {
|
||||
uint16_t BlockSize = GetNextBlockSize();
|
||||
if (FARG.InpDataLength != BlockSize || FARG.InpDataLength == 0) {IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);}
|
||||
else {
|
||||
if (BootloaderInfo.Status < IDIFMW_STATUS_Busy){
|
||||
BootloaderInfo.Status = IDIFMW_STATUS_Busy;
|
||||
_memcopy(&RxMesageBuf[3],BootloaderData,BlockSize);
|
||||
}
|
||||
//volatile uint8_t Response[3];
|
||||
//GetBootloaderStatus(Response);
|
||||
IDIBUS_ResponseProtectedWrite(NULL,0,IDIER_NOPE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (IDIMMES_COM_C_FmwBootloaderStatus) : {
|
||||
if (FARG.InpDataLength != 0) {IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);}
|
||||
else{
|
||||
uint8_t Response[5];
|
||||
GetBootloaderStatus(Response);
|
||||
IDIBUS_ResponseProtectedWrite(Response,5,IDIER_NOPE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (IDIMMES_COM_C_FmwBootloaderInfo) : {
|
||||
if (FARG.InpDataLength != 0) {IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);}
|
||||
else{
|
||||
uint8_t Response[IDIMMES_COM_C_FmwBootloaderInfo_Length];
|
||||
GetBootloaderInfo(Response);
|
||||
IDIBUS_ResponseProtectedWrite(Response,IDIMMES_COM_C_FmwBootloaderInfo_Length,IDIER_NOPE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : { IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_NO_FIRMWARE); } //TODO!!!
|
||||
}
|
||||
*/
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ResponseProtectedWrite(uint8_t *Data, uint16_t DataLength, uint8_t ErrorCode)
|
||||
{
|
||||
//TODO!!!!!
|
||||
if ( ErrorCode != IDIER_NOPE ) { FARG.SMPS |= 1; }
|
||||
else { FARG.SMPS &= ~(1); }
|
||||
FARG.OutData[IDISMES_ERROR_Pos] = ErrorCode;
|
||||
FARG.OutDataLength = (uint16_t)(FARG.OutDataLength + 1);
|
||||
|
||||
if (Data != NULL)
|
||||
{
|
||||
_memcopy(Data, &FARG.OutData[IDISMES_ERROR_Pos+1], DataLength);
|
||||
FARG.OutDataLength = (uint16_t)(FARG.OutDataLength + DataLength);
|
||||
}
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,40 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_IDIBUS_IMPL_H_
|
||||
#define _INC_IDIBUS_IMPL_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "IDIBUS_BOOTLOADER_DEFS.h"
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "System.h"
|
||||
#include "bootFunctions.h"
|
||||
//#include "MODBUS_CRC.h"
|
||||
#include <avr/pgmspace.h>
|
||||
#include "USART_COM.h"
|
||||
#include "RSLink.h"
|
||||
#include "CRCs.h"
|
||||
//#include "EEPROM_Fast.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
uint8_t ComFunc;
|
||||
uint16_t InpDataLength;
|
||||
volatile uint8_t *OutData;
|
||||
uint16_t OutDataLength;
|
||||
uint8_t SMPS;
|
||||
//uint8_t ErrorState;
|
||||
//uint8_t LongOpState;
|
||||
} IDIBUS_FARG_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
IDIBUS_FARG_TYPE FARG;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define IDIBUS_SYSTEM_SW_VERSION 0x3133U
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_ModuleCommandHandler();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_ResponseProtectedWrite(uint8_t *Data, uint16_t DataLength, uint8_t ErrorCode);
|
||||
void IDIBUS_ModuleBackgroundHandler(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_IDIBUS_IMPL_H_
|
||||
//#############################################################################################################################################################################################################
|
||||
|
@ -0,0 +1,116 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "RSLink.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_Init(/*USART_INTERFACE_TYPE *USART_INTERFACE, USART_IDIBUS_ROUTINE_TYPE *USART_ID_INTERFACE*/)
|
||||
{
|
||||
//RS_USI=USART_INTERFACE; // USART POINTER INIT
|
||||
//RS_USIID=USART_ID_INTERFACE;
|
||||
RS_NeedSpeedChangeFlag=0;
|
||||
|
||||
//RS_LastMMES_TimeInstance=System_GetTimeInstance();
|
||||
FARG.OutData = USART1_getTxBuf(); //set RX addr
|
||||
|
||||
RSLink_StatusLedInit(); // Init LEDs
|
||||
RSLink_DipsInit(); //
|
||||
RSLink_SpeedCheckAndUpdate(); // Set speed
|
||||
USART1_SetIdiBusBoudrate(RS_SpeedCode); // Set speed usart
|
||||
RSLink_AddressCheckAndUpdate(); // Set adr
|
||||
USART1_RxTransferRestart(); // Restart RX
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t RSLink_SpeedCheckAndUpdate(void)
|
||||
{
|
||||
uint8_t SpeedDSW_Code = RSLink_SpeedDecode();
|
||||
if (RS_SpeedCode != SpeedDSW_Code) { RS_SpeedCode = SpeedDSW_Code; return 1; }
|
||||
return 0;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_AddressCheckAndUpdate(void)
|
||||
{
|
||||
RS_Address = RSLink_AddrDecode();
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void RSLink_Handler(void)
|
||||
{
|
||||
// Address and Speed Change Check Routine =======================================
|
||||
if ( (RS_NeedSpeedChangeFlag == 1) || RSLink_SpeedCheckAndUpdate() )
|
||||
{
|
||||
if ( USART1_IsTxActive() ) { RS_NeedSpeedChangeFlag = 1; }
|
||||
else { USART1_SetIdiBusBoudrate(RS_SpeedCode); RS_NeedSpeedChangeFlag = 0; }
|
||||
}
|
||||
RSLink_AddressCheckAndUpdate();
|
||||
|
||||
IDIBUS_ModuleBackgroundHandler();
|
||||
|
||||
if ( USART1_IsNewRxMessage() == 0 ) { return; }
|
||||
|
||||
if ( USART1_IsRxError() == 1) {
|
||||
USART1_RxTransferRestart();
|
||||
return;
|
||||
}
|
||||
|
||||
static uint16_t RxMessageSize;
|
||||
|
||||
// Check normal Message --------------------------------------------------------->
|
||||
|
||||
// Check Message size
|
||||
uint8_t RcvAddress;
|
||||
RxMessageSize = USART1_getRxBufSize();
|
||||
if ( (RxMessageSize < (MODBUS_CRC16_SIZE+1) ) || (RxMessageSize > IDIMMES_MAX_MES_SIZE) ) { USART1_RxTransferRestart(); return; }
|
||||
else
|
||||
{
|
||||
USART1_copyRxBuf( &RxMesageBuf[IDIMMES_ADDR_Pos], IDIMMES_ADDR_Pos, RxMessageSize ); // Need for CRC
|
||||
USART1_RxTransferRestart();
|
||||
RcvAddress = RxMesageBuf[IDIMMES_ADDR_Pos];
|
||||
}
|
||||
|
||||
// MMESG(Module) or MMES ------------->
|
||||
if ( RcvAddress == RS_Address )
|
||||
{
|
||||
// Check CRC, copy RxBuf and Restart Transfer
|
||||
//USART1_copyRxBuf( &RxMesageBuf[IDIMMES_MMPS_Pos], IDIMMES_MMPS_Pos, (uint16_t)(RxMessageSize-1) );
|
||||
uint16_t CalculatedCRC = CRC16( RxMesageBuf, (uint16_t)(RxMessageSize-2) );
|
||||
uint16_t ReceivedCRC = (uint16_t)( ((uint16_t)RxMesageBuf[RxMessageSize-2] << 8) | RxMesageBuf[RxMessageSize-1] );
|
||||
if ( CalculatedCRC != ReceivedCRC ) { BootloaderInfo.Status=IDIFMW_STATUS_ErrorPacketCRC; return; }
|
||||
|
||||
FARG.OutDataLength = IDISMES_ERROR_Pos; //Set length 2 (adr+cmd)
|
||||
|
||||
uint8_t MMPS = RxMesageBuf[IDIMMES_MMPS_Pos];
|
||||
|
||||
if ( (MMPS != (IDIMMES_MMPS_MES_TYPE_Msk)) || (RxMessageSize < IDIMMESG_MODULE_MIN_MES_SIZE)) {
|
||||
//IDIBUS_ResponseProtectedWrite(NULL,0,IDIERSLV_NO_FIRMWARE);
|
||||
IDIBUS_ResponseProtectedWrite(NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT);
|
||||
}
|
||||
else
|
||||
{
|
||||
FARG.ComFunc = RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos];
|
||||
//FARG.InpData = &RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos + 1];
|
||||
FARG.InpDataLength = (uint16_t)(RxMessageSize - (IDIMMESG_DATA_COM_FUNC_Pos + 1) - MODBUS_CRC16_SIZE);
|
||||
IDIBUS_ModuleCommandHandler();
|
||||
}
|
||||
|
||||
RSLink_SendSMES();
|
||||
} //if ( (RcvAddress == RS_Address) && (RxMessageSize >= IDIMMES_MIN_MES_SIZE) )
|
||||
|
||||
|
||||
// MMESG ------------->
|
||||
// NO RESPONSE!!!
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_SendSMES()
|
||||
{
|
||||
if ( /*(USART1STR->ResponseTimeoutComplete == 0) &&*/ (FARG.OutDataLength > IDISMES_ERROR_Pos) )
|
||||
{
|
||||
FARG.OutData[IDISMES_ADDR_Pos] = RS_Address;
|
||||
FARG.OutData[IDISMES_SMPS_Pos] = FARG.SMPS;
|
||||
//if ( FARG.ErrorState != 0 ) { FARG.OutData[IDISMES_SMPS_Pos] |= (1U << IDISMES_SMPS_ERROR_BIT_Pos); }
|
||||
//if ( FARG.OutLongMesState != 0 ) { FARG.OutData[IDISMES_SMPS_Pos] |= (1U << IDISMES_SMPS_LONG_MES_Pos); }
|
||||
//if ( FARG.LongOpState != 0 ) { FARG.OutData[IDISMES_SMPS_Pos] |= (1U << IDISMES_SMPS_LONG_OP_Pos); }
|
||||
uint16_t crc16 = CRC16(&FARG.OutData[0], FARG.OutDataLength);
|
||||
FARG.OutData[FARG.OutDataLength++] = (uint8_t)(crc16 >> 8);
|
||||
FARG.OutData[FARG.OutDataLength++] = (uint8_t) crc16;
|
||||
USART1_SendTxBuf(FARG.OutDataLength);
|
||||
}
|
||||
}
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,40 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_RSLINK_H_
|
||||
#define _INC_RSLINK_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "SYSTEM.h"
|
||||
#include "USART1.h"
|
||||
#include "IDIBUS_IMPL.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// DELAYS FOR LEDS status
|
||||
|
||||
#define RSLINK_LED_T1_DEFAULT_S 15UL
|
||||
#define RSLINK_LED_T2_DEFAULT_S 60UL
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//USART_INTERFACE_TYPE *USI;
|
||||
//USART_IDIBUS_ROUTINE_TYPE *USIID;
|
||||
uint8_t RS_Address;
|
||||
uint8_t RS_SpeedCode;
|
||||
uint8_t RS_NeedSpeedChangeFlag; // ôëàã äëÿ èçìåíåíèÿ ñêîðîñòè
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t RxMesageBuf[IDIMMES_MAX_MES_SIZE]; //RX buffer for copy
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_Init(/*USART_HANDLER_TYPE *USART_INTERFACE, USART_IDIBUS_ROUTINE_TYPE *USART_ID_INTERFACE*/);
|
||||
uint8_t RSLink_SpeedCheckAndUpdate(void);
|
||||
void RSLink_AddressCheckAndUpdate(void);
|
||||
void RSLink_Handler(void);
|
||||
void RSLink_SendSMES();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_StatusLedInit(void);
|
||||
void RSLink_StatusLedSetOn(void);
|
||||
void RSLink_StatusLedSetOff(void);
|
||||
|
||||
void RSLink_DipsInit(void);
|
||||
uint8_t RSLink_AddrDecode(void);
|
||||
uint8_t RSLink_SpeedDecode(void);
|
||||
uint8_t RSLink_TypeDecode(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_RSLINK_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,108 @@
|
||||
#include "USART1.h"
|
||||
|
||||
// USARTs common settings : Speed and Timeouts
|
||||
const uint16_t USART_UBRR[8] PROGMEM={ (F_CPU/8UL)/19200-1, (F_CPU/8UL)/500000-1,
|
||||
(F_CPU/8UL)/2400-1, (F_CPU/8UL)/9600-1,
|
||||
(F_CPU/8UL)/115200-1, (F_CPU/8UL)/250000-1,
|
||||
(F_CPU/8UL)/1000000-1, /*(F_CPU/8UL)/10000000-1*/ 0}; // Fosc=16MHz : 19.2k, 500k, 2.4k, 9.6k, 115.2k, 250k, 1M, 1M
|
||||
const uint16_t USART_TIMEOUT[8] PROGMEM={ (IDIBUS_19200B_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_500K_INTERFRAME_TIMEOUT_US/8*16),
|
||||
(IDIBUS_2400B_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_9600B_INTERFRAME_TIMEOUT_US/8*16),
|
||||
(IDIBUS_115200B_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_250K_INTERFRAME_TIMEOUT_US/8*16),
|
||||
(IDIBUS_1M_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_1M_INTERFRAME_TIMEOUT_US/8*16) };
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(USART1_TX_vect){
|
||||
if (USART1STR.TxSendedCount == USART1STR.TxBufCount){
|
||||
//UCSR1B &= ~((1<<TXCIE1)|(1<<TXEN1));
|
||||
UCSR1B=(1<<RXCIE1)|(1<<RXEN1);
|
||||
USART1STR.TxSendedCount = 0;
|
||||
USART1STR.TxBufCount = 0;
|
||||
USART1STR.TxComplete = 1;
|
||||
USART1_TX_DDR&=~(1<<USART1_TX_BIT); USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> Z
|
||||
USART1_DRE_DDR&=~(1<<USART1_DRE_BIT); USART1_DRE_PORT&=~(1<<USART1_DRE_BIT); // RDE -> Z
|
||||
} else {
|
||||
UDR1=USART1_TX_BUF[USART1STR.TxSendedCount];
|
||||
USART1STR.TxSendedCount++;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(USART1_RX_vect){
|
||||
//TIMSK3=0;
|
||||
TCNT3=0; // Timeout Timer3 On, clkI/O/8 (From prescaller)
|
||||
TCCR3B=2;
|
||||
TIMSK3=1<<OCIE3A;
|
||||
|
||||
if (UCSR1A & ((1<<FE1) | (1<<DOR1)) )
|
||||
USART1STR.RxError = 1;
|
||||
|
||||
if (USART1STR.RxBufCount < USART1_BUF_SIZE){
|
||||
USART1_RX_BUF[USART1STR.RxBufCount] = UDR1;
|
||||
USART1STR.RxBufCount++;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(TIMER3_COMPA_vect) {
|
||||
TCCR3B=0; TCNT3=0; TIMSK3=0; // Timeout TIMER3 off
|
||||
UCSR1B &= ~((1<<RXCIE1)|(1<<RXEN1)); // RX off
|
||||
USART1STR.RxComplete = 1; // RX data ready
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_Init(void) {
|
||||
USART1STR.TxBufCount = 0;
|
||||
USART1STR.TxSendedCount = 0;
|
||||
USART1STR.RxBufCount = 0;
|
||||
USART1STR.RxComplete = 0;
|
||||
USART1STR.TxComplete = 1;
|
||||
USART1STR.InterFrameTimeoutTicks = 0;
|
||||
|
||||
USART1_TX_DDR&=~(1<<USART1_TX_BIT); USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> Z
|
||||
USART1_RX_DDR&=~(1<<USART1_RX_BIT); USART1_RX_PORT|=1<<USART1_RX_BIT; // RXD -> Z
|
||||
USART1_DRE_DDR&=~(1<<USART1_DRE_BIT); USART1_DRE_PORT&=~(1<<USART1_DRE_BIT); // RDE -> 0
|
||||
|
||||
UCSR1A=(1<<U2X1);
|
||||
UCSR1B=(1<<RXCIE1)|(1<<RXEN1); // RX enable
|
||||
UCSR1C=(1<<UCSZ10)|(1<<UCSZ11)|(1<<USBS1); // 8 bit, 2 stop
|
||||
TCCR3B=0; TCNT3=0; TIMSK3=0; // Timeout TIMER3 off
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// uint8_t USART1_IsNewRxMessage(void) { return USART1STR.RxComplete; }
|
||||
////--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// uint8_t USART1_IsRxError(void) { return USART1STR.RxError; }
|
||||
////--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// uint16_t USART1_getRxBufSize(void) { return USART1STR.RxBufCount; }
|
||||
////--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// uint8_t *USART1_getRxBuf(void) { return &USART1STR.RX_BUF[0]; }
|
||||
////--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// uint8_t *USART1_getTxBuf(void) { return &USART1STR.TX_BUF[0]; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count) { _memcopy(&USART1_RX_BUF[StartPos], Dst,Count); }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART1_IsTxActive(void){
|
||||
if (USART1STR.TxComplete) return 0;
|
||||
else return 1;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SetIdiBusBoudrate(enum IDIBUS_SERIAL_BAUDRATE BoudrateCode){
|
||||
UBRR1 = flash_read_word((USART_UBRR) ,(BoudrateCode<<1));
|
||||
USART1STR.InterFrameTimeoutTicks = flash_read_word((USART_TIMEOUT) ,(BoudrateCode << 1));
|
||||
OCR3A = USART1STR.InterFrameTimeoutTicks;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SendTxBuf(uint16_t Count){
|
||||
if ( (!USART1STR.TxComplete) || (Count == 0) || (Count > USART1_BUF_SIZE) ) { return; }
|
||||
USART1_TX_DDR|=1<<USART1_TX_BIT; USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> out
|
||||
USART1_DRE_DDR|=1<<USART1_DRE_BIT; USART1_DRE_PORT|=1<<USART1_DRE_BIT;
|
||||
USART1STR.TxComplete = 0;
|
||||
USART1STR.TxBufCount = Count;
|
||||
USART1STR.TxSendedCount = 1;
|
||||
//UCSR1B &= ~((1<<RXCIE1)|(1<<RXEN1)); // RX off
|
||||
UCSR1B=(1<<TXCIE1)|(1<<TXEN1);
|
||||
UDR1 = USART1_TX_BUF[0];
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_RxTransferRestart(void){
|
||||
UCSR1B|=(1<<RXCIE1)|(1<<RXEN1);
|
||||
USART1STR.RxBufCount = 0;
|
||||
USART1STR.RxComplete = 0;
|
||||
USART1STR.RxError = 0;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
@ -0,0 +1,56 @@
|
||||
#ifndef USART1_H_
|
||||
#define USART1_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "Common/IDIBUS_DEFS.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include "USART_COM.h"
|
||||
//#include <avr/pgmspace.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile USART_HANDLER_TYPE USART1STR; //Do not remove volatile!!!
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_BUF_SIZE IDIMMES_MAX_MES_SIZE + 1 // Buffer size
|
||||
volatile uint8_t USART1_RX_BUF[USART1_BUF_SIZE]; // RX buffer
|
||||
volatile uint8_t USART1_TX_BUF[USART1_BUF_SIZE]; // TX buffer
|
||||
|
||||
void USART1_Init(void);
|
||||
|
||||
//inline void USART1_IRQN_HANDLER(void);
|
||||
//inline void USART1_RX_TIMER_HANDLER(void);
|
||||
|
||||
void USART1_SendTxBuf(uint16_t Count);
|
||||
//uint8_t USART1_IsNewRxMessage(void);
|
||||
//uint8_t USART1_IsRxError(void);
|
||||
//uint16_t USART1_getRxBufSize(void);
|
||||
//uint8_t *USART1_getRxBuf(void);
|
||||
//uint8_t *USART1_getTxBuf(void);
|
||||
void USART1_RxTransferRestart(void);
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count);
|
||||
|
||||
//#define USART1_copyRxBuf(Dst,StartPos,Count) _memcopy(&USART1_RX_BUF[StartPos],Dst,Count);
|
||||
// void USART1_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count) { _memcopy(&USART1_RX_BUF[StartPos], Dst,Count); }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART1_IsTxActive(void);
|
||||
//#define USART1_IsTxActive() (USART1STR.TxComplete == 1 ? 0 : 1)
|
||||
//uint8_t USART1_IsTxActive(void){
|
||||
// if (USART1STR.TxComplete) return 0;
|
||||
// else return 1;
|
||||
//}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_IsNewRxMessage() USART1STR.RxComplete
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_IsRxError() USART1STR.RxError
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_getRxBufSize() USART1STR.RxBufCount
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_getRxBuf() &USART1_RX_BUF[0]
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_getTxBuf() &USART1_TX_BUF[0]
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SetIdiBusBoudrate(enum IDIBUS_SERIAL_BAUDRATE BoudrateCode);
|
||||
//void USART1_RxAlarmFrameStart(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* USART1_H_ */
|
@ -0,0 +1,41 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_USART_COM_H_
|
||||
#define _INC_USART_COM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#include "stm32f4xx.h"
|
||||
#include <inttypes.h>
|
||||
////#include <string.h>
|
||||
#include "System.h"
|
||||
//#include "CUST_GPIO.h"
|
||||
//#include "TIMERS.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define F_CPU 16000000UL
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _CPU_ATMEGA328PB_ //Maybe move this
|
||||
#include "m328pb_defs.h"
|
||||
#endif // #ifdef _CPU_ATMEGA328PB_
|
||||
#ifdef _CPU_ATMEGA2560_
|
||||
#include "m2560_defs.h"
|
||||
#endif // _CPU_ATMEGA2560_
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
//USART_TypeDef *USART;
|
||||
//DMA_Stream_TypeDef *DMATX;
|
||||
|
||||
volatile uint16_t TxBufCount;
|
||||
//uint16_t TxPacketSize;
|
||||
uint16_t TxSendedCount;
|
||||
volatile uint16_t RxBufCount;
|
||||
|
||||
uint16_t InterFrameTimeoutTicks;
|
||||
|
||||
volatile uint8_t TxComplete;
|
||||
volatile uint8_t RxError;
|
||||
volatile uint8_t RxComplete;
|
||||
|
||||
} USART_HANDLER_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif //_INC_USART_COM_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,79 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "System.h"
|
||||
#include "boot.h"
|
||||
#include "USART1.h"
|
||||
#include "RSLink.h"
|
||||
|
||||
#include <avr/fuse.h>
|
||||
FUSES={ .extended=F_Ext, .high = F_High, .low = F_Low }; // Fuses + Lock programming
|
||||
LOCKBITS=F_Lock;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//FUSE CHECK
|
||||
asm volatile (
|
||||
"ldi R31, 0x00 \n\t"
|
||||
"ldi R30, 0x01 \n\t"
|
||||
"ldi R16, 0x09 \n\t"
|
||||
"out 0x37, R16 \n\t"
|
||||
"lpm R17, Z \n\t"
|
||||
"cpi R17, %0 \n\t"
|
||||
"brne L_LOOP_%= \n\t"
|
||||
// Fuse Extended
|
||||
"ldi R30, 0x02 \n\t"
|
||||
"out 0x37, R16 \n\t"
|
||||
"lpm R17, Z \n\t"
|
||||
"cpi R17, %1 \n\t"
|
||||
"brne L_LOOP_%= \n\t"
|
||||
// Fuse Low Byte
|
||||
"ldi R30, 0x00 \n\t"
|
||||
"out 0x37, R16 \n\t"
|
||||
"lpm R17, Z \n\t"
|
||||
"cpi R17, %2 \n\t"
|
||||
"brne L_LOOP_%= \n\t"
|
||||
// Fuse Hi Byte
|
||||
"ldi R30, 0x03 \n\t"
|
||||
"out 0x37, R16 \n\t"
|
||||
"lpm R17, Z \n\t"
|
||||
"cpi R17, %3 \n\t"
|
||||
"breq L_EXIT_%= \n\t"
|
||||
"L_LOOP_%=: \n\t"
|
||||
"rjmp L_LOOP_%= \n\t"
|
||||
"L_EXIT_%=: \n\t"
|
||||
: //No output
|
||||
: "M" (F_Lock),
|
||||
"M" (F_Ext),
|
||||
"M" (F_Low),
|
||||
"M" (F_High)
|
||||
);
|
||||
|
||||
wdt_enable(WDTO_2S);
|
||||
wdt_reset();
|
||||
|
||||
//Move interrupt table
|
||||
uint8_t temp = MCUCR;
|
||||
MCUCR=temp|(1<<IVCE);
|
||||
MCUCR=temp|(1<<IVSEL);
|
||||
|
||||
USART1_Init();
|
||||
|
||||
RSLink_Init();
|
||||
|
||||
FindBootloaderEnterReason(); //Do checks
|
||||
wdt_reset();
|
||||
|
||||
if (BootloaderInfo.Reason == IDIFMW_REASON_NoReason) LaunchApplication();
|
||||
|
||||
BootloaderInfo.BlockNumber = -1; //Find Better Place!!
|
||||
AES_DISABLED = 0;
|
||||
|
||||
sei();
|
||||
|
||||
while (1)
|
||||
{
|
||||
RSLink_Handler();
|
||||
wdt_reset();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
#include "EEPROM_Fast.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(EE_READY_vect){
|
||||
|
||||
while (1) {
|
||||
if (EEPROM_BUF_COUNT == 0){
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_COMPLETE_NO_ERR; //isThisSafe???!!!
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_NOPE;
|
||||
EECR &= ~(1<<EERIE);
|
||||
return;
|
||||
}
|
||||
|
||||
EEAR = EEPROM_ADDR+EEPROM_BUF_COUNT-1;
|
||||
EECR |= (1<<EERE);
|
||||
uint8_t EEDRold = EEDR;
|
||||
|
||||
if (EEDRold == EEPROM_BUF[EEPROM_BUF_COUNT-1])
|
||||
EEPROM_BUF_COUNT--;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
EEDR = EEPROM_BUF[EEPROM_BUF_COUNT-1];
|
||||
EEPROM_BUF_COUNT--;
|
||||
EECR |= (1<<EEMPE);
|
||||
EECR |= (1<<EEPE);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void EEPROM_WriteEepBuf(uint8_t count,uint16_t addr){
|
||||
if (count > EEPROM_BUF_SIZE || count == 0) {
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_COMPLETE_WITH_ERR; //isThisSafe???!!!
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_NOPE;
|
||||
return;
|
||||
}
|
||||
EEPROM_BUF_COUNT = count;
|
||||
EEPROM_ADDR = addr;
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 1;
|
||||
|
||||
while (1) {
|
||||
if (EEPROM_BUF_COUNT == 0){
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_COMPLETE_NO_ERR; //isThisSafe???!!!
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_NOPE;
|
||||
EECR &= ~(1<<EERIE);
|
||||
return;
|
||||
}
|
||||
|
||||
EEAR = EEPROM_ADDR+EEPROM_BUF_COUNT-1;
|
||||
|
||||
while(EECR&(1<<EEPE)); //Wait if we somehow doing write
|
||||
EECR |= (1<<EERE);
|
||||
uint8_t EEDRold = EEDR;
|
||||
|
||||
if (EEDRold == EEPROM_BUF[EEPROM_BUF_COUNT-1])
|
||||
EEPROM_BUF_COUNT--;
|
||||
else
|
||||
break;
|
||||
}
|
||||
cli();
|
||||
EEDR = EEPROM_BUF[EEPROM_BUF_COUNT-1];
|
||||
EEPROM_BUF_COUNT--;
|
||||
EECR |= (1<<EERIE);
|
||||
EECR |= (1<<EEMPE);
|
||||
EECR |= (1<<EEPE);
|
||||
sei();
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#ifndef EEPROM_FAST_H_
|
||||
#define EEPROM_FAST_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include "IDIBUS_IMPL.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define EEPROM_BUF_SIZE 32
|
||||
uint16_t EEPROM_ADDR;
|
||||
uint8_t EEPROM_BUF[EEPROM_BUF_SIZE];
|
||||
uint8_t EEPROM_BUF_COUNT;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void EEPROM_WriteEepBuf(uint8_t count, uint16_t addr);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* EEPROM_FAST_H_ */
|
@ -0,0 +1,35 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "SYSTEM.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile uint32_t SystemSystickCounter;
|
||||
uint32_t System_GetSysTick(void)
|
||||
{
|
||||
cli();
|
||||
uint32_t SystemSysTick_Temp = SystemSystickCounter;
|
||||
sei();
|
||||
return SystemSysTick_Temp;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t HAL_GetTick(void) // redefine _weak HAL function For HAL Inits
|
||||
{
|
||||
cli();
|
||||
uint32_t SystemSysTick_Temp = SystemSystickCounter;
|
||||
sei();
|
||||
return SystemSysTick_Temp;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t System_GetSysTickDifference(uint32_t TimeInstance)
|
||||
{
|
||||
cli();
|
||||
uint32_t SystemSysTick_Temp = SystemSystickCounter;
|
||||
sei();
|
||||
if (TimeInstance<=SystemSysTick_Temp ) { return (uint32_t)(SystemSysTick_Temp-TimeInstance); }
|
||||
else { return (uint32_t)(0xFFFFFFFF-TimeInstance+SystemSysTick_Temp); }
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void System_SWReboot(void){
|
||||
cli();
|
||||
wdt_enable(WDTO_15MS);
|
||||
while(1); //Dumb reset
|
||||
}
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,30 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_SYSTEM_H_
|
||||
#define _INC_SYSTEM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "config.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <avr/pgmspace.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
#define flash_read_byte(x,y) pgm_read_byte_far(x+y)
|
||||
#define flash_read_word(x,y) pgm_read_word_far(x+y)
|
||||
#define flash_read_dword(x,y) pgm_read_dword_far(x+y)
|
||||
#else
|
||||
#define flash_read_byte(x,y) pgm_read_byte(x+y)
|
||||
#define flash_read_word(x,y) pgm_read_word(x+y)
|
||||
#define flash_read_dword(x,y) pgm_read_dword(x+y)
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define System_GetTimeInstance() System_GetSysTick()
|
||||
uint32_t System_GetSysTick(void);
|
||||
uint32_t HAL_GetTick(void);
|
||||
uint32_t System_GetSysTickDifference(uint32_t TimeInstance);
|
||||
void System_SWReboot(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_SYSTEM_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,32 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "SYSTEMCustom.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void System_InitSysTick(void)
|
||||
{
|
||||
SystemSystickCounter=0;
|
||||
TCNT0=0xFF-250; // 1 ms
|
||||
TCCR0B=0; // no clock
|
||||
TIMSK0=0; // Overflow Interrupt Disable
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(TIMER0_OVF_vect) // 1ms timer0 interrupt
|
||||
{
|
||||
TCNT0=0xFF-250; // 1 ms
|
||||
if (SystemSystickCounter==0xFFFFFFFF) SystemSystickCounter=0; else SystemSystickCounter++;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void System_SystickTimerStart(void)
|
||||
{
|
||||
SystemSystickCounter=0;
|
||||
TCNT0=0xFF-250; // 1 ms
|
||||
TCCR0B=3; // clkI/O/64 (from prescaller)
|
||||
TIMSK0=1<<TOIE0; // Overflow Interrupt Enable
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void System_SystickTimerStop(void)
|
||||
{
|
||||
TCCR0B=0; // no clock
|
||||
TIMSK0=0; // Overflow Interrupt Disable
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,15 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_SYSTEM_CUSTOM_H_
|
||||
#define _INC_SYSTEM_CUSTOM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include <avr/interrupt.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t SystemSystickCounter;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void System_InitSysTick(void);
|
||||
void System_SystickTimerStart(void);
|
||||
void System_SystickTimerStop(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_SYSTEM_CUSTOM_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,135 @@
|
||||
#include "USART0.h"
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(USART0_TX_vect){
|
||||
if (USART0STR.TxSendedCount == USART0STR.TxBufCount){
|
||||
*USART0STR.USART->UCRSB&=~((1<<TXCIE0)|(1<<TXEN0));
|
||||
USART0STR.TxSendedCount = 0;
|
||||
USART0STR.TxBufCount = 0;
|
||||
USART0STR.TxComplete = 1;
|
||||
} else {
|
||||
*USART0STR.USART->UDR=USART0STR.TX_BUF[USART0STR.TxSendedCount];
|
||||
USART0STR.TxSendedCount++;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(USART0_RX_vect){
|
||||
TIMSK4=0; TCNT4=0; // Timeout Timer4 On, clkI/O/8 (From prescaller)
|
||||
TCCR4B=2; TIMSK4=1<<OCIE4A;
|
||||
if (USART0STR.RxBufCount < USART0_BUF_SIZE){
|
||||
USART0STR.RX_BUF[USART0STR.RxBufCount] = *USART0STR.USART->UDR;
|
||||
USART0STR.RxBufCount++;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(TIMER4_COMPA_vect) {
|
||||
TCCR4B=0; TCNT4=0; TIMSK4=0; // Timeout TIMER3 off
|
||||
*USART0STR.USART->UCRSB&=~((1<<RXCIE1)|(1<<RXEN1)); // RX off
|
||||
USART0STR.RxComplete = 1; // RX data ready
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART0_Init(void) {
|
||||
//USART0STR.USART = USART0_PERIPH_POINTER;
|
||||
//USART0STR.DMATX = USART0_DMA_TX_STREAM;
|
||||
USART0_ADR.UCRSA = &UCSR0A;
|
||||
USART0_ADR.UCRSB = &UCSR0B;
|
||||
USART0_ADR.UCRSC = &UCSR0C;
|
||||
USART0_ADR.UDR = &UDR0;
|
||||
USART0_ADR.UBRR = &UBRR0;
|
||||
|
||||
USART0STR.USART = &USART0_ADR;
|
||||
USART0STR.RX_BUF = USART0_RX_BUF;
|
||||
USART0STR.TX_BUF = USART0_TX_BUF;
|
||||
USART0STR.TxBufCount = 0;
|
||||
USART0STR.TxSendedCount = 0;
|
||||
USART0STR.RxBufCount = 0;
|
||||
USART0STR.RxComplete = 0;
|
||||
USART0STR.TxComplete = 1;
|
||||
USART0STR.InterFrameTimeoutTicks = 0;
|
||||
|
||||
USART0_INTERFACE.SetNewBaudrate = USART0_SetBaudrate;
|
||||
USART0_INTERFACE.SendTxBuf = USART0_SendTxBuf;
|
||||
USART0_INTERFACE.SendByteBuf = USART0_SendByteBuf;
|
||||
USART0_INTERFACE.IsNewRxMessage = USART0_IsNewRxMessage;
|
||||
USART0_INTERFACE.IsTxActive = USART0_IsTxActive;
|
||||
USART0_INTERFACE.IsRxError = USART0_IsRxError;
|
||||
USART0_INTERFACE.getRxBufSize = USART0_getRxBufSize;
|
||||
USART0_INTERFACE.copyRxBuf = USART0_copyRxBuf;
|
||||
USART0_INTERFACE.getRxBuf = USART0_getRxBuf;
|
||||
USART0_INTERFACE.getTxBuf = USART0_getTxBuf;
|
||||
USART0_INTERFACE.RxTransferRestart = USART0_RxTransferRestart;
|
||||
|
||||
/*
|
||||
USART0_IDIBUS.SetIdiBusBoudrate = USART0_SetIdiBusBoudrate;
|
||||
USART0_IDIBUS.RxAlarmFrameStart = USART0_RxAlarmFrameStart;
|
||||
USART0_IDIBUS.ResponseTimeoutComplete = 0;
|
||||
USART0_IDIBUS.AlarmTimeoutUS = 0;
|
||||
USART0_IDIBUS.ResponseTimeoutUS = 0;
|
||||
USART0_IDIBUS.TimerMode = IDIBUS_TIMER_MODE_RX_TIMEOUT;
|
||||
*/
|
||||
|
||||
USART0_TX_DDR&=~(1<<USART0_TX_BIT); USART0_TX_PORT|=1<<USART0_TX_BIT; // TXD -> Z
|
||||
USART0_RX_DDR&=~(1<<USART0_RX_BIT); USART0_RX_PORT|=1<<USART0_RX_BIT; // RXD -> Z
|
||||
|
||||
*USART0STR.USART->UCRSA=0;
|
||||
*USART0STR.USART->UCRSB=(1<<RXCIE0)|(1<<RXEN0); // RX enable
|
||||
*USART0STR.USART->UCRSC=(1<<UCSZ00)|(1<<UCSZ01)|(1<<USBS0); // 8 bit, 2 stop
|
||||
TCCR4B=0; TCNT4=0; TIMSK4=0; // Timeout TIMER3 off
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART0_SetBaudrate(uint32_t Baudrate){
|
||||
*USART0STR.USART->UBRR = (F_CPU/16UL)/Baudrate-1;
|
||||
OCR4A = 4015;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART0_IsNewRxMessage(void) { return USART0STR.RxComplete; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART0_IsRxError(void) { return USART0STR.RxError; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint16_t USART0_getRxBufSize(void) { return USART0STR.RxBufCount; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile uint8_t *USART0_getRxBuf(void) { return &USART0STR.RX_BUF[0]; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile uint8_t *USART0_getTxBuf(void) { return &USART0STR.TX_BUF[0]; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART0_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count) { memcpy(Dst, &USART0STR.RX_BUF[StartPos], Count); }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART0_IsTxActive(void){
|
||||
if (USART0STR.TxComplete) return 0;
|
||||
else return 1;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART0_SendByteBuf(uint8_t *Buf, uint16_t Count){
|
||||
if ( (!USART0STR.TxComplete) || (Count == 0) || (Count > USART0_BUF_SIZE) ) { return; }
|
||||
memcpy(USART0STR.TX_BUF, Buf, Count);
|
||||
USART0_TX_DDR|=1<<USART0_TX_BIT; USART0_TX_PORT|=1<<USART0_TX_BIT; // TXD -> out
|
||||
USART0STR.TxComplete = 0;
|
||||
USART0STR.TxBufCount = Count;
|
||||
USART0STR.TxSendedCount = 1;
|
||||
*USART0STR.USART->UCRSB|=(1<<TXCIE0)|(1<<TXEN0);
|
||||
*USART0STR.USART->UDR = USART0STR.TX_BUF[0];
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART0_SendTxBuf(uint16_t Count){
|
||||
if ( (!USART0STR.TxComplete) || (Count == 0) || (Count > USART0_BUF_SIZE) ) { return; }
|
||||
USART0_TX_DDR|=1<<USART0_TX_BIT; USART0_TX_PORT|=1<<USART0_TX_BIT; // TXD -> out
|
||||
USART0STR.TxComplete = 0;
|
||||
USART0STR.TxBufCount = Count;
|
||||
USART0STR.TxSendedCount = 1;
|
||||
*USART0STR.USART->UCRSB|=(1<<TXCIE0)|(1<<TXEN0);
|
||||
*USART0STR.USART->UDR = USART0STR.TX_BUF[0];
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART0_RxTransferRestart(void){
|
||||
//USART0_RX_TIMER_STOP(); //We are already doing this in IRQ
|
||||
//(void) USART0STR.USART->SR;
|
||||
//(void) USART0STR.USART->DR;
|
||||
*USART0STR.USART->UCRSB|=(1<<RXCIE0)|(1<<RXEN0);
|
||||
USART0STR.RxBufCount = 0;
|
||||
USART0STR.RxComplete = 0;
|
||||
USART0STR.RxError = 0;
|
||||
USART0_IDIBUS.TimerMode = IDIBUS_TIMER_MODE_RX_TIMEOUT;
|
||||
//USART0_RX_TIMER_SET_TIMEOUT(USART0STR.InterFrameTimeoutUS);
|
||||
OCR4A = USART0STR.InterFrameTimeoutTicks; //Not necessary but why not
|
||||
//USART0STR.USART->CR1 |= (1U<<USART_CR1_RE_Pos);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
@ -0,0 +1,35 @@
|
||||
#ifndef USART0_H_
|
||||
#define USART0_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "USART_COM.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile USART_TypeDef USART0_ADR;
|
||||
volatile USART_HANDLER_TYPE USART0STR;
|
||||
volatile USART_INTERFACE_TYPE USART0_INTERFACE;
|
||||
volatile USART_IDIBUS_ROUTINE_TYPE USART0_IDIBUS;
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART0_BUF_SIZE 64 // Buffer size
|
||||
volatile uint8_t USART0_RX_BUF[USART0_BUF_SIZE]; // RX buffer
|
||||
volatile uint8_t USART0_TX_BUF[USART0_BUF_SIZE]; // TX buffer
|
||||
|
||||
void USART0_Init(void);
|
||||
void USART0_SetBaudrate(uint32_t Boudrate);
|
||||
|
||||
//inline void USART0_IRQN_HANDLER(void);
|
||||
//inline void USART0_RX_TIMER_HANDLER(void);
|
||||
|
||||
void USART0_SendByteBuf(uint8_t *Buf, uint16_t Count);
|
||||
void USART0_SendTxBuf(uint16_t Count);
|
||||
uint8_t USART0_IsTxActive(void);
|
||||
uint8_t USART0_IsNewRxMessage(void);
|
||||
uint8_t USART0_IsRxError(void);
|
||||
uint16_t USART0_getRxBufSize(void);
|
||||
void USART0_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count);
|
||||
volatile uint8_t *USART0_getRxBuf(void);
|
||||
volatile uint8_t *USART0_getTxBuf(void);
|
||||
void USART0_RxTransferRestart(void);
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* USART0_H_ */
|
@ -0,0 +1,163 @@
|
||||
#include "USART1.h"
|
||||
|
||||
// USARTs common settings : Speed and Timeouts
|
||||
const uint16_t USART_UBRR[8] PROGMEM={ (F_CPU/8UL)/19200-1, (F_CPU/8UL)/500000-1,
|
||||
(F_CPU/8UL)/2400-1, (F_CPU/8UL)/9600-1,
|
||||
(F_CPU/8UL)/115200-1, (F_CPU/8UL)/250000-1,
|
||||
(F_CPU/8UL)/1000000-1, /*(F_CPU/8UL)/10000000-1*/ 0}; // Fosc=16MHz : 19.2k, 500k, 2.4k, 9.6k, 115.2k, 250k, 1M, 1M
|
||||
const uint16_t USART_TIMEOUT[8] PROGMEM={ (IDIBUS_19200B_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_500K_INTERFRAME_TIMEOUT_US/8*16),
|
||||
(IDIBUS_2400B_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_9600B_INTERFRAME_TIMEOUT_US/8*16),
|
||||
(IDIBUS_115200B_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_250K_INTERFRAME_TIMEOUT_US/8*16),
|
||||
(IDIBUS_1M_INTERFRAME_TIMEOUT_US/8*16), (IDIBUS_1M_INTERFRAME_TIMEOUT_US/8*16) };
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(USART1_TX_vect){
|
||||
if (USART1STR.TxSendedCount == USART1STR.TxBufCount){
|
||||
*USART1STR.USART->UCRSB |= (1<<RXCIE1)|(1<<RXEN1);
|
||||
*USART1STR.USART->UCRSB &= ~((1<<TXCIE1)|(1<<TXEN1));
|
||||
USART1STR.TxSendedCount = 0;
|
||||
USART1STR.TxBufCount = 0;
|
||||
USART1STR.TxComplete = 1;
|
||||
USART1_TX_DDR&=~(1<<USART1_TX_BIT); USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> Z
|
||||
USART1_DRE_DDR&=~(1<<USART1_DRE_BIT); USART1_DRE_PORT&=~(1<<USART1_DRE_BIT); // RDE -> 0
|
||||
} else {
|
||||
*USART1STR.USART->UDR=USART1STR.TX_BUF[USART1STR.TxSendedCount];
|
||||
USART1STR.TxSendedCount++;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(USART1_RX_vect){
|
||||
TIMSK3=0; TCNT3=0; // Timeout Timer3 On, clkI/O/8 (From prescaller)
|
||||
TCCR3B=2; TIMSK3=1<<OCIE3A;
|
||||
|
||||
if (*USART1STR.USART->UCRSA & ((1<<FE1) | (1<<DOR1)) )
|
||||
USART1STR.RxError = 1;
|
||||
|
||||
if (USART1STR.RxBufCount < USART1_BUF_SIZE){
|
||||
USART1STR.RX_BUF[USART1STR.RxBufCount] = *USART1STR.USART->UDR;
|
||||
USART1STR.RxBufCount++;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ISR(TIMER3_COMPA_vect) {
|
||||
TCCR3B=0; TCNT3=0; TIMSK3=0; // Timeout TIMER3 off
|
||||
*USART1STR.USART->UCRSB&=~((1<<RXCIE1)|(1<<RXEN1)); // RX off
|
||||
USART1STR.RxComplete = 1; // RX data ready
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_Init(void) {
|
||||
//USART1STR.USART = USART1_PERIPH_POINTER;
|
||||
//USART1STR.DMATX = USART1_DMA_TX_STREAM;
|
||||
USART1_ADR.UCRSA = &UCSR1A;
|
||||
USART1_ADR.UCRSB = &UCSR1B;
|
||||
USART1_ADR.UCRSC = &UCSR1C;
|
||||
USART1_ADR.UDR = &UDR1;
|
||||
USART1_ADR.UBRR = &UBRR1;
|
||||
|
||||
USART1STR.USART = &USART1_ADR;
|
||||
USART1STR.RX_BUF = USART1_RX_BUF;
|
||||
USART1STR.TX_BUF = USART1_TX_BUF;
|
||||
USART1STR.TxBufCount = 0;
|
||||
USART1STR.TxSendedCount = 0;
|
||||
USART1STR.RxBufCount = 0;
|
||||
USART1STR.RxComplete = 0;
|
||||
USART1STR.TxComplete = 1;
|
||||
USART1STR.InterFrameTimeoutTicks = 0;
|
||||
|
||||
USART1_INTERFACE.SetNewBaudrate = USART1_SetBaudrate;
|
||||
USART1_INTERFACE.SendTxBuf = USART1_SendTxBuf;
|
||||
USART1_INTERFACE.SendByteBuf = USART1_SendByteBuf;
|
||||
USART1_INTERFACE.IsNewRxMessage = USART1_IsNewRxMessage;
|
||||
USART1_INTERFACE.IsTxActive = USART1_IsTxActive;
|
||||
USART1_INTERFACE.IsRxError = USART1_IsRxError;
|
||||
USART1_INTERFACE.getRxBufSize = USART1_getRxBufSize;
|
||||
USART1_INTERFACE.copyRxBuf = USART1_copyRxBuf;
|
||||
USART1_INTERFACE.getRxBuf = USART1_getRxBuf;
|
||||
USART1_INTERFACE.getTxBuf = USART1_getTxBuf;
|
||||
USART1_INTERFACE.RxTransferRestart = USART1_RxTransferRestart;
|
||||
|
||||
USART1_IDIBUS.SetIdiBusBoudrate = USART1_SetIdiBusBoudrate;
|
||||
USART1_IDIBUS.RxAlarmFrameStart = USART1_RxAlarmFrameStart;
|
||||
USART1_IDIBUS.ResponseTimeoutComplete = 0;
|
||||
USART1_IDIBUS.AlarmTimeoutUS = 0;
|
||||
USART1_IDIBUS.ResponseTimeoutUS = 0;
|
||||
USART1_IDIBUS.TimerMode = IDIBUS_TIMER_MODE_RX_TIMEOUT;
|
||||
|
||||
USART1_TX_DDR&=~(1<<USART1_TX_BIT); USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> Z
|
||||
USART1_RX_DDR&=~(1<<USART1_RX_BIT); USART1_RX_PORT|=1<<USART1_RX_BIT; // RXD -> Z
|
||||
USART1_DRE_DDR&=~(1<<USART1_DRE_BIT); USART1_DRE_PORT&=~(1<<USART1_DRE_BIT); // RDE -> 0
|
||||
|
||||
*USART1STR.USART->UCRSA=(1<<U2X1);
|
||||
*USART1STR.USART->UCRSB=(1<<RXCIE1)|(1<<RXEN1); // RX enable
|
||||
*USART1STR.USART->UCRSC=(1<<UCSZ10)|(1<<UCSZ11)|(1<<USBS1); // 8 bit, 2 stop
|
||||
TCCR3B=0; TCNT3=0; TIMSK3=0; // Timeout TIMER3 off
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SetBaudrate(uint32_t Baudrate){
|
||||
*USART1STR.USART->UBRR = (F_CPU/16UL)/Baudrate-1;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART1_IsNewRxMessage(void) { return USART1STR.RxComplete; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART1_IsRxError(void) { return USART1STR.RxError; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint16_t USART1_getRxBufSize(void) { return USART1STR.RxBufCount; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t *USART1_getRxBuf(void) { return &USART1STR.RX_BUF[0]; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t *USART1_getTxBuf(void) { return &USART1STR.TX_BUF[0]; }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count) { memcpy(Dst, &USART1STR.RX_BUF[StartPos], Count); }
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t USART1_IsTxActive(void){
|
||||
if (USART1STR.TxComplete) return 0;
|
||||
else return 1;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SetIdiBusBoudrate(enum IDIBUS_SERIAL_BAUDRATE BoudrateCode){
|
||||
*USART1STR.USART->UBRR = pgm_read_word(&USART_UBRR[BoudrateCode]);
|
||||
USART1STR.InterFrameTimeoutTicks = pgm_read_word(&USART_TIMEOUT[BoudrateCode]);
|
||||
OCR3A = USART1STR.InterFrameTimeoutTicks;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SendByteBuf(uint8_t *Buf, uint16_t Count){
|
||||
if ( (!USART1STR.TxComplete) || (Count == 0) || (Count > USART1_BUF_SIZE) ) { return; }
|
||||
memcpy(USART1STR.TX_BUF, Buf, Count);
|
||||
USART1_TX_DDR|=1<<USART1_TX_BIT; USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> out
|
||||
USART1_DRE_DDR|=1<<USART1_DRE_BIT; USART1_DRE_PORT|=1<<USART1_DRE_BIT;
|
||||
USART1STR.TxComplete = 0;
|
||||
USART1STR.TxBufCount = Count;
|
||||
USART1STR.TxSendedCount = 1;
|
||||
*USART1STR.USART->UCRSB&=~((1<<RXCIE1)|(1<<RXEN1)); // RX off
|
||||
*USART1STR.USART->UCRSB|=(1<<TXCIE1)|(1<<TXEN1);
|
||||
*USART1STR.USART->UDR = USART1STR.TX_BUF[0];
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SendTxBuf(uint16_t Count){
|
||||
if ( (!USART1STR.TxComplete) || (Count == 0) || (Count > USART1_BUF_SIZE) ) { return; }
|
||||
USART1_TX_DDR|=1<<USART1_TX_BIT; USART1_TX_PORT|=1<<USART1_TX_BIT; // TXD -> out
|
||||
USART1_DRE_DDR|=1<<USART1_DRE_BIT; USART1_DRE_PORT|=1<<USART1_DRE_BIT;
|
||||
USART1STR.TxComplete = 0;
|
||||
USART1STR.TxBufCount = Count;
|
||||
USART1STR.TxSendedCount = 1;
|
||||
*USART1STR.USART->UCRSB&=~((1<<RXCIE1)|(1<<RXEN1)); // RX off
|
||||
*USART1STR.USART->UCRSB|=(1<<TXCIE1)|(1<<TXEN1);
|
||||
*USART1STR.USART->UDR = USART1STR.TX_BUF[0];
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_RxTransferRestart(void){
|
||||
//USART1_RX_TIMER_STOP(); //We are already doing this in IRQ
|
||||
//(void) USART1STR.USART->SR;
|
||||
//(void) USART1STR.USART->DR;
|
||||
*USART1STR.USART->UCRSB|=(1<<RXCIE1)|(1<<RXEN1);
|
||||
USART1STR.RxBufCount = 0;
|
||||
USART1STR.RxComplete = 0;
|
||||
USART1STR.RxError = 0;
|
||||
USART1_IDIBUS.TimerMode = IDIBUS_TIMER_MODE_RX_TIMEOUT;
|
||||
//USART1_RX_TIMER_SET_TIMEOUT(USART1STR.InterFrameTimeoutUS);
|
||||
//OCR3A = USART1STR.InterFrameTimeoutTicks; //Not necessary but why not
|
||||
//USART1STR.USART->CR1 |= (1U<<USART_CR1_RE_Pos);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_RxAlarmFrameStart(void){
|
||||
//Sometimes there will be something
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#ifndef USART1_H_
|
||||
#define USART1_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "USART_COM.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile USART_TypeDef USART1_ADR;
|
||||
volatile USART_HANDLER_TYPE USART1STR;
|
||||
volatile USART_INTERFACE_TYPE USART1_INTERFACE;
|
||||
volatile USART_IDIBUS_ROUTINE_TYPE USART1_IDIBUS;
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define USART1_BUF_SIZE IDIMMES_MAX_MES_SIZE + 1 // Buffer size
|
||||
volatile uint8_t USART1_RX_BUF[USART1_BUF_SIZE]; // RX buffer
|
||||
volatile uint8_t USART1_TX_BUF[USART1_BUF_SIZE]; // TX buffer
|
||||
|
||||
void USART1_Init(void);
|
||||
void USART1_SetBaudrate(uint32_t Boudrate);
|
||||
|
||||
//inline void USART1_IRQN_HANDLER(void);
|
||||
//inline void USART1_RX_TIMER_HANDLER(void);
|
||||
|
||||
void USART1_SendByteBuf(uint8_t *Buf, uint16_t Count);
|
||||
void USART1_SendTxBuf(uint16_t Count);
|
||||
uint8_t USART1_IsTxActive(void);
|
||||
uint8_t USART1_IsNewRxMessage(void);
|
||||
uint8_t USART1_IsRxError(void);
|
||||
uint16_t USART1_getRxBufSize(void);
|
||||
void USART1_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count);
|
||||
uint8_t *USART1_getRxBuf(void);
|
||||
uint8_t *USART1_getTxBuf(void);
|
||||
void USART1_RxTransferRestart(void);
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void USART1_SetIdiBusBoudrate(enum IDIBUS_SERIAL_BAUDRATE BoudrateCode);
|
||||
void USART1_RxAlarmFrameStart(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* USART1_H_ */
|
@ -0,0 +1,71 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_USART_COM_H_
|
||||
#define _INC_USART_COM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#include "stm32f4xx.h"
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
//#include "SYSTEM.h"
|
||||
//#include "CUST_GPIO.h"
|
||||
//#include "TIMERS.h"
|
||||
#include "Common/IDIBUS_DEFS.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _CPU_ATMEGA328PB_ //Maybe move this
|
||||
#include "m328pb_defs.h"
|
||||
#endif // #ifdef _CPU_ATMEGA328PB_
|
||||
#ifdef _CPU_ATMEGA2560_
|
||||
#include "m2560_defs.h"
|
||||
#endif // _CPU_ATMEGA2560_
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
volatile uint8_t *UCRSA;
|
||||
volatile uint8_t *UCRSB;
|
||||
volatile uint8_t *UCRSC;
|
||||
volatile uint16_t *UBRR;
|
||||
volatile uint8_t *UDR;
|
||||
} USART_TypeDef;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
volatile USART_TypeDef *USART;
|
||||
//DMA_Stream_TypeDef *DMATX;
|
||||
|
||||
uint8_t *TX_BUF;
|
||||
uint8_t *RX_BUF;
|
||||
uint16_t TxBufCount;
|
||||
//uint16_t TxPacketSize;
|
||||
uint16_t TxSendedCount;
|
||||
uint16_t RxBufCount;
|
||||
|
||||
volatile uint8_t TxComplete;
|
||||
uint8_t RxError;
|
||||
uint8_t RxComplete;
|
||||
|
||||
uint16_t InterFrameTimeoutTicks; //Currently there are ticks for timer
|
||||
} USART_HANDLER_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
void (*SetNewBaudrate)(uint32_t);
|
||||
void (*SendByteBuf)(uint8_t*, uint16_t);
|
||||
void (*SendTxBuf)(uint16_t);
|
||||
uint8_t (*IsNewRxMessage)(void);
|
||||
uint8_t (*IsTxActive)(void);
|
||||
uint8_t (*IsRxError)(void);
|
||||
uint16_t (*getRxBufSize)(void);
|
||||
void (*copyRxBuf)(uint8_t*, uint16_t, uint16_t);
|
||||
uint8_t* (*getRxBuf)(void);
|
||||
uint8_t* (*getTxBuf)(void);
|
||||
void (*RxTransferRestart)(void);
|
||||
} USART_INTERFACE_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
uint8_t TimerMode;
|
||||
uint16_t ResponseTimeoutUS;
|
||||
uint16_t AlarmTimeoutUS;
|
||||
volatile uint8_t ResponseTimeoutComplete;
|
||||
void (*SetIdiBusBoudrate)(enum IDIBUS_SERIAL_BAUDRATE);
|
||||
void (*RxAlarmFrameStart)(void);
|
||||
} USART_IDIBUS_ROUTINE_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif //_INC_USART_COM_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,17 @@
|
||||
// USARTCUSTOM (FOR 2560)
|
||||
#define USART1_TX_DDR DDRD
|
||||
#define USART1_TX_PORT PORTD
|
||||
#define USART1_TX_BIT 3
|
||||
#define USART1_RX_DDR DDRD
|
||||
#define USART1_RX_PORT PORTD
|
||||
#define USART1_RX_BIT 2
|
||||
#define USART1_DRE_DDR DDRD
|
||||
#define USART1_DRE_PORT PORTD
|
||||
#define USART1_DRE_BIT 4
|
||||
// USARTCUSTOM (FOR 2560)
|
||||
#define USART0_TX_DDR DDRE
|
||||
#define USART0_TX_PORT PORTE
|
||||
#define USART0_TX_BIT 1
|
||||
#define USART0_RX_DDR DDRE
|
||||
#define USART0_RX_PORT PORTE
|
||||
#define USART0_RX_BIT 0
|
@ -0,0 +1,19 @@
|
||||
//USART CUSTOM (FOR 328pb)
|
||||
#define USART0_TX_DDR DDRD
|
||||
#define USART0_TX_PORT PORTD
|
||||
#define USART0_TX_BIT 1
|
||||
#define USART0_RX_DDR DDRD
|
||||
#define USART0_RX_PORT PORTD
|
||||
#define USART0_RX_BIT 0
|
||||
|
||||
//USART CUSTOM (FOR 328pb)
|
||||
#define USART1_TX_DDR DDRB
|
||||
#define USART1_TX_PORT PORTB
|
||||
#define USART1_TX_BIT 3
|
||||
#define USART1_RX_DDR DDRB
|
||||
#define USART1_RX_PORT PORTB
|
||||
#define USART1_RX_BIT 4
|
||||
#define USART1_DRE_DDR DDRB
|
||||
#define USART1_DRE_PORT PORTB
|
||||
#define USART1_DRE_BIT 5
|
||||
|
@ -0,0 +1,456 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_IDIBUS_DEFS_H_
|
||||
#define _INC_IDIBUS_DEFS_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define F_CPU 16000000UL
|
||||
#define MODBUS_CRC16_SIZE 2
|
||||
#define CRC32_SIZE 4
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_19200B 0x00
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_500K 0x01
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_2400B 0x02
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_9600B 0x03
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_115200B 0x04
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_250K 0x05
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_1M 0x06
|
||||
#define IDIBUS_BAUDRATE_DSW_CODE_10M 0x07
|
||||
|
||||
// Full timeout will be (InterframeTimeout + ResponseTimeout) for request(Write + Read) or InterframeTimeout for write(Write only)
|
||||
#define IDIBUS_2400B_INTERFRAME_TIMEOUT_US 16042ULL //11 * 3.5 / Baudrate
|
||||
#define IDIBUS_9600B_INTERFRAME_TIMEOUT_US 4011ULL
|
||||
#define IDIBUS_19200B_INTERFRAME_TIMEOUT_US 2006ULL
|
||||
#define IDIBUS_115200B_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_250K_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_500K_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_1M_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_10M_INTERFRAME_TIMEOUT_US 1750ULL
|
||||
|
||||
#define IDIBUS_2400B_ALARM_TIMEOUT_US 34375ULL //11 * 3.5 / Baudrate
|
||||
#define IDIBUS_9600B_ALARM_TIMEOUT_US 8594ULL
|
||||
#define IDIBUS_19200B_ALARM_TIMEOUT_US 4297ULL
|
||||
#define IDIBUS_115200B_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_250K_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_500K_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_1M_ALARM_TIMEOUT_US 1750ULL
|
||||
#define IDIBUS_10M_ALARM_TIMEOUT_US 1750ULL
|
||||
|
||||
#define IDIBUS_2400B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_2400B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_9600B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_9600B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_19200B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_19200B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_115200B_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_115200B_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_250K_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_250K_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_500K_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_500K_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_1M_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_1M_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
#define IDIBUS_10M_MASTER_RESPONSE_TIMEOUT_US (IDIBUS_10M_INTERFRAME_TIMEOUT_US * 3 / 2 )
|
||||
|
||||
#define IDIBUS_2400B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_2400B_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_9600B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_9600B_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_19200B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_19200B_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_115200B_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_115200B_INTERFRAME_TIMEOUT_US)
|
||||
#define IDIBUS_250K_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_250K_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_500K_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_500K_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_1M_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_1M_INTERFRAME_TIMEOUT_US )
|
||||
#define IDIBUS_10M_SLAVE_RESPONSE_TIMEOUT_US (IDIBUS_10M_INTERFRAME_TIMEOUT_US )
|
||||
|
||||
|
||||
enum IDIBUS_SERIAL_BAUDRATE {
|
||||
IDIBUS_BAUDRATE_2400 = IDIBUS_BAUDRATE_DSW_CODE_2400B,
|
||||
IDIBUS_BAUDRATE_9600 = IDIBUS_BAUDRATE_DSW_CODE_9600B,
|
||||
IDIBUS_BAUDRATE_19200 = IDIBUS_BAUDRATE_DSW_CODE_19200B,
|
||||
IDIBUS_BAUDRATE_115200 = IDIBUS_BAUDRATE_DSW_CODE_115200B,
|
||||
IDIBUS_BAUDRATE_250K = IDIBUS_BAUDRATE_DSW_CODE_250K,
|
||||
IDIBUS_BAUDRATE_500K = IDIBUS_BAUDRATE_DSW_CODE_500K,
|
||||
IDIBUS_BAUDRATE_1M = IDIBUS_BAUDRATE_DSW_CODE_1M,
|
||||
IDIBUS_BAUDRATE_10M = IDIBUS_BAUDRATE_DSW_CODE_10M
|
||||
};
|
||||
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_SEC 60U
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_MS ( IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_SEC * 1000U )
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_SEC 15U
|
||||
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_MS ( IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_SEC * 1000U )
|
||||
|
||||
enum IDIBUS_RXTIMER_TIMEOUT_MODE {
|
||||
IDIBUS_TIMER_MODE_RX_TIMEOUT = 0x00,
|
||||
IDIBUS_TIMER_MODE_ALARM_TIMEOUT,
|
||||
IDIBUS_TIMER_MODE_RESPONSE_TIMEOUT
|
||||
};
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDISN_FIXP_Pos 1U //Internal padding
|
||||
#define IDISN_FIXP_GS1_COUNTRY_Pos ( IDISN_FIXP_Pos + 0U)
|
||||
#define IDISN_FIXP_GS1_COUNTRY_Length 3
|
||||
#define IDISN_FIXP_GS1_COMPANY_Pos ( IDISN_FIXP_GS1_COUNTRY_Pos + IDISN_FIXP_GS1_COUNTRY_Length )
|
||||
#define IDISN_FIXP_GS1_COMPANY_Length 6
|
||||
#define IDISN_FIXP_MODULE_TYPE_Pos ( IDISN_FIXP_GS1_COMPANY_Pos + IDISN_FIXP_GS1_COMPANY_Length )
|
||||
#define IDISN_FIXP_MODULE_TYPE_Length 3
|
||||
#define IDISN_FIXP_HW_REV_Pos ( IDISN_FIXP_MODULE_TYPE_Pos + IDISN_FIXP_MODULE_TYPE_Length )
|
||||
#define IDISN_FIXP_HW_REV_Length 2
|
||||
#define IDISN_FIXP_SERIAL_Pos ( IDISN_FIXP_HW_REV_Pos + IDISN_FIXP_HW_REV_Length )
|
||||
#define IDISN_FIXP_SERIAL_Length 7
|
||||
#define IDISN_FIXP_MAC_Pos ( IDISN_FIXP_SERIAL_Pos + IDISN_FIXP_SERIAL_Length )
|
||||
#define IDISN_FIXP_MAC_Length 6
|
||||
#define IDISN_FIXP_SW_REV_Pos ( IDISN_FIXP_MAC_Pos + IDISN_FIXP_MAC_Length )
|
||||
#define IDISN_FIXP_SW_REV_Length 2
|
||||
#define IDISN_FIXP_LENGTH ( IDISN_FIXP_GS1_COUNTRY_Length + IDISN_FIXP_GS1_COMPANY_Length + IDISN_FIXP_MODULE_TYPE_Length + \
|
||||
IDISN_FIXP_HW_REV_Length + IDISN_FIXP_SERIAL_Length + IDISN_FIXP_MAC_Length + IDISN_FIXP_SW_REV_Length )
|
||||
|
||||
#define IDISN_VARP_Pos 0 //IDISN_FIXP_LENGTH
|
||||
#define IDISN_VARP_VERIF_DATE_Pos ( IDISN_VARP_Pos )
|
||||
#define IDISN_VARP_VERIF_DATE_Length 4U
|
||||
#define IDISN_VARP_EXPIR_DATE_Pos ( IDISN_VARP_VERIF_DATE_Pos + IDISN_VARP_VERIF_DATE_Length )
|
||||
#define IDISN_VARP_EXPIR_DATE_Length 4U
|
||||
#define IDISN_VARP_IPv4_Pos ( IDISN_VARP_EXPIR_DATE_Pos + IDISN_VARP_EXPIR_DATE_Length )
|
||||
#define IDISN_VARP_IPv4_Length 4U
|
||||
#define IDISN_VARP_IPv6_Pos ( IDISN_VARP_IPv4_Pos + IDISN_VARP_IPv4_Length )
|
||||
#define IDISN_VARP_IPv6_Length 16U
|
||||
#define IDISN_VARP_AES256_Pos ( IDISN_VARP_IPv6_Pos + IDISN_VARP_IPv6_Length )
|
||||
#define IDISN_VARP_AES256_Length 32U
|
||||
#define IDISN_VARP_LENGTH ( IDISN_VARP_VERIF_DATE_Length + IDISN_VARP_EXPIR_DATE_Length + \
|
||||
IDISN_VARP_IPv4_Length + IDISN_VARP_IPv6_Length + IDISN_VARP_AES256_Length )
|
||||
|
||||
#define IDISN_FULL_LENGTH ( IDISN_FIXP_LENGTH + IDISN_VARP_LENGTH )
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define ISIBUS_MASTER_MAIN_ADDR 255U
|
||||
#define ISIBUS_MASTER_SPARE_ADDR 254U
|
||||
#define IDIBUS_SLAVE_ADDR_MIN 1U
|
||||
#define IDIBUS_SLAVE_ADDR_MAX 229U
|
||||
#define IDIBUS_DEVELOPER_ADDR_0 250U
|
||||
#define IDIBUS_DEVELOPER_ADDR_1 251U
|
||||
#define IDIBUS_DEVELOPER_ADDR_2 252U
|
||||
#define IDIBUS_DEVELOPER_ADDR_3 253U
|
||||
#define IDIBUS_GROUP_0_ADDR 230U
|
||||
#define IDIBUS_GROUP_1_ADDR 231U
|
||||
#define IDIBUS_GROUP_2_ADDR 232U
|
||||
#define IDIBUS_GROUP_3_ADDR 233U
|
||||
#define IDIBUS_GROUP_4_ADDR 234U
|
||||
#define IDIBUS_GROUP_5_ADDR 235U
|
||||
#define IDIBUS_GROUP_6_ADDR 236U
|
||||
#define IDIBUS_GROUP_7_ADDR 237U
|
||||
#define IDIBUS_GROUP_8_ADDR 238U
|
||||
#define IDIBUS_GROUP_9_ADDR 239U
|
||||
#define IDIBUS_GROUP_10_ADDR 240U
|
||||
#define IDIBUS_GROUP_11_ADDR 241U
|
||||
#define IDIBUS_GROUP_12_ADDR 242U
|
||||
#define IDIBUS_GROUP_13_ADDR 243U
|
||||
#define IDIBUS_GROUP_14_ADDR 244U
|
||||
#define IDIBUS_GROUP_15_ADDR 245U
|
||||
|
||||
#define IDIBUS_GROUPS_NUMBER 16U
|
||||
#define IDIBUS_GROUP_FIRST_NUMBER 0U
|
||||
#define IDIBUS_GROUP_LAST_NUMBER 15U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIMMES_ADDR_Pos 00U
|
||||
#define IDIMMES_MMPS_Pos 01U
|
||||
#define IDIMMES_MMPS_LONG_MES_Pos 0U
|
||||
#define IDIMMES_MMPS_LONG_MES_Msk 0x01U
|
||||
#define IDIMMES_MMPS_MES_TYPE_Pos 1U
|
||||
#define IDIMMES_MMPS_MES_TYPE_Msk 0x02U
|
||||
#define IDIMMES_MMPS_MES_TYPE_MMES 0x00U
|
||||
#define IDIMMES_MMPS_MES_TYPE_MMESG 0x01U
|
||||
#define IDIMMES_MMPS_FAST_FUNC_Pos 2U
|
||||
#define IDIMMES_MMPS_FAST_FUNC_Msk 0x3CU
|
||||
#define IDIMMES_MMPS_ALARM_FRAME_Pos 6U
|
||||
#define IDIMMES_MMPS_ALARM_FRAME_Msk 0x40U
|
||||
#define IDIMMES_MMPS_ENCRYPTED_AES_Pos 7U
|
||||
#define IDIMMES_MMPS_ENCRYPTED_AES_Msk 0x80U
|
||||
#define IDIMMES_DEV_Pos 02U
|
||||
#define IDIMMES_DEV_NUM_Pos 0U
|
||||
#define IDIMMES_DEV_NUM_Msk 0x1FU
|
||||
#define IDIMMES_DEV_ALLCH_Pos 5U
|
||||
#define IDIMMES_DEV_ALLCH_Msk 0x20U
|
||||
#define IDIMMES_CHNL_Pos 03U
|
||||
#define IDIMMES_CHNL_NUM_Pos 0U
|
||||
#define IDIMMES_CHNL_NUM_Msk 0x7FU
|
||||
#define IDIMMES_CHNL_ALLSAME_Pos 7U
|
||||
#define IDIMMES_CHNL_ALLSAME_Msk 0x80U
|
||||
#define IDIMMES_DATA_FUNC_COM_DATA_Pos 04U
|
||||
#define IDIMMES_MAX_HEADER_LENGTH (IDIMMES_DATA_FUNC_COM_DATA_Pos + 1)
|
||||
#define IDIMMES_MAX_DATA_SIZE 256U
|
||||
#define IDIMMES_MAX_MES_SIZE (IDIMMES_MAX_DATA_SIZE + IDIMMES_MAX_HEADER_LENGTH + MODBUS_CRC16_SIZE)
|
||||
#define IDIMMES_MIN_MES_SIZE (IDIMMES_DATA_FUNC_COM_DATA_Pos + MODBUS_CRC16_SIZE)
|
||||
|
||||
#define IDIMMESG_DATA_COM_FUNC_Pos 02U
|
||||
#define IDIMMESG_MAX_HEADER_LENGTH (IDIMMESG_DATA_COM_FUNC_Pos + 1)
|
||||
#define IDIMMESG_MAX_DATA_SIZE IDIMMES_MAX_DATA_SIZE
|
||||
#define IDIMMESG_MAX_MES_SIZE (IDIMMESG_MAX_DATA_SIZE + IDIMMESG_MAX_HEADER_LENGTH + MODBUS_CRC16_SIZE)
|
||||
#define IDIMMESG_MODULE_MIN_MES_SIZE (IDIMMESG_DATA_COM_FUNC_Pos + 1 + MODBUS_CRC16_SIZE)
|
||||
#define IDIMMESG_GROUP_MIN_MES_SIZE (IDIMMESG_DATA_COM_FUNC_Pos + MODBUS_CRC16_SIZE)
|
||||
|
||||
#define IDIMMES_LMES_MSIZE_Pos 0U
|
||||
#define IDIMMES_LMES_BSIZE_Pos (IDIMMES_LMES_MSIZE_Pos + 4U)
|
||||
#define IDIMMES_LMES_IDENTIFIER_LENGTH (IDIMMES_LMES_BSIZE_Pos + 1U)
|
||||
#define IDIMMES_LMES_BSIZE_256B 0U
|
||||
#define IDIMMES_LMES_BSIZE_1K 1U
|
||||
#define IDIMMES_LMES_BSIZE_4K 2U
|
||||
#define IDIMMES_LMES_BSIZE_8K 3U
|
||||
#define IDIMMES_LMES_BSIZE_16K 4U
|
||||
#define IDIMMES_LMES_BSIZE_32K 5U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDISMES_ADDR_Pos 00U
|
||||
#define IDISMES_SMPS_Pos 01U
|
||||
#define IDISMES_SMPS_ERROR_BIT_Pos 0U
|
||||
#define IDISMES_SMPS_LONG_MES_Pos 1U
|
||||
#define IDISMES_SMPS_LONG_OP_Pos 2U
|
||||
#define IDISMES_ERROR_Pos 02U
|
||||
#define IDISMES_DATA_Pos 03U
|
||||
#define IDISMES_MAX_DATA_SIZE 256U
|
||||
#define IDISMES_MIN_MES_SIZE (IDISMES_DATA_Pos + MODBUS_CRC16_SIZE)
|
||||
#define IDISMES_MAX_MES_SIZE (IDISMES_DATA_Pos + IDISMES_MAX_DATA_SIZE + MODBUS_CRC16_SIZE)
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDILONGOP_STATE_COMPLETE_NO_ERR 0x00U
|
||||
#define IDILONGOP_STATE_IN_PROC 0x01U
|
||||
#define IDILONGOP_STATE_COMPLETE_WITH_ERR 0x02U
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define IDILONGOP_MES_DATA_LENGTH 5U
|
||||
#define IDILONGOP_STATE_Pos 0U
|
||||
#define IDILONGOP_REMAIN_TIME_Pos 1U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDISTATUS_B0S_Pos 00U
|
||||
#define IDISTATUS_B0S_ST_ERROR_Pos 0U
|
||||
#define IDISTATUS_B0S_ST_STATE_Pos 1U
|
||||
#define IDISTATUS_B0S_ST_STATE_Msk 0x07U
|
||||
#define IDISTATUS_B0S_ST_STATE_StNoInit 0x00U
|
||||
#define IDISTATUS_B0S_ST_STATE_StOperate 0x01U
|
||||
#define IDISTATUS_B0S_ST_STATE_StFreeze 0x02U
|
||||
#define IDISTATUS_B0S_ST_STATE_StVirtual 0x03U
|
||||
#define IDISTATUS_B0S_ST_STATE_StFirmwareUpd 0x04U
|
||||
#define IDISTATUS_B0S_ST_STATE_StReservedMaster 0x05U
|
||||
#define IDISTATUS_B0S_ST_STATE_StBroken 0x06U
|
||||
#define IDISTATUS_B0S_ST_STATE_StReserved0 0x07U
|
||||
#define IDISTATUS_B0S_AES_SUPPORTED_Pos 4U
|
||||
#define IDISTATUS_B0S_AES_INSTALLED_Pos 5U
|
||||
#define IDISTATUS_B0S_SEND_ALARM_L0_Pos 6U
|
||||
#define IDISTATUS_B0S_SEND_ALARM_L1_Pos 7U
|
||||
|
||||
#define IDISTATUS_B1S_Pos 01U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Pos 0U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Msk 0x03U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Master 0x00U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_SpareMaster 0x01U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Slave 0x02U
|
||||
#define IDISTATUS_B1S_MODULE_TYPE_Bridge 0x03U
|
||||
#define IDISTATUS_B1S_BRIDGE_CONNECTED_Pos 2U
|
||||
#define IDISTATUS_B1S_SELF_INIT_Pos 3U
|
||||
#define IDISTATUS_B1S_TIMEOUT_LED_Pos 4U
|
||||
#define IDISTATUS_B1S_NO_MMES_TIMEOUT_Pos 5U
|
||||
#define IDISTATUS_B1S_CATCH_ALARM_L0_Pos 6U
|
||||
#define IDISTATUS_B1S_CATCH_ALARM_L1_Pos 7U
|
||||
|
||||
#define IDISTATUS_SN_Pos 02U
|
||||
#define IDISTATUS_LENGTH ( IDISTATUS_SN_Pos + IDISN_FULL_LENGTH )
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIMMES_NOT_FAST_FUNC 0U
|
||||
#define IDIMMES_MAX_FAST_FUNC_NUM 15U
|
||||
#define IDIMMES_COM_START_NUM 220U
|
||||
#define IDIMMES_COM_C_Init 220U
|
||||
#define IDIMMES_COM_C_ShtDown 221U
|
||||
#define IDIMMES_COM_C_Freeze 222U
|
||||
#define IDIMMES_COM_C_Resume 223U
|
||||
#define IDIMMES_COM_C_Dummy 224U
|
||||
#define IDIMMES_COM_C_AssignGroup 225U
|
||||
#define IDIMMES_COM_C_SetAlarmL12 226U
|
||||
#define IDIMMES_COM_C_SetAlarmL 227U
|
||||
#define IDIMMES_COM_C_Virtual 228U
|
||||
#define IDIMMES_COM_C_SyncReadChnl 229U
|
||||
#define IDIMMES_COM_C_SyncRead 230U
|
||||
#define IDIMMES_COM_C_SyncDoChnl 231U
|
||||
#define IDIMMES_COM_C_SyncDo 232U
|
||||
#define IDIMMES_COM_C_SyncClear 233U
|
||||
#define IDIMMES_COM_C_BurstReadCnt 234U
|
||||
#define IDIMMES_COM_C_BurstReadTime 235U
|
||||
#define IDIMMES_COM_C_SendTimeDate 236U
|
||||
#define IDIMMES_COM_C_MkTimedMaster 237U
|
||||
#define IDIMMES_COM_C_EnterBootloader 238U //OUT OF SPEC !!!
|
||||
//#define IDIMMES_COM_C_EndFmwUpd 239U
|
||||
//#define IDIMMES_COM_C_FmwWrite 240U
|
||||
#define IDIMMES_COM_C_ReadDevFullSN_MS 241U
|
||||
#define IDIMMES_COM_C_WriteSnIPv4IPv6 242U
|
||||
#define IDIMMES_COM_C_WriteSnVerifyDates 243U
|
||||
#define IDIMMES_COM_C_WriteSnAES256 244U
|
||||
#define IDIMMES_COM_C_SendLongMessage 245U
|
||||
#define IDIMMES_COM_C_GetLondMessage 246U
|
||||
#define IDIMMES_COM_C_DummyModule 247U
|
||||
#define IDIMMES_COM_C_CheckModuleLongOp 248U
|
||||
#define IDIMMES_COM_C_CheckChannelLongOp 249U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIER_MODBUS_NUM_START 1U
|
||||
#define IDIER_MODBUS_NUM_END 9U
|
||||
#define IDIER_MODULE_MASTER_NUM_START 10U
|
||||
#define IDIER_MODULE_MASTER_NUM_END 32U
|
||||
#define IDIER_MODULE_SLAVE_NUM_START 33U
|
||||
#define IDIER_MODULE_SLAVE_NUM_END 71U
|
||||
#define IDIER_MODULE_NUM_START IDIER_MODULE_MASTER_NUM_START
|
||||
#define IDIER_MODULE_NUM_END IDIER_MODULE_SLAVE_NUM_END
|
||||
#define IDIER_DEVICE_NUM_START 72U
|
||||
#define IDIER_DEVICE_NUM_END 89U
|
||||
|
||||
#define IDIER_NOPE 0U
|
||||
#define MODBUSER_WRONGFUNC 1U
|
||||
#define MODBUSER_WRONGADDR 2U
|
||||
#define MODBUSER_WRONGDATA 3U
|
||||
#define MODBUSER_BROKE 4U
|
||||
#define MODBUSER_LONGCOMMAND 5U
|
||||
#define MODBUSER_BUSY 6U
|
||||
#define MODBUSER_CANTDOFUNC 7U
|
||||
#define MODBUSER_EXTMEMORYERROR 8U
|
||||
#define MODBUSER_RESERVED 9U
|
||||
#define IDIERMST_INVALID_ADDR_NUM 10U
|
||||
#define IDIERMST_INVALID_DEV_NUM 11U
|
||||
#define IDIERMST_INVALID_CHN_NUM 12U
|
||||
#define IDIERMST_INVALID_FUNC_NUM 13U
|
||||
#define IDIERMST_INVALID_TX_REQUEST_FORMAT 14U
|
||||
#define IDIERMST_INVALID_TX_PARAM 15U
|
||||
#define IDIERMST_TX_MES 16U
|
||||
#define IDIERMST_RCV_TIMEOUT 17U
|
||||
#define IDIERMST_MES_RX_INTEGRITY 18U
|
||||
#define IDIERMST_CRC 19U
|
||||
#define IDIERMST_MULTIPLE_CRC 20U
|
||||
#define IDIERMST_INVALID_RX_REQUEST_FORMAT 21U
|
||||
#define IDIERMST_INVALID_RX_PARAM 22U
|
||||
#define IDIERMST_RESEVED_23 23U
|
||||
#define IDIERMST_RESEVED_24 24U
|
||||
#define IDIERMST_RESEVED_25 25U
|
||||
#define IDIERMST_RESEVED_26 26U
|
||||
#define IDIERMST_RESEVED_27 27U
|
||||
#define IDIERMST_EXTRA_28 28U
|
||||
#define IDIERMST_EXTRA_29 29U
|
||||
#define IDIERMST_EXTRA_30 30U
|
||||
#define IDIERMST_EXTRA_31 31U
|
||||
#define IDIERMST_EXTRA_32 32U
|
||||
#define IDIERSLV_RESEVED_33 33U
|
||||
#define IDIERSLV_ENCRYPTION_NOT_SUPPORTED 34U
|
||||
#define IDIERSLV_ENCRYPTION_NOT_INSTALLED 35U
|
||||
#define IDIERSLV_JUMBO_NOT_SUPPORTED 36U
|
||||
#define IDIERSLV_UNSUPPORTED_FUNC_NUM 37U
|
||||
#define IDIERSLV_INVALID_RX_REQUEST_FORMAT 38U
|
||||
#define IDIERSLV_INVALID_RX_PARAM 39U
|
||||
#define IDIERSLV_IN_FREEZE 40U
|
||||
#define IDIERSLV_RESERVED_41 41U
|
||||
#define IDIERSLV_RESERVED_42 42U
|
||||
#define IDIERSLV_RESERVED_43 43U
|
||||
#define IDIERSLV_RESERVED_44 44U
|
||||
#define IDIERSLV_RESERVED_45 45U
|
||||
#define IDIERSLV_EXTRA_46 46U
|
||||
#define IDIERSLV_EXTRA_47 47U
|
||||
#define IDIERSLV_EXTRA_48 48U
|
||||
#define IDIERSLV_EXTRA_49 49U
|
||||
#define IDIERSLV_EXTRA_50 50U
|
||||
#define IDIERSLV_BROKE 51U
|
||||
#define IDIERSLV_NO_FIRMWARE 52U
|
||||
#define IDIERSLV_NO_INIT 53U
|
||||
#define IDIERSLV_OVERHEAT 54U
|
||||
#define IDIERSLV_INP_VOLTAGE 55U
|
||||
#define IDIERSLV_BRIDGE_OVERFLOW 56U
|
||||
#define IDIERSLV_BRIDGE_NOT_CONF 57U
|
||||
#define IDIERSLV_VERIF_DATE 58U
|
||||
#define IDIERSLV_RTC 59U
|
||||
#define IDIERSLV_LONG_OP_IN_PROC 60U
|
||||
#define IDIERSLV_RESERVED_61 61U
|
||||
#define IDIERSLV_RESERVED_62 62U
|
||||
#define IDIERSLV_RESERVED_63 63U
|
||||
#define IDIERSLV_RESERVED_64 64U
|
||||
#define IDIERSLV_RESERVED_65 65U
|
||||
#define IDIERSLV_RESERVED_66 66U
|
||||
#define IDIERSLV_EXTRA_67 67U
|
||||
#define IDIERSLV_EXTRA_68 68U
|
||||
#define IDIERSLV_EXTRA_69 69U
|
||||
#define IDIERSLV_EXTRA_70 70U
|
||||
#define IDIERSLV_EXTRA_71 71U
|
||||
#define IDIERDEV_INVALID_DEV_NUM 72U
|
||||
#define IDIERDEV_INVALID_CHN_NUM 73U
|
||||
#define IDIERDEV_INVALID_FUNC_NUM 74U
|
||||
#define IDIERDEV_LONG_OP_IN_PROC 75U
|
||||
#define IDIERDEV_RESERVED_76 76U
|
||||
#define IDIERDEV_PARAM_LOW_ST_TIMEOUT 77U
|
||||
#define IDIERDEV_PARAM_HIGH_ST_TIMEOUT 78U
|
||||
#define IDIERDEV_PARAM_NOT_CHANGE_TIMEOUT 79U
|
||||
#define IDIERDEV_RESERVED_80 80U
|
||||
#define IDIERDEV_RESERVED_81 81U
|
||||
#define IDIERDEV_RESERVED_82 82U
|
||||
#define IDIERDEV_RESERVED_83 83U
|
||||
#define IDIERDEV_RESERVED_84 84U
|
||||
#define IDIERDEV_RESERVED_85 85U
|
||||
#define IDIERDEV_RESERVED_86 86U
|
||||
#define IDIERDEV_RESERVED_87 87U
|
||||
#define IDIERDEV_RESERVED_88 88U
|
||||
#define IDIERDEV_RESERVED_89 89U
|
||||
|
||||
#define IDIER_MULTIPLE_CRC_AVRBUF_SIZE 16U
|
||||
#define IDIER_MULTIPLE_CRC_AVRBUF_THR 5U
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
#define IDIDATE_FORMAT_DAY_Pos 0U
|
||||
#define IDIDATE_FORMAT_MONTH_Pos 1U
|
||||
#define IDIDATE_FORMAT_CENTURY_Pos 2U
|
||||
#define IDIDATE_FORMAT_YEAR99_Pos 3U
|
||||
#define IDIDATE_FORMAT_LENGTH 4U
|
||||
|
||||
#define IDITIME_FORMAT_SECONDS_Pos 0U
|
||||
#define IDITIME_FORMAT_MINUTES_Pos 1U
|
||||
#define IDITIME_FORMAT_HOURS_Pos 2U
|
||||
#define IDITIME_FORMAT_TIMEZONE_Pos 3U
|
||||
#define IDITIME_FORMAT_LENGTH 4U
|
||||
|
||||
#define IDITIME_FORMAT_TIMEZONE_MIN (-12)
|
||||
#define IDITIME_FORMAT_TIMEZONE_MAX 14
|
||||
|
||||
#define IDIMMES_C_DATETIME_TIME_Pos 0
|
||||
#define IDIMMES_C_DATETIME_DATE_Pos (IDIMMES_C_DATETIME_TIME_Pos + IDIDATE_FORMAT_LENGTH)
|
||||
#define IDIMMES_C_DATETIME_LENGTH (IDIDATE_FORMAT_LENGTH + IDITIME_FORMAT_LENGTH)
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
typedef struct {
|
||||
struct {
|
||||
uint8_t StError : 1;
|
||||
uint8_t StState : 3;
|
||||
uint8_t AesSupported : 1;
|
||||
uint8_t AesInstalled : 1;
|
||||
uint8_t SendAlarmL0 : 1;
|
||||
uint8_t SendAlarmL1 : 1;
|
||||
} B0S;
|
||||
struct {
|
||||
uint8_t ModuleType : 2;
|
||||
uint8_t BridgeConnected : 1;
|
||||
uint8_t SelfInit : 1;
|
||||
uint8_t TimeoutLed : 1;
|
||||
uint8_t NoMMESTimeout : 1;
|
||||
uint8_t CatchAlarmL0 : 1;
|
||||
uint8_t CatchAlarmL1 : 1;
|
||||
} B1S;
|
||||
} IDISTATUS_STATE_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
IDISTATUS_STATE_TYPE STATE;
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
volatile uint_farptr_t SNfix;
|
||||
#else
|
||||
volatile uint8_t *SNfix;
|
||||
#endif
|
||||
volatile uint8_t *SNvar;
|
||||
//uint8_t SN[IDISN_FULL_LENGTH];
|
||||
} IDISTATUS_SLAVE_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif //_INC_IDIBUS_DEFS_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,33 @@
|
||||
#ifndef MEMORY_H_
|
||||
#define MEMORY_H_
|
||||
volatile typedef struct{
|
||||
volatile uint8_t Padding;
|
||||
volatile uint8_t GS1_country[IDISN_FIXP_GS1_COUNTRY_Length];
|
||||
volatile uint8_t GS1_company[IDISN_FIXP_GS1_COMPANY_Length];
|
||||
volatile uint8_t ModuleType[IDISN_FIXP_MODULE_TYPE_Length];
|
||||
volatile uint8_t HW_revision[IDISN_FIXP_HW_REV_Length];
|
||||
volatile uint8_t SN[IDISN_FIXP_SERIAL_Length];
|
||||
volatile uint8_t MAC[IDISN_FIXP_MAC_Length];
|
||||
volatile uint8_t SW[IDISN_FIXP_SW_REV_Length]; //SW Version (Bootloader/App)
|
||||
volatile uint32_t AppCRC; //Only in APP
|
||||
} FLASH_DATABLOCK;
|
||||
//Universal data block
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _BOOTLOADER_
|
||||
#include "BootVersion.h"
|
||||
const volatile FLASH_DATABLOCK STATIC_DATA_BL __attribute__((section (".locationInBoot"))) = {
|
||||
//STATIC PART
|
||||
#include "device.cfg"
|
||||
.SW = {BOOT_VERSION_MAJOR, BOOT_VERSION_MINOR} //Botloader version
|
||||
};
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define APP_VERSION
|
||||
const volatile FLASH_DATABLOCK STATIC_DATA_APP __attribute__((section (".locationInApp"))) = {
|
||||
//.AppCRC = 0x8d173a8c //CRC32 for empty flash
|
||||
#include "device.cfg"
|
||||
};
|
||||
#undef APP_VERSION
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* MEMORY_H_ */
|
@ -0,0 +1,435 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "IDIBUS_IMPL.h"
|
||||
#include "EEMEM.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// At the request of the customer
|
||||
volatile char IDUBUS_SPEC_FRAZE_RU[] = "ÍÅËÅÇÒÜ !!!";
|
||||
volatile char IDUBUS_SPEC_FRAZE_EN[] = "HANDS OFF !!!";
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
void IDIBUS_ModuleInit(USART_INTERFACE_TYPE *USART_INTERFACE, uint_farptr_t PROGMEM_SN)
|
||||
#else
|
||||
void IDIBUS_ModuleInit(USART_INTERFACE_TYPE *USART_INTERFACE, uint8_t *PROGMEM_SN)
|
||||
#endif
|
||||
{
|
||||
if (IDUBUS_SPEC_FRAZE_RU[0]) {}
|
||||
if (IDUBUS_SPEC_FRAZE_EN[0]) {}
|
||||
|
||||
IDIBUS_MODULE.USI = USART_INTERFACE;
|
||||
|
||||
IDIBUS_CustomInit();
|
||||
|
||||
IDIBUS_MODULE.FreezeMemState = IDISTATUS_B0S_ST_STATE_StOperate;
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_NOPE;
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_COMPLETE_NO_ERR;
|
||||
IDIBUS_MODULE.Error = IDIER_NOPE;
|
||||
IDIBUS_MODULE.c_InitAssignGroup = IDIBUS_GROUP_0_ADDR;
|
||||
|
||||
// SN read ------------------------------------------------------------------------------------------------------>
|
||||
IDIBUS_MODULE.STATUS.SNfix = PROGMEM_SN;
|
||||
IDIBUS_MODULE.STATUS.SNvar = &EEBLOCK.EEPROM_SN;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t InitAssignGroup = eeprom_read_byte(&EEBLOCK.EEPROM_IDIBUS_InitGroup);
|
||||
|
||||
if ( (InitAssignGroup > IDIBUS_GROUP_0_ADDR ) && (InitAssignGroup <= IDIBUS_GROUP_15_ADDR) )
|
||||
{
|
||||
for (uint8_t Dev = 0; Dev < IDIBUS_MODULE.DevicesCount; Dev++)
|
||||
{
|
||||
for (uint8_t Ch = 0; Ch<IDIBUS_MODULE.Devices[Dev].ChannelsCount; Ch++) { IDIBUS_MODULE.Devices[Dev].Channels[Ch].BcastAddr = InitAssignGroup; }
|
||||
}
|
||||
eeprom_write_byte(&EEBLOCK.EEPROM_IDIBUS_InitGroup, 0xFF);
|
||||
}
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ModuleBackgroundHandler(void)
|
||||
{
|
||||
// Long Operation Routine ------------------------>
|
||||
switch ( IDIBUS_MODULE.LONG_OP.Type )
|
||||
{
|
||||
case (IDIBUS_LONGOP_VARSN_IP_WRITE) : {
|
||||
if (IDIBUS_MODULE.LONG_OP.Switch == 0){
|
||||
EEPROM_WriteEepBuf(IDISN_VARP_IPv4_Length+IDISN_VARP_IPv6_Length,&EEBLOCK.EEPROM_SN[IDISN_VARP_IPv4_Pos]);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIBUS_LONGOP_VARSN_VERIF_EXP_WRITE) : {
|
||||
if (IDIBUS_MODULE.LONG_OP.Switch == 0){
|
||||
EEPROM_WriteEepBuf(IDISN_VARP_EXPIR_DATE_Length+IDISN_VARP_VERIF_DATE_Length,&EEBLOCK.EEPROM_SN[IDISN_VARP_VERIF_DATE_Pos]);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIBUS_LONGOP_VARSN_AES_WRITE) : {
|
||||
if (IDIBUS_MODULE.LONG_OP.Switch == 0){
|
||||
EEPROM_WriteEepBuf(IDISN_VARP_AES256_Length,&EEBLOCK.EEPROM_SN[IDISN_VARP_AES256_Pos]);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIBUS_LONGOP_INIT) : {
|
||||
|
||||
if ( IDIBUS_MODULE.c_InitAssignGroup != IDIBUS_GROUP_0_ADDR )
|
||||
eeprom_write_byte(&EEBLOCK.EEPROM_IDIBUS_InitGroup,IDIBUS_MODULE.c_InitAssignGroup);
|
||||
|
||||
uint8_t TimeoutMS = 200;
|
||||
while ( (!eeprom_is_ready() || IDIBUS_MODULE.USI->IsTxActive()) && (TimeoutMS != 0) ) { TimeoutMS--; _delay_ms(1); }
|
||||
System_SWReboot();
|
||||
break; }
|
||||
|
||||
default : {}
|
||||
}
|
||||
|
||||
// Error Handler Routine ------------------------>
|
||||
if ( IDIBUS_MODULE.LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
{
|
||||
if ( System_GetSysTickDifference(IDIBUS_MODULE.LONG_OP.StartTimeInstanceMS) > IDIBUS_MODULE.LONG_OP.DurationMS )
|
||||
{
|
||||
// Long Operation terminate function
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_COMPLETE_WITH_ERR;
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_NOPE;
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ModuleCommandHandler(IDIBUS_FARG_TYPE *farg)
|
||||
{
|
||||
// If there is special command we don't care about any error in this place
|
||||
if ( (farg->ComFunc != IDIMMES_COM_C_Init) && (farg->ComFunc != IDIMMES_COM_C_ShtDown) && (farg->ComFunc != IDIMMES_COM_C_SetAlarmL) )
|
||||
{
|
||||
// IF we somehow managed to come to the freeze state, we need to exit from freeze state
|
||||
if ( IDIBUS_MODULE.STATUS.STATE.B0S.StState == IDISTATUS_B0S_ST_STATE_StFreeze )
|
||||
{
|
||||
if ( farg->ComFunc != IDIMMES_COM_C_Resume ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_IN_FREEZE); return; }
|
||||
} // If not special command or freeze but long Operation and command not DummyModule
|
||||
else if ( IDIBUS_MODULE.Error != IDIER_NOPE ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIBUS_MODULE.Error); return; }
|
||||
else if ( IDIBUS_MODULE.LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
{
|
||||
if ( farg->ComFunc != IDIMMES_COM_C_CheckModuleLongOp ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_LONG_OP_IN_PROC); return; }
|
||||
}
|
||||
}
|
||||
|
||||
// There is no prohibited command if this place - just handle it
|
||||
switch ( farg->ComFunc )
|
||||
{
|
||||
case (IDIMMES_COM_C_DummyModule) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE); }
|
||||
break; }
|
||||
|
||||
case ( IDIMMES_COM_C_Init ) : {
|
||||
if ( farg->InpDataLength > 1 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else if ( (farg->InpDataLength == 1) && (farg->InpData[0] > IDIBUS_GROUP_LAST_NUMBER) ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_PARAM); }
|
||||
//Some custom error???!!
|
||||
//else if ( 0 /* CTRL_SelectedMode == _CTRL_MODE_MANUAL_ */ ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIBUS_CUSTDEF_ERCODE_NO_ACCESS); }
|
||||
else
|
||||
{
|
||||
if ( farg->InpDataLength == 1 ) { IDIBUS_MODULE.c_InitAssignGroup = (uint8_t)( farg->InpData[0] + IDIBUS_GROUP_0_ADDR ); }
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_INIT;
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case ( IDIMMES_COM_C_ShtDown ) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
//Some custom error???!!
|
||||
//else if ( 0 /* CTRL_SelectedMode == _CTRL_MODE_MANUAL_ */ ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIBUS_CUSTDEF_ERCODE_NO_ACCESS); }
|
||||
else
|
||||
{
|
||||
//IDIBUS_CustomShutdown();
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.StState = IDISTATUS_B0S_ST_STATE_StNoInit;
|
||||
IDIBUS_MODULE.Error = IDIERSLV_NO_INIT;
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_Freeze) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
IDIBUS_MODULE.FreezeMemState = IDIBUS_MODULE.STATUS.STATE.B0S.StState;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.StState = IDISTATUS_B0S_ST_STATE_StFreeze;
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_Resume) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.StState = (uint8_t)(IDIBUS_MODULE.FreezeMemState & 0x07U);
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIBUS_MODULE.Error);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_ReadDevFullSN_MS) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
uint8_t ResponseLength = IDISN_FULL_LENGTH - IDISN_VARP_AES256_Length + 2;
|
||||
uint8_t Response[ResponseLength];
|
||||
Response[IDISTATUS_B0S_Pos] = (uint8_t) (
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.StError << IDISTATUS_B0S_ST_ERROR_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.StState << IDISTATUS_B0S_ST_STATE_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.AesSupported << IDISTATUS_B0S_AES_SUPPORTED_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.AesInstalled << IDISTATUS_B0S_AES_INSTALLED_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.SendAlarmL0 << IDISTATUS_B0S_SEND_ALARM_L0_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.SendAlarmL1 << IDISTATUS_B0S_SEND_ALARM_L1_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B0S.StState << IDISTATUS_B0S_ST_STATE_Pos) );
|
||||
Response[IDISTATUS_B1S_Pos] = (uint8_t) (
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.ModuleType << IDISTATUS_B1S_MODULE_TYPE_Pos) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.BridgeConnected << IDISTATUS_B1S_BRIDGE_CONNECTED_Pos ) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.SelfInit << IDISTATUS_B1S_SELF_INIT_Pos ) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.TimeoutLed << IDISTATUS_B1S_TIMEOUT_LED_Pos ) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.NoMMESTimeout << IDISTATUS_B1S_NO_MMES_TIMEOUT_Pos ) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.CatchAlarmL0 << IDISTATUS_B1S_CATCH_ALARM_L0_Pos ) |
|
||||
((uint8_t)IDIBUS_MODULE.STATUS.STATE.B1S.CatchAlarmL1 << IDISTATUS_B1S_CATCH_ALARM_L1_Pos ) );
|
||||
for (uint8_t pos=0; pos < IDISN_FIXP_LENGTH; pos++) {Response[IDISTATUS_SN_Pos+pos] = flash_read_byte(IDIBUS_MODULE.STATUS.SNfix,IDISN_FIXP_Pos+pos);}
|
||||
for (uint8_t pos=0; pos < IDISN_VARP_LENGTH-IDISN_VARP_AES256_Length; pos++) {Response[IDISTATUS_SN_Pos+IDISN_FIXP_LENGTH+pos] = eeprom_read_byte(&IDIBUS_MODULE.STATUS.SNvar[pos]);}
|
||||
IDIBUS_ResponseProtectedWrite(farg, Response, ResponseLength, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_CheckModuleLongOp) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
uint8_t Response[IDILONGOP_MES_DATA_LENGTH];
|
||||
Response[IDILONGOP_STATE_Pos] = IDIBUS_MODULE.LONG_OP.State;
|
||||
uint32_t Countdown;
|
||||
if ( IDIBUS_MODULE.LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
{
|
||||
uint32_t TimeFromStart = System_GetSysTickDifference(IDIBUS_MODULE.LONG_OP.StartTimeInstanceMS);
|
||||
if ( IDIBUS_MODULE.LONG_OP.DurationMS > TimeFromStart ) { Countdown = IDIBUS_MODULE.LONG_OP.DurationMS - TimeFromStart; }
|
||||
else { Countdown = 0; }
|
||||
}
|
||||
else { Countdown = 0; }
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos] = (uint8_t)(Countdown >> 24);
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos + 1] = (uint8_t)(Countdown >> 16);
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos + 2] = (uint8_t)(Countdown >> 8);
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos + 3] = (uint8_t)(Countdown);
|
||||
IDIBUS_ResponseProtectedWrite(farg, Response, IDILONGOP_MES_DATA_LENGTH, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_SendTimeDate) : {
|
||||
if ( farg->InpDataLength != IDIMMES_C_DATETIME_LENGTH ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
if (
|
||||
( farg->InpData[IDIMMES_C_DATETIME_TIME_Pos + IDITIME_FORMAT_SECONDS_Pos] > 60U ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_TIME_Pos + IDITIME_FORMAT_MINUTES_Pos] > 60U ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_TIME_Pos + IDITIME_FORMAT_HOURS_Pos] > 23U ) ||
|
||||
( (int8_t)farg->InpData[IDIMMES_C_DATETIME_TIME_Pos + IDITIME_FORMAT_TIMEZONE_Pos] > IDITIME_FORMAT_TIMEZONE_MAX ) ||
|
||||
( (int8_t)farg->InpData[IDIMMES_C_DATETIME_TIME_Pos + IDITIME_FORMAT_TIMEZONE_Pos] < IDITIME_FORMAT_TIMEZONE_MIN ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_DATE_Pos + IDIDATE_FORMAT_DAY_Pos] > 31 ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_DATE_Pos + IDIDATE_FORMAT_DAY_Pos] == 0 ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_DATE_Pos + IDIDATE_FORMAT_MONTH_Pos] > 31 ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_DATE_Pos + IDIDATE_FORMAT_MONTH_Pos] == 0 ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_DATE_Pos + IDIDATE_FORMAT_CENTURY_Pos] > 99 ) ||
|
||||
( farg->InpData[IDIMMES_C_DATETIME_DATE_Pos + IDIDATE_FORMAT_YEAR99_Pos] > 99 )
|
||||
)
|
||||
{
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_PARAM);
|
||||
}
|
||||
else { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE); }
|
||||
}
|
||||
break; }
|
||||
|
||||
// LONG OPERATION FUNCS -------------------------------------------------------------->
|
||||
case (IDIMMES_COM_C_WriteSnIPv4IPv6) : {
|
||||
if ( farg->InpDataLength != (IDISN_VARP_IPv4_Length + IDISN_VARP_IPv6_Length) ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
memcpy(&EEPROM_BUF, farg->InpData, farg->InpDataLength);
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_VARSN_IP_WRITE;
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_IN_PROC;
|
||||
IDIBUS_MODULE.LONG_OP.StartTimeInstanceMS = System_GetTimeInstance();
|
||||
IDIBUS_MODULE.LONG_OP.DurationMS = IDIBUS_LONGOP_VARSN_IP_WRITE_DURATION_MS;
|
||||
farg->LongOpState = 1;
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_WriteSnVerifyDates) : {
|
||||
if ( farg->InpDataLength != (IDIDATE_FORMAT_LENGTH * 2) ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else if (
|
||||
(farg->InpData[IDIDATE_FORMAT_DAY_Pos] == 0)||(farg->InpData[IDIDATE_FORMAT_DAY_Pos] > 31) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_MONTH_Pos] == 0 )||(farg->InpData[IDIDATE_FORMAT_MONTH_Pos] > 12) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_CENTURY_Pos] > 99 ) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_YEAR99_Pos] > 99) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_DAY_Pos+IDIDATE_FORMAT_LENGTH] == 0)||(farg->InpData[IDIDATE_FORMAT_DAY_Pos+IDIDATE_FORMAT_LENGTH] > 31) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_MONTH_Pos+IDIDATE_FORMAT_LENGTH] == 0 )||(farg->InpData[IDIDATE_FORMAT_MONTH_Pos+IDIDATE_FORMAT_LENGTH] > 12) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_CENTURY_Pos+IDIDATE_FORMAT_LENGTH] > 99 ) ||
|
||||
(farg->InpData[IDIDATE_FORMAT_YEAR99_Pos+IDIDATE_FORMAT_LENGTH] > 99)
|
||||
)
|
||||
{
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_PARAM);
|
||||
}
|
||||
else {
|
||||
//memcpy(&EEPROM_BUF, farg->InpData, (IDIDATE_FORMAT_LENGTH * 2));
|
||||
memcpy(&EEPROM_BUF, farg->InpData, farg->InpDataLength);
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_VARSN_VERIF_EXP_WRITE;
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_IN_PROC;
|
||||
IDIBUS_MODULE.LONG_OP.StartTimeInstanceMS = System_GetTimeInstance();
|
||||
IDIBUS_MODULE.LONG_OP.DurationMS = IDIBUS_LONGOP_VARSN_VERF_EXP_WRITE_DURATION_MS;
|
||||
farg->LongOpState = 1;
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_WriteSnAES256) : {
|
||||
if ( farg->InpDataLength != IDISN_VARP_AES256_Length ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
//!!!memcpy(&IDIBUS_MODULE.STATUS.SN[IDISN_VARP_AES256_Pos], farg->InpData, farg->InpDataLength);
|
||||
memcpy(&EEPROM_BUF, farg->InpData, farg->InpDataLength);
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_VARSN_AES_WRITE;
|
||||
IDIBUS_MODULE.LONG_OP.Switch = 0;
|
||||
IDIBUS_MODULE.LONG_OP.State = IDILONGOP_STATE_IN_PROC;
|
||||
IDIBUS_MODULE.LONG_OP.StartTimeInstanceMS = System_GetTimeInstance();
|
||||
IDIBUS_MODULE.LONG_OP.DurationMS = IDIBUS_LONGOP_VARSN_AES_WRITE_DURATION_MS;
|
||||
farg->LongOpState = 1;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.AesInstalled = 0;
|
||||
for ( uint8_t I = 0; I < IDISN_VARP_AES256_Length; I++ )
|
||||
{
|
||||
if ( /*IDIBUS_MODULE.STATUS.SN[IDISN_VARP_AES256_Pos + I] != 0 */ 0 /* TODO */ ) { IDIBUS_MODULE.STATUS.STATE.B0S.AesInstalled = 1; break; }
|
||||
}
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
case (IDIMMES_COM_C_EnterBootloader) : {
|
||||
const uint8_t packageSize = IDISN_FIXP_MODULE_TYPE_Length+IDISN_FIXP_HW_REV_Length+IDISN_FIXP_SERIAL_Length;
|
||||
if ( farg->InpDataLength != packageSize) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
uint8_t Check = 1;
|
||||
for (uint8_t pos=0; pos < packageSize; pos++) {
|
||||
if (farg->InpData[pos] != flash_read_byte(IDIBUS_MODULE.STATUS.SNfix,IDISN_FIXP_MODULE_TYPE_Pos+pos))
|
||||
Check = 0;
|
||||
}
|
||||
|
||||
if (Check == 1){
|
||||
IDIBUS_MODULE.LONG_OP.Type = IDIBUS_LONGOP_INIT;
|
||||
eeprom_write_byte(&EEBLOCK.BOOTFLAG, 0xB0);
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
} else {
|
||||
IDIBUS_ResponseProtectedWrite(farg,NULL,0,IDIERSLV_INVALID_RX_PARAM);
|
||||
}
|
||||
}
|
||||
break; }
|
||||
|
||||
|
||||
default : { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_UNSUPPORTED_FUNC_NUM); }
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_ChannelBackgroundHandler (void)
|
||||
{
|
||||
|
||||
// Error Handler ------------------------>
|
||||
for ( uint8_t Dev=0; Dev < IDIBUS_MODULE.DevicesCount; Dev++ )
|
||||
{
|
||||
for ( uint8_t Ch=0; Ch<IDIBUS_MODULE.Devices[Dev].ChannelsCount; Ch++ )
|
||||
{
|
||||
IDIBUS_CHANNEL *CH = &IDIBUS_MODULE.Devices[Dev].Channels[Ch];
|
||||
if ( CH->LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
{
|
||||
if ( System_GetSysTickDifference(CH->LONG_OP.StartTimeInstanceMS) > CH->LONG_OP.DurationMS )
|
||||
{
|
||||
// Long Operation terminate function
|
||||
CH->LONG_OP.State = IDILONGOP_STATE_COMPLETE_WITH_ERR;
|
||||
CH->LONG_OP.Type = IDIBUS_LONGOP_NOPE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t IDIBUS_CnannelStaticFunc(struct IDIBUS_CHANNEL_STR* CH, IDIBUS_FARG_TYPE *farg)
|
||||
{
|
||||
if ( CH->LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
{
|
||||
farg->LongOpState = 1;
|
||||
if ( farg->ComFunc != IDIMMES_COM_C_CheckChannelLongOp ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERDEV_LONG_OP_IN_PROC); return 1; }
|
||||
}
|
||||
|
||||
if ( farg->ComFunc < IDIMMES_COM_START_NUM ) { return 0; } // If Not channel command
|
||||
|
||||
switch (farg->ComFunc)
|
||||
{
|
||||
case (IDIMMES_COM_C_Dummy) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE); }
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_AssignGroup) : {
|
||||
if ( (farg->InpDataLength != 1) || (farg->InpData[0] > IDIBUS_GROUP_LAST_NUMBER) ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
CH->BcastAddr = (uint8_t)( farg->InpData[0] + IDIBUS_GROUP_0_ADDR );
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
case (IDIMMES_COM_C_CheckChannelLongOp) : {
|
||||
if ( farg->InpDataLength != 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
uint8_t Response[IDILONGOP_MES_DATA_LENGTH];
|
||||
Response[IDILONGOP_STATE_Pos] = CH->LONG_OP.State;
|
||||
uint32_t Countdown;
|
||||
if ( CH->LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
{
|
||||
uint32_t TimeFromStart = System_GetSysTickDifference( CH->LONG_OP.StartTimeInstanceMS );
|
||||
if ( CH->LONG_OP.DurationMS > TimeFromStart ) { Countdown = CH->LONG_OP.DurationMS - TimeFromStart; }
|
||||
else { Countdown = 0; }
|
||||
}
|
||||
else { Countdown = 0; }
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos] = (uint8_t)(Countdown >> 24);
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos + 1] = (uint8_t)(Countdown >> 16);
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos + 2] = (uint8_t)(Countdown >> 8);
|
||||
Response[IDILONGOP_REMAIN_TIME_Pos + 3] = (uint8_t)(Countdown);
|
||||
IDIBUS_ResponseProtectedWrite(farg, Response, IDILONGOP_MES_DATA_LENGTH, IDIER_NOPE);
|
||||
}
|
||||
break; }
|
||||
|
||||
default : { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_UNSUPPORTED_FUNC_NUM); }
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ResponseProtectedWrite(IDIBUS_FARG_TYPE *farg, uint8_t *Data, uint16_t DataLength, uint8_t ErrorCode)
|
||||
{
|
||||
if (farg->OutData != NULL)
|
||||
{
|
||||
if ( ErrorCode != IDIER_NOPE ) { IDIBUS_MODULE.STATUS.STATE.B0S.StError = 1; farg->ErrorState = 1; }
|
||||
else { IDIBUS_MODULE.STATUS.STATE.B0S.StError = 0; }
|
||||
farg->OutData[farg->ErrorPos] = ErrorCode;
|
||||
farg->ErrorPos = (uint16_t)(farg->ErrorPos + 1);
|
||||
farg->OutDataLength = (uint16_t)(farg->OutDataLength + 1);
|
||||
|
||||
if ( (DataLength != 0) && (Data != NULL) )
|
||||
{
|
||||
memcpy(&farg->OutData[farg->OutDataPos], Data, DataLength);
|
||||
farg->OutDataPos = (uint16_t)( farg->OutDataPos + DataLength );
|
||||
farg->OutDataLength = (uint16_t)(farg->OutDataLength + DataLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
//=============================================================================================================================================================================================================
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//=============================================================================================================================================================================================================
|
||||
void IDIBUS_ServiceFunc (uint8_t *InpData, uint16_t InpDataLength, uint8_t *OutData, uint16_t *OutDataLength)
|
||||
{
|
||||
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,98 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_IDIBUS_IMPL_H_
|
||||
#define _INC_IDIBUS_IMPL_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "Common/IDIBUS_DEFS.h"
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "SYSTEM.h"
|
||||
#include "MODBUS_CRC.h"
|
||||
#include "USART_COM.h"
|
||||
#include "EEPROM_Fast.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
enum IDIBUS_MODULE_LONGOP_TYPES {
|
||||
IDIBUS_LONGOP_NOPE = 0,
|
||||
IDIBUS_LONGOP_VARSN_IP_WRITE,
|
||||
IDIBUS_LONGOP_VARSN_VERIF_EXP_WRITE,
|
||||
IDIBUS_LONGOP_VARSN_AES_WRITE,
|
||||
IDIBUS_LONGOP_FMW_WRITE,
|
||||
IDIBUS_LONGOP_INIT
|
||||
};
|
||||
|
||||
#define IDIBUS_LONGOP_VARSN_IP_WRITE_DURATION_MS 200
|
||||
#define IDIBUS_LONGOP_VARSN_VERF_EXP_WRITE_DURATION_MS 200
|
||||
#define IDIBUS_LONGOP_VARSN_AES_WRITE_DURATION_MS 200
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
uint8_t ComFunc;
|
||||
uint8_t *InpData;
|
||||
uint16_t InpDataLength;
|
||||
uint8_t *OutData;
|
||||
uint16_t OutDataPos;
|
||||
uint16_t OutDataLength;
|
||||
uint16_t ErrorPos;
|
||||
uint8_t ErrorState;
|
||||
uint8_t OutLongMesState;
|
||||
uint8_t LongOpState;
|
||||
} IDIBUS_FARG_TYPE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct IDIBUS_CHANNEL_STR {
|
||||
uint8_t BcastAddr;
|
||||
uint8_t ChNum;
|
||||
struct {
|
||||
uint8_t Type;
|
||||
uint8_t State;
|
||||
uint32_t StartTimeInstanceMS;
|
||||
uint32_t DurationMS;
|
||||
} LONG_OP;
|
||||
void (*CH_Func)(struct IDIBUS_CHANNEL_STR*, IDIBUS_FARG_TYPE*);
|
||||
} IDIBUS_CHANNEL;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
IDIBUS_CHANNEL *Channels;
|
||||
uint8_t ChannelsCount;
|
||||
} IDIBUS_DEVICE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
USART_INTERFACE_TYPE *USI;
|
||||
IDIBUS_DEVICE *Devices;
|
||||
uint8_t DevicesCount;
|
||||
IDISTATUS_SLAVE_TYPE STATUS;
|
||||
uint8_t FreezeMemState;
|
||||
uint8_t Error;
|
||||
uint8_t c_InitAssignGroup;
|
||||
struct {
|
||||
uint8_t Type;
|
||||
uint8_t Switch;
|
||||
uint8_t State;
|
||||
uint32_t StartTimeInstanceMS;
|
||||
uint32_t DurationMS;
|
||||
} LONG_OP;
|
||||
} IDIBUS_SLAVE_MODULE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define IDIBUS_SYSTEM_SW_VERSION 0x3133U
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
IDIBUS_SLAVE_MODULE IDIBUS_MODULE;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#ifdef _LONG_ADDR_SPACE_
|
||||
void IDIBUS_ModuleInit(USART_INTERFACE_TYPE *USART_INTERFACE, uint_farptr_t PROGMEM_SN);
|
||||
#else
|
||||
void IDIBUS_ModuleInit(USART_INTERFACE_TYPE *USART_INTERFACE, uint8_t *PROGMEM_SN);
|
||||
#endif
|
||||
|
||||
void IDIBUS_ModuleCommandHandler(IDIBUS_FARG_TYPE *farg);
|
||||
uint8_t IDIBUS_CnannelStaticFunc(struct IDIBUS_CHANNEL_STR* CH, IDIBUS_FARG_TYPE *farg);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_ResponseProtectedWrite(IDIBUS_FARG_TYPE *farg, uint8_t *Data, uint16_t DataLength, uint8_t ErrorCode);
|
||||
void IDIBUS_ModuleBackgroundHandler(void);
|
||||
void IDIBUS_ChannelBackgroundHandler(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_ServiceFunc (uint8_t *InpData, uint16_t InpDataLength, uint8_t *OutData, uint16_t *OutDataLength); // çà÷åì.........
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_CustomInit(void);
|
||||
//void IDIBUS_CustomShutdown(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_IDIBUS_IMPL_H_
|
||||
//#############################################################################################################################################################################################################
|
||||
|
@ -0,0 +1,71 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "MODBUS_CRC.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const uint8_t MODBUS_auchCRCHi[256] PROGMEM= // Table of CRC values for high order byte
|
||||
{
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
|
||||
};
|
||||
const uint8_t MODBUS_auchCRCLo[256] PROGMEM= // Table of CRC values for low order byte
|
||||
{
|
||||
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04,
|
||||
0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8,
|
||||
0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
|
||||
0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10,
|
||||
0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
|
||||
0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
|
||||
0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C,
|
||||
0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0,
|
||||
0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
|
||||
0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
|
||||
0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C,
|
||||
0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
|
||||
0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54,
|
||||
0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98,
|
||||
0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
|
||||
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
|
||||
};
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint16_t MODBUS_CRC16_T(uint8_t *MODBUS_puchMsg, uint16_t MODBUS_usDataLen)
|
||||
{
|
||||
uint8_t MODBUS_uchCRCHi=0xFF; // high byte of CRC initialized
|
||||
uint8_t MODBUS_uchCRCLo=0xFF; // low byte of CRC initialized
|
||||
uint8_t MODBUS_uIndex;
|
||||
for (uint16_t I=0; I<MODBUS_usDataLen; I++)
|
||||
{
|
||||
MODBUS_uIndex=MODBUS_uchCRCLo^(*MODBUS_puchMsg++); // calculate the CRC
|
||||
MODBUS_uchCRCLo=MODBUS_uchCRCHi^pgm_read_byte(&MODBUS_auchCRCHi[MODBUS_uIndex]);
|
||||
MODBUS_uchCRCHi=pgm_read_byte(&MODBUS_auchCRCLo[MODBUS_uIndex]);
|
||||
}
|
||||
return (uint16_t)(((uint16_t)MODBUS_uchCRCHi<<8)|MODBUS_uchCRCLo);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint16_t MODBUS_CRC16_S(uint8_t *MODBUS_puchMsg, uint16_t MODBUS_usDataLen)
|
||||
{
|
||||
uint16_t MODBUS_crc=0xFFFF;
|
||||
for (uint16_t Mp=0; Mp<MODBUS_usDataLen; Mp++)
|
||||
{
|
||||
MODBUS_crc=(uint16_t)(MODBUS_crc^MODBUS_puchMsg[Mp]); // XOR byte into least sig. byte of crc
|
||||
for (uint8_t Mi=8; Mi!=0; Mi--) // Loop over each bit
|
||||
{
|
||||
if ((MODBUS_crc&0x0001)!=0) { MODBUS_crc>>=1; MODBUS_crc^=0xA001; } // If the LSB is set Shift right and XOR 0xA001
|
||||
else { MODBUS_crc>>=1; } // Else LSB is not set Just shift right
|
||||
}
|
||||
}
|
||||
return MODBUS_crc;
|
||||
}
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,14 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_MODBUS_CRC_H_
|
||||
#define _INC_MODBUS_CRC_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include <avr/pgmspace.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define MODBUS_CRC16_SIZE 2
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint16_t MODBUS_CRC16_T(uint8_t *MODBUS_puchMsg, uint16_t MODBUS_usDataLen);
|
||||
uint16_t MODBUS_CRC16_S(uint8_t *MODBUS_buf, uint16_t MODBUS_len);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_MODBUS_CRC_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,329 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "RSLink.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_Init(USART_INTERFACE_TYPE *USART_INTERFACE, USART_IDIBUS_ROUTINE_TYPE *USART_ID_INTERFACE)
|
||||
{
|
||||
RSLINK.USI=USART_INTERFACE; // USART POINTER INIT
|
||||
RSLINK.USIID=USART_ID_INTERFACE;
|
||||
RSLINK.NeedSpeedChangeFlag=0;
|
||||
RSLINK.LastMMES_TimeInstance=System_GetTimeInstance();
|
||||
RSLink_StatusLedInit(); // Init LEDs
|
||||
RSLink_DipsInit(); // Init DIP switches
|
||||
RSLink_SpeedCheckAndUpdate(); // Set speed
|
||||
RSLINK.USIID->SetIdiBusBoudrate(RSLINK.SpeedCode); // Set speed usart
|
||||
RSLink_AddressCheckAndUpdate(); // Set adr
|
||||
RSLINK.USI->RxTransferRestart(); // Restart RX
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t RSLink_SpeedCheckAndUpdate(void)
|
||||
{
|
||||
uint8_t SpeedDSW_Code = RSLink_SpeedDecode();
|
||||
if (RSLINK.SpeedCode != SpeedDSW_Code) { RSLINK.SpeedCode = SpeedDSW_Code; return 1; }
|
||||
return 0;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_AddressCheckAndUpdate(void)
|
||||
{
|
||||
RSLINK.Address = RSLink_AddrDecode();
|
||||
if ((RSLINK.Address>=IDIBUS_SLAVE_ADDR_MIN)&&(RSLINK.Address<=IDIBUS_SLAVE_ADDR_MAX)) { RSLINK.Address_Error=0; }
|
||||
else { RSLINK.Address_Error=1; }
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_Handler(void)
|
||||
{
|
||||
// Address and Speed Change Check Routine =======================================
|
||||
if ( (RSLINK.NeedSpeedChangeFlag == 1) || RSLink_SpeedCheckAndUpdate() )
|
||||
{
|
||||
if ( RSLINK.USI->IsTxActive() ) { RSLINK.NeedSpeedChangeFlag = 1; }
|
||||
else { RSLINK.USIID->SetIdiBusBoudrate(RSLINK.SpeedCode); RSLINK.NeedSpeedChangeFlag = 0; }
|
||||
}
|
||||
RSLink_AddressCheckAndUpdate();
|
||||
|
||||
|
||||
// Timeout Led Routine ==========================================================
|
||||
if ( IDIBUS_MODULE.STATUS.STATE.B1S.TimeoutLed == 0 )
|
||||
{
|
||||
if (
|
||||
( (IDIBUS_MODULE.STATUS.STATE.B1S.NoMMESTimeout == 0) && (System_GetSysTickDifference( RSLINK.LastMMES_TimeInstance) >= IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_MS) ) ||
|
||||
( (IDIBUS_MODULE.STATUS.STATE.B1S.NoMMESTimeout == 1) && (System_GetSysTickDifference( RSLINK.LastMMES_TimeInstance) >= IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_MS) )
|
||||
)
|
||||
{
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.TimeoutLed=1;
|
||||
//RSLink_StatusLedSetOn();
|
||||
}
|
||||
else { RSLink_StatusLedSetOff(); }
|
||||
}
|
||||
|
||||
// Background Error Handler and Long Operations =================================
|
||||
IDIBUS_ModuleBackgroundHandler();
|
||||
IDIBUS_ChannelBackgroundHandler();
|
||||
|
||||
// Message Handling Routine =====================================================
|
||||
if ( RSLINK.USI->IsNewRxMessage() == 0 ) { return; }
|
||||
|
||||
if ( RSLINK.USI->IsRxError() == 1) {
|
||||
RSLINK.USI->RxTransferRestart();
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t RxMessageSize;
|
||||
uint8_t *TxMesageBuf = RSLINK.USI->getTxBuf();
|
||||
|
||||
// Check incorrect and Developers DIP Switch Address ---------------------------->
|
||||
if ( RSLINK.Address_Error )
|
||||
{
|
||||
switch ( RSLINK.Address )
|
||||
{
|
||||
case ( IDIBUS_DEVELOPER_ADDR_0 ) : { break; }
|
||||
case ( IDIBUS_DEVELOPER_ADDR_1 ) : { break; }
|
||||
case ( IDIBUS_DEVELOPER_ADDR_2 ) : { break; }
|
||||
case ( IDIBUS_DEVELOPER_ADDR_3 ) : { break; }
|
||||
default : {}
|
||||
}
|
||||
RSLINK.USI->RxTransferRestart();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check normal Message --------------------------------------------------------->
|
||||
|
||||
// Check Message size
|
||||
uint8_t RcvAddress;
|
||||
RxMessageSize = RSLINK.USI->getRxBufSize();
|
||||
if ( (RxMessageSize < (MODBUS_CRC16_SIZE+1) ) || (RxMessageSize > IDIMMES_MAX_MES_SIZE) ) { RSLINK.USI->RxTransferRestart(); return; }
|
||||
else
|
||||
{
|
||||
RSLINK.USI->copyRxBuf( &RxMesageBuf[IDIMMES_ADDR_Pos], IDIMMES_ADDR_Pos, 1 ); // Need for CRC
|
||||
RcvAddress = RxMesageBuf[IDIMMES_ADDR_Pos];
|
||||
}
|
||||
|
||||
// MMESG(Module) or MMES ------------->
|
||||
if ( RcvAddress == RSLINK.Address )
|
||||
{
|
||||
// Check CRC, copy RxBuf and Restart Transfer
|
||||
RSLINK.USI->copyRxBuf( &RxMesageBuf[IDIMMES_MMPS_Pos], IDIMMES_MMPS_Pos, (uint16_t)(RxMessageSize-1) );
|
||||
RSLINK.USI->RxTransferRestart();
|
||||
uint16_t CalculatedCRC = MODBUS_CRC16_T( RxMesageBuf, (uint16_t)(RxMessageSize-2) );
|
||||
uint16_t ReceivedCRC = (uint16_t)( ((uint16_t)RxMesageBuf[RxMessageSize-2] << 8) | RxMesageBuf[RxMessageSize-1] );
|
||||
if ( CalculatedCRC != ReceivedCRC ) { return; }
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.TimeoutLed = 0;
|
||||
RSLINK.LastMMES_TimeInstance = System_GetTimeInstance(); //FOR STM, (reset led)
|
||||
|
||||
IDIBUS_FARG_TYPE FARG;
|
||||
FARG.OutData = &TxMesageBuf[0]; //set RX addr
|
||||
FARG.OutDataLength = IDISMES_ERROR_Pos; //Set length 2 (adr+cmd)
|
||||
FARG.ErrorPos = IDISMES_ERROR_Pos; //set pos err
|
||||
FARG.OutDataPos = IDISMES_ERROR_Pos + 1; //set pos data
|
||||
FARG.ErrorState = 0;
|
||||
FARG.OutLongMesState = 0;
|
||||
if ( IDIBUS_MODULE.LONG_OP.State == IDILONGOP_STATE_IN_PROC ) { FARG.LongOpState = 1; }
|
||||
else { FARG.LongOpState = 0; }
|
||||
|
||||
|
||||
// Check if too short for MMESG message
|
||||
if ( RxMessageSize < (IDIMMES_MMPS_Pos + 1 + MODBUS_CRC16_SIZE) ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); RSLink_SendSMES(&FARG); return;}
|
||||
|
||||
// Get MMPS
|
||||
uint8_t MMPS_FastFunc = (RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_FAST_FUNC_Msk) >> IDIMMES_MMPS_FAST_FUNC_Pos;
|
||||
uint8_t MMPS_MesType = (RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_MES_TYPE_Msk) >> IDIMMES_MMPS_MES_TYPE_Pos;
|
||||
uint8_t MMPS_LongMessage = RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_LONG_MES_Msk;
|
||||
uint8_t MMPS_AlarmFrame = RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_ALARM_FRAME_Msk;
|
||||
uint8_t MMPS_EncryptedAes = RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_ENCRYPTED_AES_Msk;
|
||||
if ( MMPS_AlarmFrame != 0 )
|
||||
{
|
||||
// Do Alarm
|
||||
}
|
||||
if ( MMPS_EncryptedAes != 0 )
|
||||
{
|
||||
if ( IDIBUS_MODULE.STATUS.STATE.B0S.AesSupported == 0 ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_ENCRYPTION_NOT_SUPPORTED); RSLink_SendSMES(&FARG); return; }
|
||||
else if ( IDIBUS_MODULE.STATUS.STATE.B0S.AesInstalled == 0 ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_ENCRYPTION_NOT_INSTALLED); RSLink_SendSMES(&FARG); return; }
|
||||
else
|
||||
{
|
||||
// Decrypt ...
|
||||
}
|
||||
}
|
||||
if ( MMPS_LongMessage != 0 )
|
||||
{
|
||||
IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_JUMBO_NOT_SUPPORTED);
|
||||
RSLink_SendSMES(&FARG);
|
||||
return;
|
||||
}
|
||||
// If Module Function
|
||||
if ( MMPS_MesType == IDIMMES_MMPS_MES_TYPE_MMESG )
|
||||
{
|
||||
if ( (MMPS_FastFunc != 0) || (RxMessageSize < IDIMMESG_MODULE_MIN_MES_SIZE) ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
FARG.ComFunc = RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos];
|
||||
FARG.InpData = &RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos + 1];
|
||||
FARG.InpDataLength = (uint16_t)(RxMessageSize - (IDIMMESG_DATA_COM_FUNC_Pos + 1) - MODBUS_CRC16_SIZE);
|
||||
IDIBUS_ModuleCommandHandler(&FARG);
|
||||
}
|
||||
RSLink_SendSMES(&FARG);
|
||||
return;
|
||||
}
|
||||
|
||||
// IF NOT Module Function
|
||||
if ( IDIBUS_MODULE.STATUS.STATE.B0S.StState == IDISTATUS_B0S_ST_STATE_StFreeze ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_IN_FREEZE); RSLink_SendSMES(&FARG); return; }
|
||||
else if ( IDIBUS_MODULE.Error != IDIER_NOPE ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIBUS_MODULE.Error); RSLink_SendSMES(&FARG); return; }
|
||||
else if ( IDIBUS_MODULE.LONG_OP.State == IDILONGOP_STATE_IN_PROC ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_LONG_OP_IN_PROC); RSLink_SendSMES(&FARG); return; }
|
||||
|
||||
if ( MMPS_FastFunc == 0 )
|
||||
{
|
||||
if ( (RxMessageSize < (IDIMMES_MIN_MES_SIZE + 1)) || (RxMesageBuf[IDIMMES_DATA_FUNC_COM_DATA_Pos] <= IDIMMES_MAX_FAST_FUNC_NUM) ) //CHECK LEN ON MSG
|
||||
{
|
||||
IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); RSLink_SendSMES(&FARG);
|
||||
return;
|
||||
}
|
||||
FARG.ComFunc = RxMesageBuf[IDIMMES_DATA_FUNC_COM_DATA_Pos];
|
||||
FARG.InpData = &RxMesageBuf[IDIMMES_DATA_FUNC_COM_DATA_Pos + 1];
|
||||
FARG.InpDataLength = (uint16_t)(RxMessageSize - (IDIMMES_DATA_FUNC_COM_DATA_Pos + 1) - MODBUS_CRC16_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( RxMessageSize < IDIMMES_MIN_MES_SIZE ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); RSLink_SendSMES(&FARG); return; }
|
||||
FARG.ComFunc = MMPS_FastFunc;
|
||||
FARG.InpData = &RxMesageBuf[IDIMMES_DATA_FUNC_COM_DATA_Pos];
|
||||
FARG.InpDataLength = (uint16_t)(RxMessageSize - IDIMMES_DATA_FUNC_COM_DATA_Pos - MODBUS_CRC16_SIZE);
|
||||
}
|
||||
// Channels command and funcs handling
|
||||
uint8_t DeviceNum = (RxMesageBuf[IDIMMES_DEV_Pos] & IDIMMES_DEV_NUM_Msk) >> IDIMMES_DEV_NUM_Pos;
|
||||
uint8_t AllChannels = RxMesageBuf[IDIMMES_DEV_Pos] & IDIMMES_DEV_ALLCH_Msk;
|
||||
uint8_t ChannelNum = (RxMesageBuf[IDIMMES_CHNL_Pos] & IDIMMES_CHNL_NUM_Msk) >> IDIMMES_CHNL_NUM_Pos;
|
||||
uint8_t ChannelAllSame = RxMesageBuf[IDIMMES_CHNL_Pos] & IDIMMES_CHNL_ALLSAME_Msk;
|
||||
|
||||
if ( DeviceNum >= IDIBUS_MODULE.DevicesCount ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERDEV_INVALID_DEV_NUM); RSLink_SendSMES(&FARG); return; }
|
||||
if ( (ChannelNum >= IDIBUS_MODULE.Devices[DeviceNum].ChannelsCount) && (AllChannels == 0) ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERDEV_INVALID_CHN_NUM); RSLink_SendSMES(&FARG); return; }
|
||||
if ( AllChannels != 0 )
|
||||
{
|
||||
uint8_t ChannelsCount = IDIBUS_MODULE.Devices[DeviceNum].ChannelsCount;
|
||||
FARG.OutDataPos = (uint16_t)( FARG.OutDataPos + ChannelsCount - 1 ); // SMES = ADDR SMPS ERR1 ERR2 ERR3 DATA1 DATA2 DATA3 CRC
|
||||
if ( ChannelAllSame == 0 )
|
||||
{
|
||||
uint16_t DataPortionLength = (uint16_t)( FARG.InpDataLength / ChannelsCount ); // If DataLength==0 -> OK (Byte count on one channel)
|
||||
// SMES = ADDR SMPS ERR1 ERR2!=0 ERR3 DATA1 DATA3 CRC
|
||||
if ( FARG.InpDataLength != (DataPortionLength * ChannelsCount) )
|
||||
{
|
||||
for (uint8_t I=0; I < ChannelsCount; I++ ) { IDIBUS_ResponseProtectedWrite(&FARG, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
}
|
||||
else {
|
||||
FARG.InpDataLength = DataPortionLength;
|
||||
for (uint8_t I=0; I < ChannelsCount; I++ )
|
||||
{
|
||||
IDIBUS_CHANNEL *CH = &IDIBUS_MODULE.Devices[DeviceNum].Channels[I];
|
||||
CH->CH_Func( CH, &FARG );
|
||||
FARG.InpData += DataPortionLength; //Pointer offset
|
||||
}
|
||||
}
|
||||
}
|
||||
else { for (uint8_t I=0; I < IDIBUS_MODULE.Devices[DeviceNum].ChannelsCount; I++ )
|
||||
{
|
||||
IDIBUS_CHANNEL *CH = &IDIBUS_MODULE.Devices[DeviceNum].Channels[I];
|
||||
CH->CH_Func( CH, &FARG );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IDIBUS_CHANNEL *CH = &IDIBUS_MODULE.Devices[DeviceNum].Channels[ChannelNum];
|
||||
CH->CH_Func( CH, &FARG );
|
||||
}
|
||||
RSLink_SendSMES(&FARG);
|
||||
return;
|
||||
} //if ( (RcvAddress == RSLINK.Address) && (RxMessageSize >= IDIMMES_MIN_MES_SIZE) )
|
||||
|
||||
|
||||
// MMESG ------------->
|
||||
// NO RESPONSE!!!
|
||||
if ( (RcvAddress >= IDIBUS_GROUP_0_ADDR) && (RcvAddress <= IDIBUS_GROUP_15_ADDR) )
|
||||
{
|
||||
// Check CRC, copy RxBuf and Restart Transfer
|
||||
RSLINK.USI->copyRxBuf( &RxMesageBuf[IDIMMES_MMPS_Pos], IDIMMES_MMPS_Pos, (uint16_t)(RxMessageSize-1) );
|
||||
RSLINK.USI->RxTransferRestart();
|
||||
uint16_t CalculatedCRC = MODBUS_CRC16_T( RxMesageBuf, (uint16_t)(RxMessageSize-2) );
|
||||
uint16_t ReceivedCRC = (uint16_t)( ((uint16_t)RxMesageBuf[RxMessageSize-2] << 8) | RxMesageBuf[RxMessageSize-1] );
|
||||
if ( CalculatedCRC != ReceivedCRC ) { return; }
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.TimeoutLed = 0;
|
||||
RSLINK.LastMMES_TimeInstance = System_GetTimeInstance();
|
||||
|
||||
IDIBUS_FARG_TYPE FARG;
|
||||
FARG.OutData = NULL;
|
||||
|
||||
// Check if too short for MMESG message
|
||||
if ( RxMessageSize < (IDIMMES_MMPS_Pos + 1 + MODBUS_CRC16_SIZE) ) { return; }
|
||||
|
||||
// Get MMPS
|
||||
uint8_t MMPS_FastFunc = (RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_FAST_FUNC_Msk) >> IDIMMES_MMPS_FAST_FUNC_Pos;
|
||||
uint8_t MMPS_MesType = (RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_MES_TYPE_Msk) >> IDIMMES_MMPS_MES_TYPE_Pos;
|
||||
uint8_t MMPS_LongMessage = RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_LONG_MES_Msk;
|
||||
uint8_t MMPS_AlarmFrame = RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_ALARM_FRAME_Msk;
|
||||
uint8_t MMPS_EncryptedAes = RxMesageBuf[IDIMMES_MMPS_Pos] & IDIMMES_MMPS_ENCRYPTED_AES_Msk;
|
||||
if ( MMPS_AlarmFrame != 0 )
|
||||
{
|
||||
// Do Alarm
|
||||
}
|
||||
if ( MMPS_EncryptedAes != 0 )
|
||||
{
|
||||
if ( (IDIBUS_MODULE.STATUS.STATE.B0S.AesSupported == 0) || (IDIBUS_MODULE.STATUS.STATE.B0S.AesInstalled == 0) ) { return; }
|
||||
else
|
||||
{
|
||||
// Decrypt ...
|
||||
}
|
||||
}
|
||||
if ( MMPS_LongMessage != 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (
|
||||
( MMPS_MesType != IDIMMES_MMPS_MES_TYPE_MMESG ) ||
|
||||
( IDIBUS_MODULE.STATUS.STATE.B0S.StState == IDISTATUS_B0S_ST_STATE_StFreeze ) || // There are no Module commands in group
|
||||
( IDIBUS_MODULE.Error != IDIER_NOPE ) ||
|
||||
( IDIBUS_MODULE.LONG_OP.State == IDILONGOP_STATE_IN_PROC )
|
||||
) { return; }
|
||||
|
||||
if ( MMPS_FastFunc == 0 )
|
||||
{
|
||||
if ( RxMessageSize < (IDIMMESG_GROUP_MIN_MES_SIZE + 1) ) { return; }
|
||||
FARG.ComFunc = RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos];
|
||||
if ( FARG.ComFunc <= IDIMMES_MAX_FAST_FUNC_NUM ) { return; }
|
||||
FARG.InpData = &RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos + 1];
|
||||
FARG.InpDataLength = (uint16_t)(RxMessageSize - (IDIMMESG_DATA_COM_FUNC_Pos + 1) - MODBUS_CRC16_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( RxMessageSize < IDIMMESG_GROUP_MIN_MES_SIZE ) { return; }
|
||||
FARG.ComFunc = MMPS_FastFunc;
|
||||
FARG.InpData = &RxMesageBuf[IDIMMESG_DATA_COM_FUNC_Pos];
|
||||
FARG.InpDataLength = (uint16_t)(RxMessageSize - IDIMMESG_DATA_COM_FUNC_Pos - MODBUS_CRC16_SIZE);
|
||||
}
|
||||
for (uint8_t Dev = 0; Dev < IDIBUS_MODULE.DevicesCount; Dev++)
|
||||
{
|
||||
for (uint8_t Ch = 0; Ch<IDIBUS_MODULE.Devices[Dev].ChannelsCount; Ch++)
|
||||
{
|
||||
IDIBUS_CHANNEL *CH = &IDIBUS_MODULE.Devices[Dev].Channels[Ch];
|
||||
if ( (RcvAddress == IDIBUS_GROUP_0_ADDR) || (CH->BcastAddr == RcvAddress) ) { CH->CH_Func(CH, &FARG); }
|
||||
}
|
||||
}
|
||||
return;
|
||||
} //if ( ((RcvAddress >= IDIBUS_GROUP_0_ADDR) && (RcvAddress <= IDIBUS_GROUP_15_ADDR)) )
|
||||
|
||||
RSLINK.USI->RxTransferRestart(); // NOT MMES AND MMESG ------------->
|
||||
return;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_SendSMES(IDIBUS_FARG_TYPE *farg)
|
||||
{
|
||||
if ( (RSLINK.USIID->ResponseTimeoutComplete == 0) && (farg->OutDataLength > IDISMES_ERROR_Pos) )
|
||||
{
|
||||
farg->OutData[IDISMES_ADDR_Pos] = RSLINK.Address;
|
||||
farg->OutData[IDISMES_SMPS_Pos] = 0;
|
||||
if ( farg->ErrorState != 0 ) { farg->OutData[IDISMES_SMPS_Pos] |= (1U << IDISMES_SMPS_ERROR_BIT_Pos); }
|
||||
if ( farg->OutLongMesState != 0 ) { farg->OutData[IDISMES_SMPS_Pos] |= (1U << IDISMES_SMPS_LONG_MES_Pos); }
|
||||
if ( farg->LongOpState != 0 ) { farg->OutData[IDISMES_SMPS_Pos] |= (1U << IDISMES_SMPS_LONG_OP_Pos); }
|
||||
uint16_t CRC16 = MODBUS_CRC16_T(&farg->OutData[0], farg->OutDataLength);
|
||||
farg->OutData[farg->OutDataLength++] = (uint8_t)(CRC16 >> 8);
|
||||
farg->OutData[farg->OutDataLength++] = (uint8_t) CRC16;
|
||||
RSLINK.USI->SendTxBuf(farg->OutDataLength);
|
||||
}
|
||||
}
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,43 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_RSLINK_H_
|
||||
#define _INC_RSLINK_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "SYSTEM.h"
|
||||
#include "IDIBUS_IMPL.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// DELAYS FOR LEDS status
|
||||
#define RSLINK_LED_T1_DEFAULT_S 15UL
|
||||
#define RSLINK_LED_T2_DEFAULT_S 60UL
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
struct RSLINK_STRUCT
|
||||
{
|
||||
USART_INTERFACE_TYPE *USI;
|
||||
USART_IDIBUS_ROUTINE_TYPE *USIID;
|
||||
uint8_t Address;
|
||||
uint8_t Address_Error; // íåäîïóñòèìûé
|
||||
uint8_t SpeedCode;
|
||||
uint8_t NeedSpeedChangeFlag; // ôëàã äëÿ èçìåíåíèÿ ñêîðîñòè
|
||||
uint32_t LastMMES_TimeInstance; // äëÿ led
|
||||
};
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t RxMesageBuf[IDIMMES_MAX_MES_SIZE]; //RX buffer for copy
|
||||
struct RSLINK_STRUCT RSLINK;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_Init(USART_INTERFACE_TYPE *USART_INTERFACE, USART_IDIBUS_ROUTINE_TYPE *USART_ID_INTERFACE);
|
||||
uint8_t RSLink_SpeedCheckAndUpdate(void);
|
||||
void RSLink_AddressCheckAndUpdate(void);
|
||||
void RSLink_Handler(void);
|
||||
void RSLink_SendSMES(IDIBUS_FARG_TYPE *farg);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_StatusLedInit(void);
|
||||
void RSLink_StatusLedSetOn(void);
|
||||
void RSLink_StatusLedSetOff(void);
|
||||
|
||||
void RSLink_DipsInit(void);
|
||||
uint8_t RSLink_AddrDecode(void);
|
||||
uint8_t RSLink_SpeedDecode(void);
|
||||
uint8_t RSLink_TypeDecode(void);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_RSLINK_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,216 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||
<ProjectGuid>{06e88371-de74-4663-a82f-031e45168730}</ProjectGuid>
|
||||
<avrdevice>ATmega2560</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>StaticLibrary</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>lib$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.a</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AvrGccProjectExtensions>
|
||||
</AvrGccProjectExtensions>
|
||||
<AssemblyName>IdiBus</AssemblyName>
|
||||
<Name>IdiCommon</Name>
|
||||
<RootNamespace>IdiBus</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<avrtool />
|
||||
<avrtoolinterface />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Release_2560' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega2560 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega2560"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA2560_</Value>
|
||||
<Value>_LONG_ADDR_SPACE_</Value>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../CommonHW</Value>
|
||||
<Value>../IdiBus</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../idiBusFiles</Value>
|
||||
<Value>../../moduleFiles</Value>
|
||||
<Value>../../personalizationFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.DoNotDeleteTemporaryFiles>False</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.locationInApp=0x1EF80</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Debug_2560' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega2560 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega2560"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA2560_</Value>
|
||||
<Value>_LONG_ADDR_SPACE_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../CommonHW</Value>
|
||||
<Value>../IdiBus</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../idiBusFiles</Value>
|
||||
<Value>../../moduleFiles</Value>
|
||||
<Value>../../personalizationFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.locationInApp=0x1EF80</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputFileName>libIdiCommon_2560</OutputFileName>
|
||||
<OutputFileExtension>.a</OutputFileExtension>
|
||||
<OutputType>StaticLibrary</OutputType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="CommonHW" />
|
||||
<Folder Include="IdiBus" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\moduleFiles\EEMEM.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>IdiBus\EEMEM.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\EEPROM_Fast.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\EEPROM_Fast.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\m2560_defs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEM.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEMCustom.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEMCustom.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART0.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART0.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART1.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART1.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART_COM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\Common\IDIBUS_DEFS.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>IdiBus\IDIBUS_DEFS.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\IDIBUS_IMPL.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\IDIBUS_IMPL.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\MODBUS_CRC.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\MODBUS_CRC.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\RSLink.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\RSLink.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
@ -0,0 +1,235 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||
<ProjectGuid>{06e88371-de74-4663-a82f-031e45168730}</ProjectGuid>
|
||||
<avrdevice>ATmega328PB</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>StaticLibrary</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>lib$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.a</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AvrGccProjectExtensions>
|
||||
</AvrGccProjectExtensions>
|
||||
<AssemblyName>IdiBus</AssemblyName>
|
||||
<Name>IdiCommon_328pb</Name>
|
||||
<RootNamespace>IdiBus</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<avrtool />
|
||||
<avrtoolinterface />
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.47.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Release_328pb' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../CommonHW</Value>
|
||||
<Value>../IdiBus</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../moduleFiles</Value>
|
||||
<Value>../../idiBusFiles</Value>
|
||||
<Value>../../personalizationFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.DoNotDeleteTemporaryFiles>False</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputPath>bin\Release_328pb\</OutputPath>
|
||||
<OutputFileName>libIdiCommon</OutputFileName>
|
||||
<OutputFileExtension>.a</OutputFileExtension>
|
||||
<OutputType>StaticLibrary</OutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Debug_328pb' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>True</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../CommonHW</Value>
|
||||
<Value>../IdiBus</Value>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../../moduleFiles</Value>
|
||||
<Value>../../idiBusFiles</Value>
|
||||
<Value>../../personalizationFiles</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.general.NoSharedLibraries>True</avrgcc.linker.general.NoSharedLibraries>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputPath>bin\Debug_328pb\</OutputPath>
|
||||
<OutputFileName>libIdiCommon</OutputFileName>
|
||||
<OutputFileExtension>.a</OutputFileExtension>
|
||||
<OutputType>StaticLibrary</OutputType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="CommonHW" />
|
||||
<Folder Include="IdiBus" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\moduleFiles\EEMEM.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>IdiBus\EEMEM.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\EEPROM_Fast.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\EEPROM_Fast.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\m328pb_defs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEM.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEMCustom.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\SYSTEMCustom.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART0.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART0.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART1.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART1.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CommonHW\USART_COM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\Common\IDIBUS_DEFS.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>IdiBus\IDIBUS_DEFS.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\Common\MEMORY.h">
|
||||
<SubType>compile</SubType>
|
||||
<Link>IdiBus\MEMORY.h</Link>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\IDIBUS_IMPL.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\IDIBUS_IMPL.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\MODBUS_CRC.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\MODBUS_CRC.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\RSLink.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IdiBus\RSLink.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
@ -0,0 +1 @@
|
||||
Do not use this repository separetly from idiBusSlaveTemplate!!!
|
@ -0,0 +1,118 @@
|
||||
#include "IDIBUS_IMPL_Custom.h"
|
||||
|
||||
int data_flag = 0;
|
||||
uint8_t data_to_send[12] = {0};
|
||||
|
||||
void IDIBUS_CustomInit(){
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.StError = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.StState = IDISTATUS_B0S_ST_STATE_StOperate;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.AesSupported = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.AesInstalled = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.SendAlarmL0 = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B0S.SendAlarmL1 = 0;
|
||||
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.ModuleType = IDISTATUS_B1S_MODULE_TYPE_Slave;
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.BridgeConnected = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.SelfInit = 1;
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.TimeoutLed = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.NoMMESTimeout = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.CatchAlarmL0 = 0;
|
||||
IDIBUS_MODULE.STATUS.STATE.B1S.CatchAlarmL1 = 0;
|
||||
|
||||
IDIBUS_MODULE.Devices = IDIBUS_DEVICES;
|
||||
IDIBUS_MODULE.DevicesCount = IDIBUS_DEVICES_NUMBER;
|
||||
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].Channels = &IDIBUS_GEN_CHNLS[0];
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].ChannelsCount = GEN_CHN_COUNT;
|
||||
|
||||
for (uint8_t I=0; I < GEN_CHN_COUNT; I++)
|
||||
{
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].Channels[I].ChNum = I;
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].Channels[I].LONG_OP.Type = 0;
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].Channels[I].LONG_OP.State = IDILONGOP_STATE_COMPLETE_NO_ERR;
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].Channels[I].BcastAddr = IDIBUS_GROUP_0_ADDR;
|
||||
IDIBUS_MODULE.Devices[IDIBUS_GEN_DEV].Channels[I].CH_Func = IDIBUS_GEN_ChannelHandler;
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_GEN_ChannelHandler(struct IDIBUS_CHANNEL_STR* CH, IDIBUS_FARG_TYPE *farg){
|
||||
if ( IDIBUS_CnannelStaticFunc(CH, farg) != 0) { return; }
|
||||
|
||||
if (CH->ChNum >= GEN_CHN_COUNT) {IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERDEV_INVALID_CHN_NUM); return;}
|
||||
|
||||
switch (farg->ComFunc)
|
||||
{
|
||||
case (0x01) : { // Äîáàâèòü âûêëþ÷åíèå
|
||||
if ( farg->InpDataLength == 0 ) { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_INVALID_RX_REQUEST_FORMAT); }
|
||||
else
|
||||
{
|
||||
//DDRE = 2;
|
||||
uint8_t ErrorSt = IDIER_NOPE;
|
||||
memcpy(data_to_send, farg->InpData, sizeof(data_to_send));
|
||||
|
||||
if (sizeof(data_to_send) / sizeof(data_to_send[0]) != 0) {
|
||||
data_flag = 1;
|
||||
}
|
||||
|
||||
TCCR2A |= (1 << WGM21); // CTC
|
||||
TCCR2B |= (1 << CS21); // Prescaler
|
||||
OCR2A = 1;
|
||||
TIMSK2 = (1<<OCIE2A);
|
||||
|
||||
IDIBUS_ResponseProtectedWrite(farg, NULL, 0, ErrorSt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default : { IDIBUS_ResponseProtectedWrite(farg, NULL, 0, IDIERSLV_UNSUPPORTED_FUNC_NUM); }
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ISR(TIMER2_COMPA_vect) {
|
||||
//PORTE |= (1 << PORTE1);// ÃÎÐÈÒ
|
||||
//_delay_ms(50);
|
||||
//PORTE &= ~(1 << PORTE1);
|
||||
//_delay_ms(50);
|
||||
|
||||
TimerStop;
|
||||
ResetTimer;
|
||||
|
||||
switch (CurrentState) {
|
||||
|
||||
case GEN_Wait: {
|
||||
_delay_ms(10);
|
||||
|
||||
while (data_flag == 0); // Æäåì ïðèåìà äàííûõ èç èäèáàñà
|
||||
CurrentState = GEN_Send;
|
||||
break;
|
||||
}
|
||||
|
||||
case GEN_Send: {
|
||||
CurrentState = GEN_Wait;
|
||||
TimerTime = 100; // Îãðàíè÷åíèå ïî âðåìåíè - 150 ìñ
|
||||
|
||||
//_delay_ms(10);
|
||||
STMReset();
|
||||
//_delay_ms(10);
|
||||
|
||||
if ((PINC)&(1<<PORTC3)) { // STM ãîòîâ ê ïðèåìó
|
||||
_delay_ms(10);
|
||||
for (uint8_t i = 0; i < 12; i++) {
|
||||
SPI_MasterTransmit(data_to_send[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TimerStartTick;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void STMReset() {
|
||||
DDRC |= (1 << PINC4);
|
||||
PORTC &= ~(1 << PINC4);
|
||||
_delay_ms(100);
|
||||
DDRC &= ~(1 << PINC4);
|
||||
_delay_ms(100);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#ifndef IDIBUS_IMPL_CUSTOM_H_
|
||||
#define IDIBUS_IMPL_CUSTOM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include "IDIBUS_IMPL.h"
|
||||
#include "../moduleFiles/SPI.h"
|
||||
|
||||
#define TimerStop TCCR2B = 0
|
||||
#define ResetTimer TCNT2 = 0
|
||||
#define TimerTime OCR2A
|
||||
#define TimerStartTick TCCR2B = (1 << CS21) // 0.5 ìêñ (ïðåääåëèòåëü 8)
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
enum IDIBUS_MODULE_DEVICES_LIST // ????????????????????????????????????????
|
||||
{
|
||||
IDIBUS_GEN_DEV = 0x00,
|
||||
IDIBUS_DEVICES_NUMBER
|
||||
};
|
||||
|
||||
enum GenOperations {
|
||||
GEN_Wait = 0x00,
|
||||
GEN_Send
|
||||
};
|
||||
|
||||
enum GenOperations CurrentState;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
IDIBUS_DEVICE IDIBUS_DEVICES[IDIBUS_DEVICES_NUMBER];
|
||||
#define GEN_CHN_COUNT 1
|
||||
IDIBUS_CHANNEL IDIBUS_GEN_CHNLS[GEN_CHN_COUNT];
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void IDIBUS_GEN_ChannelHandler(struct IDIBUS_CHANNEL_STR* CH, IDIBUS_FARG_TYPE *farg);
|
||||
void STMReset();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* IDIBUS_IMPL_CUSTOM_H_ */
|
@ -0,0 +1,76 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#include "RSLinkCustom.h"
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_StatusLedInit(void) // Status led Init
|
||||
{
|
||||
RSLINK_LED_DDR|=1<<RSLINK_LED_BIT;
|
||||
RSLINK_LED_PORT&=~(1<<RSLINK_LED_BIT);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_StatusLedSetOn(void) // Status led On
|
||||
{
|
||||
RSLINK_LED_PORT|=1<<RSLINK_LED_BIT;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void RSLink_StatusLedSetOff(void) // Status led Off
|
||||
{
|
||||
RSLINK_LED_PORT&=~(1<<RSLINK_LED_BIT);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// FOR 328pb
|
||||
void RSLink_DipsInit(void) // Dip switch Adders, Speed, Bus Type Init
|
||||
{
|
||||
RSLINK_DIPS_CP_DDR|=1<<RSLINK_DIPS_CP_BIT; RSLINK_DIPS_CP_PORT|=1<<RSLINK_DIPS_CP_BIT; // clock, output -> 1
|
||||
RSLINK_DIPS_nPL_DDR|=1<<RSLINK_DIPS_nPL_BIT; RSLINK_DIPS_nPL_PORT|=1<<RSLINK_DIPS_nPL_BIT; // latch, output -> 1
|
||||
RSLINK_DIPS_Q7_DDR&=~(1<<RSLINK_DIPS_Q7_BIT); RSLINK_DIPS_Q7_PORT&=~(1<<RSLINK_DIPS_Q7_BIT); // data, input
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// FOR 328pb
|
||||
uint16_t RSLink_DipsRead(void) // Dip switch Adders, Speed, Bus Type Read
|
||||
{
|
||||
// RESULT = [ADDR7...0][XXXX][TYPE][SS2...0]
|
||||
RSLINK_DIPS_nPL_PORT&=~(1<<RSLINK_DIPS_nPL_BIT);
|
||||
uint16_t STATE=0;
|
||||
RSLINK_DIPS_nPL_PORT|=1<<RSLINK_DIPS_nPL_BIT;
|
||||
for (uint8_t I=0; I<16; I++)
|
||||
{
|
||||
STATE=STATE<<1;
|
||||
RSLINK_DIPS_CP_PORT&=~(1<<RSLINK_DIPS_CP_BIT);
|
||||
if ((RSLINK_DIPS_Q7_PIN&(1<<RSLINK_DIPS_Q7_BIT))!=0) STATE|=0x0001;
|
||||
RSLINK_DIPS_CP_PORT|=1<<RSLINK_DIPS_CP_BIT;
|
||||
}
|
||||
return STATE&0xFF0F;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t RSLink_SpeedDecode(void){
|
||||
return (uint8_t)(RSLink_DipsRead()&0x07);
|
||||
}
|
||||
|
||||
uint8_t RSLink_AddrDecode(void){
|
||||
return (uint8_t)(RSLink_DipsRead()>>8);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//#############################################################################################################################################################################################################
|
||||
//void RSLink_TimerInit() {
|
||||
////TCCR2A |= (1 << WGM21);
|
||||
////TCCR2A &= ~(1 << WGM20); // CTC Mode
|
||||
////TCCR2B &= ~(1 << WGM22);
|
||||
////
|
||||
//////óñòàíàâëèâàåì áèò ðàçðåøåíèÿ ïðåðûâàíèÿ 1îãî ñ÷åò÷èêà ïî ñîâïàäåíèþ ñ OCR1A(H è L)
|
||||
////TIMSK2 |= (1 << OCIE2A);
|
||||
////
|
||||
////OCR2A = 0xFF;
|
||||
////
|
||||
////TCCR2B |= (1 << CS20) | (1 << CS22) | (1 << CS21);
|
||||
//
|
||||
//TCCR1A |= (1 << WGM12) | (1 << WGM13);
|
||||
//TCCR1A &= ~(1 << WGM11); // CTC Mode
|
||||
//TCCR1B &= ~(1 << WGM10);
|
||||
//
|
||||
//TIMSK1 |= (1 << OCIE1A);
|
||||
//
|
||||
//OCR1AH = 0x27; //çàïèñûâàåì â ðåãèñòð ÷èñëî äëÿ ñðàâíåíèÿ
|
||||
//OCR1AL = 0x10;
|
||||
//
|
||||
//TCCR1B |= (1 << CS12);
|
||||
//}
|
@ -0,0 +1,32 @@
|
||||
//#############################################################################################################################################################################################################
|
||||
#ifndef _INC_RSLINK_CUSTOM_H_
|
||||
#define _INC_RSLINK_CUSTOM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include <avr/io.h>
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Status led
|
||||
#define RSLINK_LED_DDR DDRE
|
||||
#define RSLINK_LED_PORT PORTE
|
||||
#define RSLINK_LED_PIN PINE
|
||||
#define RSLINK_LED_BIT 1
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Dip switch Adders, Speed, Bus Type
|
||||
#define RSLINK_DIPS_CP_PORT PORTD
|
||||
#define RSLINK_DIPS_CP_DDR DDRD
|
||||
#define RSLINK_DIPS_CP_PIN PIND
|
||||
#define RSLINK_DIPS_CP_BIT 7
|
||||
#define RSLINK_DIPS_nPL_PORT PORTD
|
||||
#define RSLINK_DIPS_nPL_DDR DDRD
|
||||
#define RSLINK_DIPS_nPL_PIN PIND
|
||||
#define RSLINK_DIPS_nPL_BIT 6
|
||||
#define RSLINK_DIPS_Q7_PORT PORTD
|
||||
#define RSLINK_DIPS_Q7_DDR DDRD
|
||||
#define RSLINK_DIPS_Q7_PIN PIND
|
||||
#define RSLINK_DIPS_Q7_BIT 5
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint16_t RSLink_DipsRead(void);
|
||||
//void RSLink_TimerInit();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif // #ifndef _INC_RSLINK_CUSTOM_H_
|
||||
//#############################################################################################################################################################################################################
|
@ -0,0 +1,277 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
|
||||
<avrdevice>ATmega328PB</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>idiBus_Ext</AssemblyName>
|
||||
<Name>idiBus_Ext_3xThermo1HT</Name>
|
||||
<RootNamespace>idiBus_Ext</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.47.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
<avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool>
|
||||
<avrtoolserialnumber>0000B809060C</avrtoolserialnumber>
|
||||
<avrdeviceexpectedsignature>0x1E9516</avrdeviceexpectedsignature>
|
||||
<com_atmel_avrdbg_tool_simulator>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
|
||||
<ToolNumber>
|
||||
</ToolNumber>
|
||||
<ToolName>Simulator</ToolName>
|
||||
</com_atmel_avrdbg_tool_simulator>
|
||||
<avrtoolinterface>ISP</avrtoolinterface>
|
||||
<com_atmel_avrdbg_tool_stk500>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>0</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.stk500</ToolType>
|
||||
<ToolNumber>
|
||||
</ToolNumber>
|
||||
<ToolName>STK500</ToolName>
|
||||
</com_atmel_avrdbg_tool_stk500>
|
||||
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
||||
<com_atmel_avrdbg_tool_atmelice>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>125000</IspClock>
|
||||
<JtagDbgClock>0</JtagDbgClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
||||
<ToolNumber>J41800094359</ToolNumber>
|
||||
<ToolName>Atmel-ICE</ToolName>
|
||||
</com_atmel_avrdbg_tool_atmelice>
|
||||
<com_atmel_avrdbg_tool_ispmk2>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.ispmk2</ToolType>
|
||||
<ToolNumber>0000B809060C</ToolNumber>
|
||||
<ToolName>AVRISP mkII</ToolName>
|
||||
</com_atmel_avrdbg_tool_ispmk2>
|
||||
<custom>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>custom</ToolType>
|
||||
<ToolNumber>
|
||||
</ToolNumber>
|
||||
<ToolName>Custom Programming Tool</ToolName>
|
||||
</custom>
|
||||
<CustomProgrammingToolTimeout>120</CustomProgrammingToolTimeout>
|
||||
<CustomProgrammingToolCommand>
|
||||
</CustomProgrammingToolCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Release' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../idiBusCoreFiles/IdiBus</Value>
|
||||
<Value>../idiBusFiles</Value>
|
||||
<Value>../moduleFiles</Value>
|
||||
<Value>../personalizationFiles</Value>
|
||||
<Value>../idiBusCoreFiles/CommonHW</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>$(SolutionDir)\FirmwareConverter\idiBusFmwPrepTool.exe $(avrdevice) "$(OutputDirectory)\$(OutputFileName).hex" "$(SolutionDir)\personalizationFiles\keys.h" "$(SolutionDir)\personalizationFiles\device.cfg"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == '[Build] Debug' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<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.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>_CPU_ATMEGA328PB_</Value>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
<Value>../idiBusCoreFiles/IdiBus</Value>
|
||||
<Value>../idiBusFiles</Value>
|
||||
<Value>../moduleFiles</Value>
|
||||
<Value>../personalizationFiles</Value>
|
||||
<Value>../idiBusCoreFiles/CommonHW</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<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.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.locationInApp=0x37C0</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.7.374\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>$(SolutionDir)\FirmwareConverter\idiBusFmwPrepTool.exe $(avrdevice) "$(OutputDirectory)\$(OutputFileName).hex" "$(SolutionDir)\personalizationFiles\keys.h" "$(SolutionDir)\personalizationFiles\device.cfg"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="idiBusFiles\IDIBUS_IMPL_Custom.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBusFiles\IDIBUS_IMPL_Custom.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBusFiles\RSLinkCustom.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="idiBusFiles\RSLinkCustom.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="main.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="moduleFiles\EEMEM.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="moduleFiles\SPI.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="moduleFiles\SPI.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="moduleFiles\USART0Custom.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="moduleFiles\USART0Custom.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="personalizationFiles\config.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="personalizationFiles\keys.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="personalizationFiles" />
|
||||
<Folder Include="moduleFiles" />
|
||||
<Folder Include="idiBusFiles" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="personalizationFiles\device.cfg">
|
||||
<SubType>compile</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\idiBusCoreFiles\IdiCommon_328pb.cproj">
|
||||
<Name>IdiCommon_328pb</Name>
|
||||
<Project>{06e88371-de74-4663-a82f-031e45168730}</Project>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
@ -0,0 +1,86 @@
|
||||
//#####################################################################################################################################################################################################
|
||||
// idiBus_Ext_4xADC0-10_APPL
|
||||
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include "config.h"
|
||||
#include <avr/io.h>
|
||||
FUSES={ .extended=F_Ext, .high = F_High, .low = F_Low }; // Fuses + Lock programming
|
||||
LOCKBITS=F_Lock;
|
||||
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#include "USART0.h"
|
||||
#include "USART1.h"
|
||||
#include "SPI.h"
|
||||
#include "USART0Custom.h"
|
||||
#include "RSLink.h"
|
||||
#include "RSLinkCustom.h"
|
||||
#include <avr/wdt.h>
|
||||
#include "SYSTEMCustom.h"
|
||||
#include "Common/MEMORY.h"
|
||||
#include "IDIBUS_IMPL_Custom.h"
|
||||
//#####################################################################################################################################################################################################
|
||||
//uint8_t data_to_send[12] = {0x05, 0x4E, 0x20, 0x28, 0x01, 0x00, 0x01, 0x9C, 0x40, 0x28, 0x01, 0x01};
|
||||
int start_flag = 0;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//DDRD = 3; // USART PD0, PD1
|
||||
//PORTD = 3;
|
||||
///////////////////////////////
|
||||
//STM NRST
|
||||
DDRC = 0;
|
||||
PORTC = 0;
|
||||
///////////////////////////////
|
||||
//DDRE |= (1 << PORTE1);
|
||||
//PORTE = 2;
|
||||
|
||||
cli(); // Çàïðåò ïðåðûâàíèé
|
||||
wdt_enable(WDTO_2S); // Watchdog òàéìåð íà 2 ñåê
|
||||
wdt_reset(); // Ñáðîñ watchdog òàéìåðà, ÷òîá íå ñðàáàòûâàë ïðîñòî òàê
|
||||
System_InitSysTick(); // Èíèöèàëèçàöèÿ ñèñòåìíîãî ñ÷åò÷èêà âðåìåíè
|
||||
System_SystickTimerStart(); // Çàïóñê ñèñòåìíîãî ñ÷åò÷èêà âðåìåíè
|
||||
|
||||
//USART0_Init();
|
||||
//USART0_INTERFACE.SetNewBaudrate(115200);
|
||||
//USART_Init(8);
|
||||
USART1_Init();
|
||||
|
||||
IDIBUS_ModuleInit(&USART1_INTERFACE, &STATIC_DATA_APP.Padding);
|
||||
RSLink_Init(&USART1_INTERFACE, &USART1_IDIBUS);
|
||||
sei(); //Find some place for this
|
||||
|
||||
//uint8_t buf[3] = {'S','6'};
|
||||
//USART0_INTERFACE.SendByteBuf(&buf,2);
|
||||
|
||||
// -----SPI-----
|
||||
SPI_MasterInit();
|
||||
|
||||
//for (uint8_t i = 0; i < 12; i++) {
|
||||
//USART_Transmit(data_to_send[i]);
|
||||
//}
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
if (start_flag == 0) {
|
||||
STMReset();
|
||||
start_flag = 1;
|
||||
}
|
||||
|
||||
RSLink_Handler();
|
||||
//for (uint8_t i = 0; i < 12; i++) {
|
||||
//data_to_send[i] = USART_Receive();
|
||||
//}
|
||||
//_delay_ms(100);
|
||||
//STMReset();
|
||||
//_delay_ms(100);
|
||||
|
||||
//if ((PINC)&(1<<PORTC3)) { // STM ãîòîâ ê ïðèåìó
|
||||
//_delay_ms(100);
|
||||
//for (int i = 0; i < 12; i++) {
|
||||
//SPI_MasterTransmit(data_to_send[i]);
|
||||
//}
|
||||
//}
|
||||
|
||||
wdt_reset();
|
||||
}
|
||||
}
|
||||
//#####################################################################################################################################################################################################
|
@ -0,0 +1,18 @@
|
||||
#ifndef EEMEM_H_
|
||||
#define EEMEM_H_
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
volatile typedef struct{
|
||||
volatile uint8_t BOOTFLAG; //DoNotMove
|
||||
volatile uint8_t EEPROM_IDIBUS_InitGroup; //DoNotMove
|
||||
volatile uint8_t EEPROM_SN[IDISN_VARP_LENGTH]; //DoNotMove
|
||||
|
||||
//Add new things here
|
||||
// ||
|
||||
// ||
|
||||
// \/
|
||||
|
||||
} EEPROM_DATABLOCKS;
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const volatile EEMEM EEPROM_DATABLOCKS EEBLOCK; //DYNAMIC PART
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#endif /* EEMEM_H_ */
|
@ -0,0 +1,62 @@
|
||||
#include "MaxHandler.h"
|
||||
|
||||
void Max_Init(uint8_t ch,uint8_t initMode) {
|
||||
sSPI_select(ch);
|
||||
|
||||
sSPI_write_byte(0x80);
|
||||
if (initMode == AutoConversion)
|
||||
sSPI_write_byte((1<<7)|(1<<5)|(1<<0)); //Auto conversion + OC 33ms detection + 50hz rejection
|
||||
else if (initMode == OneShotConversion)
|
||||
sSPI_write_byte((1<<6)|(1<<5)|(1<<0)); //OneShot conversion + OC 33ms detection + 50hz rejection
|
||||
else
|
||||
sSPI_write_byte((1<<5)|(1<<0)); //OC 33ms detection + 50hz rejection
|
||||
|
||||
sSPI_write_byte(0b0011|(0b0011<<4)); //TC type K + 8 samples
|
||||
|
||||
sSPI_free();
|
||||
|
||||
uint8_t i = 0;
|
||||
|
||||
if (ch < THERMO_CHN_COUNT) {
|
||||
i = ch;
|
||||
++ch;
|
||||
}
|
||||
|
||||
for (; i < ch; i++) {
|
||||
ThermoSensor[i].lastTick = System_GetSysTick();
|
||||
ThermoSensor[i].state = 4; //Set NO_DATA error
|
||||
ThermoSensor[i].captureFlags = initMode;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t IsMaxDRDYLow(uint8_t ch) {
|
||||
if (ch > THERMO_CHN_COUNT-1) ch = THERMO_CHN_COUNT-1;
|
||||
|
||||
if ( ( RSLink_DipsRead() & (1<<(4+ch)) ) == 0) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Max_Handler(){
|
||||
ThermoData *Selected = &ThermoSensor[MaxSelectedChannel];
|
||||
|
||||
//If conversion ready or 5s timeout
|
||||
if ((IsMaxDRDYLow(MaxSelectedChannel) || (System_GetSysTickDifference(Selected->lastTick)>2000)) && Selected->captureFlags != 0) {
|
||||
sSPI_select(MaxSelectedChannel);
|
||||
Selected->lastTick = System_GetSysTick();
|
||||
sSPI_write_byte(0x0A);
|
||||
Selected->CJTemp = (uint16_t)sSPI_read_byte()<<8;
|
||||
Selected->CJTemp |= sSPI_read_byte();
|
||||
Selected->Temperature = (uint32_t)sSPI_read_byte()<<11;
|
||||
Selected->Temperature |= (uint32_t)sSPI_read_byte()<<3;
|
||||
Selected->Temperature |= (uint32_t)sSPI_read_byte()>>5;
|
||||
Selected->state = sSPI_read_byte()&(~4);
|
||||
sSPI_free();
|
||||
if ((Selected->captureFlags & OneShotConversion) != 0){
|
||||
Selected->captureFlags &= ~(OneShotConversion);
|
||||
}
|
||||
}
|
||||
|
||||
MaxSelectedChannel++;
|
||||
if (MaxSelectedChannel == THERMO_CHN_COUNT) MaxSelectedChannel = 0;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef MAXHANDLER_H_
|
||||
#define MAXHANDLER_H_
|
||||
|
||||
#include "software_SPI.h"
|
||||
#include "RSLinkCustom.h"
|
||||
#include "SYSTEM.h"
|
||||
|
||||
//Define some channel stuff here
|
||||
typedef struct{
|
||||
uint8_t state;
|
||||
uint32_t Temperature;
|
||||
uint16_t CJTemp;
|
||||
uint32_t lastTick;
|
||||
uint8_t captureFlags;
|
||||
//uint8_t pin;
|
||||
} ThermoData;
|
||||
|
||||
#define THERMO_CHN_COUNT 3 //TODO Duplicate from IDIBUS_IMPL_Custom
|
||||
//Also hardcoded value in sSPI
|
||||
ThermoData ThermoSensor[THERMO_CHN_COUNT];
|
||||
|
||||
enum InitMode { //BitFlags
|
||||
NoConversion = 0x00,
|
||||
OneShotConversion = 0x01,
|
||||
AutoConversion = 0x02
|
||||
};
|
||||
|
||||
uint8_t MaxSelectedChannel;
|
||||
|
||||
void Max_Init(uint8_t ch, uint8_t initMode);
|
||||
|
||||
uint8_t IsMaxDRDYLow(uint8_t ch);
|
||||
|
||||
void Max_Handler();
|
||||
|
||||
#endif /* MAXHANDLER_H_ */
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* SPI.c
|
||||
*
|
||||
* Created: 24.10.2023 15:34:10
|
||||
* Author: Katya
|
||||
*/
|
||||
|
||||
#include "SPI.h"
|
||||
|
||||
void SPI_MasterInit(void) {
|
||||
// Íàñòðîéêà ïèíà SS (PE2) êàê âûõîäà
|
||||
DDRE |= (1 << PORTE2);
|
||||
// Óñòàíîâêà SS â âûñîêîå ñîñòîÿíèå (íåàêòèâíûé)
|
||||
PORTE |= (1 << PORTE2);
|
||||
|
||||
/* Set MOSI, SS and SCK output */
|
||||
DDRE |= (1 << MOSI);
|
||||
DDRC |= (1 << SCK) | (1 << SS);
|
||||
|
||||
/* Enable SPI, Master */
|
||||
SPCR1 = (1 << SPE1) | (1 << MSTR1);
|
||||
}
|
||||
|
||||
void SPI_MasterTransmit(uint8_t data) {
|
||||
PORTC &= ~(1 << PORTC2); // íà÷àëî ïåðåäà÷è - íèçêèé óðîâåíü
|
||||
SPDR1 = data;
|
||||
while(!(SPSR1 & (1<<SPIF1)));
|
||||
PORTC |= (1 << PORTC2); // êîíåö ïåðåäà÷è - âûñîêèé óðîâåíü
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* SPI.h
|
||||
*
|
||||
* Created: 24.10.2023 15:35:09
|
||||
* Author: Katya
|
||||
*/
|
||||
|
||||
#ifndef SPI_H_
|
||||
#define SPI_H_
|
||||
|
||||
#define MOSI DDE3
|
||||
#define SCK DDC1
|
||||
#define SS DDC2
|
||||
|
||||
#define F_CPU 16000000UL
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
void SPI_MasterInit (void);
|
||||
void SPI_MasterTransmit(uint8_t data);
|
||||
|
||||
#endif /* SPI_H_ */
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* USART0Custom.c
|
||||
*
|
||||
* Created: 26.10.2023 17:37:08
|
||||
* Author: Katya
|
||||
*/
|
||||
|
||||
#include "USART0Custom.h"
|
||||
|
||||
void USART_Init (uint16_t speed) {
|
||||
// Ст. и мл. скорость
|
||||
UBRR0H = 0;
|
||||
UBRR0L = (uint8_t)(speed);
|
||||
// Прерывания при приеме, вкл прием/передача
|
||||
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
|
||||
// 8 бит данных, 2 стоп-бита
|
||||
UCSR0C = (1<<USBS0) | (3<<UCSZ00);
|
||||
}
|
||||
|
||||
void USART_Transmit (uint8_t data) {
|
||||
while (!(UCSR0A & (1<<UDRE0))); // Ожидание конца передачи
|
||||
UDR0 = data; // Начало передачи
|
||||
}
|
||||
|
||||
uint8_t USART_Receive() {
|
||||
while (!(UCSR0A & (1 << RXC0))); // Ожидание конца приема
|
||||
return UDR0; // Принятые данные
|
||||
}
|
||||
|
||||
uint8_t USART_DataAvailable() {
|
||||
// Пришел ли пакет в приемную шину
|
||||
return (UCSR0A & (1 << RXC0)) ? 1 : 0;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* USART0Custom.h
|
||||
*
|
||||
* Created: 26.10.2023 17:37:21
|
||||
* Author: Katya
|
||||
*/
|
||||
|
||||
|
||||
#ifndef USART0CUSTOM_H_
|
||||
#define USART0CUSTOM_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <util/delay.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
void USART_Init (uint16_t speed);
|
||||
void USART_Transmit (uint8_t data);
|
||||
uint8_t USART_Receive();
|
||||
uint8_t USART_DataAvailable();
|
||||
|
||||
|
||||
#endif /* USART0CUSTOM_H_ */
|
@ -0,0 +1,59 @@
|
||||
#include "software_SPI.h"
|
||||
|
||||
void sSPI_init(){
|
||||
DDRC |= (1<<DDRC0)|(1<<DDRC1);
|
||||
PORTC = 0;
|
||||
|
||||
DDRD |= (1<<DDRD2)|(1<<DDRD3)|(1<<DDRD4); //set CSx pins on out
|
||||
PORTD |= (1<<PORTD2)|(1<<PORTD3)|(1<<PORTD4); //set CSx pins HIGH
|
||||
}
|
||||
|
||||
void sSPI_select(uint8_t ch){
|
||||
if (ch > 3/*Max channel count*/) return;
|
||||
|
||||
sSPI_free();
|
||||
|
||||
if (ch == 3)
|
||||
PORTD &= (~(0b111<<(PORTD2)));
|
||||
else
|
||||
PORTD &= (~(1<<(PORTD2+ch)));
|
||||
}
|
||||
|
||||
inline void sSPI_free(){
|
||||
PORTD |= (1<<PORTD2)|(1<<PORTD3)|(1<<PORTD4); //set CSx pins HIGH
|
||||
}
|
||||
|
||||
void sSPI_write_byte(uint8_t byte){
|
||||
for (uint8_t i = 8; i > 0; i--){
|
||||
if ( (byte>>(i-1)) & 1 )
|
||||
MOSI_Hi;
|
||||
else
|
||||
MOSI_Lo;
|
||||
|
||||
_delay_us(delay);
|
||||
|
||||
CLK_invert;
|
||||
|
||||
_delay_us(delay);
|
||||
|
||||
CLK_invert;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t sSPI_read_byte(){
|
||||
uint8_t rx = 0;
|
||||
|
||||
for (uint8_t i = 8; i > 0; i--){
|
||||
CLK_invert;
|
||||
|
||||
_delay_us(delay);
|
||||
|
||||
rx |= ((PINC >> PORTC2)&1)<<(i-1);
|
||||
|
||||
CLK_invert;
|
||||
|
||||
_delay_us(delay);
|
||||
}
|
||||
|
||||
return rx;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef SOFTWARE_SPI_H_
|
||||
#define SOFTWARE_SPI_H_
|
||||
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#define delay 2
|
||||
|
||||
|
||||
//PC0 = clock
|
||||
//PC1 = MOSI (output)
|
||||
//PC2 = MISO (input)
|
||||
//PC3-5 empty
|
||||
|
||||
#define CLK_invert PORTC ^= (1<<PORTC0)
|
||||
#define MOSI_Hi PORTC |= (1<<PORTC1)
|
||||
#define MOSI_Lo PORTC &= ~(1<<PORTC1)
|
||||
|
||||
void sSPI_init();
|
||||
|
||||
void sSPI_select(uint8_t ch);
|
||||
|
||||
void sSPI_free();
|
||||
|
||||
void sSPI_write_byte(uint8_t byte);
|
||||
|
||||
uint8_t sSPI_read_byte();
|
||||
|
||||
#endif /* SOFTWARE_SPI_H_ */
|
@ -0,0 +1,67 @@
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
//Select one MCU
|
||||
|
||||
//For 328pb
|
||||
#ifdef _CPU_ATMEGA328PB_
|
||||
|
||||
#define PAGE_SIZE 128UL
|
||||
#define PAGE_SIZE_BIT 7
|
||||
|
||||
//DONT FORGET TO CHANGE LINKER OPTIONS!!!!
|
||||
#define locationInBoot (0x3FE8UL) //CAREFUL ONLY 48 byte in size for data
|
||||
#define locationInApp (0x37C0UL)
|
||||
|
||||
//FUSES
|
||||
#define F_Low 0xE0
|
||||
#define F_Ext 0xFC
|
||||
|
||||
#ifdef DEBUG
|
||||
#define F_High 0xD0 //Allow DebugWIRE + EEPROM save
|
||||
#define F_Lock 0xFF //Disable LOCKS
|
||||
#else
|
||||
#define F_High 0xC8 //No DEBUG thing + No EEPROM save
|
||||
#define F_Lock 0xCC
|
||||
#endif
|
||||
|
||||
#define SRAM_size 2048UL
|
||||
|
||||
#endif
|
||||
|
||||
//For 2560
|
||||
#ifdef _CPU_ATMEGA2560_
|
||||
|
||||
#define _LONG_ADDR_SPACE_
|
||||
#define _FAT_CRC_
|
||||
|
||||
#define PAGE_SIZE 256ULL
|
||||
#define PAGE_SIZE_BIT 8
|
||||
|
||||
//Settings in the linker
|
||||
#define locationInBoot (0x1FF80ULL)
|
||||
#define locationInApp (0x1EF80ULL)
|
||||
|
||||
//FUSES
|
||||
#define F_Low 0xE0
|
||||
#define F_Ext 0xFC
|
||||
|
||||
#ifdef DEBUG
|
||||
#define F_High 0x00 //Enable JTAG and OCD + EEPROM save
|
||||
#define F_Lock 0xFF //Disable LOCKS
|
||||
#else
|
||||
#define F_High 0xC8 //No DEBUG thing + No EEPROM save
|
||||
#define F_Lock 0xCC
|
||||
#endif
|
||||
|
||||
|
||||
#define SRAM_size 8192UL
|
||||
|
||||
#endif
|
||||
|
||||
//COMMON Define
|
||||
#define PAGE_COUNT (((locationInApp<<1)/PAGE_SIZE)+1)
|
||||
|
||||
#endif /* CONFIG_H_ */
|
@ -0,0 +1,9 @@
|
||||
.GS1_country = {'1','2','3'}, //GS1 country (ASCII)
|
||||
.GS1_company = {'1','2','3','4','5','6'}, //GS1 company (ASCII)
|
||||
.ModuleType = {'G','N','1' }, //Module type (ASCII)
|
||||
.HW_revision = {0, 7}, //HW Revision (Binary)
|
||||
.SN = {'A','N','O','T','H','E','R'}, //Serial number (ASCII)
|
||||
.MAC = {255,250,230,128,127,1}, //MAC addr (Binary)
|
||||
#ifdef APP_VERSION
|
||||
.SW = {0, 0x01 }, //SW App Version (Binary) (DO NOT SHUFFLE VERSIONS)
|
||||
#endif
|
@ -0,0 +1,7 @@
|
||||
#ifndef KEYS_H_
|
||||
#define KEYS_H_
|
||||
|
||||
const uint8_t IV[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
const uint8_t key[32] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F};
|
||||
|
||||
#endif /* KEYS_H_ */
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
:00000001FF
|
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
:100000000C945A000C9477000C9477000C947700B1
|
||||
:100010000C9477000C9477000C9477000C94770084
|
||||
:100020000C9477000C9477000C9477000C94770074
|
||||
:100030000C9477000C9477000C9477000C94770064
|
||||
:100040000C9477000C9477000C9477000C94770054
|
||||
:100050000C9477000C9477000C9477000C94770044
|
||||
:100060000C9477000C9477000C9477000C94770034
|
||||
:100070000C9477000C9477000C9477000C94770024
|
||||
:100080000C9477000C9477000C9477000C94770014
|
||||
:100090000C9477000C9477000C9477000C94770004
|
||||
:1000A0000C9477000C9477000C9477000C947700F4
|
||||
:1000B0000C94770011241FBECFEFD8E0DEBFCDBF78
|
||||
:1000C00011E0A0E0B1E0E8E1F2E002C005900D929D
|
||||
:1000D000AC30B107D9F721E0ACE0B1E001C01D922E
|
||||
:1000E000AC30B207E1F70E948F000C940A010C9427
|
||||
:1000F00000003C9A44982FEF81EE94E0215080401C
|
||||
:100100009040E1F700C000003C982FEF81EE94E0B2
|
||||
:10011000215080409040E1F700C000000895CF9347
|
||||
:10012000DF93CDB7DEB72C970FB6F894DEBF0FBEC6
|
||||
:10013000CDBF8CE0E0E0F1E0DE01119601900D9280
|
||||
:100140008A95E1F783E08AB98BB917B818B8699A2C
|
||||
:100150006A98729888E090E00E94F70078940E9474
|
||||
:10016000D4006E012DE0C20ED11C0E947900339B99
|
||||
:10017000FCCF719A8FEF93EDE0E381509040E04027
|
||||
:10018000E1F700C000008E010F5F1F4FF801F190F2
|
||||
:100190008F018F2D0E9402018F2D0E94DE000C1511
|
||||
:1001A0001D05A1F77198E1CF6A9A729A6B9A87B18F
|
||||
:1001B000866087B980E58093AC000895429880936B
|
||||
:1001C000AE008091AD00882384F0EDEAF0E0719AF2
|
||||
:1001D0002FEF81EE94E0215080409040E1F700C085
|
||||
:1001E000000071988081882394F7429A08951092B4
|
||||
:1001F000C5008093C40088E18093C1008EE08093A5
|
||||
:10020000C2000895E0ECF0E0908195FFFDCF80936F
|
||||
:08021000C6000895F894FFCF29
|
||||
:0C021800014E20280100019C402801013B
|
||||
:00000001FF
|
@ -0,0 +1,385 @@
|
||||
|
||||
GccApplication1.elf: file format elf32-avr
|
||||
|
||||
Sections:
|
||||
Idx Name Size VMA LMA File off Algn
|
||||
0 .data 0000000c 00800100 00000218 0000028c 2**0
|
||||
CONTENTS, ALLOC, LOAD, DATA
|
||||
1 .text 00000218 00000000 00000000 00000074 2**1
|
||||
CONTENTS, ALLOC, LOAD, READONLY, CODE
|
||||
2 .comment 00000030 00000000 00000000 00000298 2**0
|
||||
CONTENTS, READONLY
|
||||
3 .note.gnu.avr.deviceinfo 00000040 00000000 00000000 000002c8 2**2
|
||||
CONTENTS, READONLY
|
||||
4 .debug_aranges 00000088 00000000 00000000 00000308 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
5 .debug_info 00000d91 00000000 00000000 00000390 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
6 .debug_abbrev 00000b49 00000000 00000000 00001121 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
7 .debug_line 00000601 00000000 00000000 00001c6a 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
8 .debug_frame 000000cc 00000000 00000000 0000226c 2**2
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
9 .debug_str 0000054c 00000000 00000000 00002338 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
10 .debug_loc 000001f6 00000000 00000000 00002884 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
11 .debug_ranges 00000058 00000000 00000000 00002a7a 2**0
|
||||
CONTENTS, READONLY, DEBUGGING
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
00000000 <__vectors>:
|
||||
0: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__ctors_end>
|
||||
4: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
8: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
10: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
14: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
18: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
1c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
20: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
24: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
28: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
2c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
30: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
34: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
38: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
3c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
40: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
44: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
48: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
4c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
50: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
54: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
58: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
5c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
60: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
64: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
68: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
6c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
70: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
74: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
78: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
7c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
80: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
84: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
88: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
8c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
90: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
94: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
98: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
9c: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
a0: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
a4: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
a8: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
ac: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
b0: 0c 94 77 00 jmp 0xee ; 0xee <__bad_interrupt>
|
||||
|
||||
000000b4 <__ctors_end>:
|
||||
b4: 11 24 eor r1, r1
|
||||
b6: 1f be out 0x3f, r1 ; 63
|
||||
b8: cf ef ldi r28, 0xFF ; 255
|
||||
ba: d8 e0 ldi r29, 0x08 ; 8
|
||||
bc: de bf out 0x3e, r29 ; 62
|
||||
be: cd bf out 0x3d, r28 ; 61
|
||||
|
||||
000000c0 <__do_copy_data>:
|
||||
c0: 11 e0 ldi r17, 0x01 ; 1
|
||||
c2: a0 e0 ldi r26, 0x00 ; 0
|
||||
c4: b1 e0 ldi r27, 0x01 ; 1
|
||||
c6: e8 e1 ldi r30, 0x18 ; 24
|
||||
c8: f2 e0 ldi r31, 0x02 ; 2
|
||||
ca: 02 c0 rjmp .+4 ; 0xd0 <__do_copy_data+0x10>
|
||||
cc: 05 90 lpm r0, Z+
|
||||
ce: 0d 92 st X+, r0
|
||||
d0: ac 30 cpi r26, 0x0C ; 12
|
||||
d2: b1 07 cpc r27, r17
|
||||
d4: d9 f7 brne .-10 ; 0xcc <__do_copy_data+0xc>
|
||||
|
||||
000000d6 <__do_clear_bss>:
|
||||
d6: 21 e0 ldi r18, 0x01 ; 1
|
||||
d8: ac e0 ldi r26, 0x0C ; 12
|
||||
da: b1 e0 ldi r27, 0x01 ; 1
|
||||
dc: 01 c0 rjmp .+2 ; 0xe0 <.do_clear_bss_start>
|
||||
|
||||
000000de <.do_clear_bss_loop>:
|
||||
de: 1d 92 st X+, r1
|
||||
|
||||
000000e0 <.do_clear_bss_start>:
|
||||
e0: ac 30 cpi r26, 0x0C ; 12
|
||||
e2: b2 07 cpc r27, r18
|
||||
e4: e1 f7 brne .-8 ; 0xde <.do_clear_bss_loop>
|
||||
e6: 0e 94 8f 00 call 0x11e ; 0x11e <main>
|
||||
ea: 0c 94 0a 01 jmp 0x214 ; 0x214 <_exit>
|
||||
|
||||
000000ee <__bad_interrupt>:
|
||||
ee: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
|
||||
|
||||
000000f2 <STMReset>:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void STMReset() {
|
||||
DDRC |= (1 << PINC4);
|
||||
f2: 3c 9a sbi 0x07, 4 ; 7
|
||||
PORTC &= ~(1 << PINC4);
|
||||
f4: 44 98 cbi 0x08, 4 ; 8
|
||||
#else
|
||||
//round up by default
|
||||
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
|
||||
#endif
|
||||
|
||||
__builtin_avr_delay_cycles(__ticks_dc);
|
||||
f6: 2f ef ldi r18, 0xFF ; 255
|
||||
f8: 81 ee ldi r24, 0xE1 ; 225
|
||||
fa: 94 e0 ldi r25, 0x04 ; 4
|
||||
fc: 21 50 subi r18, 0x01 ; 1
|
||||
fe: 80 40 sbci r24, 0x00 ; 0
|
||||
100: 90 40 sbci r25, 0x00 ; 0
|
||||
102: e1 f7 brne .-8 ; 0xfc <STMReset+0xa>
|
||||
104: 00 c0 rjmp .+0 ; 0x106 <STMReset+0x14>
|
||||
106: 00 00 nop
|
||||
_delay_ms(100);
|
||||
DDRC &= ~(1 << PINC4);
|
||||
108: 3c 98 cbi 0x07, 4 ; 7
|
||||
10a: 2f ef ldi r18, 0xFF ; 255
|
||||
10c: 81 ee ldi r24, 0xE1 ; 225
|
||||
10e: 94 e0 ldi r25, 0x04 ; 4
|
||||
110: 21 50 subi r18, 0x01 ; 1
|
||||
112: 80 40 sbci r24, 0x00 ; 0
|
||||
114: 90 40 sbci r25, 0x00 ; 0
|
||||
116: e1 f7 brne .-8 ; 0x110 <STMReset+0x1e>
|
||||
118: 00 c0 rjmp .+0 ; 0x11a <STMReset+0x28>
|
||||
11a: 00 00 nop
|
||||
11c: 08 95 ret
|
||||
|
||||
0000011e <main>:
|
||||
//bytes++;
|
||||
//PORTE = 0;
|
||||
//}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
11e: cf 93 push r28
|
||||
120: df 93 push r29
|
||||
122: cd b7 in r28, 0x3d ; 61
|
||||
124: de b7 in r29, 0x3e ; 62
|
||||
126: 2c 97 sbiw r28, 0x0c ; 12
|
||||
128: 0f b6 in r0, 0x3f ; 63
|
||||
12a: f8 94 cli
|
||||
12c: de bf out 0x3e, r29 ; 62
|
||||
12e: 0f be out 0x3f, r0 ; 63
|
||||
130: cd bf out 0x3d, r28 ; 61
|
||||
uint8_t data_to_send[] = {0x01, 0x4E, 0x20, 0x28, 0x01, 0x00, 0x01, 0x9C, 0x40, 0x28, 0x01, 0x01};
|
||||
132: 8c e0 ldi r24, 0x0C ; 12
|
||||
134: e0 e0 ldi r30, 0x00 ; 0
|
||||
136: f1 e0 ldi r31, 0x01 ; 1
|
||||
138: de 01 movw r26, r28
|
||||
13a: 11 96 adiw r26, 0x01 ; 1
|
||||
13c: 01 90 ld r0, Z+
|
||||
13e: 0d 92 st X+, r0
|
||||
140: 8a 95 dec r24
|
||||
142: e1 f7 brne .-8 ; 0x13c <main+0x1e>
|
||||
DDRD = 3; // USART PD0, PD1
|
||||
144: 83 e0 ldi r24, 0x03 ; 3
|
||||
146: 8a b9 out 0x0a, r24 ; 10
|
||||
PORTD = 3;
|
||||
148: 8b b9 out 0x0b, r24 ; 11
|
||||
///////////////////////////////
|
||||
//STM NRST
|
||||
DDRC = 0;
|
||||
14a: 17 b8 out 0x07, r1 ; 7
|
||||
PORTC = 0;
|
||||
14c: 18 b8 out 0x08, r1 ; 8
|
||||
///////////////////////////////
|
||||
DDRE |= (1 << PORTE1);
|
||||
14e: 69 9a sbi 0x0d, 1 ; 13
|
||||
DDRE &= ~(1 << PORTE2);
|
||||
150: 6a 98 cbi 0x0d, 2 ; 13
|
||||
PORTE &= ~(1 << PORTE2);
|
||||
152: 72 98 cbi 0x0e, 2 ; 14
|
||||
//PORTE = 2;
|
||||
|
||||
USART_Init(8); // óñòàíîâêà ñêîðîñòè 115200: (16 000 000 / (16 * 115 200) ) - 1, U2X = 0
|
||||
154: 88 e0 ldi r24, 0x08 ; 8
|
||||
156: 90 e0 ldi r25, 0x00 ; 0
|
||||
158: 0e 94 f7 00 call 0x1ee ; 0x1ee <USART_Init>
|
||||
sei();
|
||||
15c: 78 94 sei
|
||||
|
||||
// -----SPI-----
|
||||
SPI_MasterInit();
|
||||
15e: 0e 94 d4 00 call 0x1a8 ; 0x1a8 <SPI_MasterInit>
|
||||
162: 6e 01 movw r12, r28
|
||||
164: 2d e0 ldi r18, 0x0D ; 13
|
||||
166: c2 0e add r12, r18
|
||||
168: d1 1c adc r13, r1
|
||||
//PORTE &= ~(1 << PORTE1); // STATUS âûêë
|
||||
//for (uint8_t i = 0; i < 12; i++) {
|
||||
//USART_Transmit(data_to_send[i]);
|
||||
//}
|
||||
// $05$4E$20$28$01$00$03$9C$40$28$01$01
|
||||
STMReset();
|
||||
16a: 0e 94 79 00 call 0xf2 ; 0xf2 <STMReset>
|
||||
//_delay_ms(100);
|
||||
//PORTE &= ~(1 << PORTE1); // STATUS âûêë
|
||||
//
|
||||
//PORTE |= (1 << PORTE1); // STATUS âêë
|
||||
|
||||
if ((PINC)&(1<<PORTC3)) { // STM ãîòîâ ê ïðèåìó
|
||||
16e: 33 9b sbis 0x06, 3 ; 6
|
||||
170: fc cf rjmp .-8 ; 0x16a <main+0x4c>
|
||||
PORTE |= (1 << PORTE1); // STATUS âêë
|
||||
172: 71 9a sbi 0x0e, 1 ; 14
|
||||
174: 8f ef ldi r24, 0xFF ; 255
|
||||
176: 93 ed ldi r25, 0xD3 ; 211
|
||||
178: e0 e3 ldi r30, 0x30 ; 48
|
||||
17a: 81 50 subi r24, 0x01 ; 1
|
||||
17c: 90 40 sbci r25, 0x00 ; 0
|
||||
17e: e0 40 sbci r30, 0x00 ; 0
|
||||
180: e1 f7 brne .-8 ; 0x17a <main+0x5c>
|
||||
182: 00 c0 rjmp .+0 ; 0x184 <main+0x66>
|
||||
184: 00 00 nop
|
||||
186: 8e 01 movw r16, r28
|
||||
188: 0f 5f subi r16, 0xFF ; 255
|
||||
18a: 1f 4f sbci r17, 0xFF ; 255
|
||||
_delay_ms(1000);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
USART_Transmit(data_to_send[i]);
|
||||
18c: f8 01 movw r30, r16
|
||||
18e: f1 90 ld r15, Z+
|
||||
190: 8f 01 movw r16, r30
|
||||
192: 8f 2d mov r24, r15
|
||||
194: 0e 94 02 01 call 0x204 ; 0x204 <USART_Transmit>
|
||||
SPI_MasterTransmit(data_to_send[i]);
|
||||
198: 8f 2d mov r24, r15
|
||||
19a: 0e 94 de 00 call 0x1bc ; 0x1bc <SPI_MasterTransmit>
|
||||
//PORTE |= (1 << PORTE1); // STATUS âêë
|
||||
|
||||
if ((PINC)&(1<<PORTC3)) { // STM ãîòîâ ê ïðèåìó
|
||||
PORTE |= (1 << PORTE1); // STATUS âêë
|
||||
_delay_ms(1000);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
19e: 0c 15 cp r16, r12
|
||||
1a0: 1d 05 cpc r17, r13
|
||||
1a2: a1 f7 brne .-24 ; 0x18c <main+0x6e>
|
||||
USART_Transmit(data_to_send[i]);
|
||||
SPI_MasterTransmit(data_to_send[i]);
|
||||
}
|
||||
PORTE &= ~(1 << PORTE1); // STATUS âûêë
|
||||
1a4: 71 98 cbi 0x0e, 1 ; 14
|
||||
1a6: e1 cf rjmp .-62 ; 0x16a <main+0x4c>
|
||||
|
||||
000001a8 <SPI_MasterInit>:
|
||||
*/
|
||||
#include "spi.h"
|
||||
|
||||
void SPI_MasterInit(void) {
|
||||
// Íàñòðîéêà ïèíà SS (PB2) êàê âûõîäà
|
||||
DDRE |= (1 << PORTE2);
|
||||
1a8: 6a 9a sbi 0x0d, 2 ; 13
|
||||
|
||||
// Óñòàíîâêà SS â âûñîêîå ñîñòîÿíèå (íåàêòèâíûé)
|
||||
PORTE |= (1 << PORTE2);
|
||||
1aa: 72 9a sbi 0x0e, 2 ; 14
|
||||
/* Set MOSI, SS and SCK output */
|
||||
DDRE |= (1 << MOSI);
|
||||
1ac: 6b 9a sbi 0x0d, 3 ; 13
|
||||
DDRC |= (1 << SCK) | (1 << SS);
|
||||
1ae: 87 b1 in r24, 0x07 ; 7
|
||||
1b0: 86 60 ori r24, 0x06 ; 6
|
||||
1b2: 87 b9 out 0x07, r24 ; 7
|
||||
|
||||
/* Enable SPI, Master */
|
||||
SPCR1 = (1 << SPE1) | (1 << MSTR1);
|
||||
1b4: 80 e5 ldi r24, 0x50 ; 80
|
||||
1b6: 80 93 ac 00 sts 0x00AC, r24 ; 0x8000ac <__TEXT_REGION_LENGTH__+0x7f80ac>
|
||||
1ba: 08 95 ret
|
||||
|
||||
000001bc <SPI_MasterTransmit>:
|
||||
}
|
||||
|
||||
void SPI_MasterTransmit(uint8_t data) {
|
||||
PORTC &= ~(1 << PORTC2); // íà÷àëî ïåðåäà÷è - íèçêèé óðîâåíü
|
||||
1bc: 42 98 cbi 0x08, 2 ; 8
|
||||
SPDR1 = data;
|
||||
1be: 80 93 ae 00 sts 0x00AE, r24 ; 0x8000ae <__TEXT_REGION_LENGTH__+0x7f80ae>
|
||||
while(!(SPSR1 & (1<<SPIF1))) {
|
||||
1c2: 80 91 ad 00 lds r24, 0x00AD ; 0x8000ad <__TEXT_REGION_LENGTH__+0x7f80ad>
|
||||
1c6: 88 23 and r24, r24
|
||||
1c8: 84 f0 brlt .+32 ; 0x1ea <SPI_MasterTransmit+0x2e>
|
||||
1ca: ed ea ldi r30, 0xAD ; 173
|
||||
1cc: f0 e0 ldi r31, 0x00 ; 0
|
||||
PORTE |= (1 << PORTE1); // STATUS âêë
|
||||
1ce: 71 9a sbi 0x0e, 1 ; 14
|
||||
1d0: 2f ef ldi r18, 0xFF ; 255
|
||||
1d2: 81 ee ldi r24, 0xE1 ; 225
|
||||
1d4: 94 e0 ldi r25, 0x04 ; 4
|
||||
1d6: 21 50 subi r18, 0x01 ; 1
|
||||
1d8: 80 40 sbci r24, 0x00 ; 0
|
||||
1da: 90 40 sbci r25, 0x00 ; 0
|
||||
1dc: e1 f7 brne .-8 ; 0x1d6 <SPI_MasterTransmit+0x1a>
|
||||
1de: 00 c0 rjmp .+0 ; 0x1e0 <SPI_MasterTransmit+0x24>
|
||||
1e0: 00 00 nop
|
||||
_delay_ms(100);
|
||||
PORTE &= ~(1 << PORTE1); // STATUS âûêë
|
||||
1e2: 71 98 cbi 0x0e, 1 ; 14
|
||||
}
|
||||
|
||||
void SPI_MasterTransmit(uint8_t data) {
|
||||
PORTC &= ~(1 << PORTC2); // íà÷àëî ïåðåäà÷è - íèçêèé óðîâåíü
|
||||
SPDR1 = data;
|
||||
while(!(SPSR1 & (1<<SPIF1))) {
|
||||
1e4: 80 81 ld r24, Z
|
||||
1e6: 88 23 and r24, r24
|
||||
1e8: 94 f7 brge .-28 ; 0x1ce <SPI_MasterTransmit+0x12>
|
||||
PORTE |= (1 << PORTE1); // STATUS âêë
|
||||
_delay_ms(100);
|
||||
PORTE &= ~(1 << PORTE1); // STATUS âûêë
|
||||
}
|
||||
PORTC |= (1 << PORTC2); // êîíåö ïåðåäà÷è - âûñîêèé óðîâåíü
|
||||
1ea: 42 9a sbi 0x08, 2 ; 8
|
||||
1ec: 08 95 ret
|
||||
|
||||
000001ee <USART_Init>:
|
||||
|
||||
#include "usart0.h"
|
||||
|
||||
void USART_Init (uint16_t speed) {
|
||||
// Ñò. è ìë. ñêîðîñòü
|
||||
UBRR0H = 0;
|
||||
1ee: 10 92 c5 00 sts 0x00C5, r1 ; 0x8000c5 <__TEXT_REGION_LENGTH__+0x7f80c5>
|
||||
UBRR0L = (uint8_t)(speed);
|
||||
1f2: 80 93 c4 00 sts 0x00C4, r24 ; 0x8000c4 <__TEXT_REGION_LENGTH__+0x7f80c4>
|
||||
// Ïðåðûâàíèÿ ïðè ïðèåìå, âêë ïðèåì/ïåðåäà÷à
|
||||
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
|
||||
1f6: 88 e1 ldi r24, 0x18 ; 24
|
||||
1f8: 80 93 c1 00 sts 0x00C1, r24 ; 0x8000c1 <__TEXT_REGION_LENGTH__+0x7f80c1>
|
||||
// 8 áèò äàííûõ, 2 ñòîï-áèòà
|
||||
UCSR0C = (1<<USBS0) | (3<<UCSZ00);
|
||||
1fc: 8e e0 ldi r24, 0x0E ; 14
|
||||
1fe: 80 93 c2 00 sts 0x00C2, r24 ; 0x8000c2 <__TEXT_REGION_LENGTH__+0x7f80c2>
|
||||
202: 08 95 ret
|
||||
|
||||
00000204 <USART_Transmit>:
|
||||
}
|
||||
|
||||
void USART_Transmit (uint8_t data) {
|
||||
while (!(UCSR0A & (1<<UDRE0))); // Îæèäàíèå êîíöà ïåðåäà÷è
|
||||
204: e0 ec ldi r30, 0xC0 ; 192
|
||||
206: f0 e0 ldi r31, 0x00 ; 0
|
||||
208: 90 81 ld r25, Z
|
||||
20a: 95 ff sbrs r25, 5
|
||||
20c: fd cf rjmp .-6 ; 0x208 <USART_Transmit+0x4>
|
||||
UDR0 = data; // Íà÷àëî ïåðåäà÷è
|
||||
20e: 80 93 c6 00 sts 0x00C6, r24 ; 0x8000c6 <__TEXT_REGION_LENGTH__+0x7f80c6>
|
||||
212: 08 95 ret
|
||||
|
||||
00000214 <_exit>:
|
||||
214: f8 94 cli
|
||||
|
||||
00000216 <__stop_program>:
|
||||
216: ff cf rjmp .-2 ; 0x216 <__stop_program>
|
@ -0,0 +1,549 @@
|
||||
Archive member included to satisfy reference by file (symbol)
|
||||
|
||||
c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o (exit)
|
||||
c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
main.o (__do_copy_data)
|
||||
c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
main.o (__do_clear_bss)
|
||||
|
||||
Discarded input sections
|
||||
|
||||
.data 0x00000000 0x0 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
.bss 0x00000000 0x0 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
.text 0x00000000 0x0 delay.o
|
||||
.data 0x00000000 0x0 delay.o
|
||||
.bss 0x00000000 0x0 delay.o
|
||||
.text.delay8 0x00000000 0xa delay.o
|
||||
.text.delay16 0x00000000 0xe delay.o
|
||||
.text.init_PUTR
|
||||
0x00000000 0x6 delay.o
|
||||
.text.PUTR 0x00000000 0x94 delay.o
|
||||
.debug_info 0x00000000 0x19a delay.o
|
||||
.debug_abbrev 0x00000000 0xf1 delay.o
|
||||
.debug_loc 0x00000000 0x112 delay.o
|
||||
.debug_aranges
|
||||
0x00000000 0x38 delay.o
|
||||
.debug_ranges 0x00000000 0x28 delay.o
|
||||
.debug_line 0x00000000 0x148 delay.o
|
||||
.debug_str 0x00000000 0x1a4 delay.o
|
||||
.comment 0x00000000 0x31 delay.o
|
||||
.debug_frame 0x00000000 0x78 delay.o
|
||||
.text 0x00000000 0x0 main.o
|
||||
.data 0x00000000 0x0 main.o
|
||||
.bss 0x00000000 0x0 main.o
|
||||
.bss.bytes 0x00000000 0x2 main.o
|
||||
.text 0x00000000 0x0 spi.o
|
||||
.data 0x00000000 0x0 spi.o
|
||||
.bss 0x00000000 0x0 spi.o
|
||||
.text 0x00000000 0x0 usart0.o
|
||||
.data 0x00000000 0x0 usart0.o
|
||||
.bss 0x00000000 0x0 usart0.o
|
||||
.text.USART_Receive
|
||||
0x00000000 0x10 usart0.o
|
||||
.text.USART_DataAvailable
|
||||
0x00000000 0xc usart0.o
|
||||
.text 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.data 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.bss 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc.mul
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc.div
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc.prologue
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc.builtins
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc.fmul
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text.libgcc.fixed
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
.text 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.data 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.bss 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc.mul
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc.div
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc.prologue
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc.builtins
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc.fmul
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text.libgcc.fixed
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
.text 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.data 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.bss 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc.mul
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc.div
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc 0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc.prologue
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc.builtins
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc.fmul
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
.text.libgcc.fixed
|
||||
0x00000000 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
|
||||
Memory Configuration
|
||||
|
||||
Name Origin Length Attributes
|
||||
text 0x00000000 0x00008000 xr
|
||||
data 0x00800100 0x00000800 rw !x
|
||||
eeprom 0x00810000 0x00000400 rw !x
|
||||
fuse 0x00820000 0x00000003 rw !x
|
||||
lock 0x00830000 0x00000400 rw !x
|
||||
signature 0x00840000 0x00000400 rw !x
|
||||
user_signatures 0x00850000 0x00000400 rw !x
|
||||
*default* 0x00000000 0xffffffff
|
||||
|
||||
Linker script and memory map
|
||||
|
||||
Address of section .data set to 0x800100
|
||||
LOAD C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
LOAD delay.o
|
||||
LOAD main.o
|
||||
LOAD spi.o
|
||||
LOAD usart0.o
|
||||
START GROUP
|
||||
LOAD c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5\libm.a
|
||||
END GROUP
|
||||
START GROUP
|
||||
LOAD c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a
|
||||
LOAD c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5\libm.a
|
||||
LOAD c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5\libc.a
|
||||
LOAD C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5\libatmega328pb.a
|
||||
END GROUP
|
||||
[0x00000000] __TEXT_REGION_ORIGIN__ = DEFINED (__TEXT_REGION_ORIGIN__)?__TEXT_REGION_ORIGIN__:0x0
|
||||
[0x00800100] __DATA_REGION_ORIGIN__ = DEFINED (__DATA_REGION_ORIGIN__)?__DATA_REGION_ORIGIN__:0x800060
|
||||
[0x00008000] __TEXT_REGION_LENGTH__ = DEFINED (__TEXT_REGION_LENGTH__)?__TEXT_REGION_LENGTH__:0x20000
|
||||
[0x00000800] __DATA_REGION_LENGTH__ = DEFINED (__DATA_REGION_LENGTH__)?__DATA_REGION_LENGTH__:0xffa0
|
||||
[0x00000400] __EEPROM_REGION_LENGTH__ = DEFINED (__EEPROM_REGION_LENGTH__)?__EEPROM_REGION_LENGTH__:0x10000
|
||||
[0x00000003] __FUSE_REGION_LENGTH__ = DEFINED (__FUSE_REGION_LENGTH__)?__FUSE_REGION_LENGTH__:0x400
|
||||
0x00000400 __LOCK_REGION_LENGTH__ = DEFINED (__LOCK_REGION_LENGTH__)?__LOCK_REGION_LENGTH__:0x400
|
||||
0x00000400 __SIGNATURE_REGION_LENGTH__ = DEFINED (__SIGNATURE_REGION_LENGTH__)?__SIGNATURE_REGION_LENGTH__:0x400
|
||||
0x00000400 __USER_SIGNATURE_REGION_LENGTH__ = DEFINED (__USER_SIGNATURE_REGION_LENGTH__)?__USER_SIGNATURE_REGION_LENGTH__:0x400
|
||||
|
||||
.hash
|
||||
*(.hash)
|
||||
|
||||
.dynsym
|
||||
*(.dynsym)
|
||||
|
||||
.dynstr
|
||||
*(.dynstr)
|
||||
|
||||
.gnu.version
|
||||
*(.gnu.version)
|
||||
|
||||
.gnu.version_d
|
||||
*(.gnu.version_d)
|
||||
|
||||
.gnu.version_r
|
||||
*(.gnu.version_r)
|
||||
|
||||
.rel.init
|
||||
*(.rel.init)
|
||||
|
||||
.rela.init
|
||||
*(.rela.init)
|
||||
|
||||
.rel.text
|
||||
*(.rel.text)
|
||||
*(.rel.text.*)
|
||||
*(.rel.gnu.linkonce.t*)
|
||||
|
||||
.rela.text
|
||||
*(.rela.text)
|
||||
*(.rela.text.*)
|
||||
*(.rela.gnu.linkonce.t*)
|
||||
|
||||
.rel.fini
|
||||
*(.rel.fini)
|
||||
|
||||
.rela.fini
|
||||
*(.rela.fini)
|
||||
|
||||
.rel.rodata
|
||||
*(.rel.rodata)
|
||||
*(.rel.rodata.*)
|
||||
*(.rel.gnu.linkonce.r*)
|
||||
|
||||
.rela.rodata
|
||||
*(.rela.rodata)
|
||||
*(.rela.rodata.*)
|
||||
*(.rela.gnu.linkonce.r*)
|
||||
|
||||
.rel.data
|
||||
*(.rel.data)
|
||||
*(.rel.data.*)
|
||||
*(.rel.gnu.linkonce.d*)
|
||||
|
||||
.rela.data
|
||||
*(.rela.data)
|
||||
*(.rela.data.*)
|
||||
*(.rela.gnu.linkonce.d*)
|
||||
|
||||
.rel.ctors
|
||||
*(.rel.ctors)
|
||||
|
||||
.rela.ctors
|
||||
*(.rela.ctors)
|
||||
|
||||
.rel.dtors
|
||||
*(.rel.dtors)
|
||||
|
||||
.rela.dtors
|
||||
*(.rela.dtors)
|
||||
|
||||
.rel.got
|
||||
*(.rel.got)
|
||||
|
||||
.rela.got
|
||||
*(.rela.got)
|
||||
|
||||
.rel.bss
|
||||
*(.rel.bss)
|
||||
|
||||
.rela.bss
|
||||
*(.rela.bss)
|
||||
|
||||
.rel.plt
|
||||
*(.rel.plt)
|
||||
|
||||
.rela.plt
|
||||
*(.rela.plt)
|
||||
|
||||
.text 0x00000000 0x218
|
||||
*(.vectors)
|
||||
.vectors 0x00000000 0xb4 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
0x00000000 __vector_default
|
||||
0x00000000 __vectors
|
||||
*(.vectors)
|
||||
*(.progmem.gcc*)
|
||||
0x000000b4 . = ALIGN (0x2)
|
||||
0x000000b4 __trampolines_start = .
|
||||
*(.trampolines)
|
||||
.trampolines 0x000000b4 0x0 linker stubs
|
||||
*(.trampolines*)
|
||||
0x000000b4 __trampolines_end = .
|
||||
*libprintf_flt.a:*(.progmem.data)
|
||||
*libc.a:*(.progmem.data)
|
||||
*(.progmem*)
|
||||
0x000000b4 . = ALIGN (0x2)
|
||||
*(.jumptables)
|
||||
*(.jumptables*)
|
||||
*(.lowtext)
|
||||
*(.lowtext*)
|
||||
0x000000b4 __ctors_start = .
|
||||
*(.ctors)
|
||||
0x000000b4 __ctors_end = .
|
||||
0x000000b4 __dtors_start = .
|
||||
*(.dtors)
|
||||
0x000000b4 __dtors_end = .
|
||||
SORT(*)(.ctors)
|
||||
SORT(*)(.dtors)
|
||||
*(.init0)
|
||||
.init0 0x000000b4 0x0 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
0x000000b4 __init
|
||||
*(.init0)
|
||||
*(.init1)
|
||||
*(.init1)
|
||||
*(.init2)
|
||||
.init2 0x000000b4 0xc C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
*(.init2)
|
||||
*(.init3)
|
||||
*(.init3)
|
||||
*(.init4)
|
||||
.init4 0x000000c0 0x16 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_copy_data.o)
|
||||
0x000000c0 __do_copy_data
|
||||
.init4 0x000000d6 0x10 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_clear_bss.o)
|
||||
0x000000d6 __do_clear_bss
|
||||
*(.init4)
|
||||
*(.init5)
|
||||
*(.init5)
|
||||
*(.init6)
|
||||
*(.init6)
|
||||
*(.init7)
|
||||
*(.init7)
|
||||
*(.init8)
|
||||
*(.init8)
|
||||
*(.init9)
|
||||
.init9 0x000000e6 0x8 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
*(.init9)
|
||||
*(.text)
|
||||
.text 0x000000ee 0x4 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
0x000000ee __vector_38
|
||||
0x000000ee __vector_22
|
||||
0x000000ee __vector_28
|
||||
0x000000ee __vector_1
|
||||
0x000000ee __vector_32
|
||||
0x000000ee __vector_34
|
||||
0x000000ee __vector_24
|
||||
0x000000ee __vector_12
|
||||
0x000000ee __bad_interrupt
|
||||
0x000000ee __vector_6
|
||||
0x000000ee __vector_31
|
||||
0x000000ee __vector_35
|
||||
0x000000ee __vector_39
|
||||
0x000000ee __vector_3
|
||||
0x000000ee __vector_23
|
||||
0x000000ee __vector_30
|
||||
0x000000ee __vector_25
|
||||
0x000000ee __vector_11
|
||||
0x000000ee __vector_13
|
||||
0x000000ee __vector_17
|
||||
0x000000ee __vector_19
|
||||
0x000000ee __vector_7
|
||||
0x000000ee __vector_41
|
||||
0x000000ee __vector_43
|
||||
0x000000ee __vector_27
|
||||
0x000000ee __vector_5
|
||||
0x000000ee __vector_33
|
||||
0x000000ee __vector_37
|
||||
0x000000ee __vector_4
|
||||
0x000000ee __vector_44
|
||||
0x000000ee __vector_9
|
||||
0x000000ee __vector_2
|
||||
0x000000ee __vector_21
|
||||
0x000000ee __vector_15
|
||||
0x000000ee __vector_36
|
||||
0x000000ee __vector_29
|
||||
0x000000ee __vector_40
|
||||
0x000000ee __vector_8
|
||||
0x000000ee __vector_26
|
||||
0x000000ee __vector_14
|
||||
0x000000ee __vector_10
|
||||
0x000000ee __vector_16
|
||||
0x000000ee __vector_18
|
||||
0x000000ee __vector_20
|
||||
0x000000ee __vector_42
|
||||
0x000000f2 . = ALIGN (0x2)
|
||||
*(.text.*)
|
||||
.text.STMReset
|
||||
0x000000f2 0x2c main.o
|
||||
0x000000f2 STMReset
|
||||
.text.main 0x0000011e 0x8a main.o
|
||||
0x0000011e main
|
||||
.text.SPI_MasterInit
|
||||
0x000001a8 0x14 spi.o
|
||||
0x000001a8 SPI_MasterInit
|
||||
.text.SPI_MasterTransmit
|
||||
0x000001bc 0x32 spi.o
|
||||
0x000001bc SPI_MasterTransmit
|
||||
.text.USART_Init
|
||||
0x000001ee 0x16 usart0.o
|
||||
0x000001ee USART_Init
|
||||
.text.USART_Transmit
|
||||
0x00000204 0x10 usart0.o
|
||||
0x00000204 USART_Transmit
|
||||
0x00000214 . = ALIGN (0x2)
|
||||
*(.fini9)
|
||||
.fini9 0x00000214 0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
0x00000214 _exit
|
||||
0x00000214 exit
|
||||
*(.fini9)
|
||||
*(.fini8)
|
||||
*(.fini8)
|
||||
*(.fini7)
|
||||
*(.fini7)
|
||||
*(.fini6)
|
||||
*(.fini6)
|
||||
*(.fini5)
|
||||
*(.fini5)
|
||||
*(.fini4)
|
||||
*(.fini4)
|
||||
*(.fini3)
|
||||
*(.fini3)
|
||||
*(.fini2)
|
||||
*(.fini2)
|
||||
*(.fini1)
|
||||
*(.fini1)
|
||||
*(.fini0)
|
||||
.fini0 0x00000214 0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr5\libgcc.a(_exit.o)
|
||||
*(.fini0)
|
||||
0x00000218 _etext = .
|
||||
|
||||
.data 0x00800100 0xc load address 0x00000218
|
||||
0x00800100 PROVIDE (__data_start, .)
|
||||
*(.data)
|
||||
*(.data*)
|
||||
*(.gnu.linkonce.d*)
|
||||
*(.rodata)
|
||||
.rodata 0x00800100 0xc main.o
|
||||
*(.rodata*)
|
||||
*(.gnu.linkonce.r*)
|
||||
0x0080010c . = ALIGN (0x2)
|
||||
0x0080010c _edata = .
|
||||
0x0080010c PROVIDE (__data_end, .)
|
||||
|
||||
.bss 0x0080010c 0x0
|
||||
0x0080010c PROVIDE (__bss_start, .)
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
0x0080010c PROVIDE (__bss_end, .)
|
||||
0x00000218 __data_load_start = LOADADDR (.data)
|
||||
0x00000224 __data_load_end = (__data_load_start + SIZEOF (.data))
|
||||
|
||||
.noinit 0x0080010c 0x0
|
||||
[!provide] PROVIDE (__noinit_start, .)
|
||||
*(.noinit*)
|
||||
[!provide] PROVIDE (__noinit_end, .)
|
||||
0x0080010c _end = .
|
||||
[!provide] PROVIDE (__heap_start, .)
|
||||
|
||||
.eeprom 0x00810000 0x0
|
||||
*(.eeprom*)
|
||||
0x00810000 __eeprom_end = .
|
||||
|
||||
.fuse
|
||||
*(.fuse)
|
||||
*(.lfuse)
|
||||
*(.hfuse)
|
||||
*(.efuse)
|
||||
|
||||
.lock
|
||||
*(.lock*)
|
||||
|
||||
.signature
|
||||
*(.signature*)
|
||||
|
||||
.user_signatures
|
||||
*(.user_signatures*)
|
||||
|
||||
.stab
|
||||
*(.stab)
|
||||
|
||||
.stabstr
|
||||
*(.stabstr)
|
||||
|
||||
.stab.excl
|
||||
*(.stab.excl)
|
||||
|
||||
.stab.exclstr
|
||||
*(.stab.exclstr)
|
||||
|
||||
.stab.index
|
||||
*(.stab.index)
|
||||
|
||||
.stab.indexstr
|
||||
*(.stab.indexstr)
|
||||
|
||||
.comment 0x00000000 0x30
|
||||
*(.comment)
|
||||
.comment 0x00000000 0x30 main.o
|
||||
0x31 (size before relaxing)
|
||||
.comment 0x00000030 0x31 spi.o
|
||||
.comment 0x00000030 0x31 usart0.o
|
||||
|
||||
.note.gnu.avr.deviceinfo
|
||||
0x00000000 0x40
|
||||
.note.gnu.avr.deviceinfo
|
||||
0x00000000 0x40 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
|
||||
.note.gnu.build-id
|
||||
*(.note.gnu.build-id)
|
||||
|
||||
.debug
|
||||
*(.debug)
|
||||
|
||||
.line
|
||||
*(.line)
|
||||
|
||||
.debug_srcinfo
|
||||
*(.debug_srcinfo)
|
||||
|
||||
.debug_sfnames
|
||||
*(.debug_sfnames)
|
||||
|
||||
.debug_aranges 0x00000000 0x88
|
||||
*(.debug_aranges)
|
||||
.debug_aranges
|
||||
0x00000000 0x28 main.o
|
||||
.debug_aranges
|
||||
0x00000028 0x28 spi.o
|
||||
.debug_aranges
|
||||
0x00000050 0x38 usart0.o
|
||||
|
||||
.debug_pubnames
|
||||
*(.debug_pubnames)
|
||||
|
||||
.debug_info 0x00000000 0xd91
|
||||
*(.debug_info .gnu.linkonce.wi.*)
|
||||
.debug_info 0x00000000 0x8ea C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
.debug_info 0x000008ea 0x274 main.o
|
||||
.debug_info 0x00000b5e 0x130 spi.o
|
||||
.debug_info 0x00000c8e 0x103 usart0.o
|
||||
|
||||
.debug_abbrev 0x00000000 0xb49
|
||||
*(.debug_abbrev)
|
||||
.debug_abbrev 0x00000000 0x86e C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
.debug_abbrev 0x0000086e 0x174 main.o
|
||||
.debug_abbrev 0x000009e2 0xde spi.o
|
||||
.debug_abbrev 0x00000ac0 0x89 usart0.o
|
||||
|
||||
.debug_line 0x00000000 0x601
|
||||
*(.debug_line .debug_line.* .debug_line_end)
|
||||
.debug_line 0x00000000 0x1a6 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
.debug_line 0x000001a6 0x1d2 main.o
|
||||
.debug_line 0x00000378 0x162 spi.o
|
||||
.debug_line 0x000004da 0x127 usart0.o
|
||||
|
||||
.debug_frame 0x00000000 0xcc
|
||||
*(.debug_frame)
|
||||
.debug_frame 0x00000000 0x44 main.o
|
||||
.debug_frame 0x00000044 0x34 spi.o
|
||||
.debug_frame 0x00000078 0x54 usart0.o
|
||||
|
||||
.debug_str 0x00000000 0x54c
|
||||
*(.debug_str)
|
||||
.debug_str 0x00000000 0x318 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/2.0.401/gcc/dev/atmega328pb/avr5/crtatmega328pb.o
|
||||
.debug_str 0x00000318 0x1e5 main.o
|
||||
0x21e (size before relaxing)
|
||||
.debug_str 0x000004fd 0x10 spi.o
|
||||
0x1de (size before relaxing)
|
||||
.debug_str 0x0000050d 0x3f usart0.o
|
||||
0x1bf (size before relaxing)
|
||||
|
||||
.debug_loc 0x00000000 0x1f6
|
||||
*(.debug_loc)
|
||||
.debug_loc 0x00000000 0x169 main.o
|
||||
.debug_loc 0x00000169 0x67 spi.o
|
||||
.debug_loc 0x000001d0 0x26 usart0.o
|
||||
|
||||
.debug_macinfo
|
||||
*(.debug_macinfo)
|
||||
|
||||
.debug_weaknames
|
||||
*(.debug_weaknames)
|
||||
|
||||
.debug_funcnames
|
||||
*(.debug_funcnames)
|
||||
|
||||
.debug_typenames
|
||||
*(.debug_typenames)
|
||||
|
||||
.debug_varnames
|
||||
*(.debug_varnames)
|
||||
|
||||
.debug_pubtypes
|
||||
*(.debug_pubtypes)
|
||||
|
||||
.debug_ranges 0x00000000 0x58
|
||||
*(.debug_ranges)
|
||||
.debug_ranges 0x00000000 0x18 main.o
|
||||
.debug_ranges 0x00000018 0x18 spi.o
|
||||
.debug_ranges 0x00000030 0x28 usart0.o
|
||||
|
||||
.debug_macro
|
||||
*(.debug_macro)
|
||||
OUTPUT(GccApplication1.elf elf32-avr)
|
||||
LOAD linker stubs
|
@ -0,0 +1,37 @@
|
||||
S01700004763634170706C69636174696F6E312E737265635B
|
||||
S11300000C945A000C9477000C9477000C947700AD
|
||||
S11300100C9477000C9477000C9477000C94770080
|
||||
S11300200C9477000C9477000C9477000C94770070
|
||||
S11300300C9477000C9477000C9477000C94770060
|
||||
S11300400C9477000C9477000C9477000C94770050
|
||||
S11300500C9477000C9477000C9477000C94770040
|
||||
S11300600C9477000C9477000C9477000C94770030
|
||||
S11300700C9477000C9477000C9477000C94770020
|
||||
S11300800C9477000C9477000C9477000C94770010
|
||||
S11300900C9477000C9477000C9477000C94770000
|
||||
S11300A00C9477000C9477000C9477000C947700F0
|
||||
S11300B00C94770011241FBECFEFD8E0DEBFCDBF74
|
||||
S11300C011E0A0E0B1E0E8E1F2E002C005900D9299
|
||||
S11300D0AC30B107D9F721E0ACE0B1E001C01D922A
|
||||
S11300E0AC30B207E1F70E948F000C940A010C9423
|
||||
S11300F000003C9A44982FEF81EE94E02150804018
|
||||
S11301009040E1F700C000003C982FEF81EE94E0AE
|
||||
S1130110215080409040E1F700C000000895CF9343
|
||||
S1130120DF93CDB7DEB72C970FB6F894DEBF0FBEC2
|
||||
S1130130CDBF8CE0E0E0F1E0DE01119601900D927C
|
||||
S11301408A95E1F783E08AB98BB917B818B8699A28
|
||||
S11301506A98729888E090E00E94F70078940E9470
|
||||
S1130160D4006E012DE0C20ED11C0E947900339B95
|
||||
S1130170FCCF719A8FEF93EDE0E381509040E04023
|
||||
S1130180E1F700C000008E010F5F1F4FF801F190EE
|
||||
S11301908F018F2D0E9402018F2D0E94DE000C150D
|
||||
S11301A01D05A1F77198E1CF6A9A729A6B9A87B18B
|
||||
S11301B0866087B980E58093AC0008954298809367
|
||||
S11301C0AE008091AD00882384F0EDEAF0E0719AEE
|
||||
S11301D02FEF81EE94E0215080409040E1F700C081
|
||||
S11301E0000071988081882394F7429A08951092B0
|
||||
S11301F0C5008093C40088E18093C1008EE08093A1
|
||||
S1130200C2000895E0ECF0E0908195FFFDCF80936B
|
||||
S10B0210C6000895F894FFCF25
|
||||
S10F0218014E20280100019C4028010137
|
||||
S9030000FC
|
@ -0,0 +1,163 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
SHELL := cmd.exe
|
||||
RM := rm -rf
|
||||
|
||||
USER_OBJS :=
|
||||
|
||||
LIBS :=
|
||||
PROJ :=
|
||||
|
||||
O_SRCS :=
|
||||
C_SRCS :=
|
||||
S_SRCS :=
|
||||
S_UPPER_SRCS :=
|
||||
OBJ_SRCS :=
|
||||
ASM_SRCS :=
|
||||
PREPROCESSING_SRCS :=
|
||||
OBJS :=
|
||||
OBJS_AS_ARGS :=
|
||||
C_DEPS :=
|
||||
C_DEPS_AS_ARGS :=
|
||||
EXECUTABLES :=
|
||||
OUTPUT_FILE_PATH :=
|
||||
OUTPUT_FILE_PATH_AS_ARGS :=
|
||||
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
|
||||
QUOTE := "
|
||||
ADDITIONAL_DEPENDENCIES:=
|
||||
OUTPUT_FILE_DEP:=
|
||||
LIB_DEP:=
|
||||
LINKER_SCRIPT_DEP:=
|
||||
|
||||
# Every subdirectory with source files must be described here
|
||||
SUBDIRS :=
|
||||
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
C_SRCS += \
|
||||
../delay.c \
|
||||
../main.c \
|
||||
../spi.c \
|
||||
../usart0.c
|
||||
|
||||
|
||||
PREPROCESSING_SRCS +=
|
||||
|
||||
|
||||
ASM_SRCS +=
|
||||
|
||||
|
||||
OBJS += \
|
||||
delay.o \
|
||||
main.o \
|
||||
spi.o \
|
||||
usart0.o
|
||||
|
||||
OBJS_AS_ARGS += \
|
||||
delay.o \
|
||||
main.o \
|
||||
spi.o \
|
||||
usart0.o
|
||||
|
||||
C_DEPS += \
|
||||
delay.d \
|
||||
main.d \
|
||||
spi.d \
|
||||
usart0.d
|
||||
|
||||
C_DEPS_AS_ARGS += \
|
||||
delay.d \
|
||||
main.d \
|
||||
spi.d \
|
||||
usart0.d
|
||||
|
||||
OUTPUT_FILE_PATH +=GccApplication1.elf
|
||||
|
||||
OUTPUT_FILE_PATH_AS_ARGS +=GccApplication1.elf
|
||||
|
||||
ADDITIONAL_DEPENDENCIES:=
|
||||
|
||||
OUTPUT_FILE_DEP:= ./makedep.mk
|
||||
|
||||
LIB_DEP+=
|
||||
|
||||
LINKER_SCRIPT_DEP+=
|
||||
|
||||
|
||||
# AVR32/GNU C Compiler
|
||||
./delay.o: .././delay.c
|
||||
@echo Building file: $<
|
||||
@echo Invoking: AVR/GNU C Compiler : 5.4.0
|
||||
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\include" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328pb -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\gcc\dev\atmega328pb" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
||||
@echo Finished building: $<
|
||||
|
||||
|
||||
./main.o: .././main.c
|
||||
@echo Building file: $<
|
||||
@echo Invoking: AVR/GNU C Compiler : 5.4.0
|
||||
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\include" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328pb -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\gcc\dev\atmega328pb" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
||||
@echo Finished building: $<
|
||||
|
||||
|
||||
./spi.o: .././spi.c
|
||||
@echo Building file: $<
|
||||
@echo Invoking: AVR/GNU C Compiler : 5.4.0
|
||||
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\include" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328pb -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\gcc\dev\atmega328pb" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
||||
@echo Finished building: $<
|
||||
|
||||
|
||||
./usart0.o: .././usart0.c
|
||||
@echo Building file: $<
|
||||
@echo Invoking: AVR/GNU C Compiler : 5.4.0
|
||||
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\include" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328pb -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\gcc\dev\atmega328pb" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
||||
@echo Finished building: $<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# AVR32/GNU Preprocessing Assembler
|
||||
|
||||
|
||||
|
||||
# AVR32/GNU Assembler
|
||||
|
||||
|
||||
|
||||
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(strip $(C_DEPS)),)
|
||||
-include $(C_DEPS)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
|
||||
# All Target
|
||||
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
|
||||
|
||||
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
|
||||
@echo Building target: $@
|
||||
@echo Invoking: AVR/GNU Linker : 5.4.0
|
||||
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="GccApplication1.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328pb -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\gcc\dev\atmega328pb"
|
||||
@echo Finished building target: $@
|
||||
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "GccApplication1.elf" "GccApplication1.hex"
|
||||
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "GccApplication1.elf" "GccApplication1.eep" || exit 0
|
||||
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "GccApplication1.elf" > "GccApplication1.lss"
|
||||
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "GccApplication1.elf" "GccApplication1.srec"
|
||||
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "GccApplication1.elf"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Other Targets
|
||||
clean:
|
||||
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
|
||||
-$(RM) $(C_DEPS_AS_ARGS)
|
||||
rm -rf "GccApplication1.elf" "GccApplication1.a" "GccApplication1.hex" "GccApplication1.lss" "GccApplication1.eep" "GccApplication1.map" "GccApplication1.srec" "GccApplication1.usersignatures"
|
||||
|
@ -0,0 +1,39 @@
|
||||
delay.d delay.o: .././delay.c .././delay.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdint.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h \
|
||||
C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\include/avr/iom328pb.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h \
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\cpufunc.h
|
||||
|
||||
.././delay.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdint.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h:
|
||||
|
||||
C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\2.0.401\include/avr/iom328pb.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h:
|
||||
|
||||
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\cpufunc.h:
|
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue