Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 5781

s7g2 sk GPT implementation example needed

$
0
0

In a ThreadX RTOS application,

I use a SPI external slave device in S7G2SK. This device has RequestToSend input, and ClearToSend output for making the master know it is ready to communicate. Since the device is performing some time critical tasks, it may take up to 100 microseconds to get ready, and also, if the device is not attached, CTS signal never change, and we can understand the device is missing.

For this purpose, I need to set a HW timer to 50 or 100 us, and start it just after RTS signal send to slave, and when the timer expires, I must tx_mutex_put() in the ISR. 

in the configurator, I added the settings for the GPT, and the thread implementation is as follows :


void SPI_display_CTS_check_timer_callback(timer_callback_args_t * p_args)
{
tx_mutex_put(&RTS_timer_expired);
//R_GPT_Stop ( &SPI_display_CTS_check_timer );
//SPI_display_CTS_check_timer.p_api->stop();
}

void SPI_term_entry(void)
{
/* TODO: add your own code here */
unsigned char SPI_TERM_OK = false;
unsigned char SPI_TERM_ENABLED = true;
ssp_err_t result;

// tx_mutex_put(&RTS_timer_expired);
result = tx_mutex_get(&RTS_timer_expired, 1);
SPI_display_CTS_check_timer.p_api->open(SPI_display_CTS_check_timer.p_ctrl, SPI_display_CTS_check_timer.p_cfg);

while (1)
{
if (SPI_TERM_ENABLED) {
g_ioport.p_api->pinWrite(IOPORT_PORT_04_PIN_14 , IOPORT_LEVEL_HIGH );


SPI_display_CTS_check_timer.p_api->start(SPI_display_CTS_check_timer.p_ctrl);
//result = R_GPT_Start ( &SPI_display_CTS_check_timer );
// wait for timer expires, ISR will tx_mutex_put() within 50 useconds
result = tx_mutex_get(&RTS_timer_expired, 1000);

// know if the interrupt occured and mutex put, or 1000 us expired
if (result == TX_SUCCESS) {
SPI_TERM_OK = true;
}
else {
SPI_TERM_OK = false;
}


g_ioport.p_api->pinWrite(IOPORT_PORT_04_PIN_14 , IOPORT_LEVEL_LOW );
//SPI_display_CTS_check_timer restart to toggle pin
//R_GPT_Start ( &SPI_display_CTS_check_timer );
SPI_display_CTS_check_timer.p_api->start(SPI_display_CTS_check_timer.p_ctrl);
// wait for timer expires, ISR will tx_mutex_put() within 50 useconds
result = tx_mutex_get(&RTS_timer_expired, 1000);
}

tx_thread_sleep (16);
}
}

I can not decide which function to use ,

R_GPT_Start ( &SPI_display_CTS_check_timer ); or SPI_display_CTS_check_timer.p_api->start(SPI_display_CTS_check_timer.p_ctrl);

after compiling should I create with timeropen, or is it also created?

Any help?


Viewing all articles
Browse latest Browse all 5781

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>