mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-10 18:24:11 +01:00
More cleaning, moved stopwatch files to library folder, code formatting.
This commit is contained in:
parent
3132de4e48
commit
1cc152b4dd
@ -3,36 +3,32 @@
|
|||||||
|
|
||||||
uint8_t buf[256];
|
uint8_t buf[256];
|
||||||
|
|
||||||
bool StartProgramming(void)
|
bool StartProgramming(void) {
|
||||||
{
|
|
||||||
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "Started programming\r\n");
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "Started programming\r\n");
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteData(uint32_t offset, uint8_t *buffer, uint32_t size)
|
bool WriteData(uint32_t offset, uint8_t *buffer, uint32_t size) {
|
||||||
{
|
if (size > SPI_MAX_PROGRAM_DATA_SIZE) {
|
||||||
if(size > SPI_MAX_PROGRAM_DATA_SIZE)
|
|
||||||
{
|
|
||||||
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "oversize: %d\r\n", size);
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "oversize: %d\r\n", size);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
PIOS_COM_SendFormattedString(PIOS_COM_AUX,"Wrote %d bytes to %d\r\n", size, offset);
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "Wrote %d bytes to %d\r\n",
|
||||||
|
size, offset);
|
||||||
memcpy(buf, buffer, size);
|
memcpy(buf, buffer, size);
|
||||||
PIOS_LED_Toggle(LED1);
|
PIOS_LED_Toggle(LED1);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadData(uint32_t offset, uint8_t *buffer, uint32_t size)
|
bool ReadData(uint32_t offset, uint8_t *buffer, uint32_t size) {
|
||||||
{
|
if (size > SPI_MAX_PROGRAM_DATA_SIZE) {
|
||||||
if(size > SPI_MAX_PROGRAM_DATA_SIZE)
|
|
||||||
{
|
|
||||||
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "oversize: %d\r\n", size);
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "oversize: %d\r\n", size);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
PIOS_COM_SendFormattedString(PIOS_COM_AUX,"Read %d bytes from %d\r\n", size, offset);
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "Read %d bytes from %d\r\n",
|
||||||
|
size, offset);
|
||||||
memcpy(buffer, buf, size);
|
memcpy(buffer, buf, size);
|
||||||
PIOS_LED_Toggle(LED1);
|
PIOS_LED_Toggle(LED1);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,87 +2,63 @@
|
|||||||
#include "ahrs_spi_program.h"
|
#include "ahrs_spi_program.h"
|
||||||
|
|
||||||
// Static CRC polynomial table
|
// Static CRC polynomial table
|
||||||
static uint32_t crcTable[256] =
|
static uint32_t crcTable[256] = { 0x00000000, 0x77073096, 0xEE0E612C,
|
||||||
{
|
0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
|
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
|
||||||
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
|
||||||
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
|
0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A,
|
||||||
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8,
|
||||||
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
|
0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD,
|
||||||
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
|
||||||
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
|
0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180,
|
||||||
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
|
0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E,
|
||||||
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
|
0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
|
||||||
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
0xB6662D3D,
|
||||||
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,
|
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
|
||||||
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
|
||||||
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
|
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162,
|
||||||
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
|
0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
||||||
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49,
|
||||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
|
||||||
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
|
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC,
|
||||||
0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
||||||
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
|
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3,
|
||||||
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
|
0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
|
||||||
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
|
|
||||||
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
|
||||||
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
|
|
||||||
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
|
||||||
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
|
|
||||||
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
||||||
|
|
||||||
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
|
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF,
|
||||||
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
|
0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
||||||
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2,
|
||||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
||||||
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
|
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9,
|
||||||
0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
|
||||||
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
|
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
|
||||||
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
||||||
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
|
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
|
||||||
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
|
||||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
|
|
||||||
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
|
||||||
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
|
|
||||||
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
|
|
||||||
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
|
|
||||||
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
||||||
|
|
||||||
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
|
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
|
||||||
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
|
0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
|
||||||
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
|
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
|
||||||
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
|
0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
||||||
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
|
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
|
||||||
0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
|
||||||
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
|
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
|
||||||
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
||||||
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
|
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
|
||||||
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
|
0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||||
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
|
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, };
|
||||||
0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
|
||||||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
|
|
||||||
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
|
|
||||||
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
|
||||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**generate CRC32 from a program packet
|
/**generate CRC32 from a program packet
|
||||||
this is slightly overkill but we want to be sure
|
this is slightly overkill but we want to be sure
|
||||||
*/
|
*/
|
||||||
uint32_t GenerateCRC (AhrsProgramPacket * packet)
|
uint32_t GenerateCRC(AhrsProgramPacket * packet) {
|
||||||
{
|
|
||||||
uint8_t * ptr = (uint8_t *) packet;
|
uint8_t * ptr = (uint8_t *) packet;
|
||||||
int size = ((int) &packet->crc) - (int) packet;
|
int size = ((int) &packet->crc) - (int) packet;
|
||||||
uint32_t crc = 0xFFFFFFFF;
|
uint32_t crc = 0xFFFFFFFF;
|
||||||
for(int ct=0; ct< size; ct++)
|
for (int ct = 0; ct < size; ct++) {
|
||||||
{
|
|
||||||
crc = ((crc) >> 8) ^ crcTable[(*ptr++) ^ ((crc) & 0x000000FF)];
|
crc = ((crc) >> 8) ^ crcTable[(*ptr++) ^ ((crc) & 0x000000FF)];
|
||||||
}
|
}
|
||||||
return (~crc);
|
return (~crc);
|
||||||
|
@ -29,12 +29,11 @@
|
|||||||
#include "ahrs_spi_program.h"
|
#include "ahrs_spi_program.h"
|
||||||
#include "pios_spi.h"
|
#include "pios_spi.h"
|
||||||
|
|
||||||
PROGERR TransferPacket(uint32_t spi_id, AhrsProgramPacket *txBuf, AhrsProgramPacket *rxBuf);
|
PROGERR TransferPacket(uint32_t spi_id, AhrsProgramPacket *txBuf,
|
||||||
|
AhrsProgramPacket *rxBuf);
|
||||||
|
|
||||||
#define MAX_CONNECT_TRIES 500 //half a second
|
#define MAX_CONNECT_TRIES 500 //half a second
|
||||||
|
bool AhrsProgramConnect(uint32_t spi_id) {
|
||||||
bool AhrsProgramConnect(uint32_t spi_id)
|
|
||||||
{
|
|
||||||
AhrsProgramPacket rxBuf;
|
AhrsProgramPacket rxBuf;
|
||||||
AhrsProgramPacket txBuf;
|
AhrsProgramPacket txBuf;
|
||||||
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
||||||
@ -44,7 +43,8 @@ bool AhrsProgramConnect(uint32_t spi_id)
|
|||||||
uint32_t res = PIOS_SPI_TransferBlock(spi_id, (uint8_t *) &txBuf,
|
uint32_t res = PIOS_SPI_TransferBlock(spi_id, (uint8_t *) &txBuf,
|
||||||
(uint8_t *) &rxBuf, SPI_PROGRAM_REQUEST_LENGTH + 1, NULL);
|
(uint8_t *) &rxBuf, SPI_PROGRAM_REQUEST_LENGTH + 1, NULL);
|
||||||
PIOS_SPI_RC_PinSet(spi_id, 1);
|
PIOS_SPI_RC_PinSet(spi_id, 1);
|
||||||
if(res == 0 && memcmp(&rxBuf, SPI_PROGRAM_ACK, SPI_PROGRAM_REQUEST_LENGTH) == 0) {
|
if (res == 0 && memcmp(&rxBuf, SPI_PROGRAM_ACK,
|
||||||
|
SPI_PROGRAM_REQUEST_LENGTH) == 0) {
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,9 +53,8 @@ bool AhrsProgramConnect(uint32_t spi_id)
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PROGERR AhrsProgramWrite(uint32_t spi_id, uint32_t address, void * data,
|
||||||
PROGERR AhrsProgramWrite(uint32_t spi_id, uint32_t address, void * data, uint32_t size)
|
uint32_t size) {
|
||||||
{
|
|
||||||
AhrsProgramPacket rxBuf;
|
AhrsProgramPacket rxBuf;
|
||||||
AhrsProgramPacket txBuf;
|
AhrsProgramPacket txBuf;
|
||||||
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
||||||
@ -70,8 +69,8 @@ PROGERR AhrsProgramWrite(uint32_t spi_id, uint32_t address, void * data, uint32_
|
|||||||
return (PROGRAM_ERR_OK);
|
return (PROGRAM_ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROGERR AhrsProgramRead(uint32_t spi_id, uint32_t address, void * data, uint32_t size)
|
PROGERR AhrsProgramRead(uint32_t spi_id, uint32_t address, void * data,
|
||||||
{
|
uint32_t size) {
|
||||||
AhrsProgramPacket rxBuf;
|
AhrsProgramPacket rxBuf;
|
||||||
AhrsProgramPacket txBuf;
|
AhrsProgramPacket txBuf;
|
||||||
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
||||||
@ -86,8 +85,7 @@ PROGERR AhrsProgramRead(uint32_t spi_id, uint32_t address, void * data, uint32_t
|
|||||||
return (PROGRAM_ERR_OK);
|
return (PROGRAM_ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROGERR AhrsProgramReboot(uint32_t spi_id)
|
PROGERR AhrsProgramReboot(uint32_t spi_id) {
|
||||||
{
|
|
||||||
AhrsProgramPacket rxBuf;
|
AhrsProgramPacket rxBuf;
|
||||||
AhrsProgramPacket txBuf;
|
AhrsProgramPacket txBuf;
|
||||||
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
memset(&rxBuf, 0, sizeof(AhrsProgramPacket));
|
||||||
@ -101,8 +99,8 @@ PROGERR AhrsProgramReboot(uint32_t spi_id)
|
|||||||
return (PROGRAM_ERR_FUNCTION);
|
return (PROGRAM_ERR_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROGERR TransferPacket(uint32_t spi_id, AhrsProgramPacket *txBuf, AhrsProgramPacket *rxBuf)
|
PROGERR TransferPacket(uint32_t spi_id, AhrsProgramPacket *txBuf,
|
||||||
{
|
AhrsProgramPacket *rxBuf) {
|
||||||
static uint32_t pktId = 0;
|
static uint32_t pktId = 0;
|
||||||
pktId++;
|
pktId++;
|
||||||
txBuf->packetId = pktId;
|
txBuf->packetId = pktId;
|
||||||
@ -114,9 +112,8 @@ PROGERR TransferPacket(uint32_t spi_id, AhrsProgramPacket *txBuf, AhrsProgramPac
|
|||||||
(uint8_t *) rxBuf, sizeof(AhrsProgramPacket), NULL);
|
(uint8_t *) rxBuf, sizeof(AhrsProgramPacket), NULL);
|
||||||
PIOS_SPI_RC_PinSet(spi_id, 1);
|
PIOS_SPI_RC_PinSet(spi_id, 1);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
if(rxBuf->type != PROGRAM_NULL &&
|
if (rxBuf->type != PROGRAM_NULL && rxBuf->crc == GenerateCRC(rxBuf)
|
||||||
rxBuf->crc == GenerateCRC(rxBuf) &&
|
&& rxBuf->packetId == pktId) {
|
||||||
rxBuf->packetId == pktId) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,6 +129,3 @@ PROGERR TransferPacket(uint32_t spi_id, AhrsProgramPacket *txBuf, AhrsProgramPac
|
|||||||
return (PROGRAM_ERR_OK);
|
return (PROGRAM_ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -43,25 +42,24 @@ static bool done = false;
|
|||||||
static void ProcessPacket();
|
static void ProcessPacket();
|
||||||
|
|
||||||
#define WAIT_IF_RECEIVING() while(!(GPIOB->IDR & GPIO_Pin_12)){}; //NSS must be high
|
#define WAIT_IF_RECEIVING() while(!(GPIOB->IDR & GPIO_Pin_12)){}; //NSS must be high
|
||||||
|
|
||||||
//Number of crc failures to allow before giving up
|
//Number of crc failures to allow before giving up
|
||||||
#define PROGRAM_PACKET_TRIES 4
|
#define PROGRAM_PACKET_TRIES 4
|
||||||
|
|
||||||
void AhrsProgramReceive(uint32_t spi_id)
|
void AhrsProgramReceive(uint32_t spi_id) {
|
||||||
{
|
|
||||||
done = false;
|
done = false;
|
||||||
memset(&txBuf, 0, sizeof(AhrsProgramPacket));
|
memset(&txBuf, 0, sizeof(AhrsProgramPacket));
|
||||||
//wait for a program request
|
//wait for a program request
|
||||||
int count = PROGRAM_PACKET_TRIES;
|
int count = PROGRAM_PACKET_TRIES;
|
||||||
while (1) {
|
while (1) {
|
||||||
WAIT_IF_RECEIVING();
|
WAIT_IF_RECEIVING();
|
||||||
while((PIOS_SPI_Busy(spi_id) != 0)){};
|
while ((PIOS_SPI_Busy(spi_id) != 0)) {
|
||||||
|
};
|
||||||
memset(&rxBuf, 'a', sizeof(AhrsProgramPacket));
|
memset(&rxBuf, 'a', sizeof(AhrsProgramPacket));
|
||||||
int32_t res = PIOS_SPI_TransferBlock(spi_id, NULL, (uint8_t*) &rxBuf,
|
int32_t res = PIOS_SPI_TransferBlock(spi_id, NULL, (uint8_t*) &rxBuf,
|
||||||
SPI_PROGRAM_REQUEST_LENGTH + 1, NULL);
|
SPI_PROGRAM_REQUEST_LENGTH + 1, NULL);
|
||||||
|
|
||||||
if(res == 0 &&
|
if (res == 0 && memcmp(&rxBuf, SPI_PROGRAM_REQUEST,
|
||||||
memcmp(&rxBuf, SPI_PROGRAM_REQUEST, SPI_PROGRAM_REQUEST_LENGTH) == 0) {
|
SPI_PROGRAM_REQUEST_LENGTH) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (count-- == 0) {
|
if (count-- == 0) {
|
||||||
@ -78,7 +76,8 @@ void AhrsProgramReceive(uint32_t spi_id)
|
|||||||
memcpy(&txBuf, SPI_PROGRAM_ACK, SPI_PROGRAM_REQUEST_LENGTH);
|
memcpy(&txBuf, SPI_PROGRAM_ACK, SPI_PROGRAM_REQUEST_LENGTH);
|
||||||
WAIT_IF_RECEIVING();
|
WAIT_IF_RECEIVING();
|
||||||
while (0 != PIOS_SPI_TransferBlock(spi_id, (uint8_t*) &txBuf, NULL,
|
while (0 != PIOS_SPI_TransferBlock(spi_id, (uint8_t*) &txBuf, NULL,
|
||||||
SPI_PROGRAM_REQUEST_LENGTH + 1, NULL)) {};
|
SPI_PROGRAM_REQUEST_LENGTH + 1, NULL)) {
|
||||||
|
};
|
||||||
|
|
||||||
txBuf.type = PROGRAM_NULL;
|
txBuf.type = PROGRAM_NULL;
|
||||||
|
|
||||||
@ -88,8 +87,7 @@ void AhrsProgramReceive(uint32_t spi_id)
|
|||||||
(uint8_t*) &rxBuf, sizeof(AhrsProgramPacket), NULL)) {
|
(uint8_t*) &rxBuf, sizeof(AhrsProgramPacket), NULL)) {
|
||||||
|
|
||||||
uint32_t crc = GenerateCRC(&rxBuf);
|
uint32_t crc = GenerateCRC(&rxBuf);
|
||||||
if(crc != rxBuf.crc ||
|
if (crc != rxBuf.crc || txBuf.packetId == rxBuf.packetId) {
|
||||||
txBuf.packetId == rxBuf.packetId) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ProcessPacket();
|
ProcessPacket();
|
||||||
@ -99,11 +97,7 @@ void AhrsProgramReceive(uint32_t spi_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessPacket() {
|
||||||
|
|
||||||
|
|
||||||
void ProcessPacket()
|
|
||||||
{
|
|
||||||
switch (rxBuf.type) {
|
switch (rxBuf.type) {
|
||||||
case PROGRAM_NULL:
|
case PROGRAM_NULL:
|
||||||
txBuf.type = PROGRAM_NULL;
|
txBuf.type = PROGRAM_NULL;
|
||||||
@ -128,7 +122,8 @@ void ProcessPacket()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PROGRAM_REBOOT:
|
case PROGRAM_REBOOT:
|
||||||
if(0 == memcmp(rxBuf.data,REBOOT_CONFIRMATION,REBOOT_CONFIRMATION_LENGTH)) {
|
if (0 == memcmp(rxBuf.data, REBOOT_CONFIRMATION,
|
||||||
|
REBOOT_CONFIRMATION_LENGTH)) {
|
||||||
done = true;
|
done = true;
|
||||||
txBuf.type = PROGRAM_ACK;
|
txBuf.type = PROGRAM_ACK;
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,8 +33,7 @@ static void lfsm_update_link_tx (struct lfsm_context * context);
|
|||||||
static void lfsm_init_rx(struct lfsm_context * context);
|
static void lfsm_init_rx(struct lfsm_context * context);
|
||||||
|
|
||||||
static uint32_t PIOS_SPI_OP;
|
static uint32_t PIOS_SPI_OP;
|
||||||
void lfsm_attach(uint32_t spi_id)
|
void lfsm_attach(uint32_t spi_id) {
|
||||||
{
|
|
||||||
PIOS_SPI_OP = spi_id;
|
PIOS_SPI_OP = spi_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,23 +66,20 @@ static void go_user_rxtx_active(struct lfsm_context * context);
|
|||||||
const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
||||||
[LFSM_STATE_FAULTED] = {
|
[LFSM_STATE_FAULTED] = {
|
||||||
.entry_fn = go_faulted,
|
.entry_fn = go_faulted,
|
||||||
},
|
}, [LFSM_STATE_STOPPED] = {
|
||||||
[LFSM_STATE_STOPPED] = {
|
|
||||||
.entry_fn = go_stopped,
|
.entry_fn = go_stopped,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_INIT_LINK] = LFSM_STATE_INACTIVE,
|
[LFSM_EVENT_INIT_LINK] = LFSM_STATE_INACTIVE,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_STOPPED,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_STOPPED,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_STOPPING] = {
|
||||||
[LFSM_STATE_STOPPING] = {
|
|
||||||
.entry_fn = go_stopping,
|
.entry_fn = go_stopping,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_STOPPED,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_STOPPED,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_STOPPED,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_STOPPED,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_STOPPED,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_STOPPED,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_INACTIVE] = {
|
||||||
[LFSM_STATE_INACTIVE] = {
|
|
||||||
.entry_fn = go_inactive,
|
.entry_fn = go_inactive,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_STOP] = LFSM_STATE_STOPPING,
|
[LFSM_EVENT_STOP] = LFSM_STATE_STOPPING,
|
||||||
@ -93,8 +89,7 @@ const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
|||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_INACTIVE,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_INACTIVE,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_INACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_INACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_BUSY] = {
|
||||||
[LFSM_STATE_USER_BUSY] = {
|
|
||||||
.entry_fn = go_user_busy,
|
.entry_fn = go_user_busy,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_STOP] = LFSM_STATE_STOPPING,
|
[LFSM_EVENT_STOP] = LFSM_STATE_STOPPING,
|
||||||
@ -105,8 +100,7 @@ const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
|||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_BUSY_RX_PENDING] = {
|
||||||
[LFSM_STATE_USER_BUSY_RX_PENDING] = {
|
|
||||||
.entry_fn = go_user_busy_rx_pending,
|
.entry_fn = go_user_busy_rx_pending,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_USER_SET_TX] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
[LFSM_EVENT_USER_SET_TX] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
||||||
@ -115,8 +109,7 @@ const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
|||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY_RX_PENDING,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY_RX_PENDING,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY_RX_PENDING,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY_RX_PENDING,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_BUSY_TX_PENDING] = {
|
||||||
[LFSM_STATE_USER_BUSY_TX_PENDING] = {
|
|
||||||
.entry_fn = go_user_busy_tx_pending,
|
.entry_fn = go_user_busy_tx_pending,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_USER_SET_RX] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
[LFSM_EVENT_USER_SET_RX] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
||||||
@ -125,8 +118,7 @@ const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
|||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY_TX_PENDING,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY_TX_PENDING,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY_TX_PENDING,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY_TX_PENDING,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_BUSY_RXTX_PENDING] = {
|
||||||
[LFSM_STATE_USER_BUSY_RXTX_PENDING] = {
|
|
||||||
.entry_fn = go_user_busy_rxtx_pending,
|
.entry_fn = go_user_busy_rxtx_pending,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_USER_DONE] = LFSM_STATE_USER_RXTX_PENDING,
|
[LFSM_EVENT_USER_DONE] = LFSM_STATE_USER_RXTX_PENDING,
|
||||||
@ -134,81 +126,70 @@ const static struct lfsm_transition lfsm_transitions[LFSM_STATE_NUM_STATES] = {
|
|||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_BUSY_RXTX_PENDING,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_RX_PENDING] = {
|
||||||
[LFSM_STATE_USER_RX_PENDING] = {
|
|
||||||
.entry_fn = go_user_rx_pending,
|
.entry_fn = go_user_rx_pending,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_TX_PENDING] = {
|
||||||
[LFSM_STATE_USER_TX_PENDING] = {
|
|
||||||
.entry_fn = go_user_tx_pending,
|
.entry_fn = go_user_tx_pending,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_TX_ACTIVE,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_TX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_TX_ACTIVE,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_TX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_TX_ACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_TX_ACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_RXTX_PENDING] = {
|
||||||
[LFSM_STATE_USER_RXTX_PENDING] = {
|
|
||||||
.entry_fn = go_user_rxtx_pending,
|
.entry_fn = go_user_rxtx_pending,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RXTX_ACTIVE,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RXTX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_RXTX_ACTIVE,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_RXTX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RXTX_ACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RXTX_ACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_RX_ACTIVE] = {
|
||||||
[LFSM_STATE_USER_RX_ACTIVE] = {
|
|
||||||
.entry_fn = go_user_rx_active,
|
.entry_fn = go_user_rx_active,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_TX_ACTIVE] = {
|
||||||
[LFSM_STATE_USER_TX_ACTIVE] = {
|
|
||||||
.entry_fn = go_user_tx_active,
|
.entry_fn = go_user_tx_active,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_INACTIVE,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_INACTIVE,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_INACTIVE,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_INACTIVE,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_INACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_INACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, [LFSM_STATE_USER_RXTX_ACTIVE] = {
|
||||||
[LFSM_STATE_USER_RXTX_ACTIVE] = {
|
|
||||||
.entry_fn = go_user_rxtx_active,
|
.entry_fn = go_user_rxtx_active,
|
||||||
.next_state = {
|
.next_state = {
|
||||||
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_LINK] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY,
|
[LFSM_EVENT_RX_USER] = LFSM_STATE_USER_BUSY,
|
||||||
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RX_ACTIVE,
|
[LFSM_EVENT_RX_UNKNOWN] = LFSM_STATE_USER_RX_ACTIVE,
|
||||||
},
|
},
|
||||||
},
|
}, };
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FSM State Entry Functions
|
* FSM State Entry Functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void go_faulted(struct lfsm_context * context)
|
static void go_faulted(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
PIOS_DEBUG_Assert(0);
|
PIOS_DEBUG_Assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_stopped(struct lfsm_context * context)
|
static void go_stopped(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
#if 0
|
#if 0
|
||||||
PIOS_SPI_Stop(PIOS_SPI_OP);
|
PIOS_SPI_Stop(PIOS_SPI_OP);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_stopping(struct lfsm_context * context)
|
static void go_stopping(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
context->link_tx = NULL;
|
context->link_tx = NULL;
|
||||||
context->tx = NULL;
|
context->tx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_inactive(struct lfsm_context * context)
|
static void go_inactive(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
context->link_state = OPAHRS_MSG_LINK_STATE_INACTIVE;
|
context->link_state = OPAHRS_MSG_LINK_STATE_INACTIVE;
|
||||||
lfsm_update_link_tx(context);
|
lfsm_update_link_tx(context);
|
||||||
|
|
||||||
@ -219,11 +200,11 @@ static void go_inactive(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_busy(struct lfsm_context * context)
|
static void go_user_busy(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx);
|
||||||
|
|
||||||
@ -237,11 +218,11 @@ static void go_user_busy(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_busy_rx_pending(struct lfsm_context * context)
|
static void go_user_busy_rx_pending(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx);
|
||||||
|
|
||||||
@ -252,11 +233,11 @@ static void go_user_busy_rx_pending(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_busy_tx_pending(struct lfsm_context * context)
|
static void go_user_busy_tx_pending(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_tx);
|
PIOS_DEBUG_Assert(context->user_tx);
|
||||||
|
|
||||||
@ -267,14 +248,13 @@ static void go_user_busy_tx_pending(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_busy_rxtx_pending(struct lfsm_context * context)
|
static void go_user_busy_rxtx_pending(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx); PIOS_DEBUG_Assert(context->user_tx);
|
||||||
PIOS_DEBUG_Assert(context->user_tx);
|
|
||||||
|
|
||||||
context->link_state = OPAHRS_MSG_LINK_STATE_BUSY;
|
context->link_state = OPAHRS_MSG_LINK_STATE_BUSY;
|
||||||
lfsm_update_link_tx(context);
|
lfsm_update_link_tx(context);
|
||||||
@ -283,11 +263,11 @@ static void go_user_busy_rxtx_pending(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_rx_pending(struct lfsm_context * context)
|
static void go_user_rx_pending(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx);
|
||||||
|
|
||||||
@ -298,11 +278,11 @@ static void go_user_rx_pending(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_tx_pending(struct lfsm_context * context)
|
static void go_user_tx_pending(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_tx);
|
PIOS_DEBUG_Assert(context->user_tx);
|
||||||
|
|
||||||
@ -313,14 +293,13 @@ static void go_user_tx_pending(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_rxtx_pending(struct lfsm_context * context)
|
static void go_user_rxtx_pending(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx); PIOS_DEBUG_Assert(context->user_tx);
|
||||||
PIOS_DEBUG_Assert(context->user_tx);
|
|
||||||
|
|
||||||
context->link_state = OPAHRS_MSG_LINK_STATE_BUSY;
|
context->link_state = OPAHRS_MSG_LINK_STATE_BUSY;
|
||||||
lfsm_update_link_tx(context);
|
lfsm_update_link_tx(context);
|
||||||
@ -329,11 +308,11 @@ static void go_user_rxtx_pending(struct lfsm_context * context)
|
|||||||
context->tx = context->link_tx;
|
context->tx = context->link_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_rx_active(struct lfsm_context * context)
|
static void go_user_rx_active(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx);
|
||||||
|
|
||||||
@ -343,11 +322,11 @@ static void go_user_rx_active(struct lfsm_context * context)
|
|||||||
|
|
||||||
lfsm_update_link_tx(context);
|
lfsm_update_link_tx(context);
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_tx_active(struct lfsm_context * context)
|
static void go_user_tx_active(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_tx);
|
PIOS_DEBUG_Assert(context->user_tx);
|
||||||
|
|
||||||
@ -356,21 +335,21 @@ static void go_user_tx_active(struct lfsm_context * context)
|
|||||||
context->tx = context->user_tx;
|
context->tx = context->user_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void go_user_rxtx_active(struct lfsm_context * context)
|
static void go_user_rxtx_active(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
PIOS_DEBUG_Assert(context->user_rx);
|
PIOS_DEBUG_Assert(context->user_rx); PIOS_DEBUG_Assert(context->user_tx);
|
||||||
PIOS_DEBUG_Assert(context->user_tx);
|
|
||||||
|
|
||||||
context->link_state = OPAHRS_MSG_LINK_STATE_READY;
|
context->link_state = OPAHRS_MSG_LINK_STATE_READY;
|
||||||
context->rx = context->user_rx;
|
context->rx = context->user_rx;
|
||||||
context->tx = context->user_tx;
|
context->tx = context->user_tx;
|
||||||
|
|
||||||
lfsm_init_rx(context);
|
lfsm_init_rx(context);
|
||||||
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx, context->user_payload_len, lfsm_irq_callback);
|
PIOS_SPI_TransferBlock(PIOS_SPI_OP, context->tx, context->rx,
|
||||||
|
context->user_payload_len, lfsm_irq_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -379,40 +358,40 @@ static void go_user_rxtx_active(struct lfsm_context * context)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void lfsm_update_link_tx_v0 (struct opahrs_msg_v0 * msg, enum opahrs_msg_link_state state, uint16_t errors)
|
static void lfsm_update_link_tx_v0(struct opahrs_msg_v0 * msg,
|
||||||
{
|
enum opahrs_msg_link_state state, uint16_t errors) {
|
||||||
opahrs_msg_v0_init_link_tx(msg, OPAHRS_MSG_LINK_TAG_NOP);
|
opahrs_msg_v0_init_link_tx(msg, OPAHRS_MSG_LINK_TAG_NOP);
|
||||||
|
|
||||||
msg->payload.link.state = state;
|
msg->payload.link.state = state;
|
||||||
msg->payload.link.errors = errors;
|
msg->payload.link.errors = errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lfsm_update_link_tx_v1 (struct opahrs_msg_v1 * msg, enum opahrs_msg_link_state state, uint16_t errors)
|
static void lfsm_update_link_tx_v1(struct opahrs_msg_v1 * msg,
|
||||||
{
|
enum opahrs_msg_link_state state, uint16_t errors) {
|
||||||
opahrs_msg_v1_init_link_tx(msg, OPAHRS_MSG_LINK_TAG_NOP);
|
opahrs_msg_v1_init_link_tx(msg, OPAHRS_MSG_LINK_TAG_NOP);
|
||||||
|
|
||||||
msg->payload.link.state = state;
|
msg->payload.link.state = state;
|
||||||
msg->payload.link.errors = errors;
|
msg->payload.link.errors = errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lfsm_update_link_tx (struct lfsm_context * context)
|
static void lfsm_update_link_tx(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
PIOS_DEBUG_Assert(context->link_tx);
|
PIOS_DEBUG_Assert(context->link_tx);
|
||||||
|
|
||||||
switch (context->user_payload_type) {
|
switch (context->user_payload_type) {
|
||||||
case OPAHRS_MSG_TYPE_USER_V0:
|
case OPAHRS_MSG_TYPE_USER_V0:
|
||||||
lfsm_update_link_tx_v0 ((struct opahrs_msg_v0 *)context->link_tx, context->link_state, context->errors);
|
lfsm_update_link_tx_v0((struct opahrs_msg_v0 *) context->link_tx,
|
||||||
|
context->link_state, context->errors);
|
||||||
break;
|
break;
|
||||||
case OPAHRS_MSG_TYPE_USER_V1:
|
case OPAHRS_MSG_TYPE_USER_V1:
|
||||||
lfsm_update_link_tx_v1 ((struct opahrs_msg_v1 *)context->link_tx, context->link_state, context->errors);
|
lfsm_update_link_tx_v1((struct opahrs_msg_v1 *) context->link_tx,
|
||||||
|
context->link_state, context->errors);
|
||||||
break;
|
break;
|
||||||
case OPAHRS_MSG_TYPE_LINK:
|
case OPAHRS_MSG_TYPE_LINK:
|
||||||
PIOS_DEBUG_Assert(0);
|
PIOS_DEBUG_Assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lfsm_init_rx (struct lfsm_context * context)
|
static void lfsm_init_rx(struct lfsm_context * context) {
|
||||||
{
|
|
||||||
PIOS_DEBUG_Assert(context->rx);
|
PIOS_DEBUG_Assert(context->rx);
|
||||||
|
|
||||||
switch (context->user_payload_type) {
|
switch (context->user_payload_type) {
|
||||||
@ -433,8 +412,7 @@ static void lfsm_init_rx (struct lfsm_context * context)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void lfsm_inject_event(enum lfsm_event event)
|
void lfsm_inject_event(enum lfsm_event event) {
|
||||||
{
|
|
||||||
PIOS_IRQ_Disable();
|
PIOS_IRQ_Disable();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -453,14 +431,13 @@ void lfsm_inject_event(enum lfsm_event event)
|
|||||||
PIOS_IRQ_Enable();
|
PIOS_IRQ_Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_init(void)
|
void lfsm_init(void) {
|
||||||
{
|
|
||||||
context.curr_state = LFSM_STATE_STOPPED;
|
context.curr_state = LFSM_STATE_STOPPED;
|
||||||
go_stopped(&context);
|
go_stopped(&context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_set_link_proto_v0 (struct opahrs_msg_v0 * link_tx, struct opahrs_msg_v0 * link_rx)
|
void lfsm_set_link_proto_v0(struct opahrs_msg_v0 * link_tx,
|
||||||
{
|
struct opahrs_msg_v0 * link_rx) {
|
||||||
PIOS_DEBUG_Assert(link_tx);
|
PIOS_DEBUG_Assert(link_tx);
|
||||||
|
|
||||||
context.link_tx = (uint8_t *) link_tx;
|
context.link_tx = (uint8_t *) link_tx;
|
||||||
@ -473,8 +450,8 @@ void lfsm_set_link_proto_v0 (struct opahrs_msg_v0 * link_tx, struct opahrs_msg_v
|
|||||||
lfsm_inject_event(LFSM_EVENT_INIT_LINK);
|
lfsm_inject_event(LFSM_EVENT_INIT_LINK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_set_link_proto_v1 (struct opahrs_msg_v1 * link_tx, struct opahrs_msg_v1 * link_rx)
|
void lfsm_set_link_proto_v1(struct opahrs_msg_v1 * link_tx,
|
||||||
{
|
struct opahrs_msg_v1 * link_rx) {
|
||||||
PIOS_DEBUG_Assert(link_tx);
|
PIOS_DEBUG_Assert(link_tx);
|
||||||
|
|
||||||
context.link_tx = (uint8_t *) link_tx;
|
context.link_tx = (uint8_t *) link_tx;
|
||||||
@ -487,8 +464,7 @@ void lfsm_set_link_proto_v1 (struct opahrs_msg_v1 * link_tx, struct opahrs_msg_v
|
|||||||
lfsm_inject_event(LFSM_EVENT_INIT_LINK);
|
lfsm_inject_event(LFSM_EVENT_INIT_LINK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_user_set_tx_v0 (struct opahrs_msg_v0 * user_tx)
|
void lfsm_user_set_tx_v0(struct opahrs_msg_v0 * user_tx) {
|
||||||
{
|
|
||||||
PIOS_DEBUG_Assert(user_tx);
|
PIOS_DEBUG_Assert(user_tx);
|
||||||
|
|
||||||
PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V0);
|
PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V0);
|
||||||
@ -497,55 +473,45 @@ void lfsm_user_set_tx_v0 (struct opahrs_msg_v0 * user_tx)
|
|||||||
lfsm_inject_event(LFSM_EVENT_USER_SET_TX);
|
lfsm_inject_event(LFSM_EVENT_USER_SET_TX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_user_set_rx_v0 (struct opahrs_msg_v0 * user_rx)
|
void lfsm_user_set_rx_v0(struct opahrs_msg_v0 * user_rx) {
|
||||||
{
|
PIOS_DEBUG_Assert(user_rx); PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V0);
|
||||||
PIOS_DEBUG_Assert(user_rx);
|
|
||||||
PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V0);
|
|
||||||
|
|
||||||
context.user_rx = (uint8_t *) user_rx;
|
context.user_rx = (uint8_t *) user_rx;
|
||||||
|
|
||||||
lfsm_inject_event(LFSM_EVENT_USER_SET_RX);
|
lfsm_inject_event(LFSM_EVENT_USER_SET_RX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_user_set_tx_v1 (struct opahrs_msg_v1 * user_tx)
|
void lfsm_user_set_tx_v1(struct opahrs_msg_v1 * user_tx) {
|
||||||
{
|
PIOS_DEBUG_Assert(user_tx); PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V1);
|
||||||
PIOS_DEBUG_Assert(user_tx);
|
|
||||||
PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V1);
|
|
||||||
|
|
||||||
context.user_tx = (uint8_t *) user_tx;
|
context.user_tx = (uint8_t *) user_tx;
|
||||||
|
|
||||||
lfsm_inject_event(LFSM_EVENT_USER_SET_TX);
|
lfsm_inject_event(LFSM_EVENT_USER_SET_TX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_user_set_rx_v1 (struct opahrs_msg_v1 * user_rx)
|
void lfsm_user_set_rx_v1(struct opahrs_msg_v1 * user_rx) {
|
||||||
{
|
PIOS_DEBUG_Assert(user_rx); PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V1);
|
||||||
PIOS_DEBUG_Assert(user_rx);
|
|
||||||
PIOS_DEBUG_Assert(context.user_payload_type == OPAHRS_MSG_TYPE_USER_V1);
|
|
||||||
|
|
||||||
context.user_rx = (uint8_t *) user_rx;
|
context.user_rx = (uint8_t *) user_rx;
|
||||||
|
|
||||||
lfsm_inject_event(LFSM_EVENT_USER_SET_RX);
|
lfsm_inject_event(LFSM_EVENT_USER_SET_RX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_user_done (void)
|
void lfsm_user_done(void) {
|
||||||
{
|
|
||||||
lfsm_inject_event(LFSM_EVENT_USER_DONE);
|
lfsm_inject_event(LFSM_EVENT_USER_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_stop (void)
|
void lfsm_stop(void) {
|
||||||
{
|
|
||||||
lfsm_inject_event(LFSM_EVENT_STOP);
|
lfsm_inject_event(LFSM_EVENT_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lfsm_get_link_stats (struct lfsm_link_stats * stats)
|
void lfsm_get_link_stats(struct lfsm_link_stats * stats) {
|
||||||
{
|
|
||||||
PIOS_DEBUG_Assert(stats);
|
PIOS_DEBUG_Assert(stats);
|
||||||
|
|
||||||
*stats = context.stats;
|
*stats = context.stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum lfsm_state lfsm_get_state (void)
|
enum lfsm_state lfsm_get_state(void) {
|
||||||
{
|
|
||||||
return context.curr_state;
|
return context.curr_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,8 +521,7 @@ enum lfsm_state lfsm_get_state (void)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void lfsm_irq_callback(uint8_t crc_ok, uint8_t crc_val)
|
void lfsm_irq_callback(uint8_t crc_ok, uint8_t crc_val) {
|
||||||
{
|
|
||||||
if (!crc_ok) {
|
if (!crc_ok) {
|
||||||
context.stats.rx_badcrc++;
|
context.stats.rx_badcrc++;
|
||||||
lfsm_inject_event(LFSM_EVENT_RX_UNKNOWN);
|
lfsm_inject_event(LFSM_EVENT_RX_UNKNOWN);
|
||||||
@ -589,8 +554,8 @@ void lfsm_irq_callback(uint8_t crc_ok, uint8_t crc_val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check for bad magic */
|
/* Check for bad magic */
|
||||||
if ((head->magic != OPAHRS_MSG_MAGIC_HEAD) ||
|
if ((head->magic != OPAHRS_MSG_MAGIC_HEAD) || (tail->magic
|
||||||
(tail->magic != OPAHRS_MSG_MAGIC_TAIL)) {
|
!= OPAHRS_MSG_MAGIC_TAIL)) {
|
||||||
if (head->magic != OPAHRS_MSG_MAGIC_HEAD) {
|
if (head->magic != OPAHRS_MSG_MAGIC_HEAD) {
|
||||||
context.stats.rx_badmagic_head++;
|
context.stats.rx_badmagic_head++;
|
||||||
}
|
}
|
||||||
|
@ -23,31 +23,30 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef AHRS_BL_H
|
#ifndef AHRS_BL_H
|
||||||
#define AHRS_BL_H
|
#define AHRS_BL_H
|
||||||
|
|
||||||
|
|
||||||
/* PIOS Includes */
|
/* PIOS Includes */
|
||||||
#include <pios.h>
|
#include <pios.h>
|
||||||
|
|
||||||
/** Start programming
|
/** Start programming
|
||||||
returns: true if FLASH erased and ready to program
|
returns: true if FLASH erased and ready to program
|
||||||
*/
|
*/
|
||||||
bool StartProgramming(void);
|
bool
|
||||||
|
StartProgramming(void);
|
||||||
|
|
||||||
/** Write a block to FLASH
|
/** Write a block to FLASH
|
||||||
buffer contains the data to be written
|
buffer contains the data to be written
|
||||||
returns: true if FLASH programmed correctly
|
returns: true if FLASH programmed correctly
|
||||||
*/
|
*/
|
||||||
bool WriteData(uint32_t offset, uint8_t *buffer, uint32_t size);
|
bool
|
||||||
|
WriteData(uint32_t offset, uint8_t *buffer, uint32_t size);
|
||||||
|
|
||||||
/** Read a block from FLASH
|
/** Read a block from FLASH
|
||||||
returns: true if FLASH read correctly.
|
returns: true if FLASH read correctly.
|
||||||
Buffer is set to the read data
|
Buffer is set to the read data
|
||||||
*/
|
*/
|
||||||
bool ReadData(uint32_t offset, uint8_t *buffer, uint32_t size);
|
bool
|
||||||
|
ReadData(uint32_t offset, uint8_t *buffer, uint32_t size);
|
||||||
|
|
||||||
|
|
||||||
#endif /* AHRS_BL_H */
|
#endif /* AHRS_BL_H */
|
||||||
|
@ -35,9 +35,15 @@ just to be absolutely sure
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef enum { PROGRAM_NULL, PROGRAM_WRITE, PROGRAM_READ, PROGRAM_ACK, PROGRAM_REBOOT, PROGRAM_ERR} ProgramType;
|
typedef enum {
|
||||||
|
PROGRAM_NULL,
|
||||||
|
PROGRAM_WRITE,
|
||||||
|
PROGRAM_READ,
|
||||||
|
PROGRAM_ACK,
|
||||||
|
PROGRAM_REBOOT,
|
||||||
|
PROGRAM_ERR
|
||||||
|
} ProgramType;
|
||||||
#define SPI_MAX_PROGRAM_DATA_SIZE (14 * 4) //USB comms uses 14x 32 bit words
|
#define SPI_MAX_PROGRAM_DATA_SIZE (14 * 4) //USB comms uses 14x 32 bit words
|
||||||
|
|
||||||
#define REBOOT_CONFIRMATION "AHRS REBOOT"
|
#define REBOOT_CONFIRMATION "AHRS REBOOT"
|
||||||
#define REBOOT_CONFIRMATION_LENGTH 11
|
#define REBOOT_CONFIRMATION_LENGTH 11
|
||||||
|
|
||||||
|
@ -27,12 +27,13 @@
|
|||||||
#ifndef AHRS_PROGRAM_MASTER_H
|
#ifndef AHRS_PROGRAM_MASTER_H
|
||||||
#define AHRS_PROGRAM_MASTER_H
|
#define AHRS_PROGRAM_MASTER_H
|
||||||
|
|
||||||
typedef enum {PROGRAM_ERR_OK, //OK
|
typedef enum {
|
||||||
|
PROGRAM_ERR_OK, //OK
|
||||||
PROGRAM_ERR_LINK, //comms error
|
PROGRAM_ERR_LINK, //comms error
|
||||||
PROGRAM_ERR_FUNCTION, //function failed
|
PROGRAM_ERR_FUNCTION,
|
||||||
|
//function failed
|
||||||
} PROGERR;
|
} PROGERR;
|
||||||
|
|
||||||
|
|
||||||
/** Connect to AHRS and request programming mode
|
/** Connect to AHRS and request programming mode
|
||||||
* returns: false if failed.
|
* returns: false if failed.
|
||||||
*/
|
*/
|
||||||
@ -43,14 +44,16 @@ bool AhrsProgramConnect(uint32_t spi_id);
|
|||||||
* returns: error status
|
* returns: error status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PROGERR AhrsProgramWrite(uint32_t spi_id, uint32_t address, void * data, uint32_t size);
|
PROGERR AhrsProgramWrite(uint32_t spi_id, uint32_t address, void * data,
|
||||||
|
uint32_t size);
|
||||||
|
|
||||||
/** Read data from AHRS
|
/** Read data from AHRS
|
||||||
* size must be between 1 and SPI_MAX_PROGRAM_DATA_SIZE
|
* size must be between 1 and SPI_MAX_PROGRAM_DATA_SIZE
|
||||||
* returns: error status
|
* returns: error status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PROGERR AhrsProgramRead(uint32_t spi_id, uint32_t address, void * data, uint32_t size);
|
PROGERR AhrsProgramRead(uint32_t spi_id, uint32_t address, void * data,
|
||||||
|
uint32_t size);
|
||||||
|
|
||||||
/** reboot AHRS
|
/** reboot AHRS
|
||||||
* returns: error status
|
* returns: error status
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef BL_FSM_H
|
#ifndef BL_FSM_H
|
||||||
#define BL_FSM_H
|
#define BL_FSM_H
|
||||||
|
|
||||||
@ -45,7 +44,8 @@ enum lfsm_state {
|
|||||||
LFSM_STATE_USER_TX_ACTIVE,
|
LFSM_STATE_USER_TX_ACTIVE,
|
||||||
LFSM_STATE_USER_RXTX_ACTIVE,
|
LFSM_STATE_USER_RXTX_ACTIVE,
|
||||||
|
|
||||||
LFSM_STATE_NUM_STATES /* Must be last */
|
LFSM_STATE_NUM_STATES
|
||||||
|
/* Must be last */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum lfsm_event {
|
enum lfsm_event {
|
||||||
@ -58,7 +58,8 @@ enum lfsm_event {
|
|||||||
LFSM_EVENT_RX_USER,
|
LFSM_EVENT_RX_USER,
|
||||||
LFSM_EVENT_RX_UNKNOWN,
|
LFSM_EVENT_RX_UNKNOWN,
|
||||||
|
|
||||||
LFSM_EVENT_NUM_EVENTS /* Must be last */
|
LFSM_EVENT_NUM_EVENTS
|
||||||
|
/* Must be last */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lfsm_link_stats {
|
struct lfsm_link_stats {
|
||||||
@ -81,11 +82,13 @@ extern void lfsm_irq_callback(uint8_t crc_ok, uint8_t crc_val);
|
|||||||
extern void lfsm_get_link_stats(struct lfsm_link_stats * stats);
|
extern void lfsm_get_link_stats(struct lfsm_link_stats * stats);
|
||||||
extern enum lfsm_state lfsm_get_state(void);
|
extern enum lfsm_state lfsm_get_state(void);
|
||||||
|
|
||||||
extern void lfsm_set_link_proto_v0 (struct opahrs_msg_v0 * link_tx, struct opahrs_msg_v0 * link_rx);
|
extern void lfsm_set_link_proto_v0(struct opahrs_msg_v0 * link_tx,
|
||||||
|
struct opahrs_msg_v0 * link_rx);
|
||||||
extern void lfsm_user_set_rx_v0(struct opahrs_msg_v0 * user_rx);
|
extern void lfsm_user_set_rx_v0(struct opahrs_msg_v0 * user_rx);
|
||||||
extern void lfsm_user_set_tx_v0(struct opahrs_msg_v0 * user_tx);
|
extern void lfsm_user_set_tx_v0(struct opahrs_msg_v0 * user_tx);
|
||||||
|
|
||||||
extern void lfsm_set_link_proto_v1 (struct opahrs_msg_v1 * link_tx, struct opahrs_msg_v1 * link_rx);
|
extern void lfsm_set_link_proto_v1(struct opahrs_msg_v1 * link_tx,
|
||||||
|
struct opahrs_msg_v1 * link_rx);
|
||||||
extern void lfsm_user_set_rx_v1(struct opahrs_msg_v1 * user_rx);
|
extern void lfsm_user_set_rx_v1(struct opahrs_msg_v1 * user_rx);
|
||||||
extern void lfsm_user_set_tx_v1(struct opahrs_msg_v1 * user_tx);
|
extern void lfsm_user_set_tx_v1(struct opahrs_msg_v1 * user_tx);
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef PIOS_CONFIG_H
|
#ifndef PIOS_CONFIG_H
|
||||||
#define PIOS_CONFIG_H
|
#define PIOS_CONFIG_H
|
||||||
|
|
||||||
|
@ -89,8 +89,7 @@ int main() {
|
|||||||
if (GO_dfu == FALSE) {
|
if (GO_dfu == FALSE) {
|
||||||
jump_to_app();
|
jump_to_app();
|
||||||
}
|
}
|
||||||
if(PIOS_IAP_CheckRequest())
|
if (PIOS_IAP_CheckRequest()) {
|
||||||
{
|
|
||||||
PIOS_DELAY_WaitmS(1000);
|
PIOS_DELAY_WaitmS(1000);
|
||||||
PIOS_IAP_ClearRequest();
|
PIOS_IAP_ClearRequest();
|
||||||
}
|
}
|
||||||
@ -160,7 +159,8 @@ void process_spi_request(void) {
|
|||||||
//PIOS_LED_On(LED1);
|
//PIOS_LED_On(LED1);
|
||||||
opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_VERSIONS);
|
opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_VERSIONS);
|
||||||
user_tx_v0.payload.user.v.rsp.versions.bl_version = BOOTLOADER_VERSION;
|
user_tx_v0.payload.user.v.rsp.versions.bl_version = BOOTLOADER_VERSION;
|
||||||
user_tx_v0.payload.user.v.rsp.versions.hw_version = (BOARD_TYPE << 8) | BOARD_REVISION;
|
user_tx_v0.payload.user.v.rsp.versions.hw_version = (BOARD_TYPE << 8)
|
||||||
|
| BOARD_REVISION;
|
||||||
user_tx_v0.payload.user.v.rsp.versions.fw_crc = Fw_crc;
|
user_tx_v0.payload.user.v.rsp.versions.fw_crc = Fw_crc;
|
||||||
lfsm_user_set_tx_v0(&user_tx_v0);
|
lfsm_user_set_tx_v0(&user_tx_v0);
|
||||||
break;
|
break;
|
||||||
@ -214,9 +214,9 @@ void process_spi_request(void) {
|
|||||||
case OPAHRS_MSG_V0_REQ_FWDN_DATA:
|
case OPAHRS_MSG_V0_REQ_FWDN_DATA:
|
||||||
opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_FWDN_DATA);
|
opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_FWDN_DATA);
|
||||||
uint32_t adr = user_rx_v0.payload.user.v.req.fwdn_data.adress;
|
uint32_t adr = user_rx_v0.payload.user.v.req.fwdn_data.adress;
|
||||||
for(uint8_t x=0;x<4;++x)
|
for (uint8_t x = 0; x < 4; ++x) {
|
||||||
{
|
user_tx_v0.payload.user.v.rsp.fw_dn.data[x]
|
||||||
user_tx_v0.payload.user.v.rsp.fw_dn.data[x]=*PIOS_BL_HELPER_FLASH_If_Read(adr+x);
|
= *PIOS_BL_HELPER_FLASH_If_Read(adr + x);
|
||||||
}
|
}
|
||||||
lfsm_user_set_tx_v0(&user_tx_v0);
|
lfsm_user_set_tx_v0(&user_tx_v0);
|
||||||
break;
|
break;
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <pios_spi_priv.h>
|
#include <pios_spi_priv.h>
|
||||||
|
|
||||||
|
|
||||||
/* OP Interface
|
/* OP Interface
|
||||||
*
|
*
|
||||||
* NOTE: Leave this declared as const data so that it ends up in the
|
* NOTE: Leave this declared as const data so that it ends up in the
|
||||||
@ -38,7 +37,8 @@
|
|||||||
void PIOS_SPI_op_irq_handler(void);
|
void PIOS_SPI_op_irq_handler(void);
|
||||||
void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_op_irq_handler")));
|
void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_op_irq_handler")));
|
||||||
void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_op_irq_handler")));
|
void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_op_irq_handler")));
|
||||||
static const struct pios_spi_cfg pios_spi_op_cfg = {
|
static const struct pios_spi_cfg
|
||||||
|
pios_spi_op_cfg = {
|
||||||
.regs = SPI2,
|
.regs = SPI2,
|
||||||
.init = {
|
.init = {
|
||||||
.SPI_Mode = SPI_Mode_Slave,
|
.SPI_Mode = SPI_Mode_Slave,
|
||||||
@ -93,44 +93,38 @@ static const struct pios_spi_cfg pios_spi_op_cfg = {
|
|||||||
.DMA_M2M = DMA_M2M_Disable,
|
.DMA_M2M = DMA_M2M_Disable,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}, .ssel = {
|
||||||
.ssel = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_12,
|
.GPIO_Pin = GPIO_Pin_12,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||||
},
|
},
|
||||||
},
|
}, .sclk = {
|
||||||
.sclk = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_13,
|
.GPIO_Pin = GPIO_Pin_13,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||||
},
|
},
|
||||||
},
|
}, .miso = {
|
||||||
.miso = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_14,
|
.GPIO_Pin = GPIO_Pin_14,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
},
|
},
|
||||||
},
|
}, .mosi = {
|
||||||
.mosi = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_15,
|
.GPIO_Pin = GPIO_Pin_15,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||||
},
|
},
|
||||||
},
|
}, };
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t pios_spi_op_id;
|
uint32_t pios_spi_op_id;
|
||||||
void PIOS_SPI_op_irq_handler(void)
|
void PIOS_SPI_op_irq_handler(void) {
|
||||||
{
|
|
||||||
/* Call into the generic code to handle the IRQ for this specific device */
|
/* Call into the generic code to handle the IRQ for this specific device */
|
||||||
PIOS_SPI_IRQ_Handler(pios_spi_op_id);
|
PIOS_SPI_IRQ_Handler(pios_spi_op_id);
|
||||||
}
|
}
|
||||||
@ -139,8 +133,7 @@ void PIOS_SPI_op_irq_handler(void)
|
|||||||
|
|
||||||
#include "bl_fsm.h" /* lfsm_* */
|
#include "bl_fsm.h" /* lfsm_* */
|
||||||
|
|
||||||
void PIOS_Board_Init()
|
void PIOS_Board_Init() {
|
||||||
{
|
|
||||||
/* Set up the SPI interface to the OP board */
|
/* Set up the SPI interface to the OP board */
|
||||||
if (PIOS_SPI_Init(&pios_spi_op_id, &pios_spi_op_cfg)) {
|
if (PIOS_SPI_Init(&pios_spi_op_id, &pios_spi_op_cfg)) {
|
||||||
PIOS_DEBUG_Assert(0);
|
PIOS_DEBUG_Assert(0);
|
||||||
|
@ -112,7 +112,7 @@ DOXYGENDIR = ../Doc/Doxygen
|
|||||||
SRC += $(OPSYSTEM)/main.c
|
SRC += $(OPSYSTEM)/main.c
|
||||||
SRC += $(OPSYSTEM)/pios_board.c
|
SRC += $(OPSYSTEM)/pios_board.c
|
||||||
SRC += $(OPSYSTEM)/op_dfu.c
|
SRC += $(OPSYSTEM)/op_dfu.c
|
||||||
SRC += $(OPSYSTEM)/stopwatch.c
|
SRC += $(FLIGHTLIB)/stopwatch.c
|
||||||
|
|
||||||
|
|
||||||
## PIOS Hardware (STM32F10x)
|
## PIOS Hardware (STM32F10x)
|
||||||
@ -121,35 +121,21 @@ SRC += $(PIOSSTM32F10X)/pios_led.c
|
|||||||
SRC += $(PIOSSTM32F10X)/pios_delay.c
|
SRC += $(PIOSSTM32F10X)/pios_delay.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_adc.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_servo.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_i2c.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_spi.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_ppm.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_spektrum.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_exti.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_wdg.c
|
|
||||||
|
|
||||||
|
|
||||||
# PIOS USB related files (seperated to make code maintenance more easy)
|
# PIOS USB related files (seperated to make code maintenance more easy)
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_usb_hid_endp.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||||
|
|
||||||
## PIOS Hardware (Common)
|
## PIOS Hardware (Common)
|
||||||
#SRC += $(PIOSCOMMON)/pios_sdcard.c
|
|
||||||
SRC += $(PIOSCOMMON)/pios_com.c
|
SRC += $(PIOSCOMMON)/pios_com.c
|
||||||
#SRC += $(PIOSCOMMON)/pios_bmp085.c
|
|
||||||
#SRC += $(PIOSCOMMON)/pios_opahrs_v0.c
|
|
||||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||||
#SRC += $(PIOSCOMMON)/pios_opahrs_proto.c
|
|
||||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||||
|
|
||||||
## Libraries for flight calculations
|
## Libraries for flight calculations
|
||||||
@ -160,22 +146,18 @@ SRC += $(CMSISDIR)/core_cm3.c
|
|||||||
SRC += $(CMSISDIR)/system_stm32f10x.c
|
SRC += $(CMSISDIR)/system_stm32f10x.c
|
||||||
|
|
||||||
## Used parts of the STM-Library
|
## Used parts of the STM-Library
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_adc.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_dac.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_i2c.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_iwdg.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
|
||||||
SRC += $(STMSPDSRCDIR)/misc.c
|
SRC += $(STMSPDSRCDIR)/misc.c
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ typedef enum {
|
|||||||
uploadingStarting, //9
|
uploadingStarting, //9
|
||||||
outsideDevCapabilities, //10
|
outsideDevCapabilities, //10
|
||||||
CRC_Fail,//11
|
CRC_Fail,//11
|
||||||
failed_jump,//12
|
failed_jump,
|
||||||
|
//12
|
||||||
} DFUStates;
|
} DFUStates;
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* OP_DFU commands */
|
/* OP_DFU commands */
|
||||||
@ -74,8 +75,7 @@ typedef enum {
|
|||||||
} DFUCommands;
|
} DFUCommands;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
High_Density,
|
High_Density, Medium_Density
|
||||||
Medium_Density
|
|
||||||
} DeviceType;
|
} DeviceType;
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* OP_DFU transfer types */
|
/* OP_DFU transfer types */
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint8_t programmingType;
|
uint8_t programmingType;
|
||||||
uint8_t readWriteFlags;
|
uint8_t readWriteFlags;
|
||||||
uint32_t startOfUserCode;
|
uint32_t startOfUserCode;
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef PIOS_CONFIG_H
|
#ifndef PIOS_CONFIG_H
|
||||||
#define PIOS_CONFIG_H
|
#define PIOS_CONFIG_H
|
||||||
#define PIOS_INCLUDE_BL_HELPER
|
#define PIOS_INCLUDE_BL_HELPER
|
||||||
|
@ -55,7 +55,6 @@ uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
uint8_t tempcount = 0;
|
uint8_t tempcount = 0;
|
||||||
|
|
||||||
|
|
||||||
/* Extern variables ----------------------------------------------------------*/
|
/* Extern variables ----------------------------------------------------------*/
|
||||||
DFUStates DeviceState;
|
DFUStates DeviceState;
|
||||||
int16_t status = 0;
|
int16_t status = 0;
|
||||||
@ -70,13 +69,8 @@ uint8_t processRX();
|
|||||||
void jump_to_app();
|
void jump_to_app();
|
||||||
|
|
||||||
#define BLUE LED1
|
#define BLUE LED1
|
||||||
// #define RED LED4
|
|
||||||
#define LED_PWM_TIMER TIM1
|
#define LED_PWM_TIMER TIM1
|
||||||
int main() {
|
int main() {
|
||||||
/* NOTE: Do NOT modify the following start-up sequence */
|
|
||||||
/* Any new initialization functions should be added in OpenPilotInit() */
|
|
||||||
|
|
||||||
/* Brings up System using CMSIS functions, enables the LEDs. */
|
|
||||||
PIOS_SYS_Init();
|
PIOS_SYS_Init();
|
||||||
if (BSL_HOLD_STATE == 0)
|
if (BSL_HOLD_STATE == 0)
|
||||||
USB_connected = TRUE;
|
USB_connected = TRUE;
|
||||||
@ -107,8 +101,6 @@ int main() {
|
|||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (JumpToApp == TRUE)
|
if (JumpToApp == TRUE)
|
||||||
jump_to_app();
|
jump_to_app();
|
||||||
//pwm_period = 50; // *100 uS -> 5 mS
|
|
||||||
//pwm_sweep_steps =100; // * 5 mS -> 500 mS
|
|
||||||
|
|
||||||
switch (DeviceState) {
|
switch (DeviceState) {
|
||||||
case Last_operation_Success:
|
case Last_operation_Success:
|
||||||
@ -161,7 +153,8 @@ int main() {
|
|||||||
|
|
||||||
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
|
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
|
||||||
STOPWATCH_Reset(LED_PWM_TIMER);
|
STOPWATCH_Reset(LED_PWM_TIMER);
|
||||||
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle))
|
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState
|
||||||
|
== BLidle))
|
||||||
JumpToApp = TRUE;
|
JumpToApp = TRUE;
|
||||||
|
|
||||||
processRX();
|
processRX();
|
||||||
@ -178,7 +171,6 @@ void jump_to_app() {
|
|||||||
RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
|
RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
|
||||||
_SetCNTR(0); // clear interrupt mask
|
_SetCNTR(0); // clear interrupt mask
|
||||||
_SetISTR(0); // clear all requests
|
_SetISTR(0); // clear all requests
|
||||||
|
|
||||||
JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4);
|
JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4);
|
||||||
Jump_To_Application = (pFunction) JumpAddress;
|
Jump_To_Application = (pFunction) JumpAddress;
|
||||||
/* Initialize user application's Stack Pointer */
|
/* Initialize user application's Stack Pointer */
|
||||||
|
@ -93,8 +93,8 @@ void DataDownload(DownloadAction action) {
|
|||||||
for (uint8_t x = 0; x < packetSize; ++x) {
|
for (uint8_t x = 0; x < packetSize; ++x) {
|
||||||
partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
|
partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
|
||||||
offset = baseOfAdressType(downType) + partoffset;
|
offset = baseOfAdressType(downType) + partoffset;
|
||||||
if(!flash_read(SendBuffer+(6+x*4),offset,currentProgrammingDestination))
|
if (!flash_read(SendBuffer + (6 + x * 4), offset,
|
||||||
{
|
currentProgrammingDestination)) {
|
||||||
DeviceState = Last_operation_failed;
|
DeviceState = Last_operation_failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ void processComand(uint8_t *xReceive_Buffer) {
|
|||||||
case EnterDFU:
|
case EnterDFU:
|
||||||
if (((DeviceState == BLidle) && (Data0 < numberOfDevices))
|
if (((DeviceState == BLidle) && (Data0 < numberOfDevices))
|
||||||
|| (DeviceState == DFUidle)) {
|
|| (DeviceState == DFUidle)) {
|
||||||
if (Data0 > 0)//PORQUE???
|
if (Data0 > 0)
|
||||||
OPDfuIni(TRUE);
|
OPDfuIni(TRUE);
|
||||||
DeviceState = DFUidle;
|
DeviceState = DFUidle;
|
||||||
currentProgrammingDestination = devicesTable[Data0].programmingType;
|
currentProgrammingDestination = devicesTable[Data0].programmingType;
|
||||||
@ -196,7 +196,7 @@ void processComand(uint8_t *xReceive_Buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result != 1) {
|
if (result != 1) {
|
||||||
DeviceState = Last_operation_failed;//ok
|
DeviceState = Last_operation_failed;
|
||||||
Aditionals = (uint32_t) Command;
|
Aditionals = (uint32_t) Command;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -438,8 +438,7 @@ uint32_t CalcFirmCRC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void sendData(uint8_t * buf,uint16_t size)
|
void sendData(uint8_t * buf, uint16_t size) {
|
||||||
{
|
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
|
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
|
||||||
if (DeviceState == downloading)
|
if (DeviceState == downloading)
|
||||||
PIOS_DELAY_WaitmS(20);//this is an hack, we should check wtf is wrong with hid
|
PIOS_DELAY_WaitmS(20);//this is an hack, we should check wtf is wrong with hid
|
||||||
|
@ -112,7 +112,7 @@ DOXYGENDIR = ../Doc/Doxygen
|
|||||||
SRC += $(OPSYSTEM)/main.c
|
SRC += $(OPSYSTEM)/main.c
|
||||||
SRC += $(OPSYSTEM)/pios_board.c
|
SRC += $(OPSYSTEM)/pios_board.c
|
||||||
SRC += $(OPSYSTEM)/op_dfu.c
|
SRC += $(OPSYSTEM)/op_dfu.c
|
||||||
SRC += $(OPSYSTEM)/stopwatch.c
|
SRC += $(FLIGHTLIB)/stopwatch.c
|
||||||
SRC += $(OPSYSTEM)/ssp.c
|
SRC += $(OPSYSTEM)/ssp.c
|
||||||
|
|
||||||
|
|
||||||
@ -122,31 +122,19 @@ SRC += $(PIOSSTM32F10X)/pios_led.c
|
|||||||
SRC += $(PIOSSTM32F10X)/pios_delay.c
|
SRC += $(PIOSSTM32F10X)/pios_delay.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_adc.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_servo.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_i2c.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_spi.c
|
SRC += $(PIOSSTM32F10X)/pios_spi.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_ppm.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_spektrum.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_exti.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_wdg.c
|
|
||||||
|
|
||||||
|
|
||||||
# PIOS USB related files (seperated to make code maintenance more easy)
|
# PIOS USB related files (seperated to make code maintenance more easy)
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_usb_hid_endp.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||||
|
|
||||||
## PIOS Hardware (Common)
|
## PIOS Hardware (Common)
|
||||||
#SRC += $(PIOSCOMMON)/pios_sdcard.c
|
|
||||||
SRC += $(PIOSCOMMON)/pios_com.c
|
SRC += $(PIOSCOMMON)/pios_com.c
|
||||||
#SRC += $(PIOSCOMMON)/pios_bmp085.c
|
|
||||||
SRC += $(PIOSCOMMON)/pios_opahrs_v0.c
|
SRC += $(PIOSCOMMON)/pios_opahrs_v0.c
|
||||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||||
@ -161,22 +149,18 @@ SRC += $(CMSISDIR)/core_cm3.c
|
|||||||
SRC += $(CMSISDIR)/system_stm32f10x.c
|
SRC += $(CMSISDIR)/system_stm32f10x.c
|
||||||
|
|
||||||
## Used parts of the STM-Library
|
## Used parts of the STM-Library
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_adc.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_dac.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_i2c.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_iwdg.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
|
||||||
SRC += $(STMSPDSRCDIR)/misc.c
|
SRC += $(STMSPDSRCDIR)/misc.c
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ typedef enum {
|
|||||||
uploadingStarting, //9
|
uploadingStarting, //9
|
||||||
outsideDevCapabilities, //10
|
outsideDevCapabilities, //10
|
||||||
CRC_Fail,//11
|
CRC_Fail,//11
|
||||||
failed_jump,//12
|
failed_jump,
|
||||||
|
//12
|
||||||
} DFUStates;
|
} DFUStates;
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* OP_DFU commands */
|
/* OP_DFU commands */
|
||||||
@ -74,8 +75,7 @@ typedef enum {
|
|||||||
} DFUCommands;
|
} DFUCommands;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
High_Density,
|
High_Density, Medium_Density
|
||||||
Medium_Density
|
|
||||||
} DeviceType;
|
} DeviceType;
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* OP_DFU transfer types */
|
/* OP_DFU transfer types */
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint8_t programmingType;
|
uint8_t programmingType;
|
||||||
uint8_t readWriteFlags;
|
uint8_t readWriteFlags;
|
||||||
uint32_t startOfUserCode;
|
uint32_t startOfUserCode;
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef PIOS_CONFIG_H
|
#ifndef PIOS_CONFIG_H
|
||||||
#define PIOS_CONFIG_H
|
#define PIOS_CONFIG_H
|
||||||
#define PIOS_INCLUDE_BL_HELPER
|
#define PIOS_INCLUDE_BL_HELPER
|
||||||
|
@ -45,12 +45,10 @@ typedef enum decodeState_ {
|
|||||||
} DecodeState_t;
|
} DecodeState_t;
|
||||||
|
|
||||||
typedef enum ReceiveState {
|
typedef enum ReceiveState {
|
||||||
state_escaped_e = 0,
|
state_escaped_e = 0, state_unescaped_e
|
||||||
state_unescaped_e
|
|
||||||
} ReceiveState_t;
|
} ReceiveState_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint8_t *pbuff;
|
uint8_t *pbuff;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
@ -102,20 +100,18 @@ typedef struct Port_tag {
|
|||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
} Port_t;
|
} Port_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Public Data **/
|
/** Public Data **/
|
||||||
|
|
||||||
/** PUBLIC FUNCTIONS **/
|
/** PUBLIC FUNCTIONS **/
|
||||||
int16_t ssp_ReceiveProcess(Port_t *thisport);
|
int16_t ssp_ReceiveProcess(Port_t *thisport);
|
||||||
int16_t ssp_SendProcess(Port_t *thisport);
|
int16_t ssp_SendProcess(Port_t *thisport);
|
||||||
uint16_t ssp_SendString(Port_t *thisport, char *str);
|
uint16_t ssp_SendString(Port_t *thisport, char *str);
|
||||||
int16_t ssp_SendData(Port_t *thisport, const uint8_t * data,const uint16_t length );
|
int16_t ssp_SendData(Port_t *thisport, const uint8_t * data,
|
||||||
|
const uint16_t length);
|
||||||
void ssp_Init(Port_t *thisport, const PortConfig_t* const info);
|
void ssp_Init(Port_t *thisport, const PortConfig_t* const info);
|
||||||
int16_t ssp_ReceiveByte(Port_t *thisport);
|
int16_t ssp_ReceiveByte(Port_t *thisport);
|
||||||
uint16_t ssp_Synchronise(Port_t *thisport);
|
uint16_t ssp_Synchronise(Port_t *thisport);
|
||||||
|
|
||||||
|
|
||||||
/** EXTERNAL FUNCTIONS **/
|
/** EXTERNAL FUNCTIONS **/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @addtogroup OpenPilotBL OpenPilot BootLoader
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* @file stopwatch.h
|
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
||||||
* @brief Timer functions for the LED PWM.
|
|
||||||
* @see The GNU Public License (GPL) Version 3
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
/*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _STOPWATCH_H
|
|
||||||
#define _STOPWATCH_H
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Global definitions
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Global Types
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Prototypes
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
extern s32 STOPWATCH_Init(u32 resolution, TIM_TypeDef* TIM);
|
|
||||||
extern s32 STOPWATCH_Reset(TIM_TypeDef* TIM);
|
|
||||||
extern u32 STOPWATCH_ValueGet(TIM_TypeDef* TIM);
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Export global variables
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _STOPWATCH_H */
|
|
@ -57,7 +57,6 @@ uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
uint8_t tempcount = 0;
|
uint8_t tempcount = 0;
|
||||||
|
|
||||||
|
|
||||||
/// SSP SECTION
|
/// SSP SECTION
|
||||||
/// SSP TIME SOURCE
|
/// SSP TIME SOURCE
|
||||||
#define SSP_TIMER TIM7
|
#define SSP_TIMER TIM7
|
||||||
@ -65,7 +64,8 @@ uint32_t ssp_time=0;
|
|||||||
#define MAX_PACKET_DATA_LEN 255
|
#define MAX_PACKET_DATA_LEN 255
|
||||||
#define MAX_PACKET_BUF_SIZE (1+1+MAX_PACKET_DATA_LEN+2)
|
#define MAX_PACKET_BUF_SIZE (1+1+MAX_PACKET_DATA_LEN+2)
|
||||||
#define UART_BUFFER_SIZE 1024
|
#define UART_BUFFER_SIZE 1024
|
||||||
uint8_t rx_buffer[UART_BUFFER_SIZE] __attribute__ ((aligned(4))); // align to 32-bit to try and provide speed improvement;
|
uint8_t rx_buffer[UART_BUFFER_SIZE] __attribute__ ((aligned(4)));
|
||||||
|
// align to 32-bit to try and provide speed improvement;
|
||||||
// master buffers...
|
// master buffers...
|
||||||
uint8_t SSP_TxBuf[MAX_PACKET_BUF_SIZE];
|
uint8_t SSP_TxBuf[MAX_PACKET_BUF_SIZE];
|
||||||
uint8_t SSP_RxBuf[MAX_PACKET_BUF_SIZE];
|
uint8_t SSP_RxBuf[MAX_PACKET_BUF_SIZE];
|
||||||
@ -206,7 +206,8 @@ int main() {
|
|||||||
|
|
||||||
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
|
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
|
||||||
STOPWATCH_Reset(LED_PWM_TIMER);
|
STOPWATCH_Reset(LED_PWM_TIMER);
|
||||||
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle))
|
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState
|
||||||
|
== BLidle))
|
||||||
JumpToApp = TRUE;
|
JumpToApp = TRUE;
|
||||||
|
|
||||||
processRX();
|
processRX();
|
||||||
@ -274,11 +275,9 @@ void SSP_CallBack(uint8_t *buf, uint16_t len) {
|
|||||||
fifoBuf_putData(&ssp_buffer, buf, len);
|
fifoBuf_putData(&ssp_buffer, buf, len);
|
||||||
}
|
}
|
||||||
int16_t SSP_SerialRead(void) {
|
int16_t SSP_SerialRead(void) {
|
||||||
if(PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_RF)>0)
|
if (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_RF) > 0) {
|
||||||
{
|
|
||||||
return PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_RF);
|
return PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_RF);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
void SSP_SerialWrite(uint8_t value) {
|
void SSP_SerialWrite(uint8_t value) {
|
||||||
|
@ -101,8 +101,8 @@ void DataDownload(DownloadAction action) {
|
|||||||
for (uint8_t x = 0; x < packetSize; ++x) {
|
for (uint8_t x = 0; x < packetSize; ++x) {
|
||||||
partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
|
partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
|
||||||
offset = baseOfAdressType(downType) + partoffset;
|
offset = baseOfAdressType(downType) + partoffset;
|
||||||
if(!flash_read(SendBuffer+(6+x*4),offset,currentProgrammingDestination))
|
if (!flash_read(SendBuffer + (6 + x * 4), offset,
|
||||||
{
|
currentProgrammingDestination)) {
|
||||||
DeviceState = Last_operation_failed;
|
DeviceState = Last_operation_failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,8 +545,7 @@ uint32_t CalcFirmCRC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void sendData(uint8_t * buf,uint16_t size)
|
void sendData(uint8_t * buf, uint16_t size) {
|
||||||
{
|
|
||||||
if (ProgPort == Usb) {
|
if (ProgPort == Usb) {
|
||||||
|
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
|
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
void PIOS_SPI_ahrs_irq_handler(void);
|
void PIOS_SPI_ahrs_irq_handler(void);
|
||||||
void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_ahrs_irq_handler")));
|
void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_ahrs_irq_handler")));
|
||||||
void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_ahrs_irq_handler")));
|
void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_ahrs_irq_handler")));
|
||||||
const struct pios_spi_cfg pios_spi_ahrs_cfg = {
|
const struct pios_spi_cfg
|
||||||
|
pios_spi_ahrs_cfg = {
|
||||||
.regs = SPI2,
|
.regs = SPI2,
|
||||||
.init = {
|
.init = {
|
||||||
.SPI_Mode = SPI_Mode_Master,
|
.SPI_Mode = SPI_Mode_Master,
|
||||||
@ -97,51 +98,44 @@ const struct pios_spi_cfg pios_spi_ahrs_cfg = {
|
|||||||
.DMA_M2M = DMA_M2M_Disable,
|
.DMA_M2M = DMA_M2M_Disable,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}, .ssel = {
|
||||||
.ssel = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_12,
|
.GPIO_Pin = GPIO_Pin_12,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_Out_PP,
|
.GPIO_Mode = GPIO_Mode_Out_PP,
|
||||||
},
|
},
|
||||||
},
|
}, .sclk = {
|
||||||
.sclk = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_13,
|
.GPIO_Pin = GPIO_Pin_13,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
},
|
},
|
||||||
},
|
}, .miso = {
|
||||||
.miso = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_14,
|
.GPIO_Pin = GPIO_Pin_14,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||||
},
|
},
|
||||||
},
|
}, .mosi = {
|
||||||
.mosi = {
|
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_15,
|
.GPIO_Pin = GPIO_Pin_15,
|
||||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
},
|
},
|
||||||
},
|
}, };
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t pios_spi_ahrs_id;
|
uint32_t pios_spi_ahrs_id;
|
||||||
void PIOS_SPI_ahrs_irq_handler(void)
|
void PIOS_SPI_ahrs_irq_handler(void) {
|
||||||
{
|
|
||||||
/* Call into the generic code to handle the IRQ for this specific device */
|
/* Call into the generic code to handle the IRQ for this specific device */
|
||||||
PIOS_SPI_IRQ_Handler(pios_spi_ahrs_id);
|
PIOS_SPI_IRQ_Handler(pios_spi_ahrs_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* PIOS_INCLUDE_SPI */
|
#endif /* PIOS_INCLUDE_SPI */
|
||||||
|
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
#if defined(PIOS_INCLUDE_USART)
|
||||||
|
|
||||||
#include "pios_usart_priv.h"
|
#include "pios_usart_priv.h"
|
||||||
@ -151,9 +145,7 @@ void PIOS_SPI_ahrs_irq_handler(void)
|
|||||||
*/
|
*/
|
||||||
void PIOS_USART_telem_irq_handler(void);
|
void PIOS_USART_telem_irq_handler(void);
|
||||||
void USART2_IRQHandler() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
|
void USART2_IRQHandler() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
|
||||||
const struct pios_usart_cfg pios_usart_telem_cfg = {
|
const struct pios_usart_cfg pios_usart_telem_cfg = { .regs = USART2, .init = {
|
||||||
.regs = USART2,
|
|
||||||
.init = {
|
|
||||||
#if defined (PIOS_COM_TELEM_BAUDRATE)
|
#if defined (PIOS_COM_TELEM_BAUDRATE)
|
||||||
.USART_BaudRate = PIOS_COM_TELEM_BAUDRATE,
|
.USART_BaudRate = PIOS_COM_TELEM_BAUDRATE,
|
||||||
#else
|
#else
|
||||||
@ -164,8 +156,7 @@ const struct pios_usart_cfg pios_usart_telem_cfg = {
|
|||||||
.USART_StopBits = USART_StopBits_1,
|
.USART_StopBits = USART_StopBits_1,
|
||||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||||
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
|
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
|
||||||
},
|
}, .irq = {
|
||||||
.irq = {
|
|
||||||
.handler = PIOS_USART_telem_irq_handler,
|
.handler = PIOS_USART_telem_irq_handler,
|
||||||
.init = {
|
.init = {
|
||||||
.NVIC_IRQChannel = USART2_IRQn,
|
.NVIC_IRQChannel = USART2_IRQn,
|
||||||
@ -173,28 +164,24 @@ const struct pios_usart_cfg pios_usart_telem_cfg = {
|
|||||||
.NVIC_IRQChannelSubPriority = 0,
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
.NVIC_IRQChannelCmd = ENABLE,
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
},
|
},
|
||||||
},
|
}, .rx = {
|
||||||
.rx = {
|
|
||||||
.gpio = GPIOA,
|
.gpio = GPIOA,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_3,
|
.GPIO_Pin = GPIO_Pin_3,
|
||||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_IPU,
|
.GPIO_Mode = GPIO_Mode_IPU,
|
||||||
},
|
},
|
||||||
},
|
}, .tx = {
|
||||||
.tx = {
|
|
||||||
.gpio = GPIOA,
|
.gpio = GPIOA,
|
||||||
.init = {
|
.init = {
|
||||||
.GPIO_Pin = GPIO_Pin_2,
|
.GPIO_Pin = GPIO_Pin_2,
|
||||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
},
|
},
|
||||||
},
|
}, };
|
||||||
};
|
|
||||||
|
|
||||||
static uint32_t pios_usart_telem_rf_id;
|
static uint32_t pios_usart_telem_rf_id;
|
||||||
void PIOS_USART_telem_irq_handler(void)
|
void PIOS_USART_telem_irq_handler(void) {
|
||||||
{
|
|
||||||
PIOS_USART_IRQ_Handler(pios_usart_telem_rf_id);
|
PIOS_USART_IRQ_Handler(pios_usart_telem_rf_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +207,6 @@ uint32_t pios_com_telem_usb_id;
|
|||||||
*/
|
*/
|
||||||
void PIOS_Board_Init(void) {
|
void PIOS_Board_Init(void) {
|
||||||
|
|
||||||
|
|
||||||
/* Enable Prefetch Buffer */
|
/* Enable Prefetch Buffer */
|
||||||
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
|
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
|
||||||
|
|
||||||
@ -235,7 +221,8 @@ void PIOS_Board_Init(void) {
|
|||||||
if (PIOS_USART_Init(&pios_usart_telem_rf_id, &pios_usart_telem_cfg)) {
|
if (PIOS_USART_Init(&pios_usart_telem_rf_id, &pios_usart_telem_cfg)) {
|
||||||
PIOS_DEBUG_Assert(0);
|
PIOS_DEBUG_Assert(0);
|
||||||
}
|
}
|
||||||
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_telem_rf_id)) {
|
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver,
|
||||||
|
pios_usart_telem_rf_id)) {
|
||||||
PIOS_DEBUG_Assert(0);
|
PIOS_DEBUG_Assert(0);
|
||||||
}
|
}
|
||||||
#endif /* PIOS_INCLUDE_COM */
|
#endif /* PIOS_INCLUDE_COM */
|
||||||
|
@ -85,13 +85,11 @@
|
|||||||
#define SEQNUM 1
|
#define SEQNUM 1
|
||||||
#define DATA 2
|
#define DATA 2
|
||||||
|
|
||||||
|
|
||||||
// Make larger sized integers from smaller sized integers
|
// Make larger sized integers from smaller sized integers
|
||||||
#define MAKEWORD16( ub, lb ) ((uint16_t)0x0000 | ((uint16_t)(ub) << 8) | (uint16_t)(lb) )
|
#define MAKEWORD16( ub, lb ) ((uint16_t)0x0000 | ((uint16_t)(ub) << 8) | (uint16_t)(lb) )
|
||||||
#define MAKEWORD32( uw, lw ) ((uint32_t)(0x0UL | ((uint32_t)(uw) << 16) | (uint32_t)(lw)) )
|
#define MAKEWORD32( uw, lw ) ((uint32_t)(0x0UL | ((uint32_t)(uw) << 16) | (uint32_t)(lw)) )
|
||||||
#define MAKEWORD32B( b3, b2, b1, b0 ) ((uint32_t)((uint32_t)(b3)<< 24) | ((uint32_t)(b2)<<16) | ((uint32_t)(b1)<<8) | ((uint32_t)(b0) )
|
#define MAKEWORD32B( b3, b2, b1, b0 ) ((uint32_t)((uint32_t)(b3)<< 24) | ((uint32_t)(b2)<<16) | ((uint32_t)(b1)<<8) | ((uint32_t)(b0) )
|
||||||
|
|
||||||
|
|
||||||
// Used to extract smaller integers from larger sized intergers
|
// Used to extract smaller integers from larger sized intergers
|
||||||
#define LOWERBYTE( w ) (uint8_t)((w) & 0x00ff )
|
#define LOWERBYTE( w ) (uint8_t)((w) & 0x00ff )
|
||||||
#define UPPERBYTE( w ) (uint8_t)(((w) & 0xff00) >> 8 )
|
#define UPPERBYTE( w ) (uint8_t)(((w) & 0xff00) >> 8 )
|
||||||
@ -118,7 +116,8 @@ static int16_t sf_ReceiveState( Port_t *thisport, uint8_t c );
|
|||||||
|
|
||||||
static void sf_SendPacket(Port_t *thisport);
|
static void sf_SendPacket(Port_t *thisport);
|
||||||
static void sf_SendAckPacket(Port_t *thisport, uint8_t seqNumber);
|
static void sf_SendAckPacket(Port_t *thisport, uint8_t seqNumber);
|
||||||
static void sf_MakePacket( uint8_t *buf, const uint8_t * pdata, uint16_t length, uint8_t seqNo );
|
static void sf_MakePacket(uint8_t *buf, const uint8_t * pdata, uint16_t length,
|
||||||
|
uint8_t seqNo);
|
||||||
static int16_t sf_ReceivePacket(Port_t *thisport);
|
static int16_t sf_ReceivePacket(Port_t *thisport);
|
||||||
|
|
||||||
/* Flag bit masks...*/
|
/* Flag bit masks...*/
|
||||||
@ -131,40 +130,35 @@ static int16_t sf_ReceivePacket(Port_t *thisport);
|
|||||||
#define SSP_IDLE 2
|
#define SSP_IDLE 2
|
||||||
|
|
||||||
/** PRIVATE DATA **/
|
/** PRIVATE DATA **/
|
||||||
static const uint16_t CRC_TABLE[] = {
|
static const uint16_t CRC_TABLE[] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301,
|
||||||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
|
0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1,
|
||||||
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
|
0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81,
|
||||||
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
|
0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
|
||||||
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
|
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00,
|
||||||
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
|
0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 0x1400, 0xD4C1,
|
||||||
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
|
0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380,
|
||||||
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
|
0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, 0xF001, 0x30C0, 0x3180, 0xF141,
|
||||||
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
|
0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501,
|
||||||
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
|
0x35C0, 0x3480, 0xF441, 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0,
|
||||||
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
|
0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881,
|
||||||
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
|
0x3840, 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
|
||||||
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
|
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, 0xE401,
|
||||||
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
|
0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1,
|
||||||
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
|
0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, 0xA001, 0x60C0, 0x6180,
|
||||||
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
|
0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740,
|
||||||
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
|
0xA501, 0x65C0, 0x6480, 0xA441, 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01,
|
||||||
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
|
0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1,
|
||||||
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
|
0xA881, 0x6840, 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80,
|
||||||
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
|
0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
|
||||||
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
|
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200,
|
||||||
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
|
0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, 0x5000, 0x90C1,
|
||||||
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
|
0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780,
|
||||||
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
|
0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, 0x9C01, 0x5CC0, 0x5D80, 0x9D41,
|
||||||
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
|
0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901,
|
||||||
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
|
0x59C0, 0x5880, 0x9841, 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1,
|
||||||
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
|
0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80,
|
||||||
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
|
0x8C41, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
|
||||||
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
|
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 };
|
||||||
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
|
|
||||||
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
|
|
||||||
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
|
|
||||||
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
|
|
||||||
};
|
|
||||||
|
|
||||||
/** EXTERNAL DATA **/
|
/** EXTERNAL DATA **/
|
||||||
|
|
||||||
@ -172,7 +166,6 @@ static const uint16_t CRC_TABLE[] = {
|
|||||||
|
|
||||||
/** VERIFICATION FUNCTIONS **/
|
/** VERIFICATION FUNCTIONS **/
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************************************************/
|
/***********************************************************************************************************/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -185,8 +178,7 @@ static const uint16_t CRC_TABLE[] = {
|
|||||||
* Must be called before calling the Send or REceive process functions.
|
* Must be called before calling the Send or REceive process functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ssp_Init( Port_t *thisport, const PortConfig_t* const info)
|
void ssp_Init(Port_t *thisport, const PortConfig_t* const info) {
|
||||||
{
|
|
||||||
thisport->pfCallBack = info->pfCallBack;
|
thisport->pfCallBack = info->pfCallBack;
|
||||||
thisport->pfSerialRead = info->pfSerialRead;
|
thisport->pfSerialRead = info->pfSerialRead;
|
||||||
thisport->pfSerialWrite = info->pfSerialWrite;
|
thisport->pfSerialWrite = info->pfSerialWrite;
|
||||||
@ -216,8 +208,7 @@ void ssp_Init( Port_t *thisport, const PortConfig_t* const info)
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int16_t ssp_SendProcess( Port_t *thisport )
|
int16_t ssp_SendProcess(Port_t *thisport) {
|
||||||
{
|
|
||||||
int16_t value = SSP_TX_WAITING;
|
int16_t value = SSP_TX_WAITING;
|
||||||
|
|
||||||
if (thisport->SendState == SSP_AWAITING_ACK) {
|
if (thisport->SendState == SSP_AWAITING_ACK) {
|
||||||
@ -260,8 +251,7 @@ int16_t ssp_SendProcess( Port_t *thisport )
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int16_t ssp_ReceiveProcess(Port_t *thisport)
|
int16_t ssp_ReceiveProcess(Port_t *thisport) {
|
||||||
{
|
|
||||||
int16_t b;
|
int16_t b;
|
||||||
int16_t packet_status = SSP_RX_IDLE;
|
int16_t packet_status = SSP_RX_IDLE;
|
||||||
|
|
||||||
@ -284,8 +274,7 @@ int16_t ssp_ReceiveProcess(Port_t *thisport)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t ssp_ReceiveByte(Port_t *thisport )
|
int16_t ssp_ReceiveByte(Port_t *thisport) {
|
||||||
{
|
|
||||||
int16_t b;
|
int16_t b;
|
||||||
int16_t packet_status = SSP_RX_IDLE;
|
int16_t packet_status = SSP_RX_IDLE;
|
||||||
|
|
||||||
@ -307,8 +296,7 @@ int16_t ssp_ReceiveByte(Port_t *thisport )
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint16_t ssp_SendDataBlock( Port_t *thisport, uint8_t *data, uint16_t length )
|
uint16_t ssp_SendDataBlock(Port_t *thisport, uint8_t *data, uint16_t length) {
|
||||||
{
|
|
||||||
int16_t packet_status = SSP_TX_WAITING;
|
int16_t packet_status = SSP_TX_WAITING;
|
||||||
uint16_t retval = FALSE;
|
uint16_t retval = FALSE;
|
||||||
|
|
||||||
@ -337,8 +325,8 @@ uint16_t ssp_SendDataBlock( Port_t *thisport, uint8_t *data, uint16_t length )
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int16_t ssp_SendData( Port_t *thisport, const uint8_t *data, const uint16_t length )
|
int16_t ssp_SendData(Port_t *thisport, const uint8_t *data,
|
||||||
{
|
const uint16_t length) {
|
||||||
|
|
||||||
int16_t value = SSP_TX_WAITING;
|
int16_t value = SSP_TX_WAITING;
|
||||||
|
|
||||||
@ -416,8 +404,7 @@ int16_t ssp_SendData( Port_t *thisport, const uint8_t *data, const uint16_t leng
|
|||||||
* if number of tries exceed maximum try limit then exit
|
* if number of tries exceed maximum try limit then exit
|
||||||
* C. goto A
|
* C. goto A
|
||||||
*/
|
*/
|
||||||
uint16_t ssp_Synchronise( Port_t *thisport )
|
uint16_t ssp_Synchronise(Port_t *thisport) {
|
||||||
{
|
|
||||||
int16_t packet_status;
|
int16_t packet_status;
|
||||||
uint16_t retval = FALSE;
|
uint16_t retval = FALSE;
|
||||||
|
|
||||||
@ -454,7 +441,6 @@ uint16_t ssp_Synchronise( Port_t *thisport )
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief sends out a preformatted packet for a give port
|
* \brief sends out a preformatted packet for a give port
|
||||||
* \param thisport = which port to use.
|
* \param thisport = which port to use.
|
||||||
@ -463,8 +449,7 @@ uint16_t ssp_Synchronise( Port_t *thisport )
|
|||||||
* \note
|
* \note
|
||||||
* Packet should be formed through the use of sf_MakePacket before calling this function.
|
* Packet should be formed through the use of sf_MakePacket before calling this function.
|
||||||
*/
|
*/
|
||||||
static void sf_SendPacket(Port_t *thisport)
|
static void sf_SendPacket(Port_t *thisport) {
|
||||||
{
|
|
||||||
// add 3 to packet data length for: 1 length + 2 CRC (packet overhead)
|
// add 3 to packet data length for: 1 length + 2 CRC (packet overhead)
|
||||||
uint8_t packetLen = thisport->txBuf[LENGTH] + 3;
|
uint8_t packetLen = thisport->txBuf[LENGTH] + 3;
|
||||||
|
|
||||||
@ -476,7 +461,6 @@ static void sf_SendPacket(Port_t *thisport)
|
|||||||
thisport->retryCount++;
|
thisport->retryCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief converts data to transport layer protocol packet format.
|
* \brief converts data to transport layer protocol packet format.
|
||||||
* \param txbuf = buffer to use when forming the packet
|
* \param txbuf = buffer to use when forming the packet
|
||||||
@ -493,8 +477,8 @@ static void sf_SendPacket(Port_t *thisport)
|
|||||||
* 3. TODO: Should this function return an error if data length to be sent is greater th tx buffer size?
|
* 3. TODO: Should this function return an error if data length to be sent is greater th tx buffer size?
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void sf_MakePacket( uint8_t *txBuf, const uint8_t * pdata, uint16_t length, uint8_t seqNo )
|
void sf_MakePacket(uint8_t *txBuf, const uint8_t * pdata, uint16_t length,
|
||||||
{
|
uint8_t seqNo) {
|
||||||
uint16_t crc = 0xffff;
|
uint16_t crc = 0xffff;
|
||||||
uint16_t bufPos = 0;
|
uint16_t bufPos = 0;
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
@ -525,8 +509,7 @@ void sf_MakePacket( uint8_t *txBuf, const uint8_t * pdata, uint16_t length, uint
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void sf_SendAckPacket( Port_t *thisport, uint8_t seqNumber)
|
static void sf_SendAckPacket(Port_t *thisport, uint8_t seqNumber) {
|
||||||
{
|
|
||||||
#ifdef DEBUG_SSP
|
#ifdef DEBUG_SSP
|
||||||
char str[63]= {0};
|
char str[63]= {0};
|
||||||
sprintf(str,"Sent ACK PACKET:%d|",seqNumber);
|
sprintf(str,"Sent ACK PACKET:%d|",seqNumber);
|
||||||
@ -549,8 +532,7 @@ static void sf_SendAckPacket( Port_t *thisport, uint8_t seqNumber)
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void sf_write_byte( Port_t *thisport, uint8_t c )
|
static void sf_write_byte(Port_t *thisport, uint8_t c) {
|
||||||
{
|
|
||||||
if (c == SYNC) { // check for SYNC byte
|
if (c == SYNC) { // check for SYNC byte
|
||||||
thisport->pfSerialWrite(ESC); // since we are not starting a packet we must ESCAPE the SYNCH byte
|
thisport->pfSerialWrite(ESC); // since we are not starting a packet we must ESCAPE the SYNCH byte
|
||||||
thisport->pfSerialWrite(ESC_SYNC); // now send the escaped synch char
|
thisport->pfSerialWrite(ESC_SYNC); // now send the escaped synch char
|
||||||
@ -583,12 +565,10 @@ static void sf_write_byte( Port_t *thisport, uint8_t c )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static uint16_t sf_crc16( uint16_t crc, uint8_t data )
|
static uint16_t sf_crc16(uint16_t crc, uint8_t data) {
|
||||||
{
|
|
||||||
return (crc >> 8) ^ CRC_TABLE[(crc ^ data) & 0x00FF];
|
return (crc >> 8) ^ CRC_TABLE[(crc ^ data) & 0x00FF];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief sets the timeout for the given packet
|
* \brief sets the timeout for the given packet
|
||||||
* \param thisport = which port to use
|
* \param thisport = which port to use
|
||||||
@ -598,8 +578,7 @@ static uint16_t sf_crc16( uint16_t crc, uint8_t data )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void sf_SetSendTimeout( Port_t *thisport )
|
static void sf_SetSendTimeout(Port_t *thisport) {
|
||||||
{
|
|
||||||
uint32_t timeout;
|
uint32_t timeout;
|
||||||
timeout = thisport->pfGetTime() + thisport->timeoutLen;
|
timeout = thisport->pfGetTime() + thisport->timeoutLen;
|
||||||
thisport->timeout = timeout;
|
thisport->timeout = timeout;
|
||||||
@ -614,8 +593,7 @@ static void sf_SetSendTimeout( Port_t *thisport )
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static uint16_t sf_CheckTimeout( Port_t *thisport )
|
static uint16_t sf_CheckTimeout(Port_t *thisport) {
|
||||||
{
|
|
||||||
uint16_t retval = FALSE;
|
uint16_t retval = FALSE;
|
||||||
uint32_t current_time;
|
uint32_t current_time;
|
||||||
|
|
||||||
@ -626,7 +604,6 @@ static uint16_t sf_CheckTimeout( Port_t *thisport )
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* NAME: sf_ReceiveState
|
* NAME: sf_ReceiveState
|
||||||
* DESC: Implements the receive state handling code for escaped and unescaped data
|
* DESC: Implements the receive state handling code for escaped and unescaped data
|
||||||
@ -646,8 +623,7 @@ static uint16_t sf_CheckTimeout( Port_t *thisport )
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int16_t sf_ReceiveState( Port_t *thisport, uint8_t c )
|
static int16_t sf_ReceiveState(Port_t *thisport, uint8_t c) {
|
||||||
{
|
|
||||||
int16_t retval = SSP_RX_RECEIVING;
|
int16_t retval = SSP_RX_RECEIVING;
|
||||||
|
|
||||||
switch (thisport->InputState) {
|
switch (thisport->InputState) {
|
||||||
@ -696,8 +672,7 @@ static int16_t sf_ReceiveState( Port_t *thisport, uint8_t c )
|
|||||||
* \note
|
* \note
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int16_t sf_DecodeState( Port_t *thisport, uint8_t c )
|
static int16_t sf_DecodeState(Port_t *thisport, uint8_t c) {
|
||||||
{
|
|
||||||
int16_t retval;
|
int16_t retval;
|
||||||
switch (thisport->DecodeState) {
|
switch (thisport->DecodeState) {
|
||||||
case decode_idle_e:
|
case decode_idle_e:
|
||||||
@ -787,8 +762,7 @@ static int16_t sf_DecodeState( Port_t *thisport, uint8_t c )
|
|||||||
* Created: Oct 7, 2010 12:07:22 AM by joe
|
* Created: Oct 7, 2010 12:07:22 AM by joe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int16_t sf_ReceivePacket(Port_t *thisport)
|
static int16_t sf_ReceivePacket(Port_t *thisport) {
|
||||||
{
|
|
||||||
int16_t value = FALSE;
|
int16_t value = FALSE;
|
||||||
|
|
||||||
if (ISBITSET(thisport->rxBuf[SEQNUM], ACK_BIT )) {
|
if (ISBITSET(thisport->rxBuf[SEQNUM], ACK_BIT )) {
|
||||||
|
@ -25,17 +25,12 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Include files
|
// Include files
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "stm32f10x_tim.h"
|
#include "stm32f10x_tim.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Local definitions
|
// Local definitions
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
@ -43,10 +38,10 @@
|
|||||||
#define SSP_TIMER_TIMER_BASE TIM7
|
#define SSP_TIMER_TIMER_BASE TIM7
|
||||||
#define SSP_TIMER_TIMER_RCC RCC_APB1Periph_TIM7
|
#define SSP_TIMER_TIMER_RCC RCC_APB1Periph_TIM7
|
||||||
|
|
||||||
uint32_t SSP_TIMER_Init(u32 resolution)
|
uint32_t SSP_TIMER_Init(u32 resolution) {
|
||||||
{
|
|
||||||
// enable timer clock
|
// enable timer clock
|
||||||
if( SSP_TIMER_TIMER_RCC == RCC_APB2Periph_TIM1 || SSP_TIMER_TIMER_RCC == RCC_APB2Periph_TIM8 )
|
if (SSP_TIMER_TIMER_RCC == RCC_APB2Periph_TIM1 || SSP_TIMER_TIMER_RCC
|
||||||
|
== RCC_APB2Periph_TIM8)
|
||||||
RCC_APB2PeriphClockCmd(SSP_TIMER_TIMER_RCC, ENABLE);
|
RCC_APB2PeriphClockCmd(SSP_TIMER_TIMER_RCC, ENABLE);
|
||||||
else
|
else
|
||||||
RCC_APB1PeriphClockCmd(SSP_TIMER_TIMER_RCC, ENABLE);
|
RCC_APB1PeriphClockCmd(SSP_TIMER_TIMER_RCC, ENABLE);
|
||||||
@ -68,13 +63,11 @@ uint32_t SSP_TIMER_Init(u32 resolution)
|
|||||||
return 0; // no error
|
return 0; // no error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//! Resets the SSP_TIMER
|
//! Resets the SSP_TIMER
|
||||||
//! \return < 0 on errors
|
//! \return < 0 on errors
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
uint32_t SSP_TIMER_Reset(void)
|
uint32_t SSP_TIMER_Reset(void) {
|
||||||
{
|
|
||||||
// reset counter
|
// reset counter
|
||||||
SSP_TIMER_TIMER_BASE->CNT = 1; // set to 1 instead of 0 to avoid new IRQ request
|
SSP_TIMER_TIMER_BASE->CNT = 1; // set to 1 instead of 0 to avoid new IRQ request
|
||||||
TIM_ClearITPendingBit(SSP_TIMER_TIMER_BASE, TIM_IT_Update);
|
TIM_ClearITPendingBit(SSP_TIMER_TIMER_BASE, TIM_IT_Update);
|
||||||
@ -82,14 +75,12 @@ uint32_t SSP_TIMER_Reset(void)
|
|||||||
return 0; // no error
|
return 0; // no error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//! Returns current value of SSP_TIMER
|
//! Returns current value of SSP_TIMER
|
||||||
//! \return 1..65535: valid SSP_TIMER value
|
//! \return 1..65535: valid SSP_TIMER value
|
||||||
//! \return 0xffffffff: counter overrun
|
//! \return 0xffffffff: counter overrun
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
uint32_t SSP_TIMER_ValueGet(void)
|
uint32_t SSP_TIMER_ValueGet(void) {
|
||||||
{
|
|
||||||
uint32_t value = SSP_TIMER_TIMER_BASE->CNT;
|
uint32_t value = SSP_TIMER_TIMER_BASE->CNT;
|
||||||
|
|
||||||
if (TIM_GetITStatus(SSP_TIMER_TIMER_BASE, TIM_IT_Update) != RESET)
|
if (TIM_GetITStatus(SSP_TIMER_TIMER_BASE, TIM_IT_Update) != RESET)
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @addtogroup OpenPilotBL OpenPilot BootLoader
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* @file stopwatch.c
|
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
||||||
* @brief Timer functions for the LED PWM.
|
|
||||||
* @see The GNU Public License (GPL) Version 3
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
/*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Include files
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "stm32f10x_tim.h"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Local definitions
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//#define STOPWATCH_TIMER_BASE TIM6
|
|
||||||
//#define STOPWATCH_TIMER_RCC RCC_APB1Periph_TIM6
|
|
||||||
|
|
||||||
uint32_t STOPWATCH_Init(u32 resolution, TIM_TypeDef* TIM) {
|
|
||||||
uint32_t STOPWATCH_TIMER_RCC;
|
|
||||||
switch ((uint32_t)TIM) {
|
|
||||||
case (uint32_t)TIM6:
|
|
||||||
STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM6;
|
|
||||||
break;
|
|
||||||
case (uint32_t)TIM7:
|
|
||||||
STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM7;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable timer clock
|
|
||||||
if (STOPWATCH_TIMER_RCC == RCC_APB2Periph_TIM1 || STOPWATCH_TIMER_RCC
|
|
||||||
== RCC_APB2Periph_TIM8)
|
|
||||||
RCC_APB2PeriphClockCmd(STOPWATCH_TIMER_RCC, ENABLE);
|
|
||||||
else
|
|
||||||
RCC_APB1PeriphClockCmd(STOPWATCH_TIMER_RCC, ENABLE);
|
|
||||||
|
|
||||||
// time base configuration
|
|
||||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
|
||||||
TIM_TimeBaseStructure.TIM_Period = 0xffff; // max period
|
|
||||||
TIM_TimeBaseStructure.TIM_Prescaler = (72 * resolution) - 1; // <resolution> uS accuracy @ 72 MHz
|
|
||||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
|
||||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
|
||||||
TIM_TimeBaseInit(TIM, &TIM_TimeBaseStructure);
|
|
||||||
|
|
||||||
// enable interrupt request
|
|
||||||
TIM_ITConfig(TIM, TIM_IT_Update, ENABLE);
|
|
||||||
|
|
||||||
// start counter
|
|
||||||
TIM_Cmd(TIM, ENABLE);
|
|
||||||
|
|
||||||
return 0; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//! Resets the stopwatch
|
|
||||||
//! \return < 0 on errors
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t STOPWATCH_Reset(TIM_TypeDef* TIM) {
|
|
||||||
// reset counter
|
|
||||||
TIM->CNT = 1; // set to 1 instead of 0 to avoid new IRQ request
|
|
||||||
TIM_ClearITPendingBit(TIM, TIM_IT_Update);
|
|
||||||
|
|
||||||
return 0; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//! Returns current value of stopwatch
|
|
||||||
//! \return 1..65535: valid stopwatch value
|
|
||||||
//! \return 0xffffffff: counter overrun
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t STOPWATCH_ValueGet(TIM_TypeDef* TIM) {
|
|
||||||
uint32_t value = TIM->CNT;
|
|
||||||
|
|
||||||
if (TIM_GetITStatus(TIM, TIM_IT_Update) != RESET)
|
|
||||||
value = 0xffffffff;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
@ -112,7 +112,7 @@ DOXYGENDIR = ../Doc/Doxygen
|
|||||||
SRC += $(OPSYSTEM)/main.c
|
SRC += $(OPSYSTEM)/main.c
|
||||||
SRC += $(OPSYSTEM)/pios_board.c
|
SRC += $(OPSYSTEM)/pios_board.c
|
||||||
SRC += $(OPSYSTEM)/op_dfu.c
|
SRC += $(OPSYSTEM)/op_dfu.c
|
||||||
SRC += $(OPSYSTEM)/stopwatch.c
|
SRC += $(FLIGHTLIB)/stopwatch.c
|
||||||
|
|
||||||
|
|
||||||
## PIOS Hardware (STM32F10x)
|
## PIOS Hardware (STM32F10x)
|
||||||
@ -121,35 +121,20 @@ SRC += $(PIOSSTM32F10X)/pios_led.c
|
|||||||
SRC += $(PIOSSTM32F10X)/pios_delay.c
|
SRC += $(PIOSSTM32F10X)/pios_delay.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_adc.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_servo.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_i2c.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_spi.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_ppm.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_spektrum.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_exti.c
|
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_wdg.c
|
|
||||||
|
|
||||||
|
|
||||||
# PIOS USB related files (seperated to make code maintenance more easy)
|
# PIOS USB related files (seperated to make code maintenance more easy)
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||||
#SRC += $(PIOSSTM32F10X)/pios_usb_hid_endp.c
|
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||||
|
|
||||||
## PIOS Hardware (Common)
|
## PIOS Hardware (Common)
|
||||||
#SRC += $(PIOSCOMMON)/pios_sdcard.c
|
|
||||||
SRC += $(PIOSCOMMON)/pios_com.c
|
SRC += $(PIOSCOMMON)/pios_com.c
|
||||||
#SRC += $(PIOSCOMMON)/pios_bmp085.c
|
|
||||||
#SRC += $(PIOSCOMMON)/pios_opahrs_v0.c
|
|
||||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||||
#SRC += $(PIOSCOMMON)/pios_opahrs_proto.c
|
|
||||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||||
|
|
||||||
## Libraries for flight calculations
|
## Libraries for flight calculations
|
||||||
@ -160,22 +145,18 @@ SRC += $(CMSISDIR)/core_cm3.c
|
|||||||
SRC += $(CMSISDIR)/system_stm32f10x.c
|
SRC += $(CMSISDIR)/system_stm32f10x.c
|
||||||
|
|
||||||
## Used parts of the STM-Library
|
## Used parts of the STM-Library
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_adc.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_dac.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_i2c.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
|
||||||
#SRC += $(STMSPDSRCDIR)/stm32f10x_iwdg.c
|
|
||||||
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
|
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
|
||||||
SRC += $(STMSPDSRCDIR)/misc.c
|
SRC += $(STMSPDSRCDIR)/misc.c
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ typedef enum {
|
|||||||
uploadingStarting, //9
|
uploadingStarting, //9
|
||||||
outsideDevCapabilities, //10
|
outsideDevCapabilities, //10
|
||||||
CRC_Fail,//11
|
CRC_Fail,//11
|
||||||
failed_jump,//12
|
failed_jump,
|
||||||
|
//12
|
||||||
} DFUStates;
|
} DFUStates;
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* OP_DFU commands */
|
/* OP_DFU commands */
|
||||||
@ -74,8 +75,7 @@ typedef enum {
|
|||||||
} DFUCommands;
|
} DFUCommands;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
High_Density,
|
High_Density, Medium_Density
|
||||||
Medium_Density
|
|
||||||
} DeviceType;
|
} DeviceType;
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* OP_DFU transfer types */
|
/* OP_DFU transfer types */
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint8_t programmingType;
|
uint8_t programmingType;
|
||||||
uint8_t readWriteFlags;
|
uint8_t readWriteFlags;
|
||||||
uint32_t startOfUserCode;
|
uint32_t startOfUserCode;
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef PIOS_CONFIG_H
|
#ifndef PIOS_CONFIG_H
|
||||||
#define PIOS_CONFIG_H
|
#define PIOS_CONFIG_H
|
||||||
#define PIOS_INCLUDE_BL_HELPER
|
#define PIOS_INCLUDE_BL_HELPER
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @addtogroup OpenPilotBL OpenPilot BootLoader
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* @file stopwatch.h
|
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
||||||
* @brief Timer functions for the LED PWM.
|
|
||||||
* @see The GNU Public License (GPL) Version 3
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
/*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _STOPWATCH_H
|
|
||||||
#define _STOPWATCH_H
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Global definitions
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Global Types
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Prototypes
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
extern s32 STOPWATCH_Init(u32 resolution, TIM_TypeDef* TIM);
|
|
||||||
extern s32 STOPWATCH_Reset(TIM_TypeDef* TIM);
|
|
||||||
extern u32 STOPWATCH_ValueGet(TIM_TypeDef* TIM);
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Export global variables
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _STOPWATCH_H */
|
|
@ -55,7 +55,6 @@ uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
uint8_t tempcount = 0;
|
uint8_t tempcount = 0;
|
||||||
|
|
||||||
|
|
||||||
/* Extern variables ----------------------------------------------------------*/
|
/* Extern variables ----------------------------------------------------------*/
|
||||||
DFUStates DeviceState;
|
DFUStates DeviceState;
|
||||||
int16_t status = 0;
|
int16_t status = 0;
|
||||||
@ -161,7 +160,8 @@ int main() {
|
|||||||
|
|
||||||
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
|
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100)
|
||||||
STOPWATCH_Reset(LED_PWM_TIMER);
|
STOPWATCH_Reset(LED_PWM_TIMER);
|
||||||
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState == BLidle))
|
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState
|
||||||
|
== BLidle))
|
||||||
JumpToApp = TRUE;
|
JumpToApp = TRUE;
|
||||||
|
|
||||||
processRX();
|
processRX();
|
||||||
|
@ -97,8 +97,8 @@ void DataDownload(DownloadAction action) {
|
|||||||
for (uint8_t x = 0; x < packetSize; ++x) {
|
for (uint8_t x = 0; x < packetSize; ++x) {
|
||||||
partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
|
partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
|
||||||
offset = baseOfAdressType(downType) + partoffset;
|
offset = baseOfAdressType(downType) + partoffset;
|
||||||
if(!flash_read(SendBuffer+(6+x*4),offset,currentProgrammingDestination))
|
if (!flash_read(SendBuffer + (6 + x * 4), offset,
|
||||||
{
|
currentProgrammingDestination)) {
|
||||||
DeviceState = Last_operation_failed;
|
DeviceState = Last_operation_failed;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -470,8 +470,7 @@ uint32_t CalcFirmCRC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void sendData(uint8_t * buf,uint16_t size)
|
void sendData(uint8_t * buf, uint16_t size) {
|
||||||
{
|
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
|
PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);
|
||||||
if (DeviceState == downloading)
|
if (DeviceState == downloading)
|
||||||
PIOS_DELAY_WaitmS(10);
|
PIOS_DELAY_WaitmS(10);
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @addtogroup OpenPilotBL OpenPilot BootLoader
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* @file stopwatch.c
|
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
||||||
* @brief Timer functions for the LED PWM.
|
|
||||||
* @see The GNU Public License (GPL) Version 3
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
/*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Include files
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "stm32f10x_tim.h"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Local definitions
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//#define STOPWATCH_TIMER_BASE TIM6
|
|
||||||
//#define STOPWATCH_TIMER_RCC RCC_APB1Periph_TIM6
|
|
||||||
|
|
||||||
uint32_t STOPWATCH_Init(u32 resolution, TIM_TypeDef* TIM) {
|
|
||||||
uint32_t STOPWATCH_TIMER_RCC;
|
|
||||||
switch ((uint32_t)TIM) {
|
|
||||||
case (uint32_t)TIM1: STOPWATCH_TIMER_RCC = RCC_APB2Periph_TIM1;break;
|
|
||||||
case (uint32_t)TIM2: STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM2; break;
|
|
||||||
case (uint32_t)TIM3: STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM3; break;
|
|
||||||
case (uint32_t)TIM4: STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM4; break;
|
|
||||||
default:
|
|
||||||
STOPWATCH_TIMER_RCC = RCC_APB2Periph_TIM1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable timer clock
|
|
||||||
if (STOPWATCH_TIMER_RCC == RCC_APB2Periph_TIM1 || STOPWATCH_TIMER_RCC
|
|
||||||
== RCC_APB2Periph_TIM8)
|
|
||||||
RCC_APB2PeriphClockCmd(STOPWATCH_TIMER_RCC, ENABLE);
|
|
||||||
else
|
|
||||||
RCC_APB1PeriphClockCmd(STOPWATCH_TIMER_RCC, ENABLE);
|
|
||||||
|
|
||||||
// time base configuration
|
|
||||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
|
||||||
TIM_TimeBaseStructure.TIM_Period = 0xffff; // max period
|
|
||||||
TIM_TimeBaseStructure.TIM_Prescaler = (72 * resolution) - 1; // <resolution> uS accuracy @ 72 MHz
|
|
||||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
|
||||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
|
||||||
TIM_TimeBaseInit(TIM, &TIM_TimeBaseStructure);
|
|
||||||
|
|
||||||
// enable interrupt request
|
|
||||||
TIM_ITConfig(TIM, TIM_IT_Update, ENABLE);
|
|
||||||
|
|
||||||
// start counter
|
|
||||||
TIM_Cmd(TIM, ENABLE);
|
|
||||||
|
|
||||||
return 0; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//! Resets the stopwatch
|
|
||||||
//! \return < 0 on errors
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t STOPWATCH_Reset(TIM_TypeDef* TIM) {
|
|
||||||
// reset counter
|
|
||||||
TIM->CNT = 1; // set to 1 instead of 0 to avoid new IRQ request
|
|
||||||
TIM_ClearITPendingBit(TIM, TIM_IT_Update);
|
|
||||||
|
|
||||||
return 0; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//! Returns current value of stopwatch
|
|
||||||
//! \return 1..65535: valid stopwatch value
|
|
||||||
//! \return 0xffffffff: counter overrun
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t STOPWATCH_ValueGet(TIM_TypeDef* TIM) {
|
|
||||||
uint32_t value = TIM->CNT;
|
|
||||||
|
|
||||||
if (TIM_GetITStatus(TIM, TIM_IT_Update) != RESET)
|
|
||||||
value = 0xffffffff;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
@ -38,10 +38,18 @@
|
|||||||
uint32_t STOPWATCH_Init(u32 resolution, TIM_TypeDef* TIM) {
|
uint32_t STOPWATCH_Init(u32 resolution, TIM_TypeDef* TIM) {
|
||||||
uint32_t STOPWATCH_TIMER_RCC;
|
uint32_t STOPWATCH_TIMER_RCC;
|
||||||
switch ((uint32_t) TIM) {
|
switch ((uint32_t) TIM) {
|
||||||
case (uint32_t)TIM1: STOPWATCH_TIMER_RCC = RCC_APB2Periph_TIM1;break;
|
case (uint32_t)TIM1:
|
||||||
case (uint32_t)TIM2: STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM2; break;
|
STOPWATCH_TIMER_RCC = RCC_APB2Periph_TIM1;
|
||||||
case (uint32_t)TIM3: STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM3; break;
|
break;
|
||||||
case (uint32_t)TIM4: STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM4; break;
|
case (uint32_t)TIM2:
|
||||||
|
STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM2;
|
||||||
|
break;
|
||||||
|
case (uint32_t)TIM3:
|
||||||
|
STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM3;
|
||||||
|
break;
|
||||||
|
case (uint32_t)TIM4:
|
||||||
|
STOPWATCH_TIMER_RCC = RCC_APB1Periph_TIM4;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
STOPWATCH_TIMER_RCC = RCC_APB2Periph_TIM1;
|
STOPWATCH_TIMER_RCC = RCC_APB2Periph_TIM1;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user