Saturday, August 24, 2013

bug in tclib_acquire_semaphore() and tclib_release_semaphore()

Turns out both functions were returning the value of the mutex instead of the compliment. strexb is a odd instruction code. It returns 0 when successful and 1 otherwise. But the function is setup to return 0 on error and 1 on success. In addition if a read (ldrexb) of the mutex returns it set to 1, I need to return 0 to the calling routine


/*
 *****************************************************************
 *description:  acquire semaphore
 *input:            char *ptrWord   = pointer to memory word
 *output:          0 on error 1 on success
 *void
 *tclib_acquire_semaphore(unsigned char *ptrWord)
 *****************************************************************
 */
.align  2
.global tclib_acquire_semaphore
/*
 *****************************************************************
 *r0 = ptrWord
 *****************************************************************
 */
.thumb_func
tclib_acquire_semaphore:
push    {r1-r2}


mov     r1, #1
mov     r2, r0

ldrexb  r0, [r2]                        /*get value*/
cmp     r0, #0
eorne   r0, #1
bne     tclib_get_mutex_exit

strexb  r0, r1, [r2]
eor     r0, #1
tclib_get_mutex_exit:
clrex

pop     {r1-r2}
mov     pc, lr



I also put the init routines inside stm32_init () and added a banner to to be printed to the terminal on power up. Now unto to USB firmware device development ...

No comments:

Post a Comment