Updated STM32 port to work with latest stack demos.

This commit is contained in:
skarg
2011-04-25 04:24:03 +00:00
parent 68273edcb9
commit 6df76ec9da
7 changed files with 254 additions and 38 deletions
+2 -2
View File
@@ -49,12 +49,12 @@ static struct itimer DCC_Timer;
void bacnet_init( void bacnet_init(
void) void)
{ {
dlmstp_set_mac_address(103); dlmstp_set_mac_address(255);
dlmstp_set_max_master(127); dlmstp_set_max_master(127);
/* initialize datalink layer */ /* initialize datalink layer */
dlmstp_init(NULL); dlmstp_init(NULL);
/* initialize objects */ /* initialize objects */
Device_Init(); Device_Init(NULL);
/* set up our confirmed service unrecognized service handler - required! */ /* set up our confirmed service unrecognized service handler - required! */
apdu_set_unrecognized_service_handler_handler apdu_set_unrecognized_service_handler_handler
+43 -9
View File
@@ -12,7 +12,7 @@
<name>General</name> <name>General</name>
<archiveVersion>3</archiveVersion> <archiveVersion>3</archiveVersion>
<data> <data>
<version>20</version> <version>21</version>
<wantNonLocal>1</wantNonLocal> <wantNonLocal>1</wantNonLocal>
<debug>1</debug> <debug>1</debug>
<option> <option>
@@ -87,7 +87,7 @@
</option> </option>
<option> <option>
<name>OGLastSavedByProductVersion</name> <name>OGLastSavedByProductVersion</name>
<state>6.10.3.52260</state> <state>6.10.5.52324</state>
</option> </option>
<option> <option>
<name>GeneralEnableMisra</name> <name>GeneralEnableMisra</name>
@@ -145,13 +145,21 @@
<version>18</version> <version>18</version>
<state>37</state> <state>37</state>
</option> </option>
<option>
<name>OGUseCmsis</name>
<state>0</state>
</option>
<option>
<name>OGUseCmsisDspLib</name>
<state>0</state>
</option>
</data> </data>
</settings> </settings>
<settings> <settings>
<name>ICCARM</name> <name>ICCARM</name>
<archiveVersion>2</archiveVersion> <archiveVersion>2</archiveVersion>
<data> <data>
<version>26</version> <version>27</version>
<wantNonLocal>1</wantNonLocal> <wantNonLocal>1</wantNonLocal>
<debug>1</debug> <debug>1</debug>
<option> <option>
@@ -299,6 +307,7 @@
<name>CCIncludePath2</name> <name>CCIncludePath2</name>
<state>$PROJ_DIR$</state> <state>$PROJ_DIR$</state>
<state>$PROJ_DIR$\..\..\include</state> <state>$PROJ_DIR$\..\..\include</state>
<state>$PROJ_DIR$\..\..\demo\object</state>
<state>$PROJ_DIR$\CMSIS\CM3\CoreSupport</state> <state>$PROJ_DIR$\CMSIS\CM3\CoreSupport</state>
<state>$PROJ_DIR$\CMSIS\CM3\DeviceSupport\ST\STM32F10x</state> <state>$PROJ_DIR$\CMSIS\CM3\DeviceSupport\ST\STM32F10x</state>
<state>$PROJ_DIR$\drivers\inc</state> <state>$PROJ_DIR$\drivers\inc</state>
@@ -390,6 +399,10 @@
<name>IccCppInlineSemantics</name> <name>IccCppInlineSemantics</name>
<state>0</state> <state>0</state>
</option> </option>
<option>
<name>IccCmsis</name>
<state>1</state>
</option>
</data> </data>
</settings> </settings>
<settings> <settings>
@@ -609,7 +622,7 @@
<name>ILINK</name> <name>ILINK</name>
<archiveVersion>0</archiveVersion> <archiveVersion>0</archiveVersion>
<data> <data>
<version>11</version> <version>12</version>
<wantNonLocal>1</wantNonLocal> <wantNonLocal>1</wantNonLocal>
<debug>1</debug> <debug>1</debug>
<option> <option>
@@ -855,6 +868,10 @@
<name>IlinkOptExceptionsForce</name> <name>IlinkOptExceptionsForce</name>
<state>0</state> <state>0</state>
</option> </option>
<option>
<name>IlinkCmsis</name>
<state>1</state>
</option>
</data> </data>
</settings> </settings>
<settings> <settings>
@@ -894,7 +911,7 @@
<name>General</name> <name>General</name>
<archiveVersion>3</archiveVersion> <archiveVersion>3</archiveVersion>
<data> <data>
<version>20</version> <version>21</version>
<wantNonLocal>1</wantNonLocal> <wantNonLocal>1</wantNonLocal>
<debug>0</debug> <debug>0</debug>
<option> <option>
@@ -969,7 +986,7 @@
</option> </option>
<option> <option>
<name>OGLastSavedByProductVersion</name> <name>OGLastSavedByProductVersion</name>
<state>6.10.3.52260</state> <state>6.10.5.52324</state>
</option> </option>
<option> <option>
<name>GeneralEnableMisra</name> <name>GeneralEnableMisra</name>
@@ -1027,13 +1044,21 @@
<version>18</version> <version>18</version>
<state>37</state> <state>37</state>
</option> </option>
<option>
<name>OGUseCmsis</name>
<state>0</state>
</option>
<option>
<name>OGUseCmsisDspLib</name>
<state>0</state>
</option>
</data> </data>
</settings> </settings>
<settings> <settings>
<name>ICCARM</name> <name>ICCARM</name>
<archiveVersion>2</archiveVersion> <archiveVersion>2</archiveVersion>
<data> <data>
<version>26</version> <version>27</version>
<wantNonLocal>1</wantNonLocal> <wantNonLocal>1</wantNonLocal>
<debug>0</debug> <debug>0</debug>
<option> <option>
@@ -1182,6 +1207,7 @@
<name>CCIncludePath2</name> <name>CCIncludePath2</name>
<state>$PROJ_DIR$</state> <state>$PROJ_DIR$</state>
<state>$PROJ_DIR$\..\..\include</state> <state>$PROJ_DIR$\..\..\include</state>
<state>$PROJ_DIR$\..\..\demo\object</state>
<state>$PROJ_DIR$\CMSIS\CM3\CoreSupport</state> <state>$PROJ_DIR$\CMSIS\CM3\CoreSupport</state>
<state>$PROJ_DIR$\CMSIS\CM3\DeviceSupport\ST\STM32F10x</state> <state>$PROJ_DIR$\CMSIS\CM3\DeviceSupport\ST\STM32F10x</state>
<state>$PROJ_DIR$\drivers\inc</state> <state>$PROJ_DIR$\drivers\inc</state>
@@ -1273,6 +1299,10 @@
<name>IccCppInlineSemantics</name> <name>IccCppInlineSemantics</name>
<state>0</state> <state>0</state>
</option> </option>
<option>
<name>IccCmsis</name>
<state>1</state>
</option>
</data> </data>
</settings> </settings>
<settings> <settings>
@@ -1492,12 +1522,12 @@
<name>ILINK</name> <name>ILINK</name>
<archiveVersion>0</archiveVersion> <archiveVersion>0</archiveVersion>
<data> <data>
<version>11</version> <version>12</version>
<wantNonLocal>1</wantNonLocal> <wantNonLocal>1</wantNonLocal>
<debug>0</debug> <debug>0</debug>
<option> <option>
<name>IlinkOutputFile</name> <name>IlinkOutputFile</name>
<state>c.out</state> <state>bacnet.out</state>
</option> </option>
<option> <option>
<name>IlinkLibIOConfig</name> <name>IlinkLibIOConfig</name>
@@ -1738,6 +1768,10 @@
<name>IlinkOptExceptionsForce</name> <name>IlinkOptExceptionsForce</name>
<state>0</state> <state>0</state>
</option> </option>
<option>
<name>IlinkCmsis</name>
<state>1</state>
</option>
</data> </data>
</settings> </settings>
<settings> <settings>
+39 -18
View File
@@ -141,7 +141,6 @@ static int Read_Property_Common(
{ {
int apdu_len = BACNET_STATUS_ERROR; int apdu_len = BACNET_STATUS_ERROR;
BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING char_string;
char *pString = "";
uint8_t *apdu = NULL; uint8_t *apdu = NULL;
if ((rpdata->application_data == NULL) || if ((rpdata->application_data == NULL) ||
@@ -151,29 +150,50 @@ static int Read_Property_Common(
apdu = rpdata->application_data; apdu = rpdata->application_data;
switch (rpdata->object_property) { switch (rpdata->object_property) {
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
/* Device Object exception: requested instance /* only array properties can have array options */
may not match our instance if a wildcard */ if (rpdata->array_index != BACNET_ARRAY_ALL) {
if (rpdata->object_type == OBJECT_DEVICE) { rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->object_instance = Object_Instance_Number; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR;
} else {
/* Device Object exception: requested instance
may not match our instance if a wildcard */
if (rpdata->object_type == OBJECT_DEVICE) {
rpdata->object_instance = Object_Instance_Number;
}
apdu_len =
encode_application_object_id(&apdu[0], rpdata->object_type,
rpdata->object_instance);
} }
apdu_len =
encode_application_object_id(&apdu[0], rpdata->object_type,
rpdata->object_instance);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (pObject->Object_Name) { /* only array properties can have array options */
(void)pObject->Object_Name( if (rpdata->array_index != BACNET_ARRAY_ALL) {
rpdata->object_instance, rpdata->error_class = ERROR_CLASS_PROPERTY;
&char_string); rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR;
} else { } else {
characterstring_init_ansi(&char_string, ""); characterstring_init_ansi(&char_string, "");
if (pObject->Object_Name) {
(void)pObject->Object_Name(
rpdata->object_instance,
&char_string);
}
} }
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = /* only array properties can have array options */
encode_application_enumerated(&apdu[0], rpdata->object_type); if (rpdata->array_index != BACNET_ARRAY_ALL) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR;
} else {
apdu_len =
encode_application_enumerated(&apdu[0],
rpdata->object_type);
}
break; break;
default: default:
if (pObject->Object_Read_Property) { if (pObject->Object_Read_Property) {
@@ -363,10 +383,11 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
} }
void Device_Init( void Device_Init(
void) object_functions_t * object_table)
{ {
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
(void)object_table;
pObject = &Object_Table[0]; pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Init) { if (pObject->Object_Init) {
@@ -520,7 +541,7 @@ bool Device_Valid_Object_Name(
for (i = 0; i < max_objects; i++) { for (i = 0; i < max_objects; i++) {
check_id = Device_Object_List_Identifier(i, &type, &instance); check_id = Device_Object_List_Identifier(i, &type, &instance);
if (check_id) { if (check_id) {
pObject = Device_Objects_Find_Functions(type); pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) && if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) && (pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) { characterstring_same(object_name1, &object_name2))) {
@@ -546,7 +567,7 @@ bool Device_Valid_Object_Id(
bool status = false; /* return value */ bool status = false; /* return value */
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions(object_type); pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)object_type);
if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) { if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) {
status = pObject->Object_Valid_Instance(object_instance); status = pObject->Object_Valid_Instance(object_instance);
} }
@@ -570,7 +591,7 @@ bool Device_Object_Name_Copy(
for (i = 0; i < max_objects; i++) { for (i = 0; i < max_objects; i++) {
check_id = Device_Object_List_Identifier(i, &type, &instance); check_id = Device_Object_List_Identifier(i, &type, &instance);
if (check_id) { if (check_id) {
pObject = Device_Objects_Find_Functions(type); pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
if ((pObject != NULL) && (pObject->Object_Name != NULL)) { if ((pObject != NULL) && (pObject->Object_Name != NULL)) {
found = pObject->Object_Name(instance, object_name); found = pObject->Object_Name(instance, object_name);
break; break;
+91 -7
View File
@@ -30,6 +30,7 @@ static struct itimer Off_Delay_Timer_Rx;
static struct itimer Off_Delay_Timer_Tx; static struct itimer Off_Delay_Timer_Tx;
static bool Rx_State; static bool Rx_State;
static bool Tx_State; static bool Tx_State;
static bool LD3_State;
/************************************************************************* /*************************************************************************
* Description: Activate the LED * Description: Activate the LED
@@ -104,7 +105,7 @@ bool led_tx_state(void)
} }
/************************************************************************* /*************************************************************************
* Description: Toggle the state of the setup LED * Description: Toggle the state of the LED
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
@@ -118,7 +119,7 @@ void led_tx_toggle(void)
} }
/************************************************************************* /*************************************************************************
* Description: Toggle the state of the setup LED * Description: Toggle the state of the LED
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
@@ -195,6 +196,76 @@ void led_task(
} }
} }
/*************************************************************************
* Description: Activate the LED
* Returns: nothing
* Notes: none
**************************************************************************/
void led_ld4_on(
void)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
}
/*************************************************************************
* Description: Deactivate the LED
* Returns: nothing
* Notes: none
**************************************************************************/
void led_ld4_off(
void)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
}
/*************************************************************************
* Description: Activate the LED
* Returns: nothing
* Notes: none
**************************************************************************/
void led_ld3_on(
void)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
LD3_State = true;
}
/*************************************************************************
* Description: Deactivate the LED
* Returns: nothing
* Notes: none
**************************************************************************/
void led_ld3_off(
void)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
LD3_State = false;
}
/*************************************************************************
* Description: Get the state of the LED
* Returns: true if on, false if off.
* Notes: none
*************************************************************************/
bool led_ld3_state(void)
{
return LD3_State;
}
/*************************************************************************
* Description: Toggle the state of the LED
* Returns: none
* Notes: none
*************************************************************************/
void led_ld3_toggle(void)
{
if (led_ld3_state()) {
led_ld3_off();
} else {
led_ld3_on();
}
}
/************************************************************************* /*************************************************************************
* Description: Initialize the LED hardware * Description: Initialize the LED hardware
* Returns: none * Returns: none
@@ -206,19 +277,32 @@ void led_init(
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure); GPIO_StructInit(&GPIO_InitStructure);
/* Configure the Receive LED */ /* Configure the Receive LED on MS/TP board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure the Transmit LED */ /* Configure the Transmit LED on MS/TP board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure the LD4 on Discovery board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure the LD3 on Discovery board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Enable the GPIO_LED Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
led_tx_on_interval(500); led_tx_on();
led_rx_on_interval(500); led_rx_on();
led_ld3_on();
led_ld4_on();
} }
+11
View File
@@ -31,6 +31,17 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
void led_ld3_on(
void);
void led_ld4_on(
void);
void led_ld3_off(
void);
void led_ld4_off(
void);
bool led_ld3_state(void);
void led_ld3_toggle(void);
void led_tx_on(void); void led_tx_on(void);
void led_rx_on(void); void led_rx_on(void);
+66
View File
@@ -56,20 +56,86 @@ void assert_failed(uint8_t* file, uint32_t line)
} }
#endif #endif
/* Private define ------------------------------------------------------------*/
#define LSE_FAIL_FLAG 0x80
#define LSE_PASS_FLAG 0x100
void lse_init(void)
{
uint32_t LSE_Delay = 0;
struct etimer Delay_Timer;
/* Enable access to the backup register => LSE can be enabled */
PWR_BackupAccessCmd(ENABLE);
/* Enable LSE (Low Speed External Oscillation) */
RCC_LSEConfig(RCC_LSE_ON);
/* Check the LSE Status */
while(1)
{
if(LSE_Delay < LSE_FAIL_FLAG)
{
timer_elapsed_start(&Delay_Timer);
while (!timer_elapsed_milliseconds(&Delay_Timer,500)) {
/* do nothing */
}
/* check whether LSE is ready, with 4 seconds timeout */
LSE_Delay += 0x10;
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET)
{
/* Set flag: LSE PASS */
LSE_Delay |= LSE_PASS_FLAG;
led_ld4_off();
/* Disable LSE */
RCC_LSEConfig(RCC_LSE_OFF);
break;
}
}
/* LSE_FAIL_FLAG = 0x80 */
else if(LSE_Delay >= LSE_FAIL_FLAG)
{
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
/* Set flag: LSE FAIL */
LSE_Delay |= LSE_FAIL_FLAG;
led_ld4_on();
}
/* Disable LSE */
RCC_LSEConfig(RCC_LSE_OFF);
break;
}
}
}
int main( int main(
void) void)
{ {
struct itimer Blink_Timer;
/*At this stage the microcontroller clock setting is already configured, /*At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main. file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file */ system_stm32f10x.c file */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
led_init();
RCC_APB2PeriphClockCmd(
RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, ENABLE);
timer_init(); timer_init();
lse_init();
led_init(); led_init();
rs485_init(); rs485_init();
bacnet_init(); bacnet_init();
timer_interval_start(&Blink_Timer, 125);
for (;;) { for (;;) {
if (timer_interval_expired(&Blink_Timer)) {
timer_interval_reset(&Blink_Timer);
led_ld3_toggle();
}
led_task(); led_task();
bacnet_task(); bacnet_task();
} }
@@ -5,9 +5,9 @@
define symbol __ICFEDIT_intvec_start__ = 0x08000000; define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/ /*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ; define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ;
define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF; define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF; define symbol __ICFEDIT_region_RAM_end__ = 0x20017FFF;
/*-Sizes-*/ /*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x800; define symbol __ICFEDIT_size_cstack__ = 0x800;
define symbol __ICFEDIT_size_heap__ = 0x200; define symbol __ICFEDIT_size_heap__ = 0x200;