How to generate a steady 37kHz GPIO trigger from inside linux kernel? -


i have micro controller taking care of infrared tx-carrier wave generation currently, started wondering if dispose of it, , work in linux side - bringing cost of embedded system down.

i'm running on freescale i.mx233 (454mhz arm9), , if access registry directly through /dev/mem, can achieve quite steady 5mhz triggering gpio pin.

since need 37khz, started looking ways of slowing down, seems @ least nanowait() way rough purpose. found 1 solution of calling rand() in loop, , seem able generate 38,4khz signal quite well, there unacceptable jitter time time according oscilloscope. (i understand quite bit waste of resources, when tx needs done, system has no other tasks really)

my questions: freescales kernel code (3.8 branch) doesn't have config_preempt_rt patches, 1 thing maybe should into, before that:

  • could achieve more accurate performance, writing kernel module drive gpio inside kernel ? need read on data user space (data sent), other that, need trigger led on specified frequency @ end of gpio, driver should pretty simple.

  • can force priority of driver, other tasks don't interrupt gpio triggering ? (data sending takes 400ms, , it's done seldom)

  • is there better way create interrupt every 37khz, don't stall system sw ?

micro controller perfect kind of tasks, nice avoid cost overhead if possible...

the i.mx23 pwm in "multi-chip attachment mode" designed requirement.

use 1 of pwm's in "multi-chip attachment mode", example, assuming using 24mhz clock, with

  1. matt=1 (enable multi-chip attachment mode)
  2. matt_sel=1 (user 24mhz clock)
  3. cdiv=0x2 (or div_4, i.e. divide 4)
  4. inactive_state=0x2 or 0x3
  5. active_state=0x3 or 0x2
  6. period=175 (i.e 176-1)

if use 32mhz clock need other cdiv , period parameters 34khz.

see "i.mx23 applications processor reference manual" example code. if not mistaken driver code in arch/arm/plat-mxc/pwm.c doesn't seem support matt mode. have extend code yourself.

regarding implementation -

the above answer relates cpu only. in practice, ability implement idea depends on board design. board need header (pins external connection) connects gpio pin can connected via pinmux 1 of pwms. assume reference designs have @ least 1 pwm configurable gpio exposed through header. the question if there 1 , if using other control purpose.

after determining there header free pwm configurable gpio, need configure pin mux , activate pwm. there instructions in processor reference manual noted above. systems configuration in boot loader board_init() (assuming u-boot), although can done in userspace mmap trickery after linux boots.

finally need write driver based on interface pwm module in platform-mxc_pwm.c.

if using i.mx23 evk 10.05 might able modify led pwm driver since configured @ level of bootloader , kernel , connect device led output instead of led. (you need hardware technician this.) make sure config kernel config_leds_mxs.

the above comments regarding implementation speculative since don't know evk. perhaps knows can improve on this.


update september 21, 2013

another way generate 37khz signal i.mx23 or soc similar arm cpu core use unused on-chip timer generate fiq interrupt @ required frequency , write fiq interrupt handler toggle gpio pin. maxime ripard posted complete example of method using i.mx28 soc on free electrons blog on april 30 year. use method need both unused timer , not using fiq interrupt purpose such 1 of spi, camera, or brownout-detection drivers use arm fiq. need write isr in arm assembler.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -