/*\r
- FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+ FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+\r
+\r
+ FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
+ Atollic AB - Atollic provides professional embedded systems development\r
+ tools for C/C++ development, code analysis and test automation.\r
+ See http://www.atollic.com\r
+\r
\r
***************************************************************************\r
- * *\r
- * If you are: *\r
- * *\r
- * + New to FreeRTOS, *\r
- * + Wanting to learn FreeRTOS or multitasking in general quickly *\r
- * + Looking for basic training, *\r
- * + Wanting to improve your FreeRTOS skills and productivity *\r
- * *\r
- * then take a look at the FreeRTOS books - available as PDF or paperback *\r
- * *\r
- * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *\r
- * http://www.FreeRTOS.org/Documentation *\r
- * *\r
- * A pdf reference manual is also available. Both are usually delivered *\r
- * to your inbox within 20 minutes to two hours when purchased between 8am *\r
- * and 8pm GMT (although please allow up to 24 hours in case of *\r
- * exceptional circumstances). Thank you for your support! *\r
- * *\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
***************************************************************************\r
\r
+\r
This file is part of the FreeRTOS distribution.\r
\r
FreeRTOS is free software; you can redistribute it and/or modify it under\r
the terms of the GNU General Public License (version 2) as published by the\r
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- ***NOTE*** The exception to the GPL is included to allow you to distribute\r
- a combined work that includes FreeRTOS without being obliged to provide the\r
- source code for proprietary components outside of the FreeRTOS kernel.\r
- FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
more details. You should have received a copy of the GNU General Public\r
License and the FreeRTOS license exception along with FreeRTOS; if not it\r
can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
* executed from within CCS4! Once it has been executed, re-open or refresh \r
* the CCS4 project and remove the #error line below.\r
*/\r
-//#error Ensure CreateProjectDirectoryStructure.bat has been executed before building. See comment immediately above.\r
+#error Ensure CreateProjectDirectoryStructure.bat has been executed before building. See comment immediately above.\r
\r
\r
#ifndef FREERTOS_CONFIG_H\r
#define FREERTOS_CONFIG_H\r
\r
+#include <stdint.h>\r
+#include <stddef.h>\r
+\r
/*-----------------------------------------------------------\r
* Application specific definitions.\r
*\r
* See http://www.freertos.org/a00110.html.\r
*----------------------------------------------------------*/\r
\r
+extern uint32_t SystemFrequency;\r
+\r
#define configUSE_PREEMPTION 1\r
#define configUSE_IDLE_HOOK 1\r
#define configUSE_TICK_HOOK 0\r
-#define configCPU_CLOCK_HZ ( 75000000UL )\r
+#define configCPU_CLOCK_HZ ( SystemFrequency )\r
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )\r
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )\r
-#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 )\r
-#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 40 * 1024 ) )\r
+#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 90 )\r
+#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 30 * 1024 ) )\r
#define configMAX_TASK_NAME_LEN ( 10 )\r
#define configUSE_TRACE_FACILITY 1\r
#define configUSE_16_BIT_TICKS 0\r
#define configIDLE_SHOULD_YIELD 1\r
#define configUSE_MUTEXES 1\r
#define configQUEUE_REGISTRY_SIZE 0\r
-#define configGENERATE_RUN_TIME_STATS 0\r
+#define configGENERATE_RUN_TIME_STATS 1\r
#define configCHECK_FOR_STACK_OVERFLOW 2\r
#define configUSE_RECURSIVE_MUTEXES 1\r
#define configUSE_MALLOC_FAILED_HOOK 1\r
\r
/* Software timer definitions. */\r
#define configUSE_TIMERS 1\r
-#define configTIMER_TASK_PRIORITY ( 3 )\r
+#define configTIMER_TASK_PRIORITY ( 2 )\r
#define configTIMER_QUEUE_LENGTH 10\r
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )\r
\r
#define INCLUDE_vTaskDelayUntil 1\r
#define INCLUDE_vTaskDelay 1\r
\r
+void vMainConfigureTimerForRunTimeStats( void );\r
+unsigned long ulGetRunTimeCounterValue( void );\r
+#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vMainConfigureTimerForRunTimeStats()\r
+#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()\r
+\r
/* Use the system definition, if there is one */\r
#ifdef __NVIC_PRIO_BITS\r
#define configPRIO_BITS __NVIC_PRIO_BITS\r
* SVN $Revision: 2152 $\r
* SVN $Date: 2010-02-11 14:44:11 +0000 (Thu, 11 Feb 2010) $\r
*/\r
+\r
+\r
#include "i2c.h"\r
#include "../../CMSIS/mss_assert.h"\r
\r
this_i2c->hw_reg_bit->CTRL_CR1 = (clock_speed >> 1) & 0x01;\r
this_i2c->hw_reg_bit->CTRL_CR0 = clock_speed & 0x01;\r
this_i2c->hw_reg->ADDR = this_i2c->ser_address;\r
+ \r
+ /* The interrupt can cause a context switch, so ensure its priority is\r
+ between configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY. */\r
+ NVIC_SetPriority( this_i2c->irqn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
+ \r
+ vSemaphoreCreateBinary( ( this_i2c->xI2CCompleteSemaphore ) );\r
+ xSemaphoreTake( ( this_i2c->xI2CCompleteSemaphore ), 0 );\r
+ configASSERT( ( this_i2c->xI2CCompleteSemaphore ) );\r
}\r
\r
/*------------------------------------------------------------------------------\r
uint32_t primask;\r
\r
ASSERT( (this_i2c == &g_mss_i2c0) || (this_i2c == &g_mss_i2c1) );\r
+ configASSERT( ( this_i2c->xI2CCompleteSemaphore ) );\r
\r
primask = disable_interrupts();\r
\r
{\r
ASSERT( (this_i2c == &g_mss_i2c0) || (this_i2c == &g_mss_i2c1) );\r
\r
+#ifdef USE_OLD_I2C_POLLING_CODE\r
while ( this_i2c->status == MSS_I2C_IN_PROGRESS )\r
{\r
/* Wait for transaction to compltete.*/\r
;\r
}\r
+#else\r
+ configASSERT( ( this_i2c->xI2CCompleteSemaphore ) );\r
+ if( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED )\r
+ {\r
+ while ( this_i2c->status == MSS_I2C_IN_PROGRESS )\r
+ {\r
+ /* Wait for transaction to compltete.*/\r
+ ;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ xSemaphoreTake( this_i2c->xI2CCompleteSemaphore, portMAX_DELAY );\r
+ }\r
+#endif\r
+\r
return this_i2c->status;\r
}\r
\r
static void mss_i2c_isr\r
(\r
mss_i2c_instance_t * this_i2c\r
-)\r
+ )\r
{\r
volatile uint8_t status;\r
uint8_t data;\r
uint8_t hold_bus;\r
uint8_t clear_irq = 1;\r
+ long lHigherPriorityTaskWoken = pdFALSE;\r
+ configASSERT( ( this_i2c->xI2CCompleteSemaphore ) );\r
\r
ASSERT( (this_i2c == &g_mss_i2c0) || (this_i2c == &g_mss_i2c1) );\r
\r
clear_irq = 0;\r
}\r
this_i2c->status = MSS_I2C_SUCCESS;\r
+ xSemaphoreGiveFromISR( this_i2c->xI2CCompleteSemaphore, &lHigherPriorityTaskWoken );\r
}\r
break;\r
\r
clear_irq = 0;\r
}\r
this_i2c->status = MSS_I2C_SUCCESS;\r
+ xSemaphoreGiveFromISR( this_i2c->xI2CCompleteSemaphore, &lHigherPriorityTaskWoken );\r
}\r
break;\r
\r
case ST_SLAR_NACK: /* SLA+R tx'ed; let's release the bus (send a stop condition) */\r
this_i2c->hw_reg_bit->CTRL_STO = 0x01;\r
this_i2c->status = MSS_I2C_FAILED;\r
+ xSemaphoreGiveFromISR( this_i2c->xI2CCompleteSemaphore, &lHigherPriorityTaskWoken );\r
break;\r
\r
case ST_RX_DATA_ACK: /* Data byte received, ACK returned */\r
}\r
\r
this_i2c->status = MSS_I2C_SUCCESS;\r
+// xSemaphoreGiveFromISR( this_i2c->xI2CCompleteSemaphore, &lHigherPriorityTaskWoken );\r
break;\r
\r
/******************** SLAVE RECEIVER **************************/\r
}\r
/* Mark any previous master write transaction as complete. */\r
this_i2c->status = MSS_I2C_SUCCESS;\r
+// xSemaphoreGiveFromISR( this_i2c->xI2CCompleteSemaphore, &lHigherPriorityTaskWoken );\r
break;\r
\r
case ST_SLV_RST: /* SMBUS ONLY: timeout state. must clear interrupt */\r
/* Read the status register to ensure the last I2C registers write took place\r
* in a system built around a bus making use of posted writes. */\r
status = this_i2c->hw_reg->STATUS;\r
+ \r
+ portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
}\r
\r
/*------------------------------------------------------------------------------\r
\r
#include "../../CMSIS/a2fxxxm3.h"\r
\r
+/* FreeRTOS includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
#ifdef __cplusplus\r
extern "C" {\r
#endif\r
/* Slave data: */\r
uint_fast8_t slave_mem_offset_length;\r
mss_i2c_slave_wr_handler_t slave_write_handler;\r
-\r
+ \r
+ /* Used to get access to and wait for completion of an I2C transaction. */\r
+ xSemaphoreHandle xI2CCompleteSemaphore;\r
+ \r
} mss_i2c_instance_t;\r
\r
/*-------------------------------------------------------------------------*//**\r
*\r
******************************************************************************/\r
\r
+/*\r
+ *\r
+ *\r
+ * NOTE: This driver has been modified specifically for use with the* uIP stack.\r
+ * It is no longer a generic driver.\r
+ *\r
+ *\r
+ */\r
+\r
#ifdef __cplusplus\r
extern "C" {\r
-#endif \r
+#endif\r
\r
#include "FreeRTOS.h"\r
#include "task.h"\r
/**************************** INTERNAL DEFINES ********************************/\r
\r
#define MAC_CHECK(CHECK,ERRNO) \\r
- {if(!(CHECK)){g_mss_mac.last_error=(ERRNO); ASSERT((CHECK));}}\r
+ {if(!(CHECK)){g_mss_mac.last_error=(ERRNO); configASSERT((CHECK));}}\r
\r
/*\r
* Flags\r
/* Allocating this many buffers will always ensure there is one free as, even\r
though TX_RING_SIZE is set to two, the two Tx descriptors will only ever point\r
to the same buffer. */\r
-#define macNUM_BUFFERS RX_RING_SIZE + TX_RING_SIZE\r
-#define macBUFFER_SIZE 1500\r
+#define macNUM_BUFFERS RX_RING_SIZE + TX_RING_SIZE + 1\r
+#define macBUFFER_SIZE 1488\r
\r
/***************************************************************/\r
MAC_instance_t g_mss_mac;\r
/*\r
* Null variables\r
*/\r
-static MAC_instance_t* NULL_instance;\r
static uint8_t* NULL_buffer;\r
static MSS_MAC_callback_t NULL_callback;\r
+\r
+/* Declare the uip_buf as a pointer, rather than the traditional array, as this\r
+is a zero copy driver. uip_buf just gets set to whichever buffer is being\r
+processed. */\r
unsigned char *uip_buf = NULL;\r
\r
/**************************** INTERNAL FUNCTIONS ******************************/\r
\r
-static int32_t MAC_test_instance( void );\r
-\r
static int32_t MAC_dismiss_bad_frames( void );\r
static int32_t MAC_send_setup_frame( void );\r
\r
#error This uIP Ethernet driver required TX_RING_SIZE to be set to 2\r
#endif\r
\r
-/* Buffers that will dynamically be allocated to/from the Tx and Rx descriptors. */\r
-static unsigned char ucMACBuffers[ macNUM_BUFFERS ][ macBUFFER_SIZE ];\r
+/* Buffers that will dynamically be allocated to/from the Tx and Rx descriptors.\r
+The union is used for alignment only. */\r
+static union xMAC_BUFFERS\r
+{\r
+ unsigned long ulAlignmentVariable; /* For alignment only, not used anywhere. */\r
+ unsigned char ucBuffer[ macNUM_BUFFERS ][ macBUFFER_SIZE ];\r
+} xMACBuffers;\r
\r
-/* Each array position indicated whether or not the buffer of the same index\r
-is currently allocated to a descriptor (pdFALSE) or is free for use (pdTRUE). */\r
-static unsigned char ucMACBufferFree[ macNUM_BUFFERS ];\r
+/* Each array position indicates whether or not the buffer of the same index\r
+is currently allocated to a descriptor (pdTRUE) or is free for use (pdFALSE). */\r
+static unsigned char ucMACBufferInUse[ macNUM_BUFFERS ] = { 0 };\r
\r
/***************************************************************************//**\r
* Initializes the Ethernet Controller.\r
/* To start with all buffers are free. */\r
for( a = 0; a < macNUM_BUFFERS; a++ )\r
{\r
- ucMACBufferFree[ a ] = pdTRUE;\r
+ ucMACBufferInUse[ a ] = pdFALSE;\r
}\r
\r
/* Try to reset chip */\r
\r
/* Check reset values of some registers to constrol\r
* base address validity */\r
- ASSERT( MAC->CSR0 == 0xFE000000uL );\r
- ASSERT( MAC->CSR5 == 0xF0000000uL );\r
- ASSERT( MAC->CSR6 == 0x32000040uL );\r
+ configASSERT( MAC->CSR0 == 0xFE000000uL );\r
+ configASSERT( MAC->CSR5 == 0xF0000000uL );\r
+ configASSERT( MAC->CSR6 == 0x32000040uL );\r
\r
/* Instance setup */\r
MAC_memset_All( &g_mss_mac, 0u );\r
\r
/* Allocate a buffer to the descriptor, then mark the buffer as in use\r
(not free). */\r
- g_mss_mac.rx_descriptors[a].buffer_1 = ( unsigned long ) &( ucMACBuffers[ a ][ 0 ] );\r
- ucMACBufferFree[ a ] = pdFALSE;\r
+ g_mss_mac.rx_descriptors[a].buffer_1 = ( unsigned long ) &( xMACBuffers.ucBuffer[ a ][ 0 ] );\r
+ ucMACBufferInUse[ a ] = pdTRUE;\r
}\r
g_mss_mac.rx_descriptors[RX_RING_SIZE-1].descriptor_1 |= RDES1_RER;\r
\r
MAC_BITBAND->CSR0_BAR = (uint32_t)BUS_ARBITRATION_SCHEME;\r
\r
/* Fixed settings */\r
- /* No automatic polling */\r
- MAC->CSR0 = MAC->CSR0 &~ CSR0_TAP_MASK;\r
/* No space between descriptors */\r
MAC->CSR0 = MAC->CSR0 &~ CSR0_DSL_MASK;\r
/* General-purpose timer works in continuous mode */\r
/* Start general-purpose */\r
MAC->CSR11 = (MAC->CSR11 & ~CSR11_TIM_MASK) | (0x0000FFFFuL << CSR11_TIM_SHIFT);\r
\r
- /* Disable promiscuous mode */\r
- MAC_BITBAND->CSR6_PR = 0u;\r
-\r
- /* Enable store and forward */\r
- MAC_BITBAND->CSR6_SF = 1u;\r
-\r
+ /* Ensure promiscous mode is off (it should be by default anyway). */\r
+ MAC_BITBAND->CSR6_PR = 0;\r
+ \r
+ /* Perfect filter. */\r
+ MAC_BITBAND->CSR6_HP = 1;\r
+ \r
+ /* Pass multcast. */\r
+ MAC_BITBAND->CSR6_PM = 1;\r
+ \r
/* Set descriptors */\r
MAC->CSR3 = (uint32_t)&(g_mss_mac.rx_descriptors[0].descriptor_0);\r
MAC->CSR4 = (uint32_t)&(g_mss_mac.tx_descriptors[0].descriptor_0);\r
- \r
+\r
/* enable normal interrupts */\r
MAC_BITBAND->CSR7_NIE = 1u;\r
\r
+ /* Set default MAC address and reset mac filters */\r
+ MAC_memcpy( g_mss_mac.mac_address, mac_address, 6u );\r
+ MSS_MAC_set_mac_address((uint8_t *)mac_address);\r
+ \r
/* Detect PHY */\r
if( g_mss_mac.phy_address > MSS_PHY_ADDRESS_MAX )\r
{\r
PHY_probe();\r
- ASSERT( g_mss_mac.phy_address <= MSS_PHY_ADDRESS_MAX );\r
+ configASSERT( g_mss_mac.phy_address <= MSS_PHY_ADDRESS_MAX );\r
}\r
\r
/* Reset PHY */\r
PHY_reset();\r
\r
- /* Set flags */\r
- g_mss_mac.flags = FLAG_MAC_INIT_DONE | FLAG_PERFECT_FILTERING;\r
-\r
/* Configure chip according to PHY status */\r
MSS_MAC_auto_setup_link();\r
-\r
- /* Set default MAC address and reset mac filters */\r
- MAC_memcpy( g_mss_mac.mac_address, mac_address, 6u );\r
- MSS_MAC_set_mac_filters( 0u, NULL_buffer );\r
- MAC_BITBAND->CSR6_RA = 1; /* Receive all. */\r
+ \r
+ /* Ensure uip_buf starts by pointing somewhere. */\r
+ uip_buf = MAC_obtain_buffer(); \r
}\r
\r
\r
{\r
int32_t ret;\r
\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
ret = MAC_stop_transmission();\r
- ASSERT( ret == MAC_OK );\r
+ configASSERT( ret == MAC_OK );\r
\r
ret = MAC_stop_receiving();\r
- ASSERT( ret == MAC_OK );\r
+ configASSERT( ret == MAC_OK );\r
\r
MAC_BITBAND->CSR6_RA = (uint32_t)(((configuration & MSS_MAC_CFG_RECEIVE_ALL) != 0u) ? 1u : 0u );\r
MAC_BITBAND->CSR6_TTM = (((configuration & MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE) != 0u) ? 1u : 0u );\r
MAC_BITBAND->CSR6_SF = (uint32_t)(((configuration & MSS_MAC_CFG_STORE_AND_FORWARD) != 0u) ? 1u : 0u );\r
- \r
+\r
switch( configuration & MSS_MAC_CFG_THRESHOLD_CONTROL_11 ) {\r
case MSS_MAC_CFG_THRESHOLD_CONTROL_00:\r
MAC->CSR6 = MAC->CSR6 & ~CSR6_TR_MASK;\r
{\r
uint32_t configuration;\r
\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
configuration = 0u;\r
if( MAC_BITBAND->CSR6_RA != 0u ) {\r
configuration |= MSS_MAC_CFG_RECEIVE_ALL;\r
if( MAC_BITBAND->CSR6_HP != 0u ) {\r
configuration |= MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE;\r
}\r
- \r
+\r
return (int32_t)configuration;\r
}\r
\r
the transmit FIFO and then activates the transmitter for this packet. If space\r
is available in the FIFO, the function will return once pac_len bytes of the\r
packet have been placed into the FIFO and the transmitter has been started.\r
- This function will not wait for the transmission to complete. \r
+ This function will not wait for the transmission to complete.\r
\r
@return\r
The function returns zero if a timeout occurs otherwise it returns size of the packet.\r
- \r
+\r
@see MAC_rx_packet()\r
*/\r
\r
uint32_t desc;\r
unsigned long ulDescriptor;\r
int32_t error = MAC_OK;\r
- extern unsigned char *uip_buf;\r
-\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
\r
- ASSERT( uip_buf != NULL_buffer );\r
+ configASSERT( uip_buf != NULL_buffer );\r
\r
- ASSERT( usLength >= 12 );\r
+ configASSERT( usLength >= 12 );\r
\r
if( (g_mss_mac.flags & FLAG_EXCEED_LIMIT) == 0u )\r
{\r
- ASSERT( usLength <= MSS_MAX_PACKET_SIZE );\r
+ configASSERT( usLength <= MSS_MAX_PACKET_SIZE );\r
}\r
\r
/* Check if second descriptor is free, if it is then the first must\r
also be free. */\r
- if(((g_mss_mac.tx_descriptors[ 1 ].descriptor_0) & TDES0_OWN) == TDES0_OWN )\r
+ if( ( ( (g_mss_mac.tx_descriptors[ 0 ].descriptor_0) & TDES0_OWN) == TDES0_OWN ) || ( ( (g_mss_mac.tx_descriptors[ 1 ].descriptor_0) & TDES0_OWN) == TDES0_OWN ) )\r
{\r
error = MAC_BUFFER_IS_FULL;\r
}\r
\r
- if( error == MAC_OK ) {\r
- /* Assumed TX_RING_SIZE == 2. */\r
+ \r
+ if( error == MAC_OK )\r
+ {\r
+ /* Assumed TX_RING_SIZE == 2. A #error directive checks this is the\r
+ case. */\r
for( ulDescriptor = 0; ulDescriptor < TX_RING_SIZE; ulDescriptor++ )\r
{\r
- g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 = 0u;\r
+ g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 = 0u;\r
\r
if( (g_mss_mac.flags & FLAG_CRC_DISABLE) != 0u ) {\r
- g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 |= TDES1_AC;\r
+ g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 |= TDES1_AC;\r
}\r
\r
/* Every buffer can hold a full frame so they are always first and last\r
descriptor */\r
- g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 |= TDES1_LS | TDES1_FS;\r
+ g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 |= TDES1_LS | TDES1_FS | TDES1_IC;\r
\r
/* set data size */\r
- g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_1 |= usLength;\r
+ g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_1 |= usLength;\r
\r
/* reset end of ring */\r
g_mss_mac.tx_descriptors[TX_RING_SIZE-1].descriptor_1 |= TDES1_TER;\r
}\r
\r
/* The data buffer is assigned to the Tx descriptor. */\r
- g_mss_mac.tx_descriptors[ ulDescriptor ].buffer_1 = ( unsigned long ) uip_buf;\r
+ g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].buffer_1 = ( unsigned long ) uip_buf;\r
\r
/* update counters */\r
- desc = g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_0;\r
+ desc = g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_0;\r
if( (desc & TDES0_LO) != 0u ) {\r
g_mss_mac.statistics.tx_loss_of_carrier++;\r
}\r
(desc >> TDES0_CC_OFFSET) & TDES0_CC_MASK;\r
\r
/* Give ownership of descriptor to the MAC */\r
- g_mss_mac.tx_descriptors[ ulDescriptor ].descriptor_0 = TDES0_OWN;\r
-\r
- g_mss_mac.tx_desc_index = 0; \r
- }\r
+ g_mss_mac.tx_descriptors[ g_mss_mac.tx_desc_index ].descriptor_0 = RDES0_OWN;\r
+ \r
+ g_mss_mac.tx_desc_index = (g_mss_mac.tx_desc_index + 1u) % (uint32_t)TX_RING_SIZE;\r
+ \r
+ MAC_start_transmission();\r
+ MAC->CSR1 = 1u;\r
+ } \r
}\r
-\r
- /* Start transmission */\r
- MAC_start_transmission();\r
-\r
- /* transmit poll demand */\r
- MAC->CSR1 = 1u;\r
-\r
- \r
\r
if (error == MAC_OK)\r
{\r
- /* The buffer uip_buf was pointing to is now under the control of the \r
- MAC (it is being transmitted). Set uip_buf to point to a free buffer. */\r
- uip_buf = MAC_obtain_buffer();\r
error = (int32_t)usLength;\r
+ \r
+ /* The buffer pointed to by uip_buf is now assigned to a Tx descriptor.\r
+ Find anothere free buffer for uip_buf. */\r
+ uip_buf = MAC_obtain_buffer();\r
}\r
else\r
{\r
)\r
{\r
int32_t retval;\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
MAC_dismiss_bad_frames();\r
\r
if( (g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].descriptor_0 & RDES0_OWN) != 0u )\r
* Receives a packet from the Ethernet Controller into the uIP stack.\r
* This function reads a packet from the receive FIFO of the controller and\r
* places it into uip_buf.\r
- \r
+\r
* @return Size of packet if packet fits in uip_buf.\r
* 0 if there is no received packet.\r
* @see MAC_rx_pckt_size()\r
{\r
uint16_t frame_length=0u;\r
\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
- \r
MAC_dismiss_bad_frames();\r
\r
if( (g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].descriptor_0 & RDES0_OWN) == 0u )\r
if( frame_length > macBUFFER_SIZE ) {\r
return MAC_NOT_ENOUGH_SPACE;\r
}\r
- \r
+\r
/* uip_buf is about to point to the buffer that contains the received\r
data, mark the buffer that uip_buf is currently pointing to as free\r
again. */\r
/***************************************************************************//**\r
* Receives a packet from the Ethernet Controller.\r
* This function reads a packet from the receive FIFO of the controller and\r
- * sets the address of pacData to the received data. \r
+ * sets the address of pacData to the received data.\r
* If time_out parameter is zero the function will return\r
* immediately (after the copy operation if data is available. Otherwise the function\r
* will keep trying to read till time_out expires or data is read, if MSS_MAC_BLOCKING\r
uint16_t frame_length = 0u;\r
int8_t exit = 0;\r
\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
- ASSERT( (time_out == MSS_MAC_BLOCKING) ||\r
+ configASSERT( (time_out == MSS_MAC_BLOCKING) ||\r
(time_out == MSS_MAC_NONBLOCKING) ||\r
((time_out >= 1) && (time_out <= 0x01000000UL)) );\r
\r
\r
/* Here we are setting the buffer 'pacData' address to the address\r
RX descriptor address. After this is called, the following function\r
- must be called 'MAC_prepare_rx_descriptor' \r
+ must be called 'MAC_prepare_rx_descriptor'\r
to prepare the current rx descriptor for receiving the next packet.\r
- */ \r
- *pacData = (uint8_t *)g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].buffer_1 ; \r
- \r
+ */\r
+ *pacData = (uint8_t *)g_mss_mac.rx_descriptors[ g_mss_mac.rx_desc_index ].buffer_1 ;\r
+\r
}\r
return ((int32_t)frame_length);\r
}\r
{\r
uint32_t link;\r
\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
link = PHY_link_status();\r
if( link == MSS_MAC_LINK_STATUS_LINK ) {\r
link |= PHY_link_type();\r
)\r
{\r
int32_t link;\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
\r
PHY_auto_negotiate();\r
\r
const uint8_t *new_address\r
)\r
{\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
/* Check if the new address is unicast */\r
- ASSERT( (new_address[0]&1) == 0 );\r
+ configASSERT( (new_address[0]&1) == 0 );\r
\r
MAC_memcpy( g_mss_mac.mac_address, new_address, 6u );\r
\r
uint8_t *address\r
)\r
{\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
MAC_memcpy( address, g_mss_mac.mac_address, 6u );\r
}\r
\r
const uint8_t *filters\r
)\r
{\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
- ASSERT( (filter_count==0) || (filters != NULL_buffer) );\r
+ configASSERT( (filter_count==0) || (filters != NULL_buffer) );\r
/* Check if the mac addresses is multicast */\r
{\r
int32_t a;\r
for( a = 0u; a < filter_count; a++ ) {\r
- ASSERT( (filters[a*6]&1) == 1 );\r
+ configASSERT( (filters[a*6]&1) == 1 );\r
}\r
}\r
\r
uint32_t events;\r
uint32_t intr_status;\r
\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
events = 0u;\r
intr_status = MAC->CSR5;\r
\r
\r
/* Clear interrupts */\r
MAC->CSR5 = CSR5_INT_BITS;\r
- \r
+\r
if( (events != 0u) && (g_mss_mac.listener != NULL_callback) ) {\r
g_mss_mac.listener( events );\r
}\r
MSS_MAC_callback_t listener\r
)\r
{\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
-\r
/* disable tx and rx interrupts */\r
MAC_BITBAND->CSR7_RIE = 0u;\r
MAC_BITBAND->CSR7_TIE = 0u;\r
- \r
+\r
g_mss_mac.listener = listener;\r
\r
if( listener != NULL_callback ) {\r
{\r
int8_t error_msg_nb;\r
const int8_t* returnvalue;\r
- \r
- ASSERT( MAC_test_instance() == MAC_OK );\r
\r
error_msg_nb = -(g_mss_mac.last_error);\r
if( error_msg_nb >= ERROR_MESSAGE_COUNT ) {\r
)\r
{\r
uint32_t returnval = 0u;\r
- ASSERT( MAC_test_instance() == MAC_OK );\r
\r
switch( stat_id ) {\r
case MSS_MAC_RX_INTERRUPTS:\r
\r
/**************************** INTERNAL FUNCTIONS ******************************/\r
\r
-/***************************************************************************//**\r
- * Checks if instace is valid.\r
- */\r
-static int32_t\r
-MAC_test_instance\r
-(\r
- void\r
-)\r
-{\r
- uint32_t val1;\r
- uint32_t val2;\r
- int32_t retval = MAC_WRONG_PARAMETER;\r
-\r
- val1 = MAC->CSR3;\r
- val2 = MAC->CSR4;\r
-\r
- if( (&g_mss_mac != NULL_instance) &&\r
- ((g_mss_mac.flags & FLAG_MAC_INIT_DONE) != 0u) &&\r
- ( val1 == (uint32_t)g_mss_mac.rx_descriptors) &&\r
- (val2 == (uint32_t)g_mss_mac.tx_descriptors ) )\r
- {\r
- retval = MAC_OK;\r
- }\r
- return retval;\r
-}\r
\r
/***************************************************************************//**\r
* Prepares current rx descriptor for receiving.\r
if( (desc & RDES0_CE) != 0u ) {\r
g_mss_mac.statistics.rx_crc_error++;\r
}\r
- \r
+\r
desc = MAC->CSR8;\r
g_mss_mac.statistics.rx_fifo_overflow +=\r
(desc & (CSR8_OCO_MASK|CSR8_FOC_MASK)) >> CSR8_FOC_SHIFT;\r
\r
/* Stop transmission */\r
ret = MAC_stop_transmission();\r
- ASSERT( ret == MAC_OK );\r
+ configASSERT( ret == MAC_OK );\r
\r
ret = MAC_stop_receiving();\r
- ASSERT( ret == MAC_OK );\r
+ configASSERT( ret == MAC_OK );\r
\r
/* Set descriptor */\r
MAC->CSR4 = (uint32_t)&descriptor;\r
- \r
+\r
/* Start transmission */\r
MAC_start_transmission();\r
\r
/* Wait until transmission over */\r
ret = MAC_OK;\r
MAC_set_time_out( (uint32_t)SETUP_FRAME_TIME_OUT );\r
- \r
- while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) != \r
+\r
+ while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) !=\r
CSR5_TS_SUSPENDED) && (MAC_OK == ret) )\r
{\r
/* transmit poll demand */\r
\r
/* Set tx descriptor */\r
MAC->CSR4 = (uint32_t)g_mss_mac.tx_descriptors;\r
- \r
+\r
/* Start receiving and transmission */\r
MAC_start_receiving();\r
MAC_start_transmission();\r
{\r
int32_t retval = MAC_OK;\r
MAC_set_time_out( (uint16_t)STATE_CHANGE_TIME_OUT );\r
- \r
+\r
while( (((MAC->CSR5 & CSR5_TS_MASK) >> CSR5_TS_SHIFT) !=\r
CSR5_TS_STOPPED) && (retval == MAC_OK) )\r
{\r
{\r
int32_t dc = 0;\r
int8_t cont = 1;\r
- \r
+\r
if( MAC_BITBAND->CSR6_PB != 0u ) {\r
/* User wants bad frames too, don't dismiss anything */\r
cont = 0;\r
{\r
uint32_t timer;\r
uint32_t time = 0u;\r
- \r
+\r
timer = ( MAC->CSR11 & CSR11_TIM_MASK );\r
- \r
+\r
if( timer > g_mss_mac.last_timer_value ) {\r
time = 0x0000ffffUL;\r
}\r
time += g_mss_mac.last_timer_value - timer;\r
- \r
+\r
if( MAC_BITBAND->CSR6_TTM == 0u ) {\r
time *= 10u;\r
}\r
MAC_memset( s->mac_address, (uint8_t)c, 6u );\r
MAC_memset( s->mac_filter_data, (uint8_t)c, 90u );\r
s->phy_address = (uint8_t)c;\r
-// for(count = 0; count<RX_RING_SIZE ;count++)\r
-// {\r
-// MAC_memset(s->rx_buffers[count], (uint8_t)c, (MSS_RX_BUFF_SIZE + 4u) );\r
-// }\r
s->rx_desc_index =c;\r
for(count = 0; count<RX_RING_SIZE ;count++)\r
{\r
s->statistics.tx_no_carrier = c;\r
s->statistics.tx_underflow_error = c;\r
s->time_out_value = c;\r
-// for(count = 0; count < TX_RING_SIZE ;count++)\r
-// {\r
-// MAC_memset( s->tx_buffers[count], (uint8_t)c, MSS_TX_BUFF_SIZE );\r
-// }\r
s->tx_desc_index = c;\r
for(count = 0; count < TX_RING_SIZE ;count++)\r
{\r
}\r
}\r
\r
-void MSS_MAC_TxBufferCompleted( void )\r
+/***************************************************************************//**\r
+ * Tx has completed, mark the buffers that were assigned to the Tx descriptors\r
+ * as free again.\r
+ *\r
+ */\r
+void MSS_MAC_FreeTxBuffers( void )\r
{\r
-unsigned char *pxTransmittedBuffer;\r
-\r
- /* Was it the second transmission that has completed? */\r
- if( ( g_mss_mac.tx_descriptors[ 1 ].descriptor_0 & TDES0_OWN ) == 0UL )\r
+ if( ( ( (g_mss_mac.tx_descriptors[ 0 ].descriptor_0) & TDES0_OWN) == 0 ) && ( ( (g_mss_mac.tx_descriptors[ 1 ].descriptor_0) & TDES0_OWN) == 0 ) )\r
{\r
- pxTransmittedBuffer = ( unsigned char * ) g_mss_mac.tx_descriptors[ 1 ].buffer_1;\r
-\r
- /* The buffer has been transmitted and is no longer in use. */\r
- MAC_release_buffer( pxTransmittedBuffer );\r
+ MAC_release_buffer( ( unsigned char * ) g_mss_mac.tx_descriptors[ 0 ].buffer_1 );\r
+ MAC_release_buffer( ( unsigned char * ) g_mss_mac.tx_descriptors[ 1 ].buffer_1 );\r
}\r
}\r
\r
-static unsigned char *MAC_obtain_buffer( void )\r
+/***************************************************************************//**\r
+ * Look through the array of buffers until one is found that is free for use -\r
+ * that is, not currently assigned to an Rx or a Tx descriptor. Mark the buffer\r
+ * as in use, then return its address.\r
+ *\r
+ * @return a pointer to a free buffer.\r
+ */\r
+unsigned char *MAC_obtain_buffer( void )\r
{\r
long lIndex;\r
unsigned char *pcReturn = NULL;\r
the buffer as now in use. */\r
for( lIndex = 0; lIndex < macNUM_BUFFERS; lIndex++ )\r
{\r
- if( ucMACBufferFree[ lIndex ] == pdTRUE )\r
+ if( ucMACBufferInUse[ lIndex ] == pdFALSE )\r
{\r
- pcReturn = &( ucMACBuffers[ lIndex ][ 0 ] );\r
+ pcReturn = &( xMACBuffers.ucBuffer[ lIndex ][ 0 ] );\r
+ ucMACBufferInUse[ lIndex ] = pdTRUE;\r
break;\r
}\r
}\r
return pcReturn;\r
}\r
\r
+/***************************************************************************//**\r
+ * Return a buffer to the list of free buffers, it was in use, but is not now.\r
+ *\r
+ */\r
void MAC_release_buffer( unsigned char *pucBufferToRelease )\r
{\r
long lIndex;\r
it is currently pointing to is marked as being free again. */\r
for( lIndex = 0; lIndex < macNUM_BUFFERS; lIndex++ )\r
{\r
- if( pucBufferToRelease == &( ucMACBuffers[ lIndex ][ 0 ] ) )\r
+ if( pucBufferToRelease == &( xMACBuffers.ucBuffer[ lIndex ][ 0 ] ) )\r
{\r
/* This is the buffer in use, mark it as being free. */\r
- ucMACBufferFree[ lIndex ] = pdTRUE;\r
+ ucMACBufferInUse[ lIndex ] = pdFALSE;\r
break;\r
}\r
}\r
+ \r
+ configASSERT( lIndex < macNUM_BUFFERS );\r
}\r
\r
\r
\r
#ifdef __cplusplus\r
extern "C" {\r
-#endif \r
+#endif\r
\r
/******************************** DEFINES *************************************/\r
\r
#define MSS_PHY_ADDRESS_AUTO_DETECT 255u\r
\r
/***************************************************************************//**\r
- * Listener function type defines the function prototype that might be followed \r
+ * Listener function type defines the function prototype that might be followed\r
* by MAC_isr which is triggered with each receive and transmit related interrupts.\r
* Listener functions should follow the following prototype:\r
* void MAC_Listener( uint32_t events );\r
* or events. Events input to the system are:\r
* #define MSS_MAC_EVENT_PACKET_SEND 1\r
* #define MSS_MAC_EVENT_PACKET_RECEIVED 2\r
- * Listener function should be defined by the application using this driver if \r
+ * Listener function should be defined by the application using this driver if\r
* needed. This function may be assigned to the driver using MAC_set_callback\r
* routine and may be un assigned again by using the same routine with a NULL pointer\r
* as the event listener function. It is recommended to use this property for interrupt\r
typedef void (*MSS_MAC_callback_t)(uint32_t events);\r
\r
/***************************************************************************//**\r
- * Statistics counter identifiers are used with MAC_get_statistics routine to \r
+ * Statistics counter identifiers are used with MAC_get_statistics routine to\r
* receive the count of the requested errors/interrupts occurrences.\r
*\r
* MSS_MAC_RX_INTERRUPTS\r
MSS_MAC_TX_EXCESSIVE_COLLISION,\r
MSS_MAC_TX_COLLISION_COUNT,\r
MSS_MAC_TX_UNDERFLOW_ERROR\r
-} mss_mac_statistics_id_t; \r
+} mss_mac_statistics_id_t;\r
\r
/******************************* FUNCTIONS ************************************/\r
\r
\r
/***************************************************************************//**\r
* Returns the configuration of the Ethernet Controller.\r
- * After the MAC_init function has been called, this API function can be used to \r
+ * After the MAC_init function has been called, this API function can be used to\r
* get the configuration of the Ethernet Controller.\r
*\r
* @return The logical OR of the following values:\r
* Returns available packet's size.\r
*\r
* @return Size of packet, bigger than 0, if a packet is available,\r
- * if not, returns 0. \r
+ * if not, returns 0.\r
* @see MAC_rx_packet()\r
*/\r
int32_t\r
used by the user application or copied to another buffer, the\r
MSS_MAC_prepare_rx_descriptor() function must be called to free up the receive\r
memory buffer used by the MSS Ethernet MAC\r
- \r
+\r
@param pacData\r
The pacData parameter is a pointer to a memory buffer pointer. The uint8_t\r
pointer pointed to by the pacData parameter will contain the address of the\r
memory buffer containing the received packet after this function returns. The\r
value of pacData is only valid if the return value is larger than zero,\r
indicating that a packet was received.\r
- \r
+\r
@param time_out\r
The time_out parameter is the timeout value for the transmission in milliseconds.\r
The time_out parameter value can be one of the following values:\r
\95 Unsigned integer greater than 0 and less than 0x01000000\r
- \95 MSS_MAC_BLOCKING \96 there will be no timeout. \r
+ \95 MSS_MAC_BLOCKING \96 there will be no timeout.\r
\95 MSS_MAC_NONBLOCKING \96 the function will return immediately if no packets\r
- have been received. \r
+ have been received.\r
\r
@return\r
The function returns the size of the packet if the packet fits in pacData.\r
Returns zero if there is no received packet.\r
- \r
+\r
@see MAC_rx_pckt_size()\r
@see MAC_tx_packet()\r
*/\r
/***************************************************************************//**\r
* Returns description of latest error happened.\r
*\r
- * @return A string describing the error. This string must not be \r
+ * @return A string describing the error. This string must not be\r
* modified by the application.\r
*/\r
-const int8_t* \r
+const int8_t*\r
MSS_MAC_last_error\r
(\r
void\r
\r
/***************************************************************************//**\r
* Returns statistics counter of stat_id identifier.\r
- * \r
+ *\r
* @param stat_id Identifier of statistics counter.\r
* @return Statistics counter of stat_id identifier.\r
* On error returns 0.\r
mss_mac_statistics_id_t stat_id\r
);\r
\r
-/*\r
- * Ensure uip_buf is pointing to a valid and free buffer before any transmissions\r
- * initiated by the uIP stack occur.
- */\r
-unsigned char *MSS_MAC_GetTxDescriptor( void );\r
-\r
-/*\r
- * A buffer is no longer required by the application. Hand it back to the\r
- * control of the MAC hardware.
- */\r
-void MSS_MAC_ReleaseBuffer( unsigned char *pucBuffer );\r
-\r
/*\r
* The double Tx has completed. Hand back the Tx buffer to the control of\r
- * the MAC hardware.
+ * the MAC hardware.\r
*/\r
-void MSS_MAC_TxBufferCompleted( void );\r
+void MSS_MAC_FreeTxBuffers( void );\r
#ifdef __cplusplus\r
}\r
#endif\r
\r
#ifdef __cplusplus\r
extern "C" {\r
-#endif \r
+#endif\r
\r
#include "../../CMSIS/a2fxxxm3.h"\r
#include "mss_ethernet_mac.h"\r
#include "mss_ethernet_mac_user_cfg.h"\r
- \r
+\r
typedef uint32_t addr_t;\r
\r
\r
/***************************************************************************//**\r
* There should be one instance of this structure for each instance of\r
* the MAC in your system. MSS_MAC_init routine initializes this structure.\r
- * It is used to identify the various MACs in your system and an initilized \r
- * MAC instance's structure should be passed as first parameter to MAC functions \r
+ * It is used to identify the various MACs in your system and an initilized\r
+ * MAC instance's structure should be passed as first parameter to MAC functions\r
* to identify which MAC should perform the requested operation.\r
- * Software using the MAC driver should only need to create one single \r
- * instance of this data structure for each MAC hardware instance in \r
+ * Software using the MAC driver should only need to create one single\r
+ * instance of this data structure for each MAC hardware instance in\r
* the system. Using MAC_get_configuration routine, latest status of the driver\r
* may be read by receiving its flags field, similarly MAC_configure routine lets\r
* you modify some of these flags.\r
*/\r
+#include "net/pack_struct_start.h"\r
typedef struct {\r
addr_t base_address; /**< Register base address of the driver*/\r
uint8_t flags; /**< Configuration of the driver*/\r
int8_t last_error; /**< Index of last error happened inside the driver*/\r
uint8_t mac_address[6]; /**< MAC address of the drived instance*/\r
- uint8_t mac_filter_data[90]; /**< MAC filter data, 15 addresses to be used for \r
+ uint8_t mac_filter_data[90]; /**< MAC filter data, 15 addresses to be used for\r
received data filtering*/\r
uint16_t last_timer_value; /**< Last read value of timer */\r
uint32_t time_out_value; /**< Time out value */\r
- MSS_MAC_callback_t listener; /**< Pointer to the call-back function to be triggered \r
+ MSS_MAC_callback_t listener; /**< Pointer to the call-back function to be triggered\r
when a package is received*/\r
\r
/* transmit related info: */\r
uint32_t tx_desc_index; /**< index of the transmit descriptor getting used*/\r
-// uint8_t tx_buffers[TX_RING_SIZE][MSS_TX_BUFF_SIZE];/**< array of transmit buffers*/\r
MAC_descriptor_t tx_descriptors[TX_RING_SIZE];/**< array of transmit descriptors*/\r
\r
/* receive related info: */\r
uint32_t rx_desc_index; /**< index of the receive descriptor getting used*/\r
-// uint8_t rx_buffers[RX_RING_SIZE][MSS_RX_BUFF_SIZE+4];/**< array of receive buffers*/\r
MAC_descriptor_t rx_descriptors[RX_RING_SIZE];/**< array of receive descriptors*/\r
- \r
+\r
uint8_t phy_address; /**< MII address of the connected PHY*/\r
- \r
+\r
struct {\r
uint32_t rx_interrupts; /**< Number of receive interrupts occurred.*/\r
- uint32_t rx_filtering_fail; /**< Number of received frames which did not pass \r
+ uint32_t rx_filtering_fail; /**< Number of received frames which did not pass\r
the address recognition process.*/\r
uint32_t rx_descriptor_error; /**< Number of occurrences of; no receive buffer was\r
available when trying to store the received data.*/\r
- uint32_t rx_runt_frame; /**< Number of occurrences of; the frame is damaged by \r
- a collision or by a premature termination before \r
+ uint32_t rx_runt_frame; /**< Number of occurrences of; the frame is damaged by\r
+ a collision or by a premature termination before\r
the end of a collision window.*/\r
- uint32_t rx_not_first; /**< Number of occurrences of; start of the frame is \r
+ uint32_t rx_not_first; /**< Number of occurrences of; start of the frame is\r
not the first descriptor of a frame.*/\r
- uint32_t rx_not_last; /**< Number of occurrences of; end of the frame is not \r
+ uint32_t rx_not_last; /**< Number of occurrences of; end of the frame is not\r
the first descriptor of a frame.*/\r
- uint32_t rx_frame_too_long; /**< Number of occurrences of; a current frame is \r
- longer than maximum size of 1,518 bytes, as specified \r
+ uint32_t rx_frame_too_long; /**< Number of occurrences of; a current frame is\r
+ longer than maximum size of 1,518 bytes, as specified\r
by 802.3.*/\r
- uint32_t rx_collision_seen; /**< Number of occurrences of; a late collision was seen \r
+ uint32_t rx_collision_seen; /**< Number of occurrences of; a late collision was seen\r
(collision after 64 bytes following SFD).*/\r
- uint32_t rx_crc_error; /**< Number of occurrences of; a CRC error has occurred \r
+ uint32_t rx_crc_error; /**< Number of occurrences of; a CRC error has occurred\r
in the received frame.*/\r
- uint32_t rx_fifo_overflow; /**< Number of frames not accepted due to the receive \r
+ uint32_t rx_fifo_overflow; /**< Number of frames not accepted due to the receive\r
FIFO overflow.*/\r
- uint32_t rx_missed_frame; /**< Number of frames not accepted due to the \r
+ uint32_t rx_missed_frame; /**< Number of frames not accepted due to the\r
unavailability of the receive descriptor.*/\r
\r
uint32_t tx_interrupts; /**< Number of transmit interrupts occurred.*/\r
- uint32_t tx_loss_of_carrier; /**< Number of occurrences of; a loss of the carrier \r
+ uint32_t tx_loss_of_carrier; /**< Number of occurrences of; a loss of the carrier\r
during a transmission.*/\r
uint32_t tx_no_carrier; /**< Number of occurrences of; the carrier was not asserted\r
by an external transceiver during the transmission.*/\r
- uint32_t tx_late_collision; /**< Number of occurrences of; a collision was detected \r
+ uint32_t tx_late_collision; /**< Number of occurrences of; a collision was detected\r
after transmitting 64 bytes.*/\r
- uint32_t tx_excessive_collision;/**< Number of occurrences of; the transmission was \r
+ uint32_t tx_excessive_collision;/**< Number of occurrences of; the transmission was\r
aborted after 16 retries.*/\r
uint32_t tx_collision_count; /**< Number of collisions occurred.*/\r
- uint32_t tx_underflow_error; /**< Number of occurrences of; the FIFO was empty during \r
+ uint32_t tx_underflow_error; /**< Number of occurrences of; the FIFO was empty during\r
the frame transmission.*/\r
} statistics;\r
-} MAC_instance_t;\r
+} MAC_instance_t\r
+#include "net/pack_struct_end.h"\r
\r
\r
/*------------------------------------------------------------------------------\r
uint32_t CSR0_TAP[3];\r
uint32_t CSR0_DBO;\r
uint32_t CSR0_RESERVED1[11];\r
- \r
+\r
uint32_t MAC_CSR_RESERVED0[32];\r
- \r
+\r
uint32_t CSR1[32];\r
- \r
+\r
uint32_t MAC_CSR_RESERVED1[32];\r
- \r
+\r
uint32_t CSR2[32];\r
- \r
+\r
uint32_t MAC_CSR_RESERVED2[32];\r
- \r
+\r
uint32_t CSR3[32];\r
- \r
+\r
uint32_t MAC_CSR_RESERVED3[32];\r
- \r
+\r
uint32_t CSR4[32];\r
- \r
+\r
uint32_t MAC_CSR_RESERVED4[32];\r
- \r
+\r
uint32_t CSR5_TI;\r
uint32_t CSR5_TPS;\r
uint32_t CSR5_TU;\r
- uint32_t CSR5_RESERVED0[2]; \r
+ uint32_t CSR5_RESERVED0[2];\r
uint32_t CSR5_UNF;\r
uint32_t CSR5_RI;\r
uint32_t CSR5_RU;\r
uint32_t CSR5_RESERVED3[9];\r
\r
uint32_t MAC_CSR_RESERVED5[32];\r
- \r
+\r
uint32_t CSR6_HP;\r
uint32_t CSR6_SR;\r
uint32_t CSR6_HO;\r
uint32_t CSR6_RESERVED5;\r
\r
uint32_t MAC_CSR_RESERVED6[32];\r
- \r
+\r
uint32_t CSR7_TIE;\r
uint32_t CSR7_TSE;\r
uint32_t CSR7_TUE;\r
uint32_t CSR7[15];\r
\r
uint32_t MAC_CSR_RESERVED7[32];\r
- \r
+\r
uint32_t CSR8[32];\r
\r
uint32_t MAC_CSR_RESERVED8[32];\r
- \r
+\r
uint32_t CSR9_SCS;\r
uint32_t CSR9_SCLK;\r
uint32_t CSR9_SDI;\r
uint32_t CSR9_RESERVED1[12];\r
\r
uint32_t MAC_CSR_RESERVED9[32];\r
- \r
+\r
uint32_t CSR10[32];\r
\r
uint32_t MAC_CSR_RESERVED10[32];\r
- \r
+\r
uint32_t CSR11_TIM[16];\r
uint32_t CSR11_CON;\r
uint32_t CSR11_NRP[3];\r
#define CSR5_TS_SHIFT 20\r
\r
/** 000 - Stopped; RESET or STOP TRANSMIT command issued. */\r
-#define CSR5_TS_STOPPED 0u \r
+#define CSR5_TS_STOPPED 0u\r
/** 001 - Running, fetching the transmit descriptor. */\r
-#define CSR5_TS_RUNNING_FD 1u \r
+#define CSR5_TS_RUNNING_FD 1u\r
/** 010 - Running, waiting for end of transmission. */\r
-#define CSR5_TS_RUNNING_WT 2u \r
+#define CSR5_TS_RUNNING_WT 2u\r
/** 011 - Running, transferring data buffer from host memory to FIFO. */\r
-#define CSR5_TS_RUNNING_TD 3u \r
+#define CSR5_TS_RUNNING_TD 3u\r
/** 101 - Running, setup packet. */\r
-#define CSR5_TS_RUNNING_SP 5u \r
+#define CSR5_TS_RUNNING_SP 5u\r
/** 110 - Suspended; FIFO underflow or unavailable descriptor. */\r
-#define CSR5_TS_SUSPENDED 6u \r
+#define CSR5_TS_SUSPENDED 6u\r
/** 111 - Running, closing transmit descriptor. */\r
-#define CSR5_TS_RUNNING_CD 7u \r
+#define CSR5_TS_RUNNING_CD 7u\r
\r
/*------------------------------------------------------------------------------\r
* CSR5_RS:\r
#define CSR5_RS_SHIFT 17\r
\r
/** 000 - Stopped; RESET or STOP RECEIVE command issued. */\r
-#define CSR5_RS_STOPPED 0u \r
+#define CSR5_RS_STOPPED 0u\r
/** 001 - Running, fetching the receive descriptor. */\r
-#define CSR5_RS_RUNNING_FD 1u \r
+#define CSR5_RS_RUNNING_FD 1u\r
/** 010 - Running, waiting for the end-of-receive packet before prefetch of the\r
- *next descriptor. */ \r
-#define CSR5_RS_RUNNING_WR 2u \r
+ *next descriptor. */\r
+#define CSR5_RS_RUNNING_WR 2u\r
/** 011 - Running, waiting for the receive packet. */\r
-#define CSR5_RS_RUNNING_RB 3u \r
+#define CSR5_RS_RUNNING_RB 3u\r
/** 100 - Suspended, unavailable receive buffer. */\r
-#define CSR5_RS_SUSPENDED 4u \r
+#define CSR5_RS_SUSPENDED 4u\r
/** 101 - Running, closing the receive descriptor. */\r
-#define CSR5_RS_RUNNING_CD 5u \r
-/** 111 - Running, transferring data from FIFO to host memory. */ \r
+#define CSR5_RS_RUNNING_CD 5u\r
+/** 111 - Running, transferring data from FIFO to host memory. */\r
#define CSR5_RS_RUNNING_TD 7u\r
\r
/*------------------------------------------------------------------------------\r
lReturn = pdTRUE;\r
}\r
}\r
+ taskEXIT_CRITICAL();\r
}\r
\r
return lReturn;\r
( void ) arg;\r
\r
/* Are the dynamically setable LEDs currently on or off? */\r
- if( lParTestGetLEDState( 8 ) )\r
+ if( lParTestGetLEDState( 3 ) )\r
{\r
pcStatus = "checked";\r
}\r
/*---------------------------------------------------------------------------*/\r
extern void vTaskGetRunTimeStats( signed char *pcWriteBuffer );\r
extern unsigned short usMaxJitter;\r
-static char cJitterBuffer[ 200 ];\r
static unsigned short generate_runtime_stats( void *arg )\r
{\r
( void ) arg;\r
lRefreshCount++;\r
sprintf( cCountBuf, "<p><br>Refresh count = %d", ( int ) lRefreshCount );\r
\r
- #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
- {\r
- sprintf( cJitterBuffer, "<p><br>Max high frequency timer jitter = %d peripheral clock periods.<p><br>", ( int ) usMaxJitter );\r
- vTaskGetRunTimeStats( uip_appdata );\r
- strcat( uip_appdata, cJitterBuffer );\r
- }\r
- #else\r
- {\r
- ( void ) cJitterBuffer;\r
- strcpy( uip_appdata, "<p>Run time stats are only available in the debug_with_optimisation build configuration.<p>" );\r
- }\r
- #endif \r
-\r
+ vTaskGetRunTimeStats( uip_appdata );\r
strcat( uip_appdata, cCountBuf );\r
\r
return strlen( uip_appdata );\r
* incorporates a Cortex-M3 microcontroller.\r
*\r
* The main() Function:\r
- * main() creates three demo specific software timers, one demo specific queue,\r
- * and two demo specific tasks. It then creates a whole host of 'standard demo'\r
- * tasks/queues/semaphores, before starting the scheduler. The demo specific\r
- * tasks and timers are described in the comments here. The standard demo\r
- * tasks are described on the FreeRTOS.org web site.\r
+ * main() creates two demo specific software timers, one demo specific queue,\r
+ * and three demo specific tasks. It then creates a whole host of 'standard\r
+ * demo' tasks/queues/semaphores, before starting the scheduler. The demo\r
+ * specific tasks and timers are described in the comments here. The standard\r
+ * demo tasks are described on the FreeRTOS.org web site.\r
*\r
* The standard demo tasks provide no specific functionality. They are\r
* included to both test the FreeRTOS port, and provide examples of how the\r
* the Blocked state every 200 milliseconds, and therefore toggles the LED\r
* every 200 milliseconds.\r
*\r
+ * The Demo Specific OLED Task:\r
+ * The OLED task is a very simple task that just scrolls a message across the\r
+ * OLED. Ideally this would be done in a timer, but the OLED driver accesses\r
+ * the I2C which is time consuming.\r
+ *\r
* The Demo Specific LED Software Timer and the Button Interrupt:\r
* The user button SW1 is configured to generate an interrupt each time it is\r
* pressed. The interrupt service routine switches an LED on, and resets the\r
* Therefore, pressing the user button will turn the LED on, and the LED will\r
* remain on until a full five seconds pass without the button being pressed.\r
*\r
- * The Demo Specific OLED Software Timer:\r
- * The OLED software timer is responsible for drawing a scrolling text message\r
- * on the OLED.\r
- *\r
* The Demo Specific "Check" Callback Function:\r
* This is called each time the 'check' timer expires. The check timer\r
* callback function inspects all the standard demo tasks to see if they are\r
* is ever discovered. The check timer callback toggles the LED defined by\r
* the mainCHECK_LED definition each time it executes. Therefore, if LED\r
* mainCHECK_LED is toggling every three seconds, then no error have been found.\r
- * If LED mainCHECK_LED is toggling every 500ms, then at least one error has\r
+ * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has\r
* been found. The task in which the error was discovered is displayed at the\r
* bottom of the "task stats" page that is served by the embedded web server.\r
*\r
/* Microsemi drivers/libraries includes. */\r
#include "mss_gpio.h"\r
#include "mss_watchdog.h"\r
+#include "mss_timer.h"\r
#include "oled.h"\r
\r
/* Common demo includes. */\r
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
#define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainOLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
\r
\r
/* The period at which the check timer will expire, in ms, provided no errors\r
have been reported by any of the standard demo tasks. */\r
-#define mainCHECK_TIMER_PERIOD_ms ( 3000UL )\r
+#define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )\r
\r
/* The period at which the OLED timer will expire. Each time it expires, it's\r
callback function updates the OLED text. */\r
-#define mainOLED_PERIOD_ms ( 75UL )\r
+#define mainOLED_PERIOD_MS ( 75UL / portTICK_RATE_MS )\r
\r
/* The period at which the check timer will expire, in ms, if an error has been\r
-reported in one of the standard demo tasks. */
-#define mainERROR_CHECK_TIMER_PERIOD_ms ( 500UL )\r
+reported in one of the standard demo tasks. */\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS ( 500UL / portTICK_RATE_MS )\r
+\r
+/* The LED will remain on until the button has not been pushed for a full\r
+5000ms. */\r
+#define mainLED_TIMER_PERIOD_MS ( 5000UL / portTICK_RATE_MS )\r
\r
/* A zero block time. */\r
#define mainDONT_BLOCK ( 0UL )\r
static void prvQueueSendTask( void *pvParameters );\r
\r
/*\r
- * The LED timer callback function. This does nothing but switch the red LED \r
+ * The LED timer callback function. This does nothing but switch the red LED\r
* off.\r
*/\r
-static void vLEDTimerCallback( xTimerHandle xTimer );\r
-\r
-/*\r
- * The check timer callback function, as described at the top of this file.
- */\r
-static void vCheckTimerCallback( xTimerHandle xTimer );\r
+static void prvLEDTimerCallback( xTimerHandle xTimer );\r
\r
/*\r
- * The OLED timer callback function, as described at the top of this file.
+ * The check timer callback function, as described at the top of this file.\r
*/\r
-static void vOLEDTimerCallback( xTimerHandle xHandle );\r
+static void prvCheckTimerCallback( xTimerHandle xTimer );\r
\r
/*\r
* This is not a 'standard' partest function, so the prototype is not in\r
- * partest.h, and is instead included here.
+ * partest.h, and is instead included here.\r
*/\r
void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );\r
\r
*/\r
extern void vuIP_Task( void *pvParameters );\r
\r
+/*\r
+ * A very simply task that does nothing but scroll the OLED display. Ideally\r
+ * this would be done within a timer, but it accesses the I2C port which is\r
+ * time consuming.\r
+ */\r
+static void prvOLEDTask( void * pvParameters);\r
+\r
/*-----------------------------------------------------------*/\r
\r
/* The queue used by both application specific demo tasks defined in this file. */\r
static xQueueHandle xQueue = NULL;\r
\r
-/* The LED software timer. This uses vLEDTimerCallback() as it's callback\r
+/* The LED software timer. This uses prvLEDTimerCallback() as it's callback\r
function. */\r
static xTimerHandle xLEDTimer = NULL;\r
\r
-/* The check timer. This uses vCheckTimerCallback() as it's callback\r
+/* The check timer. This uses prvCheckTimerCallback() as it's callback\r
function. */\r
static xTimerHandle xCheckTimer = NULL;\r
\r
-/* The OLED software timer. Writes a moving text string to the OLED. */\r
-static xTimerHandle xOLEDTimer = NULL;\r
-\r
/* The status message that is displayed at the bottom of the "task stats" web\r
page, which is served by the uIP task. This will report any errors picked up\r
by the check timer callback. */\r
\r
if( xQueue != NULL )\r
{\r
- /* Start the two application specific demo tasks, as described in the\r
+ /* Start the three application specific demo tasks, as described in the\r
comments at the top of this file. */\r
xTaskCreate( prvQueueReceiveTask, ( signed char * ) "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
+ xTaskCreate( prvOLEDTask, ( signed char * ) "OLED", configMINIMAL_STACK_SIZE, NULL, mainOLED_TASK_PRIORITY, NULL );\r
\r
- /* Create the software timer that is responsible for turning off the LED \r
- if the button is not pushed within 5000ms, as described at the top of \r
+ /* Create the software timer that is responsible for turning off the LED\r
+ if the button is not pushed within 5000ms, as described at the top of\r
this file. */\r
xLEDTimer = xTimerCreate( ( const signed char * ) "LEDTimer", /* A text name, purely to help debugging. */\r
- ( 5000 / portTICK_RATE_MS ), /* The timer period, in this case 5000ms (5s). */\r
+ ( mainLED_TIMER_PERIOD_MS ), /* The timer period, in this case 5000ms (5s). */\r
pdFALSE, /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
( void * ) 0, /* The ID is not used, so can be set to anything. */\r
- vLEDTimerCallback /* The callback function that switches the LED off. */\r
+ prvLEDTimerCallback /* The callback function that switches the LED off. */\r
);\r
\r
/* Create the software timer that performs the 'check' functionality,\r
as described at the top of this file. */\r
- xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer", /* A text name, purely to help debugging. */\r
- ( mainCHECK_TIMER_PERIOD_ms / portTICK_RATE_MS ),/* The timer period, in this case 3000ms (3s). */\r
- pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
- ( void * ) 0, /* The ID is not used, so can be set to anything. */\r
- vCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */\r
+ xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
+ ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */\r
+ pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
+ ( void * ) 0, /* The ID is not used, so can be set to anything. */\r
+ prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */\r
);\r
\r
- /* Create the OLED timer as described at the top of this file. */\r
- xOLEDTimer = xTimerCreate( ( const signed char * ) "OLEDTimer", ( mainOLED_PERIOD_ms / portTICK_RATE_MS ), pdTRUE, ( void * ) 0, vOLEDTimerCallback );\r
-\r
/* Create a lot of 'standard demo' tasks. */\r
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
vCreateBlockTimeTasks();\r
vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
\r
/* Create the web server task. */\r
-// xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
+ xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
+ \r
+ /* The suicide tasks must be created last, as they need to know how many\r
+ tasks were running prior to their creation in order to ascertain whether\r
+ or not the correct/expected number of tasks are running at any given\r
+ time. */\r
+ vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
\r
/* Start the tasks and timer running. */\r
vTaskStartScheduler();\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void vCheckTimerCallback( xTimerHandle xTimer )\r
+static void prvCheckTimerCallback( xTimerHandle xTimer )\r
{\r
/* Check the standard demo tasks are running without error. Latch the\r
latest reported error in the pcStatusMessage character pointer. */\r
pcStatusMessage = "Error: RecMutex\r\n";\r
}\r
\r
- if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_ms / portTICK_RATE_MS ) ) != pdTRUE )\r
+ if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_MS ) ) != pdTRUE )\r
{\r
pcStatusMessage = "Error: TimerDemo";\r
}\r
\r
/* Toggle the check LED to give an indication of the system status. If\r
- the LED toggles every mainCHECK_TIMER_PERIOD_ms milliseconds then\r
+ the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
everything is ok. A faster toggle indicates an error. */\r
vParTestToggleLED( mainCHECK_LED );\r
\r
/* Have any errors been latch in pcStatusMessage? If so, shorten the\r
- period of the check timer to mainERROR_CHECK_TIMER_PERIOD_ms milliseconds.\r
+ period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
This will result in an increase in the rate at which mainCHECK_LED\r
toggles. */\r
if( pcStatusMessage != NULL )\r
/* This call to xTimerChangePeriod() uses a zero block time. Functions\r
called from inside of a timer callback function must *never* attempt\r
to block. */\r
- xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_ms / portTICK_RATE_MS ), mainDONT_BLOCK );\r
+ xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void vLEDTimerCallback( xTimerHandle xTimer )\r
+static void prvLEDTimerCallback( xTimerHandle xTimer )\r
{\r
/* The timer has expired - so no button pushes have occurred in the last\r
five seconds - turn the LED off. */\r
portTickType xNextWakeTime;\r
const unsigned long ulValueToSend = 100UL;\r
\r
- /* The suicide tasks must be created last, as they need to know how many\r
- tasks were running prior to their creation in order to ascertain whether\r
- or not the correct/expected number of tasks are running at any given time.\r
- Therefore the standard demo 'death' tasks are not created in main(), but\r
- instead created here. */\r
- vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
-\r
/* The timer command queue will have been filled when the timer test tasks\r
were created in main() (this is part of the test they perform). Therefore,\r
while the check and OLED timers can be created in main(), they cannot be\r
started from main(). Once the scheduler has started, the timer service\r
task will drain the command queue, and now the check and OLED timers can be\r
- started successfully. */
+ started successfully. */\r
xTimerStart( xCheckTimer, portMAX_DELAY );\r
- xTimerStart( xOLEDTimer, portMAX_DELAY );\r
\r
/* Initialise xNextWakeTime - this only needs to be done once. */\r
xNextWakeTime = xTaskGetTickCount();\r
toggle an LED. 0 is used as the block time so the sending operation\r
will not block - it shouldn't need to block as the queue should always\r
be empty at this point in the code. */\r
- xQueueSend( xQueue, &ulValueToSend, 0 );\r
+ xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void vOLEDTimerCallback( xTimerHandle xHandle )\r
+static void prvOLEDTask( void * pvParameters)\r
{\r
-volatile size_t xFreeStackSpace;\r
static struct oled_data xOLEDData;\r
static unsigned char ucOffset1 = 0, ucOffset2 = 5;\r
+static portTickType xLastScrollTime = 0UL;\r
\r
- /* This function is called on each cycle of the idle task. In this case it\r
- does nothing useful, other than report the amount of FreeRTOS heap that\r
- remains unallocated. */\r
- xFreeStackSpace = xPortGetFreeHeapSize();\r
-\r
- if( xFreeStackSpace > 100 )\r
- {\r
- /* By now, the kernel has allocated everything it is going to, so\r
- if there is a lot of heap remaining unallocated then\r
- the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be\r
- reduced accordingly. */\r
- }\r
+ /* Initialise the display. */\r
+ OLED_init();\r
\r
+ /* Initialise the parts of the oled_data structure that do not change. */\r
xOLEDData.line1 = FIRST_LINE;\r
- xOLEDData.char_offset1 = ucOffset1++;\r
- xOLEDData.string1 = "www.FreeRTOS.org";\r
-\r
+ xOLEDData.string1 = " www.FreeRTOS.org";\r
xOLEDData.line2 = SECOND_LINE;\r
- xOLEDData.char_offset2 = ucOffset2++;\r
- xOLEDData.string2 = "www.FreeRTOS.org";\r
-\r
+ xOLEDData.string2 = " www.FreeRTOS.org";\r
xOLEDData.contrast_val = OLED_CONTRAST_VAL;\r
xOLEDData.on_off = OLED_HORIZ_SCROLL_OFF;\r
xOLEDData.column_scrool_per_step = OLED_HORIZ_SCROLL_STEP;\r
xOLEDData.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;\r
xOLEDData.end_page = OLED_END_PAGE;\r
\r
- OLED_write_data( &xOLEDData, BOTH_LINES );\r
+\r
+ /* Initialise the last scroll time. This only needs to be done once,\r
+ because from this point on it will get automatically updated in the\r
+ xTaskDelayUntil() API function. */\r
+ xLastScrollTime = xTaskGetTickCount();\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait until it is time to update the OLED again. */\r
+ vTaskDelayUntil( &xLastScrollTime, mainOLED_PERIOD_MS );\r
+ \r
+ xOLEDData.char_offset1 = ucOffset1++;\r
+ xOLEDData.char_offset2 = ucOffset2++;\r
+ \r
+ OLED_write_data( &xOLEDData, BOTH_LINES );\r
+ }\r
}\r
/*-----------------------------------------------------------*/\r
\r
static void prvSetupHardware( void )\r
{\r
+ SystemCoreClockUpdate();\r
+ \r
/* Disable the Watch Dog Timer */\r
MSS_WD_disable( );\r
\r
/* Configure the GPIO for the LEDs. */\r
vParTestInitialise();\r
\r
- /* Initialise the display. */\r
- OLED_init();\r
-\r
/* Setup the GPIO and the NVIC for the switch used in this simple demo. */\r
NVIC_SetPriority( GPIO8_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
NVIC_EnableIRQ( GPIO8_IRQn );\r
{\r
/* Called if a call to pvPortMalloc() fails because there is insufficient\r
free memory available in the FreeRTOS heap. pvPortMalloc() is called\r
- internally by FreeRTOS API functions that create tasks, queues, software \r
+ internally by FreeRTOS API functions that create tasks, queues, software\r
timers, and semaphores. The size of the FreeRTOS heap is set by the\r
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
for( ;; );\r
}\r
/*-----------------------------------------------------------*/\r
\r
+void vMainConfigureTimerForRunTimeStats( void )\r
+{\r
+const unsigned long ulMax32BitValue = 0xffffffffUL;\r
+\r
+ MSS_TIM64_init( MSS_TIMER_PERIODIC_MODE );\r
+ MSS_TIM64_load_immediate( ulMax32BitValue, ulMax32BitValue );\r
+ MSS_TIM64_start();\r
+}\r
+/*-----------------------------------------------------------*/\r
+unsigned long ulGetRunTimeCounterValue( void )\r
+{\r
+unsigned long long ullCurrentValue;\r
+const unsigned long long ulMax64BitValue = 0xffffffffffffffffULL;\r
+unsigned long *pulHighWord, *pulLowWord;\r
+\r
+ pulHighWord = ( unsigned long * ) &ullCurrentValue;\r
+ pulLowWord = pulHighWord++;\r
+ \r
+ MSS_TIM64_get_current_value( ( uint32_t * ) pulHighWord, ( uint32_t * ) pulLowWord );\r
+ \r
+ /* Convert the down count into an upcount. */\r
+ ullCurrentValue = ulMax64BitValue - ullCurrentValue;\r
+ \r
+ /* Scale to a 32bit number of suitable frequency. */\r
+ ullCurrentValue >>= 13;\r
+\r
+ /* Just return 32 bits. */\r
+ return ( unsigned long ) ullCurrentValue;\r
+}\r
+\r
#include "mss_ethernet_mac_regs.h"\r
#include "mss_ethernet_mac.h"\r
\r
-/* The buffer used by the uIP stack to both receive and send. This points to\r
-one of the Ethernet buffers when its actually in use. */\r
+/* The buffer used by the uIP stack to both receive and send. In this case,\r
+because the Ethernet driver has been modified to be zero copy - the uip_buf\r
+variable is just a pointer to an Ethernet buffer, and not a buffer in its own\r
+right. */\r
extern unsigned char *uip_buf;\r
\r
-static const unsigned char ucMACAddress[] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };\r
-\r
+/* The ARP timer and the periodic timer share a callback function, so the\r
+respective timer IDs are used to determine which timer actually expired. These\r
+constants are assigned to the timer IDs. */\r
#define uipARP_TIMER 0\r
#define uipPERIODIC_TIMER 1\r
\r
+/* The length of the queue used to send events from timers or the Ethernet\r
+driver to the uIP stack. */\r
#define uipEVENT_QUEUE_LENGTH 10\r
\r
-#define uipETHERNET_RX_EVENT 0x01UL\r
-#define uipETHERNET_TX_EVENT 0x02UL\r
-#define uipARP_TIMER_EVENT 0x04UL\r
-#define uipPERIODIC_TIMER_EVENT 0x08UL\r
-#define uipAPPLICATION_SEND_EVENT 0x10UL\r
-\r
+/* A block time of zero simply means "don't block". */\r
#define uipDONT_BLOCK 0UL\r
\r
-/*-----------------------------------------------------------*/\r
-\r
/* How long to wait before attempting to connect the MAC again. */\r
#define uipINIT_WAIT ( 100 / portTICK_RATE_MS )\r
\r
\r
/*\r
* Perform any uIP initialisation required to ready the stack for http\r
- * processing.
+ * processing.\r
*/\r
static void prvInitialise_uIP( void );\r
\r
/*\r
- * Handles Ethernet interrupt events.
+ * Handles Ethernet interrupt events.\r
*/\r
static void prvEMACEventListener( unsigned long ulISREvents );\r
\r
+/*\r
+ * The callback function that is assigned to both the periodic timer and the\r
+ * ARP timer.\r
+ */\r
static void prvUIPTimerCallback( xTimerHandle xTimer );\r
\r
/*\r
- * Initialise the MAC hardware.
+ * Initialise the MAC hardware.\r
*/\r
static void prvInitEmac( void );\r
\r
+/*\r
+ * Write data to the Ethener. Note that this actually writes data twice for the\r
+ * to get around delayed ack issues when communicating with a non real-time\r
+ * peer (for example, a Windows machine).\r
+ */\r
void vEMACWrite( void );\r
\r
-long lEMACWaitForLink( void );\r
-\r
/*\r
* Port functions required by the uIP stack.\r
*/\r
-void clock_init( void );\r
clock_time_t clock_time( void );\r
\r
/*-----------------------------------------------------------*/\r
/* The queue used to send TCP/IP events to the uIP stack. */\r
xQueueHandle xEMACEventQueue = NULL;\r
\r
-static unsigned long ulUIP_Events = 0UL;\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-void clock_init(void)\r
-{\r
- /* This is done when the scheduler starts. */\r
-}\r
/*-----------------------------------------------------------*/\r
\r
clock_time_t clock_time( void )\r
void vuIP_Task( void *pvParameters )\r
{\r
portBASE_TYPE i;\r
-unsigned long ulNewEvent;\r
+unsigned long ulNewEvent = 0UL;\r
+unsigned long ulUIP_Events = 0UL;\r
\r
+ /* Just to prevent compiler warnings about the unused parameter. */\r
( void ) pvParameters;\r
\r
/* Initialise the uIP stack, configuring for web server usage. */\r
prvInitialise_uIP();\r
\r
- /* Initialise the MAC. */\r
+ /* Initialise the MAC and PHY. */\r
prvInitEmac();\r
\r
for( ;; )\r
{\r
- if( ( ulUIP_Events & uipETHERNET_TX_EVENT ) != 0UL )\r
- {\r
- ulUIP_Events &= ~uipETHERNET_TX_EVENT;\r
- MSS_MAC_TxBufferCompleted();\r
- }\r
+ /* Is there received data ready to be processed? */\r
+ uip_len = MSS_MAC_rx_packet();\r
\r
- if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )\r
+ /* Statements to be executed if data has been received on the Ethernet. */\r
+ if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
{\r
- ulUIP_Events &= ~uipETHERNET_RX_EVENT;\r
-\r
- /* Is there received data ready to be processed? */\r
- uip_len = MSS_MAC_rx_packet();\r
-\r
- if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
+ /* Standard uIP loop taken from the uIP manual. */\r
+ if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
{\r
- /* Standard uIP loop taken from the uIP manual. */\r
- if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
- {\r
- uip_arp_ipin();\r
- uip_input();\r
+ uip_arp_ipin();\r
+ uip_input();\r
\r
- /* If the above function invocation resulted in data that\r
- should be sent out on the network, the global variable\r
- uip_len is set to a value > 0. */\r
- if( uip_len > 0 )\r
- {\r
- uip_arp_out();\r
- vEMACWrite();\r
- }\r
- }\r
- else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
+ /* If the above function invocation resulted in data that\r
+ should be sent out on the network, the global variable\r
+ uip_len is set to a value > 0. */\r
+ if( uip_len > 0 )\r
{\r
- uip_arp_arpin();\r
+ uip_arp_out();\r
+ vEMACWrite();\r
+ }\r
+ }\r
+ else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
+ {\r
+ uip_arp_arpin();\r
\r
- /* If the above function invocation resulted in data that\r
- should be sent out on the network, the global variable\r
- uip_len is set to a value > 0. */\r
- if( uip_len > 0 )\r
- {\r
- vEMACWrite();\r
- }\r
+ /* If the above function invocation resulted in data that\r
+ should be sent out on the network, the global variable\r
+ uip_len is set to a value > 0. */\r
+ if( uip_len > 0 )\r
+ {\r
+ vEMACWrite();\r
}\r
}\r
}\r
+ else\r
+ {\r
+ /* Clear the RX event latched in ulUIP_Events - if one was latched. */\r
+ ulUIP_Events &= ~uipETHERNET_RX_EVENT;\r
+ }\r
\r
+ /* Statements to be executed if the TCP/IP period timer has expired. */\r
if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )\r
{\r
ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;\r
\r
- for( i = 0; i < UIP_CONNS; i++ )\r
+ if( uip_buf != NULL )\r
{\r
- uip_periodic( i );\r
-\r
- /* If the above function invocation resulted in data that\r
- should be sent out on the network, the global variable\r
- uip_len is set to a value > 0. */\r
- if( uip_len > 0 )\r
+ for( i = 0; i < UIP_CONNS; i++ )\r
{\r
- uip_arp_out();\r
- vEMACWrite();\r
+ uip_periodic( i );\r
+ \r
+ /* If the above function invocation resulted in data that\r
+ should be sent out on the network, the global variable\r
+ uip_len is set to a value > 0. */\r
+ if( uip_len > 0 )\r
+ {\r
+ uip_arp_out();\r
+ vEMACWrite();\r
+ }\r
}\r
}\r
}\r
\r
- /* Call the ARP timer function every 10 seconds. */\r
+ /* Statements to be executed if the ARP timer has expired. */\r
if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )\r
{\r
ulUIP_Events &= ~uipARP_TIMER_EVENT;\r
uip_arp_timer();\r
}\r
\r
+ /* If all latched events have been cleared - block until another event\r
+ occurs. */\r
if( ulUIP_Events == pdFALSE )\r
{\r
xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vApplicationProcessFormInput( char *pcInputString )\r
-{\r
-char *c;\r
-\r
- /* Only interested in processing form input if this is the IO page. */\r
- c = strstr( pcInputString, "io.shtml" );\r
- \r
- if( c )\r
- {\r
- /* Is there a command in the string? */\r
- c = strstr( pcInputString, "?" );\r
- if( c )\r
- {\r
- /* Turn the LED's on or off in accordance with the check box status. */\r
- if( strstr( c, "LED0=1" ) != NULL )\r
- {\r
- /* Turn the LEDs on. */\r
- vParTestSetLED( 7, 1 );\r
- vParTestSetLED( 8, 1 );\r
- vParTestSetLED( 9, 1 );\r
- vParTestSetLED( 10, 1 );\r
- }\r
- else\r
- {\r
- /* Turn the LEDs off. */\r
- vParTestSetLED( 7, 0 );\r
- vParTestSetLED( 8, 0 );\r
- vParTestSetLED( 9, 0 );\r
- vParTestSetLED( 10, 0 );\r
- }\r
- }\r
- else\r
- {\r
- /* Commands to turn LEDs off are not always explicit. */\r
- vParTestSetLED( 7, 0 );\r
- vParTestSetLED( 8, 0 );\r
- vParTestSetLED( 9, 0 );\r
- vParTestSetLED( 10, 0 );\r
- }\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
static void prvInitialise_uIP( void )\r
{\r
uip_ipaddr_t xIPAddr;\r
\r
/* Create and start the uIP timers. */\r
xARPTimer = xTimerCreate( ( const signed char * const ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */\r
- ( 500 / portTICK_RATE_MS ), /* Timer period. */\r
+ ( 10000UL / portTICK_RATE_MS ), /* Timer period. */\r
pdTRUE, /* Autor-reload. */\r
( void * ) uipARP_TIMER,\r
prvUIPTimerCallback\r
);\r
\r
xPeriodicTimer = xTimerCreate( ( const signed char * const ) "PeriodicTimer",\r
- ( 5000 / portTICK_RATE_MS ),\r
+ ( 500UL / portTICK_RATE_MS ),\r
pdTRUE, /* Autor-reload. */\r
( void * ) uipPERIODIC_TIMER,\r
prvUIPTimerCallback\r
);\r
\r
+ /* Sanity check that the timers were indeed created. */\r
configASSERT( xARPTimer );\r
configASSERT( xPeriodicTimer );\r
\r
+ /* These commands will block indefinitely until they succeed, so there is\r
+ no point in checking their return values. */\r
xTimerStart( xARPTimer, portMAX_DELAY );\r
xTimerStart( xPeriodicTimer, portMAX_DELAY );\r
}\r
static void prvEMACEventListener( unsigned long ulISREvents )\r
{\r
long lHigherPriorityTaskWoken = pdFALSE;\r
-unsigned long ulUIPEvents = 0UL;\r
+const unsigned long ulRxEvent = uipETHERNET_RX_EVENT;\r
\r
+ /* Sanity check that the event queue was indeed created. */\r
configASSERT( xEMACEventQueue );\r
\r
if( ( ulISREvents & MSS_MAC_EVENT_PACKET_SEND ) != 0UL )\r
{\r
- ulUIP_Events |= uipETHERNET_TX_EVENT;\r
+ /* An Ethernet Tx event has occurred. */\r
+ MSS_MAC_FreeTxBuffers();\r
}\r
\r
if( ( ulISREvents & MSS_MAC_EVENT_PACKET_RECEIVED ) != 0UL )\r
{\r
- /* Wake the uIP task as new data has arrived. */\r
- ulUIPEvents |= uipETHERNET_RX_EVENT;\r
- }\r
-\r
- if( ulUIPEvents != 0UL )\r
- {\r
- xQueueSendFromISR( xEMACEventQueue, &ulUIPEvents, &lHigherPriorityTaskWoken );\r
+ /* An Ethernet Rx event has occurred. */\r
+ xQueueSendFromISR( xEMACEventQueue, &ulRxEvent, &lHigherPriorityTaskWoken );\r
}\r
\r
portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
{\r
const unsigned char ucPHYAddress = 1;\r
\r
+ /* Initialise the MAC and PHY hardware. */\r
MSS_MAC_init( ucPHYAddress );\r
\r
- MSS_MAC_set_callback( prvEMACEventListener );\r
+ /* Register the event listener. The Ethernet interrupt handler will call\r
+ this listener whenever an Rx or a Tx interrupt occurs. */\r
+ MSS_MAC_set_callback( ( MSS_MAC_callback_t ) prvEMACEventListener );\r
\r
/* Setup the EMAC and the NVIC for MAC interrupts. */\r
NVIC_SetPriority( EthernetMAC_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
long lAttempt;\r
const portTickType xShortDelay = ( 10 / portTICK_RATE_MS );\r
\r
+ /* Try to send data to the Ethernet. Keep trying for a while if data cannot\r
+ be sent immediately. Note that this will actually cause the data to be sent\r
+ twice to get around delayed ACK problems when communicating with non real-\r
+ time TCP/IP stacks (such as a Windows machine). */\r
for( lAttempt = 0; lAttempt < lMaxAttempts; lAttempt++ )\r
{\r
if( MSS_MAC_tx_packet( uip_len ) != 0 )\r
}\r
/*-----------------------------------------------------------*/\r
\r
-long lEMACWaitForLink( void )\r
-{\r
-long lReturn = pdFAIL;\r
-unsigned long ulStatus;\r
-\r
- ulStatus = MSS_MAC_link_status();\r
- if( ( ulStatus & ( unsigned long ) MSS_MAC_LINK_STATUS_LINK ) != 0UL )\r
- {\r
- lReturn = pdPASS;\r
- }\r
-\r
- return lReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
static void prvUIPTimerCallback( xTimerHandle xTimer )\r
{\r
static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;\r
static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;\r
\r
/* This is a time callback, so calls to xQueueSend() must not attempt to\r
- block. */\r
+ block. As this callback is assigned to both the ARP and Periodic timers, the\r
+ first thing to do is ascertain which timer it was that actually expired. */\r
switch( ( int ) pvTimerGetTimerID( xTimer ) )\r
{\r
case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
+\r
+void vApplicationProcessFormInput( char *pcInputString )\r
+{\r
+char *c;\r
+\r
+ /* Only interested in processing form input if this is the IO page. */\r
+ c = strstr( pcInputString, "io.shtml" );\r
+ \r
+ if( c )\r
+ {\r
+ /* Is there a command in the string? */\r
+ c = strstr( pcInputString, "?" );\r
+ if( c )\r
+ {\r
+ /* Turn the LED's on or off in accordance with the check box status. */\r
+ if( strstr( c, "LED0=1" ) != NULL )\r
+ {\r
+ /* Turn the LEDs on. */\r
+ vParTestSetLED( 3, 1 );\r
+ vParTestSetLED( 4, 1 );\r
+ }\r
+ else\r
+ {\r
+ /* Turn the LEDs off. */\r
+ vParTestSetLED( 3, 0 );\r
+ vParTestSetLED( 4, 0 );\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Commands to turn LEDs off are not always explicit. */\r
+ vParTestSetLED( 3, 0 );\r
+ vParTestSetLED( 4, 0 );\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r